@runchr/gstack-antigravity 0.1.1 → 0.1.3
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.
Potentially problematic release.
This version of @runchr/gstack-antigravity might be problematic. Click here for more details.
- package/.agents/skills/gstack/.agents/skills/gstack/SKILL.md +651 -0
- package/.agents/skills/gstack/.agents/skills/gstack-autoplan/SKILL.md +678 -0
- package/.agents/skills/gstack/.agents/skills/gstack-benchmark/SKILL.md +482 -0
- package/.agents/skills/gstack/.agents/skills/gstack-browse/SKILL.md +511 -0
- package/.agents/skills/gstack/.agents/skills/gstack-canary/SKILL.md +486 -0
- package/.agents/skills/gstack/.agents/skills/gstack-careful/SKILL.md +50 -0
- package/.agents/skills/gstack/.agents/skills/gstack-cso/SKILL.md +607 -0
- package/.agents/skills/gstack/.agents/skills/gstack-design-consultation/SKILL.md +615 -0
- package/.agents/skills/gstack/.agents/skills/gstack-design-review/SKILL.md +988 -0
- package/.agents/skills/gstack/.agents/skills/gstack-document-release/SKILL.md +604 -0
- package/.agents/skills/gstack/.agents/skills/gstack-freeze/SKILL.md +67 -0
- package/.agents/skills/gstack/.agents/skills/gstack-guard/SKILL.md +62 -0
- package/.agents/skills/gstack/.agents/skills/gstack-investigate/SKILL.md +415 -0
- package/.agents/skills/gstack/.agents/skills/gstack-land-and-deploy/SKILL.md +873 -0
- package/.agents/skills/gstack/.agents/skills/gstack-office-hours/SKILL.md +986 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-ceo-review/SKILL.md +1268 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-design-review/SKILL.md +668 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-eng-review/SKILL.md +826 -0
- package/.agents/skills/gstack/.agents/skills/gstack-qa/SKILL.md +1006 -0
- package/.agents/skills/gstack/.agents/skills/gstack-qa-only/SKILL.md +626 -0
- package/.agents/skills/gstack/.agents/skills/gstack-retro/SKILL.md +1065 -0
- package/.agents/skills/gstack/.agents/skills/gstack-review/SKILL.md +704 -0
- package/.agents/skills/gstack/.agents/skills/gstack-setup-browser-cookies/SKILL.md +325 -0
- package/.agents/skills/gstack/.agents/skills/gstack-setup-deploy/SKILL.md +450 -0
- package/.agents/skills/gstack/.agents/skills/gstack-ship/SKILL.md +1312 -0
- package/.agents/skills/gstack/.agents/skills/gstack-unfreeze/SKILL.md +36 -0
- package/.agents/skills/gstack/.agents/skills/gstack-upgrade/SKILL.md +220 -0
- package/.agents/skills/gstack/.env.example +5 -0
- package/.agents/skills/gstack/.github/workflows/skill-docs.yml +17 -0
- package/.agents/skills/gstack/AGENTS.md +49 -0
- package/.agents/skills/gstack/ARCHITECTURE.md +359 -0
- package/.agents/skills/gstack/BROWSER.md +271 -0
- package/.agents/skills/gstack/CHANGELOG.md +800 -0
- package/.agents/skills/gstack/CLAUDE.md +284 -0
- package/.agents/skills/gstack/CONTRIBUTING.md +370 -0
- package/.agents/skills/gstack/ETHOS.md +129 -0
- package/.agents/skills/gstack/LICENSE +21 -0
- package/.agents/skills/gstack/README.md +228 -0
- package/.agents/skills/gstack/SKILL.md +657 -0
- package/.agents/skills/gstack/SKILL.md.tmpl +281 -0
- package/.agents/skills/gstack/TODOS.md +564 -0
- package/.agents/skills/gstack/VERSION +1 -0
- package/.agents/skills/gstack/autoplan/SKILL.md +689 -0
- package/.agents/skills/gstack/autoplan/SKILL.md.tmpl +416 -0
- package/.agents/skills/gstack/benchmark/SKILL.md +489 -0
- package/.agents/skills/gstack/benchmark/SKILL.md.tmpl +233 -0
- package/.agents/skills/gstack/bin/dev-setup +68 -0
- package/.agents/skills/gstack/bin/dev-teardown +56 -0
- package/.agents/skills/gstack/bin/gstack-analytics +191 -0
- package/.agents/skills/gstack/bin/gstack-community-dashboard +113 -0
- package/.agents/skills/gstack/bin/gstack-config +38 -0
- package/.agents/skills/gstack/bin/gstack-diff-scope +71 -0
- package/.agents/skills/gstack/bin/gstack-global-discover.ts +591 -0
- package/.agents/skills/gstack/bin/gstack-repo-mode +93 -0
- package/.agents/skills/gstack/bin/gstack-review-log +9 -0
- package/.agents/skills/gstack/bin/gstack-review-read +12 -0
- package/.agents/skills/gstack/bin/gstack-slug +15 -0
- package/.agents/skills/gstack/bin/gstack-telemetry-log +158 -0
- package/.agents/skills/gstack/bin/gstack-telemetry-sync +127 -0
- package/.agents/skills/gstack/bin/gstack-update-check +196 -0
- package/.agents/skills/gstack/browse/SKILL.md +517 -0
- package/.agents/skills/gstack/browse/SKILL.md.tmpl +141 -0
- package/.agents/skills/gstack/browse/bin/find-browse +21 -0
- package/.agents/skills/gstack/browse/bin/remote-slug +14 -0
- package/.agents/skills/gstack/browse/scripts/build-node-server.sh +48 -0
- package/.agents/skills/gstack/browse/src/browser-manager.ts +634 -0
- package/.agents/skills/gstack/browse/src/buffers.ts +137 -0
- package/.agents/skills/gstack/browse/src/bun-polyfill.cjs +109 -0
- package/.agents/skills/gstack/browse/src/cli.ts +420 -0
- package/.agents/skills/gstack/browse/src/commands.ts +111 -0
- package/.agents/skills/gstack/browse/src/config.ts +150 -0
- package/.agents/skills/gstack/browse/src/cookie-import-browser.ts +417 -0
- package/.agents/skills/gstack/browse/src/cookie-picker-routes.ts +207 -0
- package/.agents/skills/gstack/browse/src/cookie-picker-ui.ts +541 -0
- package/.agents/skills/gstack/browse/src/find-browse.ts +61 -0
- package/.agents/skills/gstack/browse/src/meta-commands.ts +269 -0
- package/.agents/skills/gstack/browse/src/platform.ts +17 -0
- package/.agents/skills/gstack/browse/src/read-commands.ts +335 -0
- package/.agents/skills/gstack/browse/src/server.ts +369 -0
- package/.agents/skills/gstack/browse/src/snapshot.ts +398 -0
- package/.agents/skills/gstack/browse/src/url-validation.ts +91 -0
- package/.agents/skills/gstack/browse/src/write-commands.ts +352 -0
- package/.agents/skills/gstack/browse/test/bun-polyfill.test.ts +72 -0
- package/.agents/skills/gstack/browse/test/commands.test.ts +1836 -0
- package/.agents/skills/gstack/browse/test/config.test.ts +250 -0
- package/.agents/skills/gstack/browse/test/cookie-import-browser.test.ts +397 -0
- package/.agents/skills/gstack/browse/test/cookie-picker-routes.test.ts +205 -0
- package/.agents/skills/gstack/browse/test/find-browse.test.ts +50 -0
- package/.agents/skills/gstack/browse/test/fixtures/basic.html +33 -0
- package/.agents/skills/gstack/browse/test/fixtures/cursor-interactive.html +22 -0
- package/.agents/skills/gstack/browse/test/fixtures/dialog.html +15 -0
- package/.agents/skills/gstack/browse/test/fixtures/empty.html +2 -0
- package/.agents/skills/gstack/browse/test/fixtures/forms.html +55 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval-checkout.html +108 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval-spa.html +98 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval.html +51 -0
- package/.agents/skills/gstack/browse/test/fixtures/responsive.html +49 -0
- package/.agents/skills/gstack/browse/test/fixtures/snapshot.html +55 -0
- package/.agents/skills/gstack/browse/test/fixtures/spa.html +24 -0
- package/.agents/skills/gstack/browse/test/fixtures/states.html +17 -0
- package/.agents/skills/gstack/browse/test/fixtures/upload.html +25 -0
- package/.agents/skills/gstack/browse/test/gstack-config.test.ts +125 -0
- package/.agents/skills/gstack/browse/test/gstack-update-check.test.ts +467 -0
- package/.agents/skills/gstack/browse/test/handoff.test.ts +235 -0
- package/.agents/skills/gstack/browse/test/path-validation.test.ts +63 -0
- package/.agents/skills/gstack/browse/test/platform.test.ts +37 -0
- package/.agents/skills/gstack/browse/test/snapshot.test.ts +467 -0
- package/.agents/skills/gstack/browse/test/test-server.ts +57 -0
- package/.agents/skills/gstack/browse/test/url-validation.test.ts +72 -0
- package/.agents/skills/gstack/canary/SKILL.md +493 -0
- package/.agents/skills/gstack/canary/SKILL.md.tmpl +220 -0
- package/.agents/skills/gstack/careful/SKILL.md +59 -0
- package/.agents/skills/gstack/careful/SKILL.md.tmpl +57 -0
- package/.agents/skills/gstack/careful/bin/check-careful.sh +112 -0
- package/.agents/skills/gstack/codex/SKILL.md +677 -0
- package/.agents/skills/gstack/codex/SKILL.md.tmpl +356 -0
- package/.agents/skills/gstack/conductor.json +6 -0
- package/.agents/skills/gstack/cso/SKILL.md +615 -0
- package/.agents/skills/gstack/cso/SKILL.md.tmpl +376 -0
- package/.agents/skills/gstack/design-consultation/SKILL.md +625 -0
- package/.agents/skills/gstack/design-consultation/SKILL.md.tmpl +369 -0
- package/.agents/skills/gstack/design-review/SKILL.md +998 -0
- package/.agents/skills/gstack/design-review/SKILL.md.tmpl +262 -0
- package/.agents/skills/gstack/docs/images/github-2013.png +0 -0
- package/.agents/skills/gstack/docs/images/github-2026.png +0 -0
- package/.agents/skills/gstack/docs/skills.md +877 -0
- package/.agents/skills/gstack/document-release/SKILL.md +613 -0
- package/.agents/skills/gstack/document-release/SKILL.md.tmpl +357 -0
- package/.agents/skills/gstack/freeze/SKILL.md +82 -0
- package/.agents/skills/gstack/freeze/SKILL.md.tmpl +80 -0
- package/.agents/skills/gstack/freeze/bin/check-freeze.sh +68 -0
- package/.agents/skills/gstack/gstack-upgrade/SKILL.md +226 -0
- package/.agents/skills/gstack/gstack-upgrade/SKILL.md.tmpl +224 -0
- package/.agents/skills/gstack/guard/SKILL.md +82 -0
- package/.agents/skills/gstack/guard/SKILL.md.tmpl +80 -0
- package/.agents/skills/gstack/investigate/SKILL.md +435 -0
- package/.agents/skills/gstack/investigate/SKILL.md.tmpl +196 -0
- package/.agents/skills/gstack/land-and-deploy/SKILL.md +880 -0
- package/.agents/skills/gstack/land-and-deploy/SKILL.md.tmpl +575 -0
- package/.agents/skills/gstack/office-hours/SKILL.md +996 -0
- package/.agents/skills/gstack/office-hours/SKILL.md.tmpl +624 -0
- package/.agents/skills/gstack/package.json +55 -0
- package/.agents/skills/gstack/plan-ceo-review/SKILL.md +1277 -0
- package/.agents/skills/gstack/plan-ceo-review/SKILL.md.tmpl +838 -0
- package/.agents/skills/gstack/plan-design-review/SKILL.md +676 -0
- package/.agents/skills/gstack/plan-design-review/SKILL.md.tmpl +314 -0
- package/.agents/skills/gstack/plan-eng-review/SKILL.md +836 -0
- package/.agents/skills/gstack/plan-eng-review/SKILL.md.tmpl +279 -0
- package/.agents/skills/gstack/qa/SKILL.md +1016 -0
- package/.agents/skills/gstack/qa/SKILL.md.tmpl +316 -0
- package/.agents/skills/gstack/qa/references/issue-taxonomy.md +85 -0
- package/.agents/skills/gstack/qa/templates/qa-report-template.md +126 -0
- package/.agents/skills/gstack/qa-only/SKILL.md +633 -0
- package/.agents/skills/gstack/qa-only/SKILL.md.tmpl +101 -0
- package/.agents/skills/gstack/retro/SKILL.md +1072 -0
- package/.agents/skills/gstack/retro/SKILL.md.tmpl +833 -0
- package/.agents/skills/gstack/review/SKILL.md +849 -0
- package/.agents/skills/gstack/review/SKILL.md.tmpl +259 -0
- package/.agents/skills/gstack/review/TODOS-format.md +62 -0
- package/.agents/skills/gstack/review/checklist.md +190 -0
- package/.agents/skills/gstack/review/design-checklist.md +132 -0
- package/.agents/skills/gstack/review/greptile-triage.md +220 -0
- package/.agents/skills/gstack/scripts/analytics.ts +190 -0
- package/.agents/skills/gstack/scripts/dev-skill.ts +82 -0
- package/.agents/skills/gstack/scripts/eval-compare.ts +96 -0
- package/.agents/skills/gstack/scripts/eval-list.ts +116 -0
- package/.agents/skills/gstack/scripts/eval-select.ts +86 -0
- package/.agents/skills/gstack/scripts/eval-summary.ts +187 -0
- package/.agents/skills/gstack/scripts/eval-watch.ts +172 -0
- package/.agents/skills/gstack/scripts/gen-skill-docs.ts +2414 -0
- package/.agents/skills/gstack/scripts/skill-check.ts +167 -0
- package/.agents/skills/gstack/setup +269 -0
- package/.agents/skills/gstack/setup-browser-cookies/SKILL.md +330 -0
- package/.agents/skills/gstack/setup-browser-cookies/SKILL.md.tmpl +74 -0
- package/.agents/skills/gstack/setup-deploy/SKILL.md +459 -0
- package/.agents/skills/gstack/setup-deploy/SKILL.md.tmpl +220 -0
- package/.agents/skills/gstack/ship/SKILL.md +1457 -0
- package/.agents/skills/gstack/ship/SKILL.md.tmpl +528 -0
- package/.agents/skills/gstack/supabase/config.sh +10 -0
- package/.agents/skills/gstack/supabase/functions/community-pulse/index.ts +59 -0
- package/.agents/skills/gstack/supabase/functions/telemetry-ingest/index.ts +135 -0
- package/.agents/skills/gstack/supabase/functions/update-check/index.ts +37 -0
- package/.agents/skills/gstack/supabase/migrations/001_telemetry.sql +89 -0
- package/.agents/skills/gstack/test/analytics.test.ts +277 -0
- package/.agents/skills/gstack/test/codex-e2e.test.ts +197 -0
- package/.agents/skills/gstack/test/fixtures/coverage-audit-fixture.ts +76 -0
- package/.agents/skills/gstack/test/fixtures/eval-baselines.json +7 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-checkout-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-spa-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-design-slop.css +86 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-design-slop.html +41 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-enum-diff.rb +30 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-enum.rb +27 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-vuln.rb +14 -0
- package/.agents/skills/gstack/test/gemini-e2e.test.ts +173 -0
- package/.agents/skills/gstack/test/gen-skill-docs.test.ts +1049 -0
- package/.agents/skills/gstack/test/global-discover.test.ts +187 -0
- package/.agents/skills/gstack/test/helpers/codex-session-runner.ts +282 -0
- package/.agents/skills/gstack/test/helpers/e2e-helpers.ts +239 -0
- package/.agents/skills/gstack/test/helpers/eval-store.test.ts +548 -0
- package/.agents/skills/gstack/test/helpers/eval-store.ts +689 -0
- package/.agents/skills/gstack/test/helpers/gemini-session-runner.test.ts +104 -0
- package/.agents/skills/gstack/test/helpers/gemini-session-runner.ts +201 -0
- package/.agents/skills/gstack/test/helpers/llm-judge.ts +130 -0
- package/.agents/skills/gstack/test/helpers/observability.test.ts +283 -0
- package/.agents/skills/gstack/test/helpers/session-runner.test.ts +96 -0
- package/.agents/skills/gstack/test/helpers/session-runner.ts +357 -0
- package/.agents/skills/gstack/test/helpers/skill-parser.ts +206 -0
- package/.agents/skills/gstack/test/helpers/touchfiles.ts +260 -0
- package/.agents/skills/gstack/test/hook-scripts.test.ts +373 -0
- package/.agents/skills/gstack/test/skill-e2e-browse.test.ts +293 -0
- package/.agents/skills/gstack/test/skill-e2e-deploy.test.ts +279 -0
- package/.agents/skills/gstack/test/skill-e2e-design.test.ts +614 -0
- package/.agents/skills/gstack/test/skill-e2e-plan.test.ts +538 -0
- package/.agents/skills/gstack/test/skill-e2e-qa-bugs.test.ts +194 -0
- package/.agents/skills/gstack/test/skill-e2e-qa-workflow.test.ts +412 -0
- package/.agents/skills/gstack/test/skill-e2e-review.test.ts +535 -0
- package/.agents/skills/gstack/test/skill-e2e-workflow.test.ts +586 -0
- package/.agents/skills/gstack/test/skill-e2e.test.ts +3325 -0
- package/.agents/skills/gstack/test/skill-llm-eval.test.ts +787 -0
- package/.agents/skills/gstack/test/skill-parser.test.ts +179 -0
- package/.agents/skills/gstack/test/skill-routing-e2e.test.ts +605 -0
- package/.agents/skills/gstack/test/skill-validation.test.ts +1520 -0
- package/.agents/skills/gstack/test/telemetry.test.ts +278 -0
- package/.agents/skills/gstack/test/touchfiles.test.ts +262 -0
- package/.agents/skills/gstack/unfreeze/SKILL.md +40 -0
- package/.agents/skills/gstack/unfreeze/SKILL.md.tmpl +38 -0
- package/package.json +2 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command registry — single source of truth for all browse commands.
|
|
3
|
+
*
|
|
4
|
+
* Dependency graph:
|
|
5
|
+
* commands.ts ──▶ server.ts (runtime dispatch)
|
|
6
|
+
* ──▶ gen-skill-docs.ts (doc generation)
|
|
7
|
+
* ──▶ skill-parser.ts (validation)
|
|
8
|
+
* ──▶ skill-check.ts (health reporting)
|
|
9
|
+
*
|
|
10
|
+
* Zero side effects. Safe to import from build scripts and tests.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const READ_COMMANDS = new Set([
|
|
14
|
+
'text', 'html', 'links', 'forms', 'accessibility',
|
|
15
|
+
'js', 'eval', 'css', 'attrs',
|
|
16
|
+
'console', 'network', 'cookies', 'storage', 'perf',
|
|
17
|
+
'dialog', 'is',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const WRITE_COMMANDS = new Set([
|
|
21
|
+
'goto', 'back', 'forward', 'reload',
|
|
22
|
+
'click', 'fill', 'select', 'hover', 'type', 'press', 'scroll', 'wait',
|
|
23
|
+
'viewport', 'cookie', 'cookie-import', 'cookie-import-browser', 'header', 'useragent',
|
|
24
|
+
'upload', 'dialog-accept', 'dialog-dismiss',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
export const META_COMMANDS = new Set([
|
|
28
|
+
'tabs', 'tab', 'newtab', 'closetab',
|
|
29
|
+
'status', 'stop', 'restart',
|
|
30
|
+
'screenshot', 'pdf', 'responsive',
|
|
31
|
+
'chain', 'diff',
|
|
32
|
+
'url', 'snapshot',
|
|
33
|
+
'handoff', 'resume',
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
export const ALL_COMMANDS = new Set([...READ_COMMANDS, ...WRITE_COMMANDS, ...META_COMMANDS]);
|
|
37
|
+
|
|
38
|
+
export const COMMAND_DESCRIPTIONS: Record<string, { category: string; description: string; usage?: string }> = {
|
|
39
|
+
// Navigation
|
|
40
|
+
'goto': { category: 'Navigation', description: 'Navigate to URL', usage: 'goto <url>' },
|
|
41
|
+
'back': { category: 'Navigation', description: 'History back' },
|
|
42
|
+
'forward': { category: 'Navigation', description: 'History forward' },
|
|
43
|
+
'reload': { category: 'Navigation', description: 'Reload page' },
|
|
44
|
+
'url': { category: 'Navigation', description: 'Print current URL' },
|
|
45
|
+
// Reading
|
|
46
|
+
'text': { category: 'Reading', description: 'Cleaned page text' },
|
|
47
|
+
'html': { category: 'Reading', description: 'innerHTML of selector (throws if not found), or full page HTML if no selector given', usage: 'html [selector]' },
|
|
48
|
+
'links': { category: 'Reading', description: 'All links as "text → href"' },
|
|
49
|
+
'forms': { category: 'Reading', description: 'Form fields as JSON' },
|
|
50
|
+
'accessibility': { category: 'Reading', description: 'Full ARIA tree' },
|
|
51
|
+
// Inspection
|
|
52
|
+
'js': { category: 'Inspection', description: 'Run JavaScript expression and return result as string', usage: 'js <expr>' },
|
|
53
|
+
'eval': { category: 'Inspection', description: 'Run JavaScript from file and return result as string (path must be under /tmp or cwd)', usage: 'eval <file>' },
|
|
54
|
+
'css': { category: 'Inspection', description: 'Computed CSS value', usage: 'css <sel> <prop>' },
|
|
55
|
+
'attrs': { category: 'Inspection', description: 'Element attributes as JSON', usage: 'attrs <sel|@ref>' },
|
|
56
|
+
'is': { category: 'Inspection', description: 'State check (visible/hidden/enabled/disabled/checked/editable/focused)', usage: 'is <prop> <sel>' },
|
|
57
|
+
'console': { category: 'Inspection', description: 'Console messages (--errors filters to error/warning)', usage: 'console [--clear|--errors]' },
|
|
58
|
+
'network': { category: 'Inspection', description: 'Network requests', usage: 'network [--clear]' },
|
|
59
|
+
'dialog': { category: 'Inspection', description: 'Dialog messages', usage: 'dialog [--clear]' },
|
|
60
|
+
'cookies': { category: 'Inspection', description: 'All cookies as JSON' },
|
|
61
|
+
'storage': { category: 'Inspection', description: 'Read all localStorage + sessionStorage as JSON, or set <key> <value> to write localStorage', usage: 'storage [set k v]' },
|
|
62
|
+
'perf': { category: 'Inspection', description: 'Page load timings' },
|
|
63
|
+
// Interaction
|
|
64
|
+
'click': { category: 'Interaction', description: 'Click element', usage: 'click <sel>' },
|
|
65
|
+
'fill': { category: 'Interaction', description: 'Fill input', usage: 'fill <sel> <val>' },
|
|
66
|
+
'select': { category: 'Interaction', description: 'Select dropdown option by value, label, or visible text', usage: 'select <sel> <val>' },
|
|
67
|
+
'hover': { category: 'Interaction', description: 'Hover element', usage: 'hover <sel>' },
|
|
68
|
+
'type': { category: 'Interaction', description: 'Type into focused element', usage: 'type <text>' },
|
|
69
|
+
'press': { category: 'Interaction', description: 'Press key — Enter, Tab, Escape, ArrowUp/Down/Left/Right, Backspace, Delete, Home, End, PageUp, PageDown, or modifiers like Shift+Enter', usage: 'press <key>' },
|
|
70
|
+
'scroll': { category: 'Interaction', description: 'Scroll element into view, or scroll to page bottom if no selector', usage: 'scroll [sel]' },
|
|
71
|
+
'wait': { category: 'Interaction', description: 'Wait for element, network idle, or page load (timeout: 15s)', usage: 'wait <sel|--networkidle|--load>' },
|
|
72
|
+
'upload': { category: 'Interaction', description: 'Upload file(s)', usage: 'upload <sel> <file> [file2...]' },
|
|
73
|
+
'viewport':{ category: 'Interaction', description: 'Set viewport size', usage: 'viewport <WxH>' },
|
|
74
|
+
'cookie': { category: 'Interaction', description: 'Set cookie on current page domain', usage: 'cookie <name>=<value>' },
|
|
75
|
+
'cookie-import': { category: 'Interaction', description: 'Import cookies from JSON file', usage: 'cookie-import <json>' },
|
|
76
|
+
'cookie-import-browser': { category: 'Interaction', description: 'Import cookies from Comet, Chrome, Arc, Brave, or Edge (opens picker, or use --domain for direct import)', usage: 'cookie-import-browser [browser] [--domain d]' },
|
|
77
|
+
'header': { category: 'Interaction', description: 'Set custom request header (colon-separated, sensitive values auto-redacted)', usage: 'header <name>:<value>' },
|
|
78
|
+
'useragent': { category: 'Interaction', description: 'Set user agent', usage: 'useragent <string>' },
|
|
79
|
+
'dialog-accept': { category: 'Interaction', description: 'Auto-accept next alert/confirm/prompt. Optional text is sent as the prompt response', usage: 'dialog-accept [text]' },
|
|
80
|
+
'dialog-dismiss': { category: 'Interaction', description: 'Auto-dismiss next dialog' },
|
|
81
|
+
// Visual
|
|
82
|
+
'screenshot': { category: 'Visual', description: 'Save screenshot (supports element crop via CSS/@ref, --clip region, --viewport)', usage: 'screenshot [--viewport] [--clip x,y,w,h] [selector|@ref] [path]' },
|
|
83
|
+
'pdf': { category: 'Visual', description: 'Save as PDF', usage: 'pdf [path]' },
|
|
84
|
+
'responsive': { category: 'Visual', description: 'Screenshots at mobile (375x812), tablet (768x1024), desktop (1280x720). Saves as {prefix}-mobile.png etc.', usage: 'responsive [prefix]' },
|
|
85
|
+
'diff': { category: 'Visual', description: 'Text diff between pages', usage: 'diff <url1> <url2>' },
|
|
86
|
+
// Tabs
|
|
87
|
+
'tabs': { category: 'Tabs', description: 'List open tabs' },
|
|
88
|
+
'tab': { category: 'Tabs', description: 'Switch to tab', usage: 'tab <id>' },
|
|
89
|
+
'newtab': { category: 'Tabs', description: 'Open new tab', usage: 'newtab [url]' },
|
|
90
|
+
'closetab':{ category: 'Tabs', description: 'Close tab', usage: 'closetab [id]' },
|
|
91
|
+
// Server
|
|
92
|
+
'status': { category: 'Server', description: 'Health check' },
|
|
93
|
+
'stop': { category: 'Server', description: 'Shutdown server' },
|
|
94
|
+
'restart': { category: 'Server', description: 'Restart server' },
|
|
95
|
+
// Meta
|
|
96
|
+
'snapshot':{ category: 'Snapshot', description: 'Accessibility tree with @e refs for element selection. Flags: -i interactive only, -c compact, -d N depth limit, -s sel scope, -D diff vs previous, -a annotated screenshot, -o path output, -C cursor-interactive @c refs', usage: 'snapshot [flags]' },
|
|
97
|
+
'chain': { category: 'Meta', description: 'Run commands from JSON stdin. Format: [["cmd","arg1",...],...]' },
|
|
98
|
+
// Handoff
|
|
99
|
+
'handoff': { category: 'Server', description: 'Open visible Chrome at current page for user takeover', usage: 'handoff [message]' },
|
|
100
|
+
'resume': { category: 'Server', description: 'Re-snapshot after user takeover, return control to AI', usage: 'resume' },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Load-time validation: descriptions must cover exactly the command sets
|
|
104
|
+
const allCmds = new Set([...READ_COMMANDS, ...WRITE_COMMANDS, ...META_COMMANDS]);
|
|
105
|
+
const descKeys = new Set(Object.keys(COMMAND_DESCRIPTIONS));
|
|
106
|
+
for (const cmd of allCmds) {
|
|
107
|
+
if (!descKeys.has(cmd)) throw new Error(`COMMAND_DESCRIPTIONS missing entry for: ${cmd}`);
|
|
108
|
+
}
|
|
109
|
+
for (const key of descKeys) {
|
|
110
|
+
if (!allCmds.has(key)) throw new Error(`COMMAND_DESCRIPTIONS has unknown command: ${key}`);
|
|
111
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared config for browse CLI + server.
|
|
3
|
+
*
|
|
4
|
+
* Resolution:
|
|
5
|
+
* 1. BROWSE_STATE_FILE env → derive stateDir from parent
|
|
6
|
+
* 2. git rev-parse --show-toplevel → projectDir/.gstack/
|
|
7
|
+
* 3. process.cwd() fallback (non-git environments)
|
|
8
|
+
*
|
|
9
|
+
* The CLI computes the config and passes BROWSE_STATE_FILE to the
|
|
10
|
+
* spawned server. The server derives all paths from that env var.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
|
|
16
|
+
export interface BrowseConfig {
|
|
17
|
+
projectDir: string;
|
|
18
|
+
stateDir: string;
|
|
19
|
+
stateFile: string;
|
|
20
|
+
consoleLog: string;
|
|
21
|
+
networkLog: string;
|
|
22
|
+
dialogLog: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Detect the git repository root, or null if not in a repo / git unavailable.
|
|
27
|
+
*/
|
|
28
|
+
export function getGitRoot(): string | null {
|
|
29
|
+
try {
|
|
30
|
+
const proc = Bun.spawnSync(['git', 'rev-parse', '--show-toplevel'], {
|
|
31
|
+
stdout: 'pipe',
|
|
32
|
+
stderr: 'pipe',
|
|
33
|
+
timeout: 2_000, // Don't hang if .git is broken
|
|
34
|
+
});
|
|
35
|
+
if (proc.exitCode !== 0) return null;
|
|
36
|
+
return proc.stdout.toString().trim() || null;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolve all browse config paths.
|
|
44
|
+
*
|
|
45
|
+
* If BROWSE_STATE_FILE is set (e.g. by CLI when spawning server, or by
|
|
46
|
+
* tests for isolation), all paths are derived from it. Otherwise, the
|
|
47
|
+
* project root is detected via git or cwd.
|
|
48
|
+
*/
|
|
49
|
+
export function resolveConfig(
|
|
50
|
+
env: Record<string, string | undefined> = process.env,
|
|
51
|
+
): BrowseConfig {
|
|
52
|
+
let stateFile: string;
|
|
53
|
+
let stateDir: string;
|
|
54
|
+
let projectDir: string;
|
|
55
|
+
|
|
56
|
+
if (env.BROWSE_STATE_FILE) {
|
|
57
|
+
stateFile = env.BROWSE_STATE_FILE;
|
|
58
|
+
stateDir = path.dirname(stateFile);
|
|
59
|
+
projectDir = path.dirname(stateDir); // parent of .gstack/
|
|
60
|
+
} else {
|
|
61
|
+
projectDir = getGitRoot() || process.cwd();
|
|
62
|
+
stateDir = path.join(projectDir, '.gstack');
|
|
63
|
+
stateFile = path.join(stateDir, 'browse.json');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
projectDir,
|
|
68
|
+
stateDir,
|
|
69
|
+
stateFile,
|
|
70
|
+
consoleLog: path.join(stateDir, 'browse-console.log'),
|
|
71
|
+
networkLog: path.join(stateDir, 'browse-network.log'),
|
|
72
|
+
dialogLog: path.join(stateDir, 'browse-dialog.log'),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create the .gstack/ state directory if it doesn't exist.
|
|
78
|
+
* Throws with a clear message on permission errors.
|
|
79
|
+
*/
|
|
80
|
+
export function ensureStateDir(config: BrowseConfig): void {
|
|
81
|
+
try {
|
|
82
|
+
fs.mkdirSync(config.stateDir, { recursive: true });
|
|
83
|
+
} catch (err: any) {
|
|
84
|
+
if (err.code === 'EACCES') {
|
|
85
|
+
throw new Error(`Cannot create state directory ${config.stateDir}: permission denied`);
|
|
86
|
+
}
|
|
87
|
+
if (err.code === 'ENOTDIR') {
|
|
88
|
+
throw new Error(`Cannot create state directory ${config.stateDir}: a file exists at that path`);
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Ensure .gstack/ is in the project's .gitignore
|
|
94
|
+
const gitignorePath = path.join(config.projectDir, '.gitignore');
|
|
95
|
+
try {
|
|
96
|
+
const content = fs.readFileSync(gitignorePath, 'utf-8');
|
|
97
|
+
if (!content.match(/^\.gstack\/?$/m)) {
|
|
98
|
+
const separator = content.endsWith('\n') ? '' : '\n';
|
|
99
|
+
fs.appendFileSync(gitignorePath, `${separator}.gstack/\n`);
|
|
100
|
+
}
|
|
101
|
+
} catch (err: any) {
|
|
102
|
+
if (err.code !== 'ENOENT') {
|
|
103
|
+
// Write warning to server log (visible even in daemon mode)
|
|
104
|
+
const logPath = path.join(config.stateDir, 'browse-server.log');
|
|
105
|
+
try {
|
|
106
|
+
fs.appendFileSync(logPath, `[${new Date().toISOString()}] Warning: could not update .gitignore at ${gitignorePath}: ${err.message}\n`);
|
|
107
|
+
} catch {
|
|
108
|
+
// stateDir write failed too — nothing more we can do
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// ENOENT (no .gitignore) — skip silently
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Derive a slug from the git remote origin URL (owner-repo format).
|
|
117
|
+
* Falls back to the directory basename if no remote is configured.
|
|
118
|
+
*/
|
|
119
|
+
export function getRemoteSlug(): string {
|
|
120
|
+
try {
|
|
121
|
+
const proc = Bun.spawnSync(['git', 'remote', 'get-url', 'origin'], {
|
|
122
|
+
stdout: 'pipe',
|
|
123
|
+
stderr: 'pipe',
|
|
124
|
+
timeout: 2_000,
|
|
125
|
+
});
|
|
126
|
+
if (proc.exitCode !== 0) throw new Error('no remote');
|
|
127
|
+
const url = proc.stdout.toString().trim();
|
|
128
|
+
// SSH: git@github.com:owner/repo.git → owner-repo
|
|
129
|
+
// HTTPS: https://github.com/owner/repo.git → owner-repo
|
|
130
|
+
const match = url.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
|
131
|
+
if (match) return `${match[1]}-${match[2]}`;
|
|
132
|
+
throw new Error('unparseable');
|
|
133
|
+
} catch {
|
|
134
|
+
const root = getGitRoot();
|
|
135
|
+
return path.basename(root || process.cwd());
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Read the binary version (git SHA) from browse/dist/.version.
|
|
141
|
+
* Returns null if the file doesn't exist or can't be read.
|
|
142
|
+
*/
|
|
143
|
+
export function readVersionHash(execPath: string = process.execPath): string | null {
|
|
144
|
+
try {
|
|
145
|
+
const versionFile = path.resolve(path.dirname(execPath), '.version');
|
|
146
|
+
return fs.readFileSync(versionFile, 'utf-8').trim() || null;
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chromium browser cookie import — read and decrypt cookies from real browsers
|
|
3
|
+
*
|
|
4
|
+
* Supports macOS Chromium-based browsers: Comet, Chrome, Arc, Brave, Edge.
|
|
5
|
+
* Pure logic module — no Playwright dependency, no HTTP concerns.
|
|
6
|
+
*
|
|
7
|
+
* Decryption pipeline (Chromium macOS "v10" format):
|
|
8
|
+
*
|
|
9
|
+
* ┌──────────────────────────────────────────────────────────────────┐
|
|
10
|
+
* │ 1. Keychain: `security find-generic-password -s "<svc>" -w` │
|
|
11
|
+
* │ → base64 password string │
|
|
12
|
+
* │ │
|
|
13
|
+
* │ 2. Key derivation: │
|
|
14
|
+
* │ PBKDF2(password, salt="saltysalt", iter=1003, len=16, sha1) │
|
|
15
|
+
* │ → 16-byte AES key │
|
|
16
|
+
* │ │
|
|
17
|
+
* │ 3. For each cookie with encrypted_value starting with "v10": │
|
|
18
|
+
* │ - Ciphertext = encrypted_value[3:] │
|
|
19
|
+
* │ - IV = 16 bytes of 0x20 (space character) │
|
|
20
|
+
* │ - Plaintext = AES-128-CBC-decrypt(key, iv, ciphertext) │
|
|
21
|
+
* │ - Remove PKCS7 padding │
|
|
22
|
+
* │ - Skip first 32 bytes (HMAC-SHA256 authentication tag) │
|
|
23
|
+
* │ - Remaining bytes = cookie value (UTF-8) │
|
|
24
|
+
* │ │
|
|
25
|
+
* │ 4. If encrypted_value is empty but `value` field is set, │
|
|
26
|
+
* │ use value directly (unencrypted cookie) │
|
|
27
|
+
* │ │
|
|
28
|
+
* │ 5. Chromium epoch: microseconds since 1601-01-01 │
|
|
29
|
+
* │ Unix seconds = (epoch - 11644473600000000) / 1000000 │
|
|
30
|
+
* │ │
|
|
31
|
+
* │ 6. sameSite: 0→"None", 1→"Lax", 2→"Strict", else→"Lax" │
|
|
32
|
+
* └──────────────────────────────────────────────────────────────────┘
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { Database } from 'bun:sqlite';
|
|
36
|
+
import * as crypto from 'crypto';
|
|
37
|
+
import * as fs from 'fs';
|
|
38
|
+
import * as path from 'path';
|
|
39
|
+
import * as os from 'os';
|
|
40
|
+
|
|
41
|
+
// ─── Types ──────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
export interface BrowserInfo {
|
|
44
|
+
name: string;
|
|
45
|
+
dataDir: string; // relative to ~/Library/Application Support/
|
|
46
|
+
keychainService: string;
|
|
47
|
+
aliases: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DomainEntry {
|
|
51
|
+
domain: string;
|
|
52
|
+
count: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ImportResult {
|
|
56
|
+
cookies: PlaywrightCookie[];
|
|
57
|
+
count: number;
|
|
58
|
+
failed: number;
|
|
59
|
+
domainCounts: Record<string, number>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PlaywrightCookie {
|
|
63
|
+
name: string;
|
|
64
|
+
value: string;
|
|
65
|
+
domain: string;
|
|
66
|
+
path: string;
|
|
67
|
+
expires: number;
|
|
68
|
+
secure: boolean;
|
|
69
|
+
httpOnly: boolean;
|
|
70
|
+
sameSite: 'Strict' | 'Lax' | 'None';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class CookieImportError extends Error {
|
|
74
|
+
constructor(
|
|
75
|
+
message: string,
|
|
76
|
+
public code: string,
|
|
77
|
+
public action?: 'retry',
|
|
78
|
+
) {
|
|
79
|
+
super(message);
|
|
80
|
+
this.name = 'CookieImportError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ─── Browser Registry ───────────────────────────────────────────
|
|
85
|
+
// Hardcoded — NEVER interpolate user input into shell commands.
|
|
86
|
+
|
|
87
|
+
const BROWSER_REGISTRY: BrowserInfo[] = [
|
|
88
|
+
{ name: 'Comet', dataDir: 'Comet/', keychainService: 'Comet Safe Storage', aliases: ['comet', 'perplexity'] },
|
|
89
|
+
{ name: 'Chrome', dataDir: 'Google/Chrome/', keychainService: 'Chrome Safe Storage', aliases: ['chrome', 'google-chrome'] },
|
|
90
|
+
{ name: 'Arc', dataDir: 'Arc/User Data/', keychainService: 'Arc Safe Storage', aliases: ['arc'] },
|
|
91
|
+
{ name: 'Brave', dataDir: 'BraveSoftware/Brave-Browser/', keychainService: 'Brave Safe Storage', aliases: ['brave'] },
|
|
92
|
+
{ name: 'Edge', dataDir: 'Microsoft Edge/', keychainService: 'Microsoft Edge Safe Storage', aliases: ['edge'] },
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
// ─── Key Cache ──────────────────────────────────────────────────
|
|
96
|
+
// Cache derived AES keys per browser. First import per browser does
|
|
97
|
+
// Keychain + PBKDF2. Subsequent imports reuse the cached key.
|
|
98
|
+
|
|
99
|
+
const keyCache = new Map<string, Buffer>();
|
|
100
|
+
|
|
101
|
+
// ─── Public API ─────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Find which browsers are installed (have a cookie DB on disk).
|
|
105
|
+
*/
|
|
106
|
+
export function findInstalledBrowsers(): BrowserInfo[] {
|
|
107
|
+
const appSupport = path.join(os.homedir(), 'Library', 'Application Support');
|
|
108
|
+
return BROWSER_REGISTRY.filter(b => {
|
|
109
|
+
const dbPath = path.join(appSupport, b.dataDir, 'Default', 'Cookies');
|
|
110
|
+
try { return fs.existsSync(dbPath); } catch { return false; }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* List unique cookie domains + counts from a browser's DB. No decryption.
|
|
116
|
+
*/
|
|
117
|
+
export function listDomains(browserName: string, profile = 'Default'): { domains: DomainEntry[]; browser: string } {
|
|
118
|
+
const browser = resolveBrowser(browserName);
|
|
119
|
+
const dbPath = getCookieDbPath(browser, profile);
|
|
120
|
+
const db = openDb(dbPath, browser.name);
|
|
121
|
+
try {
|
|
122
|
+
const now = chromiumNow();
|
|
123
|
+
const rows = db.query(
|
|
124
|
+
`SELECT host_key AS domain, COUNT(*) AS count
|
|
125
|
+
FROM cookies
|
|
126
|
+
WHERE has_expires = 0 OR expires_utc > ?
|
|
127
|
+
GROUP BY host_key
|
|
128
|
+
ORDER BY count DESC`
|
|
129
|
+
).all(now) as DomainEntry[];
|
|
130
|
+
return { domains: rows, browser: browser.name };
|
|
131
|
+
} finally {
|
|
132
|
+
db.close();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Decrypt and return Playwright-compatible cookies for specific domains.
|
|
138
|
+
*/
|
|
139
|
+
export async function importCookies(
|
|
140
|
+
browserName: string,
|
|
141
|
+
domains: string[],
|
|
142
|
+
profile = 'Default',
|
|
143
|
+
): Promise<ImportResult> {
|
|
144
|
+
if (domains.length === 0) return { cookies: [], count: 0, failed: 0, domainCounts: {} };
|
|
145
|
+
|
|
146
|
+
const browser = resolveBrowser(browserName);
|
|
147
|
+
const derivedKey = await getDerivedKey(browser);
|
|
148
|
+
const dbPath = getCookieDbPath(browser, profile);
|
|
149
|
+
const db = openDb(dbPath, browser.name);
|
|
150
|
+
|
|
151
|
+
try {
|
|
152
|
+
const now = chromiumNow();
|
|
153
|
+
// Parameterized query — no SQL injection
|
|
154
|
+
const placeholders = domains.map(() => '?').join(',');
|
|
155
|
+
const rows = db.query(
|
|
156
|
+
`SELECT host_key, name, value, encrypted_value, path, expires_utc,
|
|
157
|
+
is_secure, is_httponly, has_expires, samesite
|
|
158
|
+
FROM cookies
|
|
159
|
+
WHERE host_key IN (${placeholders})
|
|
160
|
+
AND (has_expires = 0 OR expires_utc > ?)
|
|
161
|
+
ORDER BY host_key, name`
|
|
162
|
+
).all(...domains, now) as RawCookie[];
|
|
163
|
+
|
|
164
|
+
const cookies: PlaywrightCookie[] = [];
|
|
165
|
+
let failed = 0;
|
|
166
|
+
const domainCounts: Record<string, number> = {};
|
|
167
|
+
|
|
168
|
+
for (const row of rows) {
|
|
169
|
+
try {
|
|
170
|
+
const value = decryptCookieValue(row, derivedKey);
|
|
171
|
+
const cookie = toPlaywrightCookie(row, value);
|
|
172
|
+
cookies.push(cookie);
|
|
173
|
+
domainCounts[row.host_key] = (domainCounts[row.host_key] || 0) + 1;
|
|
174
|
+
} catch {
|
|
175
|
+
failed++;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return { cookies, count: cookies.length, failed, domainCounts };
|
|
180
|
+
} finally {
|
|
181
|
+
db.close();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ─── Internal: Browser Resolution ───────────────────────────────
|
|
186
|
+
|
|
187
|
+
function resolveBrowser(nameOrAlias: string): BrowserInfo {
|
|
188
|
+
const needle = nameOrAlias.toLowerCase().trim();
|
|
189
|
+
const found = BROWSER_REGISTRY.find(b =>
|
|
190
|
+
b.aliases.includes(needle) || b.name.toLowerCase() === needle
|
|
191
|
+
);
|
|
192
|
+
if (!found) {
|
|
193
|
+
const supported = BROWSER_REGISTRY.flatMap(b => b.aliases).join(', ');
|
|
194
|
+
throw new CookieImportError(
|
|
195
|
+
`Unknown browser '${nameOrAlias}'. Supported: ${supported}`,
|
|
196
|
+
'unknown_browser',
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function validateProfile(profile: string): void {
|
|
203
|
+
if (/[/\\]|\.\./.test(profile) || /[\x00-\x1f]/.test(profile)) {
|
|
204
|
+
throw new CookieImportError(
|
|
205
|
+
`Invalid profile name: '${profile}'`,
|
|
206
|
+
'bad_request',
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getCookieDbPath(browser: BrowserInfo, profile: string): string {
|
|
212
|
+
validateProfile(profile);
|
|
213
|
+
const appSupport = path.join(os.homedir(), 'Library', 'Application Support');
|
|
214
|
+
const dbPath = path.join(appSupport, browser.dataDir, profile, 'Cookies');
|
|
215
|
+
if (!fs.existsSync(dbPath)) {
|
|
216
|
+
throw new CookieImportError(
|
|
217
|
+
`${browser.name} is not installed (no cookie database at ${dbPath})`,
|
|
218
|
+
'not_installed',
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
return dbPath;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ─── Internal: SQLite Access ────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
function openDb(dbPath: string, browserName: string): Database {
|
|
227
|
+
try {
|
|
228
|
+
return new Database(dbPath, { readonly: true });
|
|
229
|
+
} catch (err: any) {
|
|
230
|
+
if (err.message?.includes('SQLITE_BUSY') || err.message?.includes('database is locked')) {
|
|
231
|
+
return openDbFromCopy(dbPath, browserName);
|
|
232
|
+
}
|
|
233
|
+
if (err.message?.includes('SQLITE_CORRUPT') || err.message?.includes('malformed')) {
|
|
234
|
+
throw new CookieImportError(
|
|
235
|
+
`Cookie database for ${browserName} is corrupt`,
|
|
236
|
+
'db_corrupt',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
throw err;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function openDbFromCopy(dbPath: string, browserName: string): Database {
|
|
244
|
+
const tmpPath = `/tmp/browse-cookies-${browserName.toLowerCase()}-${crypto.randomUUID()}.db`;
|
|
245
|
+
try {
|
|
246
|
+
fs.copyFileSync(dbPath, tmpPath);
|
|
247
|
+
// Also copy WAL and SHM if they exist (for consistent reads)
|
|
248
|
+
const walPath = dbPath + '-wal';
|
|
249
|
+
const shmPath = dbPath + '-shm';
|
|
250
|
+
if (fs.existsSync(walPath)) fs.copyFileSync(walPath, tmpPath + '-wal');
|
|
251
|
+
if (fs.existsSync(shmPath)) fs.copyFileSync(shmPath, tmpPath + '-shm');
|
|
252
|
+
|
|
253
|
+
const db = new Database(tmpPath, { readonly: true });
|
|
254
|
+
// Schedule cleanup after the DB is closed
|
|
255
|
+
const origClose = db.close.bind(db);
|
|
256
|
+
db.close = () => {
|
|
257
|
+
origClose();
|
|
258
|
+
try { fs.unlinkSync(tmpPath); } catch {}
|
|
259
|
+
try { fs.unlinkSync(tmpPath + '-wal'); } catch {}
|
|
260
|
+
try { fs.unlinkSync(tmpPath + '-shm'); } catch {}
|
|
261
|
+
};
|
|
262
|
+
return db;
|
|
263
|
+
} catch {
|
|
264
|
+
// Clean up on failure
|
|
265
|
+
try { fs.unlinkSync(tmpPath); } catch {}
|
|
266
|
+
throw new CookieImportError(
|
|
267
|
+
`Cookie database is locked (${browserName} may be running). Try closing ${browserName} first.`,
|
|
268
|
+
'db_locked',
|
|
269
|
+
'retry',
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ─── Internal: Keychain Access (async, 10s timeout) ─────────────
|
|
275
|
+
|
|
276
|
+
async function getDerivedKey(browser: BrowserInfo): Promise<Buffer> {
|
|
277
|
+
const cached = keyCache.get(browser.keychainService);
|
|
278
|
+
if (cached) return cached;
|
|
279
|
+
|
|
280
|
+
const password = await getKeychainPassword(browser.keychainService);
|
|
281
|
+
const derived = crypto.pbkdf2Sync(password, 'saltysalt', 1003, 16, 'sha1');
|
|
282
|
+
keyCache.set(browser.keychainService, derived);
|
|
283
|
+
return derived;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async function getKeychainPassword(service: string): Promise<string> {
|
|
287
|
+
// Use async Bun.spawn with timeout to avoid blocking the event loop.
|
|
288
|
+
// macOS may show an Allow/Deny dialog that blocks until the user responds.
|
|
289
|
+
const proc = Bun.spawn(
|
|
290
|
+
['security', 'find-generic-password', '-s', service, '-w'],
|
|
291
|
+
{ stdout: 'pipe', stderr: 'pipe' },
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const timeout = new Promise<never>((_, reject) =>
|
|
295
|
+
setTimeout(() => {
|
|
296
|
+
proc.kill();
|
|
297
|
+
reject(new CookieImportError(
|
|
298
|
+
`macOS is waiting for Keychain permission. Look for a dialog asking to allow access to "${service}".`,
|
|
299
|
+
'keychain_timeout',
|
|
300
|
+
'retry',
|
|
301
|
+
));
|
|
302
|
+
}, 10_000),
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const exitCode = await Promise.race([proc.exited, timeout]);
|
|
307
|
+
const stdout = await new Response(proc.stdout).text();
|
|
308
|
+
const stderr = await new Response(proc.stderr).text();
|
|
309
|
+
|
|
310
|
+
if (exitCode !== 0) {
|
|
311
|
+
// Distinguish denied vs not found vs other
|
|
312
|
+
const errText = stderr.trim().toLowerCase();
|
|
313
|
+
if (errText.includes('user canceled') || errText.includes('denied') || errText.includes('interaction not allowed')) {
|
|
314
|
+
throw new CookieImportError(
|
|
315
|
+
`Keychain access denied. Click "Allow" in the macOS dialog for "${service}".`,
|
|
316
|
+
'keychain_denied',
|
|
317
|
+
'retry',
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (errText.includes('could not be found') || errText.includes('not found')) {
|
|
321
|
+
throw new CookieImportError(
|
|
322
|
+
`No Keychain entry for "${service}". Is this a Chromium-based browser?`,
|
|
323
|
+
'keychain_not_found',
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
throw new CookieImportError(
|
|
327
|
+
`Could not read Keychain: ${stderr.trim()}`,
|
|
328
|
+
'keychain_error',
|
|
329
|
+
'retry',
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return stdout.trim();
|
|
334
|
+
} catch (err) {
|
|
335
|
+
if (err instanceof CookieImportError) throw err;
|
|
336
|
+
throw new CookieImportError(
|
|
337
|
+
`Could not read Keychain: ${(err as Error).message}`,
|
|
338
|
+
'keychain_error',
|
|
339
|
+
'retry',
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ─── Internal: Cookie Decryption ────────────────────────────────
|
|
345
|
+
|
|
346
|
+
interface RawCookie {
|
|
347
|
+
host_key: string;
|
|
348
|
+
name: string;
|
|
349
|
+
value: string;
|
|
350
|
+
encrypted_value: Buffer | Uint8Array;
|
|
351
|
+
path: string;
|
|
352
|
+
expires_utc: number | bigint;
|
|
353
|
+
is_secure: number;
|
|
354
|
+
is_httponly: number;
|
|
355
|
+
has_expires: number;
|
|
356
|
+
samesite: number;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function decryptCookieValue(row: RawCookie, key: Buffer): string {
|
|
360
|
+
// Prefer unencrypted value if present
|
|
361
|
+
if (row.value && row.value.length > 0) return row.value;
|
|
362
|
+
|
|
363
|
+
const ev = Buffer.from(row.encrypted_value);
|
|
364
|
+
if (ev.length === 0) return '';
|
|
365
|
+
|
|
366
|
+
const prefix = ev.slice(0, 3).toString('utf-8');
|
|
367
|
+
if (prefix !== 'v10') {
|
|
368
|
+
throw new Error(`Unknown encryption prefix: ${prefix}`);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const ciphertext = ev.slice(3);
|
|
372
|
+
const iv = Buffer.alloc(16, 0x20); // 16 space characters
|
|
373
|
+
const decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
|
|
374
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
375
|
+
|
|
376
|
+
// First 32 bytes are HMAC-SHA256 authentication tag; actual value follows
|
|
377
|
+
if (plaintext.length <= 32) return '';
|
|
378
|
+
return plaintext.slice(32).toString('utf-8');
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function toPlaywrightCookie(row: RawCookie, value: string): PlaywrightCookie {
|
|
382
|
+
return {
|
|
383
|
+
name: row.name,
|
|
384
|
+
value,
|
|
385
|
+
domain: row.host_key,
|
|
386
|
+
path: row.path || '/',
|
|
387
|
+
expires: chromiumEpochToUnix(row.expires_utc, row.has_expires),
|
|
388
|
+
secure: row.is_secure === 1,
|
|
389
|
+
httpOnly: row.is_httponly === 1,
|
|
390
|
+
sameSite: mapSameSite(row.samesite),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// ─── Internal: Chromium Epoch Conversion ────────────────────────
|
|
395
|
+
|
|
396
|
+
const CHROMIUM_EPOCH_OFFSET = 11644473600000000n;
|
|
397
|
+
|
|
398
|
+
function chromiumNow(): bigint {
|
|
399
|
+
// Current time in Chromium epoch (microseconds since 1601-01-01)
|
|
400
|
+
return BigInt(Date.now()) * 1000n + CHROMIUM_EPOCH_OFFSET;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function chromiumEpochToUnix(epoch: number | bigint, hasExpires: number): number {
|
|
404
|
+
if (hasExpires === 0 || epoch === 0 || epoch === 0n) return -1; // session cookie
|
|
405
|
+
const epochBig = BigInt(epoch);
|
|
406
|
+
const unixMicro = epochBig - CHROMIUM_EPOCH_OFFSET;
|
|
407
|
+
return Number(unixMicro / 1000000n);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function mapSameSite(value: number): 'Strict' | 'Lax' | 'None' {
|
|
411
|
+
switch (value) {
|
|
412
|
+
case 0: return 'None';
|
|
413
|
+
case 1: return 'Lax';
|
|
414
|
+
case 2: return 'Strict';
|
|
415
|
+
default: return 'Lax';
|
|
416
|
+
}
|
|
417
|
+
}
|