opengstack 0.13.10 → 0.14.2

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.
Files changed (189) hide show
  1. package/AGENTS.md +4 -4
  2. package/CLAUDE.md +127 -110
  3. package/README.md +10 -5
  4. package/SKILL.md +500 -70
  5. package/bin/opengstack.js +69 -69
  6. package/{skills/land-and-deploy/SKILL.md → commands/autoplan.md} +7 -25
  7. package/{skills/benchmark/SKILL.md → commands/benchmark.md} +84 -108
  8. package/{skills/browse/SKILL.md → commands/browse.md} +60 -81
  9. package/{skills/ship/SKILL.md → commands/canary.md} +7 -27
  10. package/{skills/careful/SKILL.md → commands/careful.md} +2 -22
  11. package/{skills/canary/SKILL.md → commands/codex.md} +7 -26
  12. package/{skills/connect-chrome/SKILL.md → commands/connect-chrome.md} +7 -24
  13. package/commands/cso.md +70 -0
  14. package/commands/design-consultation.md +70 -0
  15. package/commands/design-review.md +70 -0
  16. package/commands/design-shotgun.md +70 -0
  17. package/commands/document-release.md +70 -0
  18. package/{skills/freeze/SKILL.md → commands/freeze.md} +3 -29
  19. package/{skills/guard/SKILL.md → commands/guard.md} +4 -35
  20. package/commands/investigate.md +70 -0
  21. package/commands/land-and-deploy.md +70 -0
  22. package/commands/office-hours.md +70 -0
  23. package/{skills/gstack-upgrade/SKILL.md → commands/opengstack-upgrade.md} +64 -79
  24. package/commands/plan-ceo-review.md +70 -0
  25. package/commands/plan-design-review.md +70 -0
  26. package/commands/plan-eng-review.md +70 -0
  27. package/commands/qa-only.md +70 -0
  28. package/commands/qa.md +70 -0
  29. package/commands/retro.md +70 -0
  30. package/commands/review.md +70 -0
  31. package/{skills/setup-browser-cookies/SKILL.md → commands/setup-browser-cookies.md} +22 -40
  32. package/commands/setup-deploy.md +70 -0
  33. package/commands/ship.md +70 -0
  34. package/commands/unfreeze.md +25 -0
  35. package/docs/designs/CHROME_VS_CHROMIUM_EXPLORATION.md +9 -9
  36. package/docs/designs/CONDUCTOR_CHROME_SIDEBAR_INTEGRATION.md +2 -2
  37. package/docs/designs/CONDUCTOR_SESSION_API.md +16 -16
  38. package/docs/designs/DESIGN_SHOTGUN.md +74 -74
  39. package/docs/designs/DESIGN_TOOLS_V1.md +111 -111
  40. package/docs/skills.md +483 -202
  41. package/package.json +42 -43
  42. package/scripts/analytics.ts +188 -0
  43. package/scripts/dev-skill.ts +83 -0
  44. package/scripts/discover-skills.ts +39 -0
  45. package/scripts/eval-compare.ts +97 -0
  46. package/scripts/eval-list.ts +117 -0
  47. package/scripts/eval-select.ts +86 -0
  48. package/scripts/eval-summary.ts +188 -0
  49. package/scripts/eval-watch.ts +172 -0
  50. package/scripts/gen-skill-docs.ts +473 -0
  51. package/scripts/resolvers/browse.ts +129 -0
  52. package/scripts/resolvers/codex-helpers.ts +133 -0
  53. package/scripts/resolvers/composition.ts +48 -0
  54. package/scripts/resolvers/confidence.ts +37 -0
  55. package/scripts/resolvers/constants.ts +50 -0
  56. package/scripts/resolvers/design.ts +950 -0
  57. package/scripts/resolvers/index.ts +59 -0
  58. package/scripts/resolvers/learnings.ts +96 -0
  59. package/scripts/resolvers/preamble.ts +505 -0
  60. package/scripts/resolvers/review.ts +884 -0
  61. package/scripts/resolvers/testing.ts +573 -0
  62. package/scripts/resolvers/types.ts +45 -0
  63. package/scripts/resolvers/utility.ts +421 -0
  64. package/scripts/skill-check.ts +190 -0
  65. package/scripts/cleanup.py +0 -100
  66. package/scripts/filter-skills.sh +0 -114
  67. package/scripts/filter_skills.py +0 -164
  68. package/scripts/install-skills.js +0 -60
  69. package/skills/autoplan/SKILL.md +0 -96
  70. package/skills/autoplan/SKILL.md.tmpl +0 -694
  71. package/skills/benchmark/SKILL.md.tmpl +0 -222
  72. package/skills/browse/SKILL.md.tmpl +0 -131
  73. package/skills/browse/bin/find-browse +0 -21
  74. package/skills/browse/bin/remote-slug +0 -14
  75. package/skills/browse/scripts/build-node-server.sh +0 -48
  76. package/skills/browse/src/activity.ts +0 -208
  77. package/skills/browse/src/browser-manager.ts +0 -959
  78. package/skills/browse/src/buffers.ts +0 -137
  79. package/skills/browse/src/bun-polyfill.cjs +0 -109
  80. package/skills/browse/src/cli.ts +0 -678
  81. package/skills/browse/src/commands.ts +0 -128
  82. package/skills/browse/src/config.ts +0 -150
  83. package/skills/browse/src/cookie-import-browser.ts +0 -625
  84. package/skills/browse/src/cookie-picker-routes.ts +0 -230
  85. package/skills/browse/src/cookie-picker-ui.ts +0 -688
  86. package/skills/browse/src/find-browse.ts +0 -61
  87. package/skills/browse/src/meta-commands.ts +0 -550
  88. package/skills/browse/src/platform.ts +0 -17
  89. package/skills/browse/src/read-commands.ts +0 -358
  90. package/skills/browse/src/server.ts +0 -1192
  91. package/skills/browse/src/sidebar-agent.ts +0 -280
  92. package/skills/browse/src/sidebar-utils.ts +0 -21
  93. package/skills/browse/src/snapshot.ts +0 -407
  94. package/skills/browse/src/url-validation.ts +0 -95
  95. package/skills/browse/src/write-commands.ts +0 -364
  96. package/skills/browse/test/activity.test.ts +0 -120
  97. package/skills/browse/test/adversarial-security.test.ts +0 -32
  98. package/skills/browse/test/browser-manager-unit.test.ts +0 -17
  99. package/skills/browse/test/bun-polyfill.test.ts +0 -72
  100. package/skills/browse/test/commands.test.ts +0 -2075
  101. package/skills/browse/test/compare-board.test.ts +0 -342
  102. package/skills/browse/test/config.test.ts +0 -316
  103. package/skills/browse/test/cookie-import-browser.test.ts +0 -519
  104. package/skills/browse/test/cookie-picker-routes.test.ts +0 -260
  105. package/skills/browse/test/file-drop.test.ts +0 -271
  106. package/skills/browse/test/find-browse.test.ts +0 -50
  107. package/skills/browse/test/findport.test.ts +0 -191
  108. package/skills/browse/test/fixtures/basic.html +0 -33
  109. package/skills/browse/test/fixtures/cursor-interactive.html +0 -22
  110. package/skills/browse/test/fixtures/dialog.html +0 -15
  111. package/skills/browse/test/fixtures/empty.html +0 -2
  112. package/skills/browse/test/fixtures/forms.html +0 -55
  113. package/skills/browse/test/fixtures/iframe.html +0 -30
  114. package/skills/browse/test/fixtures/network-idle.html +0 -30
  115. package/skills/browse/test/fixtures/qa-eval-checkout.html +0 -108
  116. package/skills/browse/test/fixtures/qa-eval-spa.html +0 -98
  117. package/skills/browse/test/fixtures/qa-eval.html +0 -51
  118. package/skills/browse/test/fixtures/responsive.html +0 -49
  119. package/skills/browse/test/fixtures/snapshot.html +0 -55
  120. package/skills/browse/test/fixtures/spa.html +0 -24
  121. package/skills/browse/test/fixtures/states.html +0 -17
  122. package/skills/browse/test/fixtures/upload.html +0 -25
  123. package/skills/browse/test/gstack-config.test.ts +0 -138
  124. package/skills/browse/test/gstack-update-check.test.ts +0 -514
  125. package/skills/browse/test/handoff.test.ts +0 -235
  126. package/skills/browse/test/path-validation.test.ts +0 -91
  127. package/skills/browse/test/platform.test.ts +0 -37
  128. package/skills/browse/test/server-auth.test.ts +0 -65
  129. package/skills/browse/test/sidebar-agent-roundtrip.test.ts +0 -226
  130. package/skills/browse/test/sidebar-agent.test.ts +0 -199
  131. package/skills/browse/test/sidebar-integration.test.ts +0 -320
  132. package/skills/browse/test/sidebar-unit.test.ts +0 -96
  133. package/skills/browse/test/snapshot.test.ts +0 -467
  134. package/skills/browse/test/state-ttl.test.ts +0 -35
  135. package/skills/browse/test/test-server.ts +0 -57
  136. package/skills/browse/test/url-validation.test.ts +0 -72
  137. package/skills/browse/test/watch.test.ts +0 -129
  138. package/skills/canary/SKILL.md.tmpl +0 -212
  139. package/skills/careful/SKILL.md.tmpl +0 -56
  140. package/skills/careful/bin/check-careful.sh +0 -112
  141. package/skills/codex/SKILL.md +0 -90
  142. package/skills/codex/SKILL.md.tmpl +0 -417
  143. package/skills/connect-chrome/SKILL.md.tmpl +0 -195
  144. package/skills/cso/ACKNOWLEDGEMENTS.md +0 -14
  145. package/skills/cso/SKILL.md +0 -93
  146. package/skills/cso/SKILL.md.tmpl +0 -606
  147. package/skills/design-consultation/SKILL.md +0 -94
  148. package/skills/design-consultation/SKILL.md.tmpl +0 -415
  149. package/skills/design-review/SKILL.md +0 -94
  150. package/skills/design-review/SKILL.md.tmpl +0 -290
  151. package/skills/design-shotgun/SKILL.md +0 -91
  152. package/skills/design-shotgun/SKILL.md.tmpl +0 -285
  153. package/skills/document-release/SKILL.md +0 -91
  154. package/skills/document-release/SKILL.md.tmpl +0 -359
  155. package/skills/freeze/SKILL.md.tmpl +0 -77
  156. package/skills/freeze/bin/check-freeze.sh +0 -79
  157. package/skills/gstack-upgrade/SKILL.md.tmpl +0 -222
  158. package/skills/guard/SKILL.md.tmpl +0 -77
  159. package/skills/investigate/SKILL.md +0 -105
  160. package/skills/investigate/SKILL.md.tmpl +0 -194
  161. package/skills/land-and-deploy/SKILL.md.tmpl +0 -881
  162. package/skills/office-hours/SKILL.md +0 -96
  163. package/skills/office-hours/SKILL.md.tmpl +0 -645
  164. package/skills/plan-ceo-review/SKILL.md +0 -94
  165. package/skills/plan-ceo-review/SKILL.md.tmpl +0 -811
  166. package/skills/plan-design-review/SKILL.md +0 -92
  167. package/skills/plan-design-review/SKILL.md.tmpl +0 -446
  168. package/skills/plan-eng-review/SKILL.md +0 -93
  169. package/skills/plan-eng-review/SKILL.md.tmpl +0 -303
  170. package/skills/qa/SKILL.md +0 -95
  171. package/skills/qa/SKILL.md.tmpl +0 -316
  172. package/skills/qa/references/issue-taxonomy.md +0 -85
  173. package/skills/qa/templates/qa-report-template.md +0 -126
  174. package/skills/qa-only/SKILL.md +0 -89
  175. package/skills/qa-only/SKILL.md.tmpl +0 -101
  176. package/skills/retro/SKILL.md +0 -89
  177. package/skills/retro/SKILL.md.tmpl +0 -820
  178. package/skills/review/SKILL.md +0 -92
  179. package/skills/review/SKILL.md.tmpl +0 -281
  180. package/skills/review/TODOS-format.md +0 -62
  181. package/skills/review/checklist.md +0 -220
  182. package/skills/review/design-checklist.md +0 -132
  183. package/skills/review/greptile-triage.md +0 -220
  184. package/skills/setup-browser-cookies/SKILL.md.tmpl +0 -81
  185. package/skills/setup-deploy/SKILL.md +0 -92
  186. package/skills/setup-deploy/SKILL.md.tmpl +0 -215
  187. package/skills/ship/SKILL.md.tmpl +0 -636
  188. package/skills/unfreeze/SKILL.md +0 -37
  189. package/skills/unfreeze/SKILL.md.tmpl +0 -36
@@ -1,625 +0,0 @@
1
- /**
2
- * Chromium browser cookie import — read and decrypt cookies from real browsers
3
- *
4
- * Supports macOS and Linux Chromium-based browsers.
5
- * Pure logic module — no Playwright dependency, no HTTP concerns.
6
- *
7
- * Decryption pipeline:
8
- *
9
- * ┌──────────────────────────────────────────────────────────────────┐
10
- * │ 1. Resolve the cookie DB from the browser profile dir │
11
- * │ - macOS: ~/Library/Application Support/<browser>/<profile> │
12
- * │ - Linux: ~/.config/<browser>/<profile> │
13
- * │ │
14
- * │ 2. Derive the AES key │
15
- * │ - macOS v10: Keychain password, PBKDF2(..., iter=1003) │
16
- * │ - Linux v10: "peanuts", PBKDF2(..., iter=1) │
17
- * │ - Linux v11: libsecret/secret-tool password, iter=1 │
18
- * │ │
19
- * │ 3. For each cookie with encrypted_value starting with "v10"/ │
20
- * │ "v11": │
21
- * │ - Ciphertext = encrypted_value[3:] │
22
- * │ - IV = 16 bytes of 0x20 (space character) │
23
- * │ - Plaintext = AES-128-CBC-decrypt(key, iv, ciphertext) │
24
- * │ - Remove PKCS7 padding │
25
- * │ - Skip first 32 bytes of Chromium cookie metadata │
26
- * │ - Remaining bytes = cookie value (UTF-8) │
27
- * │ │
28
- * │ 4. If encrypted_value is empty but `value` field is set, │
29
- * │ use value directly (unencrypted cookie) │
30
- * │ │
31
- * │ 5. Chromium epoch: microseconds since 1601-01-01 │
32
- * │ Unix seconds = (epoch - 11644473600000000) / 1000000 │
33
- * │ │
34
- * │ 6. sameSite: 0→"None", 1→"Lax", 2→"Strict", else→"Lax" │
35
- * └──────────────────────────────────────────────────────────────────┘
36
- */
37
-
38
- import { Database } from 'bun:sqlite';
39
- import * as crypto from 'crypto';
40
- import * as fs from 'fs';
41
- import * as path from 'path';
42
- import * as os from 'os';
43
-
44
- // ─── Types ──────────────────────────────────────────────────────
45
-
46
- export interface BrowserInfo {
47
- name: string;
48
- dataDir: string; // primary storage dir (retained for compatibility with existing callers/tests)
49
- keychainService: string;
50
- aliases: string[];
51
- linuxDataDir?: string;
52
- linuxApplication?: string;
53
- }
54
-
55
- export interface ProfileEntry {
56
- name: string; // e.g. "Default", "Profile 1", "Profile 3"
57
- displayName: string; // human-friendly name from Preferences, or falls back to dir name
58
- }
59
-
60
- export interface DomainEntry {
61
- domain: string;
62
- count: number;
63
- }
64
-
65
- export interface ImportResult {
66
- cookies: PlaywrightCookie[];
67
- count: number;
68
- failed: number;
69
- domainCounts: Record<string, number>;
70
- }
71
-
72
- export interface PlaywrightCookie {
73
- name: string;
74
- value: string;
75
- domain: string;
76
- path: string;
77
- expires: number;
78
- secure: boolean;
79
- httpOnly: boolean;
80
- sameSite: 'Strict' | 'Lax' | 'None';
81
- }
82
-
83
- export class CookieImportError extends Error {
84
- constructor(
85
- message: string,
86
- public code: string,
87
- public action?: 'retry',
88
- ) {
89
- super(message);
90
- this.name = 'CookieImportError';
91
- }
92
- }
93
-
94
- type BrowserPlatform = 'darwin' | 'linux';
95
-
96
- interface BrowserMatch {
97
- browser: BrowserInfo;
98
- platform: BrowserPlatform;
99
- dbPath: string;
100
- }
101
-
102
- // ─── Browser Registry ───────────────────────────────────────────
103
- // Hardcoded — NEVER interpolate user input into shell commands.
104
-
105
- const BROWSER_REGISTRY: BrowserInfo[] = [
106
- { name: 'Comet', dataDir: 'Comet/', keychainService: 'Comet Safe Storage', aliases: ['comet', 'perplexity'] },
107
- { name: 'Chrome', dataDir: 'Google/Chrome/', keychainService: 'Chrome Safe Storage', aliases: ['chrome', 'google-chrome', 'google-chrome-stable'], linuxDataDir: 'google-chrome/', linuxApplication: 'chrome' },
108
- { name: 'Chromium', dataDir: 'chromium/', keychainService: 'Chromium Safe Storage', aliases: ['chromium'], linuxDataDir: 'chromium/', linuxApplication: 'chromium' },
109
- { name: 'Arc', dataDir: 'Arc/User Data/', keychainService: 'Arc Safe Storage', aliases: ['arc'] },
110
- { name: 'Brave', dataDir: 'BraveSoftware/Brave-Browser/', keychainService: 'Brave Safe Storage', aliases: ['brave'], linuxDataDir: 'BraveSoftware/Brave-Browser/', linuxApplication: 'brave' },
111
- { name: 'Edge', dataDir: 'Microsoft Edge/', keychainService: 'Microsoft Edge Safe Storage', aliases: ['edge'], linuxDataDir: 'microsoft-edge/', linuxApplication: 'microsoft-edge' },
112
- ];
113
-
114
- // ─── Key Cache ──────────────────────────────────────────────────
115
- // Cache derived AES keys per browser. First import per browser does
116
- // Keychain + PBKDF2. Subsequent imports reuse the cached key.
117
-
118
- const keyCache = new Map<string, Buffer>();
119
-
120
- // ─── Public API ─────────────────────────────────────────────────
121
-
122
- /**
123
- * Find which browsers are installed (have a cookie DB on disk in any profile).
124
- */
125
- export function findInstalledBrowsers(): BrowserInfo[] {
126
- return BROWSER_REGISTRY.filter(browser => {
127
- // Check Default profile on any platform
128
- if (findBrowserMatch(browser, 'Default') !== null) return true;
129
- // Check numbered profiles (Profile 1, Profile 2, etc.)
130
- for (const platform of getSearchPlatforms()) {
131
- const dataDir = getDataDirForPlatform(browser, platform);
132
- if (!dataDir) continue;
133
- const browserDir = path.join(getBaseDir(platform), dataDir);
134
- try {
135
- const entries = fs.readdirSync(browserDir, { withFileTypes: true });
136
- if (entries.some(e =>
137
- e.isDirectory() && e.name.startsWith('Profile ') &&
138
- fs.existsSync(path.join(browserDir, e.name, 'Cookies'))
139
- )) return true;
140
- } catch {}
141
- }
142
- return false;
143
- });
144
- }
145
-
146
- export function listSupportedBrowserNames(): string[] {
147
- const hostPlatform = getHostPlatform();
148
- return BROWSER_REGISTRY
149
- .filter(browser => hostPlatform ? getDataDirForPlatform(browser, hostPlatform) !== null : true)
150
- .map(browser => browser.name);
151
- }
152
-
153
- /**
154
- * List available profiles for a browser.
155
- */
156
- export function listProfiles(browserName: string): ProfileEntry[] {
157
- const browser = resolveBrowser(browserName);
158
- const profiles: ProfileEntry[] = [];
159
-
160
- // Scan each supported platform for profile directories
161
- for (const platform of getSearchPlatforms()) {
162
- const dataDir = getDataDirForPlatform(browser, platform);
163
- if (!dataDir) continue;
164
- const browserDir = path.join(getBaseDir(platform), dataDir);
165
- if (!fs.existsSync(browserDir)) continue;
166
-
167
- let entries: fs.Dirent[];
168
- try {
169
- entries = fs.readdirSync(browserDir, { withFileTypes: true });
170
- } catch {
171
- continue;
172
- }
173
-
174
- for (const entry of entries) {
175
- if (!entry.isDirectory()) continue;
176
- if (entry.name !== 'Default' && !entry.name.startsWith('Profile ')) continue;
177
- const cookiePath = path.join(browserDir, entry.name, 'Cookies');
178
- if (!fs.existsSync(cookiePath)) continue;
179
-
180
- // Avoid duplicates if the same profile appears on multiple platforms
181
- if (profiles.some(p => p.name === entry.name)) continue;
182
-
183
- // Try to read display name from Preferences.
184
- // Prefer account email — signed-in Chrome profiles often have generic
185
- // names like "Person 2" while the email is far more readable.
186
- let displayName = entry.name;
187
- try {
188
- const prefsPath = path.join(browserDir, entry.name, 'Preferences');
189
- if (fs.existsSync(prefsPath)) {
190
- const prefs = JSON.parse(fs.readFileSync(prefsPath, 'utf-8'));
191
- const email = prefs?.account_info?.[0]?.email;
192
- if (email && typeof email === 'string') {
193
- displayName = email;
194
- } else {
195
- const profileName = prefs?.profile?.name;
196
- if (profileName && typeof profileName === 'string') {
197
- displayName = profileName;
198
- }
199
- }
200
- }
201
- } catch {
202
- // Ignore — fall back to directory name
203
- }
204
-
205
- profiles.push({ name: entry.name, displayName });
206
- }
207
-
208
- // Found profiles on this platform — no need to check others
209
- if (profiles.length > 0) break;
210
- }
211
-
212
- return profiles;
213
- }
214
-
215
- /**
216
- * List unique cookie domains + counts from a browser's DB. No decryption.
217
- */
218
- export function listDomains(browserName: string, profile = 'Default'): { domains: DomainEntry[]; browser: string } {
219
- const browser = resolveBrowser(browserName);
220
- const match = getBrowserMatch(browser, profile);
221
- const db = openDb(match.dbPath, browser.name);
222
- try {
223
- const now = chromiumNow();
224
- const rows = db.query(
225
- `SELECT host_key AS domain, COUNT(*) AS count
226
- FROM cookies
227
- WHERE has_expires = 0 OR expires_utc > ?
228
- GROUP BY host_key
229
- ORDER BY count DESC`
230
- ).all(now) as DomainEntry[];
231
- return { domains: rows, browser: browser.name };
232
- } finally {
233
- db.close();
234
- }
235
- }
236
-
237
- /**
238
- * Decrypt and return Playwright-compatible cookies for specific domains.
239
- */
240
- export async function importCookies(
241
- browserName: string,
242
- domains: string[],
243
- profile = 'Default',
244
- ): Promise<ImportResult> {
245
- if (domains.length === 0) return { cookies: [], count: 0, failed: 0, domainCounts: {} };
246
-
247
- const browser = resolveBrowser(browserName);
248
- const match = getBrowserMatch(browser, profile);
249
- const derivedKeys = await getDerivedKeys(match);
250
- const db = openDb(match.dbPath, browser.name);
251
-
252
- try {
253
- const now = chromiumNow();
254
- // Parameterized query — no SQL injection
255
- const placeholders = domains.map(() => '?').join(',');
256
- const rows = db.query(
257
- `SELECT host_key, name, value, encrypted_value, path, expires_utc,
258
- is_secure, is_httponly, has_expires, samesite
259
- FROM cookies
260
- WHERE host_key IN (${placeholders})
261
- AND (has_expires = 0 OR expires_utc > ?)
262
- ORDER BY host_key, name`
263
- ).all(...domains, now) as RawCookie[];
264
-
265
- const cookies: PlaywrightCookie[] = [];
266
- let failed = 0;
267
- const domainCounts: Record<string, number> = {};
268
-
269
- for (const row of rows) {
270
- try {
271
- const value = decryptCookieValue(row, derivedKeys);
272
- const cookie = toPlaywrightCookie(row, value);
273
- cookies.push(cookie);
274
- domainCounts[row.host_key] = (domainCounts[row.host_key] || 0) + 1;
275
- } catch {
276
- failed++;
277
- }
278
- }
279
-
280
- return { cookies, count: cookies.length, failed, domainCounts };
281
- } finally {
282
- db.close();
283
- }
284
- }
285
-
286
- // ─── Internal: Browser Resolution ───────────────────────────────
287
-
288
- function resolveBrowser(nameOrAlias: string): BrowserInfo {
289
- const needle = nameOrAlias.toLowerCase().trim();
290
- const found = BROWSER_REGISTRY.find(b =>
291
- b.aliases.includes(needle) || b.name.toLowerCase() === needle
292
- );
293
- if (!found) {
294
- const supported = BROWSER_REGISTRY.flatMap(b => b.aliases).join(', ');
295
- throw new CookieImportError(
296
- `Unknown browser '${nameOrAlias}'. Supported: ${supported}`,
297
- 'unknown_browser',
298
- );
299
- }
300
- return found;
301
- }
302
-
303
- function validateProfile(profile: string): void {
304
- if (/[/\\]|\.\./.test(profile) || /[\x00-\x1f]/.test(profile)) {
305
- throw new CookieImportError(
306
- `Invalid profile name: '${profile}'`,
307
- 'bad_request',
308
- );
309
- }
310
- }
311
-
312
- function getHostPlatform(): BrowserPlatform | null {
313
- if (process.platform === 'darwin' || process.platform === 'linux') return process.platform;
314
- return null;
315
- }
316
-
317
- function getSearchPlatforms(): BrowserPlatform[] {
318
- const current = getHostPlatform();
319
- const order: BrowserPlatform[] = [];
320
- if (current) order.push(current);
321
- for (const platform of ['darwin', 'linux'] as BrowserPlatform[]) {
322
- if (!order.includes(platform)) order.push(platform);
323
- }
324
- return order;
325
- }
326
-
327
- function getDataDirForPlatform(browser: BrowserInfo, platform: BrowserPlatform): string | null {
328
- return platform === 'darwin' ? browser.dataDir : browser.linuxDataDir || null;
329
- }
330
-
331
- function getBaseDir(platform: BrowserPlatform): string {
332
- return platform === 'darwin'
333
- ? path.join(os.homedir(), 'Library', 'Application Support')
334
- : path.join(os.homedir(), '.config');
335
- }
336
-
337
- function findBrowserMatch(browser: BrowserInfo, profile: string): BrowserMatch | null {
338
- validateProfile(profile);
339
- for (const platform of getSearchPlatforms()) {
340
- const dataDir = getDataDirForPlatform(browser, platform);
341
- if (!dataDir) continue;
342
- const dbPath = path.join(getBaseDir(platform), dataDir, profile, 'Cookies');
343
- try {
344
- if (fs.existsSync(dbPath)) {
345
- return { browser, platform, dbPath };
346
- }
347
- } catch {}
348
- }
349
- return null;
350
- }
351
-
352
- function getBrowserMatch(browser: BrowserInfo, profile: string): BrowserMatch {
353
- const match = findBrowserMatch(browser, profile);
354
- if (match) return match;
355
-
356
- const attempted = getSearchPlatforms()
357
- .map(platform => {
358
- const dataDir = getDataDirForPlatform(browser, platform);
359
- return dataDir ? path.join(getBaseDir(platform), dataDir, profile, 'Cookies') : null;
360
- })
361
- .filter((entry): entry is string => entry !== null);
362
-
363
- throw new CookieImportError(
364
- `${browser.name} is not installed (no cookie database at ${attempted.join(' or ')})`,
365
- 'not_installed',
366
- );
367
- }
368
-
369
- // ─── Internal: SQLite Access ────────────────────────────────────
370
-
371
- function openDb(dbPath: string, browserName: string): Database {
372
- try {
373
- return new Database(dbPath, { readonly: true });
374
- } catch (err: any) {
375
- if (err.message?.includes('SQLITE_BUSY') || err.message?.includes('database is locked')) {
376
- return openDbFromCopy(dbPath, browserName);
377
- }
378
- if (err.message?.includes('SQLITE_CORRUPT') || err.message?.includes('malformed')) {
379
- throw new CookieImportError(
380
- `Cookie database for ${browserName} is corrupt`,
381
- 'db_corrupt',
382
- );
383
- }
384
- throw err;
385
- }
386
- }
387
-
388
- function openDbFromCopy(dbPath: string, browserName: string): Database {
389
- const tmpPath = `/tmp/browse-cookies-${browserName.toLowerCase()}-${crypto.randomUUID()}.db`;
390
- try {
391
- fs.copyFileSync(dbPath, tmpPath);
392
- // Also copy WAL and SHM if they exist (for consistent reads)
393
- const walPath = dbPath + '-wal';
394
- const shmPath = dbPath + '-shm';
395
- if (fs.existsSync(walPath)) fs.copyFileSync(walPath, tmpPath + '-wal');
396
- if (fs.existsSync(shmPath)) fs.copyFileSync(shmPath, tmpPath + '-shm');
397
-
398
- const db = new Database(tmpPath, { readonly: true });
399
- // Schedule cleanup after the DB is closed
400
- const origClose = db.close.bind(db);
401
- db.close = () => {
402
- origClose();
403
- try { fs.unlinkSync(tmpPath); } catch {}
404
- try { fs.unlinkSync(tmpPath + '-wal'); } catch {}
405
- try { fs.unlinkSync(tmpPath + '-shm'); } catch {}
406
- };
407
- return db;
408
- } catch {
409
- // Clean up on failure
410
- try { fs.unlinkSync(tmpPath); } catch {}
411
- throw new CookieImportError(
412
- `Cookie database is locked (${browserName} may be running). Try closing ${browserName} first.`,
413
- 'db_locked',
414
- 'retry',
415
- );
416
- }
417
- }
418
-
419
- // ─── Internal: Keychain Access (async, 10s timeout) ─────────────
420
-
421
- function deriveKey(password: string, iterations: number): Buffer {
422
- return crypto.pbkdf2Sync(password, 'saltysalt', iterations, 16, 'sha1');
423
- }
424
-
425
- function getCachedDerivedKey(cacheKey: string, password: string, iterations: number): Buffer {
426
- const cached = keyCache.get(cacheKey);
427
- if (cached) return cached;
428
- const derived = deriveKey(password, iterations);
429
- keyCache.set(cacheKey, derived);
430
- return derived;
431
- }
432
-
433
- async function getDerivedKeys(match: BrowserMatch): Promise<Map<string, Buffer>> {
434
- if (match.platform === 'darwin') {
435
- const password = await getMacKeychainPassword(match.browser.keychainService);
436
- return new Map([
437
- ['v10', getCachedDerivedKey(`darwin:${match.browser.keychainService}:v10`, password, 1003)],
438
- ]);
439
- }
440
-
441
- const keys = new Map<string, Buffer>();
442
- keys.set('v10', getCachedDerivedKey('linux:v10', 'peanuts', 1));
443
-
444
- const linuxPassword = await getLinuxSecretPassword(match.browser);
445
- if (linuxPassword) {
446
- keys.set(
447
- 'v11',
448
- getCachedDerivedKey(`linux:${match.browser.keychainService}:v11`, linuxPassword, 1),
449
- );
450
- }
451
- return keys;
452
- }
453
-
454
- async function getMacKeychainPassword(service: string): Promise<string> {
455
- // Use async Bun.spawn with timeout to avoid blocking the event loop.
456
- // macOS may show an Allow/Deny dialog that blocks until the user responds.
457
- const proc = Bun.spawn(
458
- ['security', 'find-generic-password', '-s', service, '-w'],
459
- { stdout: 'pipe', stderr: 'pipe' },
460
- );
461
-
462
- const timeout = new Promise<never>((_, reject) =>
463
- setTimeout(() => {
464
- proc.kill();
465
- reject(new CookieImportError(
466
- `macOS is waiting for Keychain permission. Look for a dialog asking to allow access to "${service}".`,
467
- 'keychain_timeout',
468
- 'retry',
469
- ));
470
- }, 10_000),
471
- );
472
-
473
- try {
474
- const exitCode = await Promise.race([proc.exited, timeout]);
475
- const stdout = await new Response(proc.stdout).text();
476
- const stderr = await new Response(proc.stderr).text();
477
-
478
- if (exitCode !== 0) {
479
- // Distinguish denied vs not found vs other
480
- const errText = stderr.trim().toLowerCase();
481
- if (errText.includes('user canceled') || errText.includes('denied') || errText.includes('interaction not allowed')) {
482
- throw new CookieImportError(
483
- `Keychain access denied. Click "Allow" in the macOS dialog for "${service}".`,
484
- 'keychain_denied',
485
- 'retry',
486
- );
487
- }
488
- if (errText.includes('could not be found') || errText.includes('not found')) {
489
- throw new CookieImportError(
490
- `No Keychain entry for "${service}". Is this a Chromium-based browser?`,
491
- 'keychain_not_found',
492
- );
493
- }
494
- throw new CookieImportError(
495
- `Could not read Keychain: ${stderr.trim()}`,
496
- 'keychain_error',
497
- 'retry',
498
- );
499
- }
500
-
501
- return stdout.trim();
502
- } catch (err) {
503
- if (err instanceof CookieImportError) throw err;
504
- throw new CookieImportError(
505
- `Could not read Keychain: ${(err as Error).message}`,
506
- 'keychain_error',
507
- 'retry',
508
- );
509
- }
510
- }
511
-
512
- async function getLinuxSecretPassword(browser: BrowserInfo): Promise<string | null> {
513
- const attempts: string[][] = [
514
- ['secret-tool', 'lookup', 'Title', browser.keychainService],
515
- ];
516
-
517
- if (browser.linuxApplication) {
518
- attempts.push(
519
- ['secret-tool', 'lookup', 'xdg:schema', 'chrome_libsecret_os_crypt_password_v2', 'application', browser.linuxApplication],
520
- ['secret-tool', 'lookup', 'xdg:schema', 'chrome_libsecret_os_crypt_password', 'application', browser.linuxApplication],
521
- );
522
- }
523
-
524
- for (const cmd of attempts) {
525
- const password = await runPasswordLookup(cmd, 3_000);
526
- if (password) return password;
527
- }
528
-
529
- return null;
530
- }
531
-
532
- async function runPasswordLookup(cmd: string[], timeoutMs: number): Promise<string | null> {
533
- try {
534
- const proc = Bun.spawn(cmd, { stdout: 'pipe', stderr: 'pipe' });
535
- const timeout = new Promise<never>((_, reject) =>
536
- setTimeout(() => {
537
- proc.kill();
538
- reject(new Error('timeout'));
539
- }, timeoutMs),
540
- );
541
-
542
- const exitCode = await Promise.race([proc.exited, timeout]);
543
- const stdout = await new Response(proc.stdout).text();
544
- if (exitCode !== 0) return null;
545
-
546
- const password = stdout.trim();
547
- return password.length > 0 ? password : null;
548
- } catch {
549
- return null;
550
- }
551
- }
552
-
553
- // ─── Internal: Cookie Decryption ────────────────────────────────
554
-
555
- interface RawCookie {
556
- host_key: string;
557
- name: string;
558
- value: string;
559
- encrypted_value: Buffer | Uint8Array;
560
- path: string;
561
- expires_utc: number | bigint;
562
- is_secure: number;
563
- is_httponly: number;
564
- has_expires: number;
565
- samesite: number;
566
- }
567
-
568
- function decryptCookieValue(row: RawCookie, keys: Map<string, Buffer>): string {
569
- // Prefer unencrypted value if present
570
- if (row.value && row.value.length > 0) return row.value;
571
-
572
- const ev = Buffer.from(row.encrypted_value);
573
- if (ev.length === 0) return '';
574
-
575
- const prefix = ev.slice(0, 3).toString('utf-8');
576
- const key = keys.get(prefix);
577
- if (!key) throw new Error(`No decryption key available for ${prefix} cookies`);
578
-
579
- const ciphertext = ev.slice(3);
580
- const iv = Buffer.alloc(16, 0x20); // 16 space characters
581
- const decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
582
- const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
583
-
584
- // Chromium prefixes encrypted cookie payloads with 32 bytes of metadata.
585
- if (plaintext.length <= 32) return '';
586
- return plaintext.slice(32).toString('utf-8');
587
- }
588
-
589
- function toPlaywrightCookie(row: RawCookie, value: string): PlaywrightCookie {
590
- return {
591
- name: row.name,
592
- value,
593
- domain: row.host_key,
594
- path: row.path || '/',
595
- expires: chromiumEpochToUnix(row.expires_utc, row.has_expires),
596
- secure: row.is_secure === 1,
597
- httpOnly: row.is_httponly === 1,
598
- sameSite: mapSameSite(row.samesite),
599
- };
600
- }
601
-
602
- // ─── Internal: Chromium Epoch Conversion ────────────────────────
603
-
604
- const CHROMIUM_EPOCH_OFFSET = 11644473600000000n;
605
-
606
- function chromiumNow(): bigint {
607
- // Current time in Chromium epoch (microseconds since 1601-01-01)
608
- return BigInt(Date.now()) * 1000n + CHROMIUM_EPOCH_OFFSET;
609
- }
610
-
611
- function chromiumEpochToUnix(epoch: number | bigint, hasExpires: number): number {
612
- if (hasExpires === 0 || epoch === 0 || epoch === 0n) return -1; // session cookie
613
- const epochBig = BigInt(epoch);
614
- const unixMicro = epochBig - CHROMIUM_EPOCH_OFFSET;
615
- return Number(unixMicro / 1000000n);
616
- }
617
-
618
- function mapSameSite(value: number): 'Strict' | 'Lax' | 'None' {
619
- switch (value) {
620
- case 0: return 'None';
621
- case 1: return 'Lax';
622
- case 2: return 'Strict';
623
- default: return 'Lax';
624
- }
625
- }