browserpaw 0.0.0-stage → 5.0.1
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/LICENSE +681 -0
- package/README.md +4 -2
- package/dist/v5/cli-files.cjs +147 -0
- package/dist/v5/cli.cjs +4900 -0
- package/dist/v5/extension/assets/popup-Djl4pI1R.css +359 -0
- package/dist/v5/extension/background.js +39389 -0
- package/dist/v5/extension/browserpaw-build.json +191 -0
- package/dist/v5/extension/chunks/popup-BSqTH70w.js +6575 -0
- package/dist/v5/extension/content-scripts/agent-cursor.js +1475 -0
- package/dist/v5/extension/icon/128.png +0 -0
- package/dist/v5/extension/icon/16.png +0 -0
- package/dist/v5/extension/icon/32.png +0 -0
- package/dist/v5/extension/icon/48.png +0 -0
- package/dist/v5/extension/icon/96.png +0 -0
- package/dist/v5/extension/images/cursor-chat.png +0 -0
- package/dist/v5/extension/inject-scripts/accessibility-tree-helper.js +2031 -0
- package/dist/v5/extension/inject-scripts/keyboard-helper.js +412 -0
- package/dist/v5/extension/inject-scripts/network-helper.js +378 -0
- package/dist/v5/extension/inject-scripts/screenshot-helper.js +449 -0
- package/dist/v5/extension/inpage-engine.js +9437 -0
- package/dist/v5/extension/manifest.json +1 -0
- package/dist/v5/extension/popup.html +14 -0
- package/dist/v5/host.cjs +19813 -0
- package/dist/v5/recipes/bilibili-popular-videos.json +364 -0
- package/dist/v5/recipes/bilibili-video-detail.json +395 -0
- package/dist/v5/recipes/developer.mozilla.org.md +15 -0
- package/dist/v5/recipes/github-issue-thread.json +313 -0
- package/dist/v5/recipes/github-releases.json +218 -0
- package/dist/v5/recipes/github-repo-readme.json +306 -0
- package/dist/v5/recipes/github-repo-search.json +313 -0
- package/dist/v5/recipes/mdn-search.json +219 -0
- package/dist/v5/recipes/npm-compare.json +458 -0
- package/dist/v5/recipes/reddit-post-read.json +289 -0
- package/dist/v5/recipes/reddit-subreddit-posts.json +331 -0
- package/dist/v5/recipes/v2ex-node-topics.json +334 -0
- package/dist/v5/recipes/v2ex-topic-read.json +325 -0
- package/dist/v5/recipes/x-profile-posts.json +332 -0
- package/dist/v5/recipes/x-search-thread.json +293 -0
- package/dist/v5/recipes/x-visible-thread.json +260 -0
- package/dist/v5/recipes/youtube-search-videos.json +279 -0
- package/dist/v5/recipes/youtube-video-read.json +349 -0
- package/dist/v5/run_host.bat +7 -0
- package/dist/v5/run_host.sh +6 -0
- package/dist/v5/skill/browserpaw/SKILL.md +48 -0
- package/dist/v5/skill/browserpaw/assets/recipes/bilibili-popular-videos.json +364 -0
- package/dist/v5/skill/browserpaw/assets/recipes/bilibili-video-detail.json +395 -0
- package/dist/v5/skill/browserpaw/assets/recipes/developer.mozilla.org.md +15 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-issue-thread.json +313 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +218 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-repo-readme.json +306 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-repo-search.json +313 -0
- package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +219 -0
- package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +458 -0
- package/dist/v5/skill/browserpaw/assets/recipes/reddit-post-read.json +289 -0
- package/dist/v5/skill/browserpaw/assets/recipes/reddit-subreddit-posts.json +331 -0
- package/dist/v5/skill/browserpaw/assets/recipes/v2ex-node-topics.json +334 -0
- package/dist/v5/skill/browserpaw/assets/recipes/v2ex-topic-read.json +325 -0
- package/dist/v5/skill/browserpaw/assets/recipes/x-profile-posts.json +332 -0
- package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +293 -0
- package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +260 -0
- package/dist/v5/skill/browserpaw/assets/recipes/youtube-search-videos.json +279 -0
- package/dist/v5/skill/browserpaw/assets/recipes/youtube-video-read.json +349 -0
- package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.md +7 -0
- package/dist/v5/skill/browserpaw/references/TROUBLESHOOTING.zh-CN.md +5 -0
- package/dist/v5/skill/browserpaw/references/browser-data.md +33 -0
- package/dist/v5/skill/browserpaw/references/commands.md +103 -0
- package/dist/v5/skill/browserpaw/references/debugging.md +32 -0
- package/dist/v5/skill/browserpaw/references/recipe-contract.md +47 -0
- package/package.json +67 -4
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BrowserPaw npm package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Install with `npm install -g browserpaw` or run `npx browserpaw setup` once the package is published. Use `browserpaw setup` to install the local host and Agent Skill (`~/.agents/skills/browserpaw` by default, or `browserpaw setup --skill-scope project` for `./.agents/skills/browserpaw`). In `chrome://extensions`, turn on Developer mode and load the extension at the path printed by setup.
|
|
4
|
+
|
|
5
|
+
Run `browserpaw status` to verify the connection, `browserpaw recipe find` to inspect learned workflows under `~/.browserpaw`, and `browserpaw help` to discover commands.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { randomUUID } = require('node:crypto');
|
|
4
|
+
|
|
5
|
+
const STALE_LOCK_AGE_MS = 10 * 60 * 1000;
|
|
6
|
+
|
|
7
|
+
function assertNoLinks(target) {
|
|
8
|
+
let current = path.resolve(target);
|
|
9
|
+
for (;;) {
|
|
10
|
+
const stat = fs.lstatSync(current, { throwIfNoEntry: false });
|
|
11
|
+
const isMacSystemRootLink =
|
|
12
|
+
stat?.isSymbolicLink() &&
|
|
13
|
+
(current === '/var' || current === '/tmp' || current === '/etc') &&
|
|
14
|
+
path.resolve(path.dirname(current), fs.readlinkSync(current)) === `/private${current}`;
|
|
15
|
+
if (stat?.isSymbolicLink() && !isMacSystemRootLink)
|
|
16
|
+
throw new Error(`Symlink or junction forbidden: ${current}`);
|
|
17
|
+
const parent = path.dirname(current);
|
|
18
|
+
if (parent === current) return;
|
|
19
|
+
current = parent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function ensureDirectory(target) {
|
|
24
|
+
assertNoLinks(target);
|
|
25
|
+
fs.mkdirSync(target, { recursive: true, mode: 0o700 });
|
|
26
|
+
assertNoLinks(target);
|
|
27
|
+
if (!fs.statSync(target).isDirectory()) throw new Error(`Not a directory: ${target}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function readJson(target) {
|
|
31
|
+
assertNoLinks(target);
|
|
32
|
+
const stat = fs.lstatSync(target, { throwIfNoEntry: false });
|
|
33
|
+
if (!stat) return undefined;
|
|
34
|
+
if (!stat.isFile()) throw new Error(`Not a regular file: ${target}`);
|
|
35
|
+
return JSON.parse(fs.readFileSync(target, 'utf8'));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function atomicWrite(target, data) {
|
|
39
|
+
assertNoLinks(target);
|
|
40
|
+
const temporary = path.join(
|
|
41
|
+
path.dirname(target),
|
|
42
|
+
`.${path.basename(target)}.${randomUUID()}.tmp`,
|
|
43
|
+
);
|
|
44
|
+
try {
|
|
45
|
+
fs.writeFileSync(temporary, data, { flag: 'wx', mode: 0o600 });
|
|
46
|
+
fs.renameSync(temporary, target);
|
|
47
|
+
} finally {
|
|
48
|
+
fs.rmSync(temporary, { force: true });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function acquireLock(target) {
|
|
53
|
+
assertNoLinks(target);
|
|
54
|
+
const busy = () =>
|
|
55
|
+
new Error(
|
|
56
|
+
'Session busy or stale lock; verify the previous CLI has stopped before removing its .lock file. Unknown actions must not be replayed.',
|
|
57
|
+
);
|
|
58
|
+
const reapTarget = `${target}.reap`;
|
|
59
|
+
const token = randomUUID();
|
|
60
|
+
const payload = { pid: process.pid, token, createdAt: new Date().toISOString() };
|
|
61
|
+
|
|
62
|
+
const readLock = () => {
|
|
63
|
+
try {
|
|
64
|
+
const value = JSON.parse(fs.readFileSync(target, 'utf8'));
|
|
65
|
+
if (!Number.isInteger(value.pid) || value.pid < 1 || typeof value.token !== 'string')
|
|
66
|
+
return undefined;
|
|
67
|
+
return value;
|
|
68
|
+
} catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const isDead = (pid) => {
|
|
73
|
+
try {
|
|
74
|
+
process.kill(pid, 0);
|
|
75
|
+
return false;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.code === 'ESRCH') return true;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const isStaleCorruptLock = () => {
|
|
82
|
+
const stat = fs.lstatSync(target, { throwIfNoEntry: false });
|
|
83
|
+
return (
|
|
84
|
+
Boolean(stat?.isFile()) &&
|
|
85
|
+
Date.now() - stat.mtimeMs > STALE_LOCK_AGE_MS &&
|
|
86
|
+
!readLock()
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
const writeFresh = (allowReapGuard = false) => {
|
|
90
|
+
let descriptor;
|
|
91
|
+
try {
|
|
92
|
+
descriptor = fs.openSync(target, 'wx', 0o600);
|
|
93
|
+
fs.writeFileSync(descriptor, JSON.stringify(payload));
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (descriptor !== undefined) fs.closeSync(descriptor);
|
|
96
|
+
if (readLock()?.token === token) fs.rmSync(target, { force: true });
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
fs.closeSync(descriptor);
|
|
100
|
+
// A stale reaper cannot remove this lock after this point without first
|
|
101
|
+
// observing the live PID. If it owns the guard already, yield to it.
|
|
102
|
+
if (!allowReapGuard && fs.existsSync(reapTarget)) {
|
|
103
|
+
const current = readLock();
|
|
104
|
+
if (current?.token === token) fs.rmSync(target, { force: true });
|
|
105
|
+
throw busy();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
writeFresh();
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code !== 'EEXIST') throw error;
|
|
113
|
+
|
|
114
|
+
const existing = readLock();
|
|
115
|
+
if (!existing && !isStaleCorruptLock()) throw busy();
|
|
116
|
+
if (existing && !isDead(existing.pid)) throw busy();
|
|
117
|
+
|
|
118
|
+
let reapDescriptor;
|
|
119
|
+
try {
|
|
120
|
+
assertNoLinks(reapTarget);
|
|
121
|
+
reapDescriptor = fs.openSync(reapTarget, 'wx', 0o600);
|
|
122
|
+
} catch (reapError) {
|
|
123
|
+
if (reapError.code === 'EEXIST') throw busy();
|
|
124
|
+
throw reapError;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const confirmed = readLock();
|
|
128
|
+
if (existing) {
|
|
129
|
+
if (!confirmed || confirmed.token !== existing.token || !isDead(confirmed.pid)) throw busy();
|
|
130
|
+
} else if (confirmed || !isStaleCorruptLock()) {
|
|
131
|
+
throw busy();
|
|
132
|
+
}
|
|
133
|
+
fs.rmSync(target, { force: true });
|
|
134
|
+
writeFresh(true);
|
|
135
|
+
} finally {
|
|
136
|
+
fs.closeSync(reapDescriptor);
|
|
137
|
+
fs.rmSync(reapTarget, { force: true });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return () => {
|
|
142
|
+
const current = readLock();
|
|
143
|
+
if (current?.token === token) fs.rmSync(target, { force: true });
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
module.exports = { assertNoLinks, ensureDirectory, readJson, atomicWrite, acquireLock };
|