opengstack 0.13.7 → 0.13.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/opengstack.js +35 -90
- package/package.json +2 -3
- package/scripts/install-skills.js +47 -58
- package/skills/browse/bin/find-browse +21 -0
- package/skills/browse/bin/remote-slug +14 -0
- package/skills/browse/scripts/build-node-server.sh +48 -0
- package/skills/browse/src/activity.ts +208 -0
- package/skills/browse/src/browser-manager.ts +959 -0
- package/skills/browse/src/buffers.ts +137 -0
- package/skills/browse/src/bun-polyfill.cjs +109 -0
- package/skills/browse/src/cli.ts +678 -0
- package/skills/browse/src/commands.ts +128 -0
- package/skills/browse/src/config.ts +150 -0
- package/skills/browse/src/cookie-import-browser.ts +625 -0
- package/skills/browse/src/cookie-picker-routes.ts +230 -0
- package/skills/browse/src/cookie-picker-ui.ts +688 -0
- package/skills/browse/src/find-browse.ts +61 -0
- package/skills/browse/src/meta-commands.ts +550 -0
- package/skills/browse/src/platform.ts +17 -0
- package/skills/browse/src/read-commands.ts +358 -0
- package/skills/browse/src/server.ts +1192 -0
- package/skills/browse/src/sidebar-agent.ts +280 -0
- package/skills/browse/src/sidebar-utils.ts +21 -0
- package/skills/browse/src/snapshot.ts +407 -0
- package/skills/browse/src/url-validation.ts +95 -0
- package/skills/browse/src/write-commands.ts +364 -0
- package/skills/browse/test/activity.test.ts +120 -0
- package/skills/browse/test/adversarial-security.test.ts +32 -0
- package/skills/browse/test/browser-manager-unit.test.ts +17 -0
- package/skills/browse/test/bun-polyfill.test.ts +72 -0
- package/skills/browse/test/commands.test.ts +2075 -0
- package/skills/browse/test/compare-board.test.ts +342 -0
- package/skills/browse/test/config.test.ts +316 -0
- package/skills/browse/test/cookie-import-browser.test.ts +519 -0
- package/skills/browse/test/cookie-picker-routes.test.ts +260 -0
- package/skills/browse/test/file-drop.test.ts +271 -0
- package/skills/browse/test/find-browse.test.ts +50 -0
- package/skills/browse/test/findport.test.ts +191 -0
- package/skills/browse/test/fixtures/basic.html +33 -0
- package/skills/browse/test/fixtures/cursor-interactive.html +22 -0
- package/skills/browse/test/fixtures/dialog.html +15 -0
- package/skills/browse/test/fixtures/empty.html +2 -0
- package/skills/browse/test/fixtures/forms.html +55 -0
- package/skills/browse/test/fixtures/iframe.html +30 -0
- package/skills/browse/test/fixtures/network-idle.html +30 -0
- package/skills/browse/test/fixtures/qa-eval-checkout.html +108 -0
- package/skills/browse/test/fixtures/qa-eval-spa.html +98 -0
- package/skills/browse/test/fixtures/qa-eval.html +51 -0
- package/skills/browse/test/fixtures/responsive.html +49 -0
- package/skills/browse/test/fixtures/snapshot.html +55 -0
- package/skills/browse/test/fixtures/spa.html +24 -0
- package/skills/browse/test/fixtures/states.html +17 -0
- package/skills/browse/test/fixtures/upload.html +25 -0
- package/skills/browse/test/gstack-config.test.ts +138 -0
- package/skills/browse/test/gstack-update-check.test.ts +514 -0
- package/skills/browse/test/handoff.test.ts +235 -0
- package/skills/browse/test/path-validation.test.ts +91 -0
- package/skills/browse/test/platform.test.ts +37 -0
- package/skills/browse/test/server-auth.test.ts +65 -0
- package/skills/browse/test/sidebar-agent-roundtrip.test.ts +226 -0
- package/skills/browse/test/sidebar-agent.test.ts +199 -0
- package/skills/browse/test/sidebar-integration.test.ts +320 -0
- package/skills/browse/test/sidebar-unit.test.ts +96 -0
- package/skills/browse/test/snapshot.test.ts +467 -0
- package/skills/browse/test/state-ttl.test.ts +35 -0
- package/skills/browse/test/test-server.ts +57 -0
- package/skills/browse/test/url-validation.test.ts +72 -0
- package/skills/browse/test/watch.test.ts +129 -0
- package/skills/careful/bin/check-careful.sh +112 -0
- package/skills/cso/ACKNOWLEDGEMENTS.md +14 -0
- package/skills/freeze/bin/check-freeze.sh +79 -0
- package/skills/qa/references/issue-taxonomy.md +85 -0
- package/skills/qa/templates/qa-report-template.md +126 -0
- package/skills/review/TODOS-format.md +62 -0
- package/skills/review/checklist.md +220 -0
- package/skills/review/design-checklist.md +132 -0
- package/skills/review/greptile-triage.md +220 -0
- /package/{autoplan → skills/autoplan}/SKILL.md +0 -0
- /package/{autoplan → skills/autoplan}/SKILL.md.tmpl +0 -0
- /package/{benchmark → skills/benchmark}/SKILL.md +0 -0
- /package/{benchmark → skills/benchmark}/SKILL.md.tmpl +0 -0
- /package/{browse → skills/browse}/SKILL.md +0 -0
- /package/{browse → skills/browse}/SKILL.md.tmpl +0 -0
- /package/{canary → skills/canary}/SKILL.md +0 -0
- /package/{canary → skills/canary}/SKILL.md.tmpl +0 -0
- /package/{careful → skills/careful}/SKILL.md +0 -0
- /package/{careful → skills/careful}/SKILL.md.tmpl +0 -0
- /package/{codex → skills/codex}/SKILL.md +0 -0
- /package/{codex → skills/codex}/SKILL.md.tmpl +0 -0
- /package/{connect-chrome → skills/connect-chrome}/SKILL.md +0 -0
- /package/{connect-chrome → skills/connect-chrome}/SKILL.md.tmpl +0 -0
- /package/{cso → skills/cso}/SKILL.md +0 -0
- /package/{cso → skills/cso}/SKILL.md.tmpl +0 -0
- /package/{design-consultation → skills/design-consultation}/SKILL.md +0 -0
- /package/{design-consultation → skills/design-consultation}/SKILL.md.tmpl +0 -0
- /package/{design-review → skills/design-review}/SKILL.md +0 -0
- /package/{design-review → skills/design-review}/SKILL.md.tmpl +0 -0
- /package/{design-shotgun → skills/design-shotgun}/SKILL.md +0 -0
- /package/{design-shotgun → skills/design-shotgun}/SKILL.md.tmpl +0 -0
- /package/{document-release → skills/document-release}/SKILL.md +0 -0
- /package/{document-release → skills/document-release}/SKILL.md.tmpl +0 -0
- /package/{freeze → skills/freeze}/SKILL.md +0 -0
- /package/{freeze → skills/freeze}/SKILL.md.tmpl +0 -0
- /package/{gstack-upgrade → skills/gstack-upgrade}/SKILL.md +0 -0
- /package/{gstack-upgrade → skills/gstack-upgrade}/SKILL.md.tmpl +0 -0
- /package/{guard → skills/guard}/SKILL.md +0 -0
- /package/{guard → skills/guard}/SKILL.md.tmpl +0 -0
- /package/{investigate → skills/investigate}/SKILL.md +0 -0
- /package/{investigate → skills/investigate}/SKILL.md.tmpl +0 -0
- /package/{land-and-deploy → skills/land-and-deploy}/SKILL.md +0 -0
- /package/{land-and-deploy → skills/land-and-deploy}/SKILL.md.tmpl +0 -0
- /package/{office-hours → skills/office-hours}/SKILL.md +0 -0
- /package/{office-hours → skills/office-hours}/SKILL.md.tmpl +0 -0
- /package/{plan-ceo-review → skills/plan-ceo-review}/SKILL.md +0 -0
- /package/{plan-ceo-review → skills/plan-ceo-review}/SKILL.md.tmpl +0 -0
- /package/{plan-design-review → skills/plan-design-review}/SKILL.md +0 -0
- /package/{plan-design-review → skills/plan-design-review}/SKILL.md.tmpl +0 -0
- /package/{plan-eng-review → skills/plan-eng-review}/SKILL.md +0 -0
- /package/{plan-eng-review → skills/plan-eng-review}/SKILL.md.tmpl +0 -0
- /package/{qa → skills/qa}/SKILL.md +0 -0
- /package/{qa → skills/qa}/SKILL.md.tmpl +0 -0
- /package/{qa-only → skills/qa-only}/SKILL.md +0 -0
- /package/{qa-only → skills/qa-only}/SKILL.md.tmpl +0 -0
- /package/{retro → skills/retro}/SKILL.md +0 -0
- /package/{retro → skills/retro}/SKILL.md.tmpl +0 -0
- /package/{review → skills/review}/SKILL.md +0 -0
- /package/{review → skills/review}/SKILL.md.tmpl +0 -0
- /package/{setup-browser-cookies → skills/setup-browser-cookies}/SKILL.md +0 -0
- /package/{setup-browser-cookies → skills/setup-browser-cookies}/SKILL.md.tmpl +0 -0
- /package/{setup-deploy → skills/setup-deploy}/SKILL.md +0 -0
- /package/{setup-deploy → skills/setup-deploy}/SKILL.md.tmpl +0 -0
- /package/{ship → skills/ship}/SKILL.md +0 -0
- /package/{ship → skills/ship}/SKILL.md.tmpl +0 -0
- /package/{unfreeze → skills/unfreeze}/SKILL.md +0 -0
- /package/{unfreeze → skills/unfreeze}/SKILL.md.tmpl +0 -0
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|