btcp-browser-agent 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.
- package/CLAUDE.md +230 -0
- package/LICENSE +21 -0
- package/README.md +309 -0
- package/SKILL.md +143 -0
- package/SNAPSHOT_IMPROVEMENTS.md +302 -0
- package/USAGE.md +146 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/docs/browser-cli-design.md +500 -0
- package/examples/chrome-extension/CHANGELOG.md +210 -0
- package/examples/chrome-extension/DEBUG.md +231 -0
- package/examples/chrome-extension/ERROR_FIXED.md +147 -0
- package/examples/chrome-extension/QUICK_TEST.md +189 -0
- package/examples/chrome-extension/README.md +149 -0
- package/examples/chrome-extension/SESSION_ONLY_MODE.md +305 -0
- package/examples/chrome-extension/TEST_WITH_YOUR_TABS.md +97 -0
- package/examples/chrome-extension/build.js +43 -0
- package/examples/chrome-extension/manifest.json +37 -0
- package/examples/chrome-extension/package-lock.json +1063 -0
- package/examples/chrome-extension/package.json +21 -0
- package/examples/chrome-extension/popup.html +195 -0
- package/examples/chrome-extension/src/background.ts +12 -0
- package/examples/chrome-extension/src/content.ts +7 -0
- package/examples/chrome-extension/src/popup.ts +303 -0
- package/examples/chrome-extension/src/scenario-google-github.ts +389 -0
- package/examples/chrome-extension/test-page.html +127 -0
- package/examples/chrome-extension/tests/README.md +206 -0
- package/examples/chrome-extension/tests/scenario-google-to-github-star.ts +380 -0
- package/examples/chrome-extension/tsconfig.json +14 -0
- package/examples/snapshots/README.md +207 -0
- package/examples/snapshots/amazon-com-detail.html +9528 -0
- package/examples/snapshots/amazon-com-detail.snapshot.txt +997 -0
- package/examples/snapshots/convert-snapshots.ts +97 -0
- package/examples/snapshots/edition-cnn-com.html +13292 -0
- package/examples/snapshots/edition-cnn-com.snapshot.txt +562 -0
- package/examples/snapshots/github-com-microsoft-vscode.html +2916 -0
- package/examples/snapshots/github-com-microsoft-vscode.snapshot.txt +455 -0
- package/examples/snapshots/google-search.html +20012 -0
- package/examples/snapshots/google-search.snapshot.txt +195 -0
- package/examples/snapshots/metadata.json +86 -0
- package/examples/snapshots/npr-org-templates.html +2031 -0
- package/examples/snapshots/npr-org-templates.snapshot.txt +224 -0
- package/examples/snapshots/stackoverflow-com.html +5216 -0
- package/examples/snapshots/stackoverflow-com.snapshot.txt +2404 -0
- package/examples/snapshots/test-all-mode.html +46 -0
- package/examples/snapshots/test-all-mode.snapshot.txt +5 -0
- package/examples/snapshots/validate.test.ts +296 -0
- package/package.json +65 -0
- package/packages/cli/package.json +42 -0
- package/packages/cli/src/__tests__/cli.test.ts +434 -0
- package/packages/cli/src/__tests__/errors.test.ts +226 -0
- package/packages/cli/src/__tests__/executor.test.ts +275 -0
- package/packages/cli/src/__tests__/formatter.test.ts +260 -0
- package/packages/cli/src/__tests__/parser.test.ts +288 -0
- package/packages/cli/src/__tests__/suggestions.test.ts +255 -0
- package/packages/cli/src/commands/back.ts +22 -0
- package/packages/cli/src/commands/check.ts +33 -0
- package/packages/cli/src/commands/clear.ts +33 -0
- package/packages/cli/src/commands/click.ts +32 -0
- package/packages/cli/src/commands/closetab.ts +31 -0
- package/packages/cli/src/commands/eval.ts +41 -0
- package/packages/cli/src/commands/fill.ts +30 -0
- package/packages/cli/src/commands/focus.ts +33 -0
- package/packages/cli/src/commands/forward.ts +22 -0
- package/packages/cli/src/commands/goto.ts +34 -0
- package/packages/cli/src/commands/help.ts +162 -0
- package/packages/cli/src/commands/hover.ts +34 -0
- package/packages/cli/src/commands/index.ts +129 -0
- package/packages/cli/src/commands/newtab.ts +35 -0
- package/packages/cli/src/commands/press.ts +40 -0
- package/packages/cli/src/commands/reload.ts +25 -0
- package/packages/cli/src/commands/screenshot.ts +27 -0
- package/packages/cli/src/commands/scroll.ts +64 -0
- package/packages/cli/src/commands/select.ts +35 -0
- package/packages/cli/src/commands/snapshot.ts +21 -0
- package/packages/cli/src/commands/tab.ts +32 -0
- package/packages/cli/src/commands/tabs.ts +26 -0
- package/packages/cli/src/commands/text.ts +27 -0
- package/packages/cli/src/commands/title.ts +17 -0
- package/packages/cli/src/commands/type.ts +38 -0
- package/packages/cli/src/commands/uncheck.ts +33 -0
- package/packages/cli/src/commands/url.ts +17 -0
- package/packages/cli/src/commands/wait.ts +54 -0
- package/packages/cli/src/errors.ts +164 -0
- package/packages/cli/src/executor.ts +68 -0
- package/packages/cli/src/formatter.ts +215 -0
- package/packages/cli/src/index.ts +257 -0
- package/packages/cli/src/parser.ts +195 -0
- package/packages/cli/src/suggestions.ts +207 -0
- package/packages/cli/src/terminal/Terminal.ts +365 -0
- package/packages/cli/src/terminal/index.ts +5 -0
- package/packages/cli/src/types.ts +155 -0
- package/packages/cli/tsconfig.json +20 -0
- package/packages/core/package.json +35 -0
- package/packages/core/src/actions.ts +1210 -0
- package/packages/core/src/errors.ts +296 -0
- package/packages/core/src/index.test.ts +638 -0
- package/packages/core/src/index.ts +220 -0
- package/packages/core/src/ref-map.ts +107 -0
- package/packages/core/src/snapshot.ts +873 -0
- package/packages/core/src/types.ts +536 -0
- package/packages/core/tsconfig.json +23 -0
- package/packages/extension/README.md +129 -0
- package/packages/extension/package.json +43 -0
- package/packages/extension/src/background.ts +888 -0
- package/packages/extension/src/content.ts +172 -0
- package/packages/extension/src/index.ts +579 -0
- package/packages/extension/src/session-manager.ts +385 -0
- package/packages/extension/src/session-types.ts +144 -0
- package/packages/extension/src/types.ts +162 -0
- package/packages/extension/tsconfig.json +28 -0
- package/src/index.ts +64 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +26 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
/**
|
|
3
|
+
* Snapshot conversion script
|
|
4
|
+
*
|
|
5
|
+
* Generates snapshots from all HTML files in the snapshots directory.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx tsx convert-snapshots.ts
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync, writeFileSync, readdirSync } from 'fs';
|
|
12
|
+
import { join, basename } from 'path';
|
|
13
|
+
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
14
|
+
import { createSnapshot } from '../../packages/core/src/snapshot.js';
|
|
15
|
+
import { createSimpleRefMap } from '../../packages/core/src/ref-map.js';
|
|
16
|
+
|
|
17
|
+
// Support running from repo root or snapshots directory
|
|
18
|
+
const SNAPSHOTS_DIR = process.cwd().endsWith('snapshots')
|
|
19
|
+
? process.cwd()
|
|
20
|
+
: join(process.cwd(), 'examples', 'snapshots');
|
|
21
|
+
|
|
22
|
+
// Create a JSDOM instance from HTML content
|
|
23
|
+
function createDom(html: string) {
|
|
24
|
+
const virtualConsole = new VirtualConsole();
|
|
25
|
+
virtualConsole.on('error', () => {});
|
|
26
|
+
virtualConsole.on('warn', () => {});
|
|
27
|
+
|
|
28
|
+
return new JSDOM(html, {
|
|
29
|
+
url: 'http://localhost',
|
|
30
|
+
contentType: 'text/html',
|
|
31
|
+
pretendToBeVisual: true,
|
|
32
|
+
virtualConsole,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Process a single HTML file and save snapshot
|
|
37
|
+
function processFile(htmlPath: string) {
|
|
38
|
+
const filename = basename(htmlPath, '.html');
|
|
39
|
+
const htmlFile = basename(htmlPath);
|
|
40
|
+
const snapshotFile = `${filename}.snapshot.txt`;
|
|
41
|
+
|
|
42
|
+
console.log(` Processing: ${htmlFile}`);
|
|
43
|
+
|
|
44
|
+
const html = readFileSync(htmlPath, 'utf-8');
|
|
45
|
+
const dom = createDom(html);
|
|
46
|
+
const { document } = dom.window;
|
|
47
|
+
const refMap = createSimpleRefMap();
|
|
48
|
+
|
|
49
|
+
const start = performance.now();
|
|
50
|
+
const snapshotTree = createSnapshot(document, refMap, {
|
|
51
|
+
interactive: true,
|
|
52
|
+
compact: true,
|
|
53
|
+
maxDepth: 50,
|
|
54
|
+
includeHidden: true,
|
|
55
|
+
});
|
|
56
|
+
const duration = performance.now() - start;
|
|
57
|
+
|
|
58
|
+
const elementCount = snapshotTree.split('\n').filter(line => line.trim()).length;
|
|
59
|
+
// Extract ref count from @ref: markers in the tree
|
|
60
|
+
const refCount = (snapshotTree.match(/@ref:\d+/g) || []).length;
|
|
61
|
+
|
|
62
|
+
// Save snapshot
|
|
63
|
+
writeFileSync(join(SNAPSHOTS_DIR, snapshotFile), snapshotTree, 'utf-8');
|
|
64
|
+
|
|
65
|
+
console.log(` -> ${snapshotFile} (${elementCount} elements, ${refCount} refs, ${Math.round(duration)}ms)`);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
filename,
|
|
69
|
+
htmlFile,
|
|
70
|
+
snapshotFile,
|
|
71
|
+
generatedAt: new Date().toISOString(),
|
|
72
|
+
stats: { elementCount, refCount, outputSize: snapshotTree.length, generationTime: Math.round(duration) },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Main
|
|
77
|
+
function main() {
|
|
78
|
+
const files = readdirSync(SNAPSHOTS_DIR)
|
|
79
|
+
.filter(f => f.endsWith('.html'))
|
|
80
|
+
.map(f => join(SNAPSHOTS_DIR, f));
|
|
81
|
+
|
|
82
|
+
console.log(`Converting ${files.length} HTML files...\n`);
|
|
83
|
+
|
|
84
|
+
const metadata = [];
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
try {
|
|
87
|
+
metadata.push(processFile(file));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(` Error: ${basename(file)} - ${error}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
writeFileSync(join(SNAPSHOTS_DIR, 'metadata.json'), JSON.stringify(metadata, null, 2), 'utf-8');
|
|
94
|
+
console.log(`\nDone! Generated ${metadata.length} snapshots.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
main();
|