@tea-agent/loop-agent 0.35.0-beta.2 → 0.35.1-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.
- package/AGENTS.md +108 -108
- package/CHANGELOG.md +55 -4
- package/README.md +165 -165
- package/bin/agent-worker.js +0 -0
- package/bin/loop-agent.js +21 -21
- package/dist/application/task-lifecycle/advance.js +1 -0
- package/dist/commands/cursor-prompt.js +6 -6
- package/dist/commands/init-upgrade.js +351 -19
- package/dist/commands/init.js +14 -67
- package/dist/commands/loop-benchmark.js +11 -11
- package/dist/commands/pi-reuse-benchmark.js +16 -16
- package/dist/commands/run-dag-progress.js +14 -0
- package/dist/commands/task-advance.js +33 -3
- package/dist/shared/operator/capabilities.js +38 -1
- package/dist/sidecars/cursor-prompt/executor.js +1 -1
- package/dist/worker/console/chat/pi-runtime.js +41 -25
- package/dist/worker/console/chat/routes.js +27 -4
- package/dist/worker/console/operation-runner.js +24 -0
- package/dist/worker/console/operation-wait.js +241 -0
- package/dist/worker/console/operator-actions.js +58 -0
- package/dist/worker/console/static/assets/{index-hJqCPs_g.css → index-Dups4sSM.css} +1 -1
- package/dist/worker/console/static/assets/index-SjjjZnV3.js +56 -0
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/operator-chat/slash-palette-nav.js +141 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +13 -2
- package/dist/worker/console/static-src/operator-chat/useComposer.js +30 -7
- package/dist/worker/observe/static/copy.js +67 -67
- package/dist/worker/observe/static/dag-layout.d.ts +36 -36
- package/dist/worker/observe/static/dom.js +220 -220
- package/dist/worker/observe/static/relations.js +133 -133
- package/dist/worker/observe/static/run-processing.js +148 -148
- package/dist/worker/observe/static/views/batch.js +227 -227
- package/dist/worker/observe/static/views/failures.js +143 -143
- package/dist/worker/observe/static/views/feature.js +492 -492
- package/dist/worker/observe/static/views/run.js +453 -453
- package/dist/worker/observe/static/views/shell.js +7 -7
- package/dist/worker/observe/static/views/timeline.js +163 -163
- package/dist/workflows/dag/canvas-observer.js +275 -275
- package/dist/workflows/dag/frontend-prewrite-gate.js +9 -1
- package/dist/workflows/dag/init-hybrid.js +2 -0
- package/docs/architecture/evolution.md +73 -73
- package/docs/architecture/system-overview.md +100 -100
- package/docs/architecture/worker-and-feature.md +122 -122
- package/docs/skills/README.md +7 -7
- package/docs/templates/adr.md +60 -60
- package/docs/templates/agent-dag-authority-surface-audit.prompt.md +94 -94
- package/docs/templates/agent-dag-decision-envelope.schema.json +213 -213
- package/docs/templates/agent-dag-decision-gate.prompt.md +246 -246
- package/docs/templates/agent-dag-process-supervisor.prompt.md +98 -98
- package/docs/templates/agent-dag-report.schema.json +473 -473
- package/docs/templates/agent-dag-review-verdict.prompt.md +68 -68
- package/docs/templates/backend-test-result.schema.json +99 -99
- package/docs/templates/evaluation/agents-map-slim-v1.md +87 -87
- package/docs/templates/evaluation/agents-map-verbose-v0.md +153 -153
- package/docs/templates/feature-spec.md +53 -53
- package/docs/templates/frontend-design-contract.md +42 -42
- package/docs/templates/frontend-eval/fixtures/failures/01-type-build-error.md +17 -17
- package/docs/templates/frontend-eval/fixtures/failures/02-unit-component-test-fail.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/03-fixture-schema-drift.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/04-missing-loading-empty-error-state.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/05-forbidden-write-writeset-expansion.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/06-unapproved-dependency-add.md +16 -16
- package/docs/templates/frontend-eval/fixtures/failures/07-mock-production-on.md +21 -21
- package/docs/templates/frontend-eval/fixtures/functional/01-simple-component-style.md +29 -29
- package/docs/templates/frontend-eval/fixtures/functional/02-form-validation.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/03-list-detail-page.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/04-api-mock.md +29 -29
- package/docs/templates/frontend-eval/fixtures/functional/05-permission-auth-gated-ui.md +27 -27
- package/docs/templates/frontend-eval/fixtures/functional/06-ssr-server-client-boundary.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/07-shared-public-component-api.md +28 -28
- package/docs/templates/frontend-eval/fixtures/functional/08-pure-local-no-remote.md +27 -27
- package/docs/templates/frontend-eval/metrics.md +138 -138
- package/docs/templates/frontend-eval/smoke-targets.md +53 -53
- package/docs/templates/frontend-task-constraints.md +35 -35
- package/docs/templates/frontend-task-requirement.md +70 -70
- package/docs/templates/init-evolution-review.md +35 -35
- package/docs/templates/init-managed-agents.md +156 -154
- package/docs/templates/interactive-ui-round2-experiment.md +66 -66
- package/docs/templates/knowledge-graph-bootstrap-dag.json +118 -118
- package/docs/templates/knowledge-sync-dag.json +178 -178
- package/docs/templates/knowledge-sync-draft.schema.json +71 -71
- package/docs/templates/product-line/closeout.yaml +9 -9
- package/docs/templates/product-line/design.md +13 -13
- package/docs/templates/product-line/links.md +10 -10
- package/docs/templates/product-line/requirement.md +17 -17
- package/docs/templates/product-line/test-plan.md +7 -7
- package/docs/templates/project-start-checklist.md +9 -9
- package/docs/templates/qa-report.md +48 -48
- package/docs/templates/sprint-contract.md +29 -29
- package/docs/templates/worker-dogfood-evidence.md +80 -80
- package/docs/templates/worker-dogfood-setup.md +68 -68
- package/harness.json +5 -2
- package/package.json +1 -1
- package/scripts/kb-bootstrap-init-skeleton.sh +0 -0
- package/scripts/kb-graph-incremental-prepare.mjs +0 -0
- package/scripts/kb-graph-materialize.mjs +105 -105
- package/scripts/kb-graph-promote.mjs +164 -164
- package/scripts/kb-query.mjs +554 -554
- package/skills/agent-worker/SKILL.md +48 -48
- package/skills/agent-worker/references/agent-worker-operator.md +159 -159
- package/skills/ai-engineering-context/SKILL.md +48 -48
- package/skills/analyze-product-dependencies/scripts/test-validators.mjs +0 -0
- package/skills/analyze-product-dependencies/scripts/validate-api-documentation.mjs +0 -0
- package/skills/analyze-product-dependencies/scripts/validate-dependency-analysis.mjs +0 -0
- package/skills/analyze-product-dependencies/scripts/validate-product-requirement-input.mjs +0 -0
- package/skills/analyze-product-requirements/scripts/compute-source-identity.mjs +0 -0
- package/skills/analyze-product-requirements/scripts/test-validators.mjs +0 -0
- package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +0 -0
- package/skills/analyze-product-requirements/scripts/validate-product-requirement.mjs +0 -0
- package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +0 -0
- package/skills/browser-tools/browser-content.js +103 -103
- package/skills/browser-tools/browser-cookies.js +35 -35
- package/skills/browser-tools/browser-eval.js +53 -53
- package/skills/browser-tools/browser-hn-scraper.js +108 -108
- package/skills/browser-tools/browser-nav.js +44 -44
- package/skills/browser-tools/browser-pick.js +162 -162
- package/skills/browser-tools/browser-screenshot.js +34 -34
- package/skills/browser-tools/browser-start.js +86 -86
- package/skills/browser-tools/package-lock.json +2556 -2556
- package/skills/browser-tools/package.json +19 -19
- package/skills/code-review-core/SKILL.md +20 -20
- package/skills/codebase-scout/SKILL.md +19 -19
- package/skills/grill-me/SKILL.md +10 -10
- package/skills/local-jacoco-coverage/scripts/run-coverage-analysis.sh +0 -0
- package/skills/local-jacoco-coverage/scripts/start-jacoco-agent.sh +0 -0
- package/skills/loop-agent/SKILL.md +1 -0
- package/skills/loop-agent/references/command-reference.md +641 -639
- package/skills/loop-agent/references/docs-converge.md +126 -126
- package/skills/loop-agent/references/learned/README.md +21 -21
- package/skills/loop-agent/references/pi-prompt.md +23 -23
- package/skills/loop-agent/references/pi-subagent-assisted-mode.md +84 -84
- package/skills/playwright-cli/references/element-attributes.md +23 -23
- package/skills/playwright-cli/references/playwright-tests.md +39 -39
- package/skills/playwright-cli/references/request-mocking.md +87 -87
- package/skills/playwright-cli/references/running-code.md +241 -241
- package/skills/playwright-cli/references/session-management.md +225 -225
- package/skills/playwright-cli/references/storage-state.md +275 -275
- package/skills/playwright-cli/references/test-generation.md +433 -433
- package/skills/requesting-code-review/SKILL.md +101 -101
- package/skills/requesting-code-review/code-reviewer.md +168 -168
- package/skills/systematic-debugging/CREATION-LOG.md +119 -119
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -158
- package/skills/systematic-debugging/condition-based-waiting.md +115 -115
- package/skills/systematic-debugging/defense-in-depth.md +122 -122
- package/skills/systematic-debugging/find-polluter.sh +63 -63
- package/skills/systematic-debugging/root-cause-tracing.md +169 -169
- package/skills/systematic-debugging/test-academic.md +14 -14
- package/skills/systematic-debugging/test-pressure-1.md +58 -58
- package/skills/systematic-debugging/test-pressure-2.md +68 -68
- package/skills/systematic-debugging/test-pressure-3.md +69 -69
- package/skills/using-git-worktrees/SKILL.md +215 -215
- package/skills/verification-before-completion/SKILL.md +154 -154
- package/skills/webapp-testing/SKILL.md +19 -19
- package/dist/worker/console/static/assets/index-fsjzREob.js +0 -56
|
@@ -1,103 +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);
|
|
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);
|
|
@@ -1,35 +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();
|
|
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();
|
|
@@ -1,53 +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();
|
|
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();
|
|
@@ -1,108 +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 };
|
|
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 };
|