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,128 +0,0 @@
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
- 'connect', 'disconnect', 'focus',
35
- 'inbox',
36
- 'watch',
37
- 'state',
38
- 'frame',
39
- ]);
40
-
41
- export const ALL_COMMANDS = new Set([...READ_COMMANDS, ...WRITE_COMMANDS, ...META_COMMANDS]);
42
-
43
- export const COMMAND_DESCRIPTIONS: Record<string, { category: string; description: string; usage?: string }> = {
44
- // Navigation
45
- 'goto': { category: 'Navigation', description: 'Navigate to URL', usage: 'goto <url>' },
46
- 'back': { category: 'Navigation', description: 'History back' },
47
- 'forward': { category: 'Navigation', description: 'History forward' },
48
- 'reload': { category: 'Navigation', description: 'Reload page' },
49
- 'url': { category: 'Navigation', description: 'Print current URL' },
50
- // Reading
51
- 'text': { category: 'Reading', description: 'Cleaned page text' },
52
- 'html': { category: 'Reading', description: 'innerHTML of selector (throws if not found), or full page HTML if no selector given', usage: 'html [selector]' },
53
- 'links': { category: 'Reading', description: 'All links as "text → href"' },
54
- 'forms': { category: 'Reading', description: 'Form fields as JSON' },
55
- 'accessibility': { category: 'Reading', description: 'Full ARIA tree' },
56
- // Inspection
57
- 'js': { category: 'Inspection', description: 'Run JavaScript expression and return result as string', usage: 'js <expr>' },
58
- 'eval': { category: 'Inspection', description: 'Run JavaScript from file and return result as string (path must be under /tmp or cwd)', usage: 'eval <file>' },
59
- 'css': { category: 'Inspection', description: 'Computed CSS value', usage: 'css <sel> <prop>' },
60
- 'attrs': { category: 'Inspection', description: 'Element attributes as JSON', usage: 'attrs <sel|@ref>' },
61
- 'is': { category: 'Inspection', description: 'State check (visible/hidden/enabled/disabled/checked/editable/focused)', usage: 'is <prop> <sel>' },
62
- 'console': { category: 'Inspection', description: 'Console messages (--errors filters to error/warning)', usage: 'console [--clear|--errors]' },
63
- 'network': { category: 'Inspection', description: 'Network requests', usage: 'network [--clear]' },
64
- 'dialog': { category: 'Inspection', description: 'Dialog messages', usage: 'dialog [--clear]' },
65
- 'cookies': { category: 'Inspection', description: 'All cookies as JSON' },
66
- 'storage': { category: 'Inspection', description: 'Read all localStorage + sessionStorage as JSON, or set <key> <value> to write localStorage', usage: 'storage [set k v]' },
67
- 'perf': { category: 'Inspection', description: 'Page load timings' },
68
- // Interaction
69
- 'click': { category: 'Interaction', description: 'Click element', usage: 'click <sel>' },
70
- 'fill': { category: 'Interaction', description: 'Fill input', usage: 'fill <sel> <val>' },
71
- 'select': { category: 'Interaction', description: 'Select dropdown option by value, label, or visible text', usage: 'select <sel> <val>' },
72
- 'hover': { category: 'Interaction', description: 'Hover element', usage: 'hover <sel>' },
73
- 'type': { category: 'Interaction', description: 'Type into focused element', usage: 'type <text>' },
74
- '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>' },
75
- 'scroll': { category: 'Interaction', description: 'Scroll element into view, or scroll to page bottom if no selector', usage: 'scroll [sel]' },
76
- 'wait': { category: 'Interaction', description: 'Wait for element, network idle, or page load (timeout: 15s)', usage: 'wait <sel|--networkidle|--load>' },
77
- 'upload': { category: 'Interaction', description: 'Upload file(s)', usage: 'upload <sel> <file> [file2...]' },
78
- 'viewport':{ category: 'Interaction', description: 'Set viewport size', usage: 'viewport <WxH>' },
79
- 'cookie': { category: 'Interaction', description: 'Set cookie on current page domain', usage: 'cookie <name>=<value>' },
80
- 'cookie-import': { category: 'Interaction', description: 'Import cookies from JSON file', usage: 'cookie-import <json>' },
81
- 'cookie-import-browser': { category: 'Interaction', description: 'Import cookies from installed Chromium browsers (opens picker, or use --domain for direct import)', usage: 'cookie-import-browser [browser] [--domain d]' },
82
- 'header': { category: 'Interaction', description: 'Set custom request header (colon-separated, sensitive values auto-redacted)', usage: 'header <name>:<value>' },
83
- 'useragent': { category: 'Interaction', description: 'Set user agent', usage: 'useragent <string>' },
84
- 'dialog-accept': { category: 'Interaction', description: 'Auto-accept next alert/confirm/prompt. Optional text is sent as the prompt response', usage: 'dialog-accept [text]' },
85
- 'dialog-dismiss': { category: 'Interaction', description: 'Auto-dismiss next dialog' },
86
- // Visual
87
- '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]' },
88
- 'pdf': { category: 'Visual', description: 'Save as PDF', usage: 'pdf [path]' },
89
- 'responsive': { category: 'Visual', description: 'Screenshots at mobile (375x812), tablet (768x1024), desktop (1280x720). Saves as {prefix}-mobile.png etc.', usage: 'responsive [prefix]' },
90
- 'diff': { category: 'Visual', description: 'Text diff between pages', usage: 'diff <url1> <url2>' },
91
- // Tabs
92
- 'tabs': { category: 'Tabs', description: 'List open tabs' },
93
- 'tab': { category: 'Tabs', description: 'Switch to tab', usage: 'tab <id>' },
94
- 'newtab': { category: 'Tabs', description: 'Open new tab', usage: 'newtab [url]' },
95
- 'closetab':{ category: 'Tabs', description: 'Close tab', usage: 'closetab [id]' },
96
- // Server
97
- 'status': { category: 'Server', description: 'Health check' },
98
- 'stop': { category: 'Server', description: 'Shutdown server' },
99
- 'restart': { category: 'Server', description: 'Restart server' },
100
- // Meta
101
- '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]' },
102
- 'chain': { category: 'Meta', description: 'Run commands from JSON stdin. Format: [["cmd","arg1",...],...]' },
103
- // Handoff
104
- 'handoff': { category: 'Server', description: 'Open visible Chrome at current page for user takeover', usage: 'handoff [message]' },
105
- 'resume': { category: 'Server', description: 'Re-snapshot after user takeover, return control to AI', usage: 'resume' },
106
- // Headed mode
107
- 'connect': { category: 'Server', description: 'Launch headed Chromium with Chrome extension', usage: 'connect' },
108
- 'disconnect': { category: 'Server', description: 'Disconnect headed browser, return to headless mode' },
109
- 'focus': { category: 'Server', description: 'Bring headed browser window to foreground (macOS)', usage: 'focus [@ref]' },
110
- // Inbox
111
- 'inbox': { category: 'Meta', description: 'List messages from sidebar scout inbox', usage: 'inbox [--clear]' },
112
- // Watch
113
- 'watch': { category: 'Meta', description: 'Passive observation — periodic snapshots while user browses', usage: 'watch [stop]' },
114
- // State
115
- 'state': { category: 'Server', description: 'Save/load browser state (cookies + URLs)', usage: 'state save|load <name>' },
116
- // Frame
117
- 'frame': { category: 'Meta', description: 'Switch to iframe context (or main to return)', usage: 'frame <sel|@ref|--name n|--url pattern|main>' },
118
- };
119
-
120
- // Load-time validation: descriptions must cover exactly the command sets
121
- const allCmds = new Set([...READ_COMMANDS, ...WRITE_COMMANDS, ...META_COMMANDS]);
122
- const descKeys = new Set(Object.keys(COMMAND_DESCRIPTIONS));
123
- for (const cmd of allCmds) {
124
- if (!descKeys.has(cmd)) throw new Error(`COMMAND_DESCRIPTIONS missing entry for: ${cmd}`);
125
- }
126
- for (const key of descKeys) {
127
- if (!allCmds.has(key)) throw new Error(`COMMAND_DESCRIPTIONS has unknown command: ${key}`);
128
- }
@@ -1,150 +0,0 @@
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
- }