Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions browse/bin/find-browse
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ DIR="$(cd "$(dirname "$0")/.." && pwd)/dist"
if test -x "$DIR/find-browse"; then
exec "$DIR/find-browse" "$@"
fi
if test -x "$DIR/find-browse.exe"; then
exec "$DIR/find-browse.exe" "$@"
fi
# Fallback: basic discovery with priority chain
ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
if test "$(uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]')" = "mingw64_nt" || \
test "$(uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]')" = "mingw32_nt" || \
test "$(uname -s 2>/dev/null | tr '[:upper:]' '[:lower:]')" = "msys_nt"; then
BROWSE_BIN="browse.exe"
else
BROWSE_BIN="browse"
fi
for MARKER in .codex .agents .claude; do
if [ -n "$ROOT" ] && test -x "$ROOT/$MARKER/skills/gstack/browse/dist/browse"; then
echo "$ROOT/$MARKER/skills/gstack/browse/dist/browse"
if [ -n "$ROOT" ] && test -x "$ROOT/$MARKER/skills/gstack/browse/dist/$BROWSE_BIN"; then
echo "$ROOT/$MARKER/skills/gstack/browse/dist/$BROWSE_BIN"
exit 0
fi
if test -x "$HOME/$MARKER/skills/gstack/browse/dist/browse"; then
echo "$HOME/$MARKER/skills/gstack/browse/dist/browse"
if test -x "$HOME/$MARKER/skills/gstack/browse/dist/$BROWSE_BIN"; then
echo "$HOME/$MARKER/skills/gstack/browse/dist/$BROWSE_BIN"
exit 0
fi
done
Expand Down
4 changes: 2 additions & 2 deletions browse/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function resolveServerScript(
);
}

const SERVER_SCRIPT = resolveServerScript();
const SERVER_SCRIPT = IS_WINDOWS ? null : resolveServerScript();

/**
* On Windows, resolve the Node.js-compatible server bundle.
Expand Down Expand Up @@ -240,7 +240,7 @@ async function startServer(extraEnv?: Record<string, string>): Promise<ServerSta
Bun.spawnSync(['node', '-e', launcherCode], { stdio: ['ignore', 'ignore', 'ignore'] });
} else {
// macOS/Linux: Bun.spawn + unref works correctly
proc = Bun.spawn(['bun', 'run', SERVER_SCRIPT], {
proc = Bun.spawn(['bun', 'run', SERVER_SCRIPT!], {
stdio: ['ignore', 'pipe', 'pipe'],
env: { ...process.env, BROWSE_STATE_FILE: config.stateFile, ...extraEnv },
});
Expand Down
6 changes: 4 additions & 2 deletions browse/src/find-browse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { existsSync } from 'fs';
import { join } from 'path';
import { homedir } from 'os';

const BROWSE_BIN = process.platform === 'win32' ? 'browse.exe' : 'browse';

// ─── Binary Discovery ───────────────────────────────────────────

function getGitRoot(): string | null {
Expand All @@ -32,14 +34,14 @@ export function locateBinary(): string | null {
// Workspace-local takes priority (for development)
if (root) {
for (const m of markers) {
const local = join(root, m, 'skills', 'gstack', 'browse', 'dist', 'browse');
const local = join(root, m, 'skills', 'gstack', 'browse', 'dist', BROWSE_BIN);
if (existsSync(local)) return local;
}
}

// Global fallback
for (const m of markers) {
const global = join(home, m, 'skills', 'gstack', 'browse', 'dist', 'browse');
const global = join(home, m, 'skills', 'gstack', 'browse', 'dist', BROWSE_BIN);
if (existsSync(global)) return global;
}

Expand Down
5 changes: 5 additions & 0 deletions browse/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ describe('resolveServerScript', () => {
expect(() => resolveServerScript({}, '/nonexistent/$bunfs', '/nonexistent/browse'))
.toThrow('Cannot find server.ts');
});

test('Windows startup does not eagerly resolve server.ts at module load', () => {
const src = require('fs').readFileSync(require('path').join(__dirname, '../src/cli.ts'), 'utf-8');
expect(src).toContain('const SERVER_SCRIPT = IS_WINDOWS ? null : resolveServerScript();');
});
});

describe('resolveNodeServerScript', () => {
Expand Down
5 changes: 5 additions & 0 deletions browse/test/find-browse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe('locateBinary', () => {
expect(agentsIdx).toBeLessThan(claudeIdx);
});

test('Windows discovery uses .exe browse binaries', () => {
const src = require('fs').readFileSync(require('path').join(__dirname, '../src/find-browse.ts'), 'utf-8');
expect(src).toContain("process.platform === 'win32' ? 'browse.exe' : 'browse'");
});

test('function signature accepts no arguments', () => {
// locateBinary should be callable with no arguments
expect(typeof locateBinary).toBe('function');
Expand Down
3 changes: 3 additions & 0 deletions setup
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ create_codex_runtime_root() {
if [ -d "$gstack_dir/bin" ]; then
ln -snf "$gstack_dir/bin" "$codex_gstack/bin"
fi
if [ -d "$gstack_dir/node_modules" ]; then
ln -snf "$gstack_dir/node_modules" "$codex_gstack/node_modules"
fi
if [ -d "$gstack_dir/browse/dist" ]; then
ln -snf "$gstack_dir/browse/dist" "$codex_gstack/browse/dist"
fi
Expand Down
1 change: 1 addition & 0 deletions test/gen-skill-docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,7 @@ describe('setup script validation', () => {
const fnEnd = setupContent.indexOf('}', setupContent.indexOf('done', setupContent.indexOf('review/', fnStart)));
const fnBody = setupContent.slice(fnStart, fnEnd);
expect(fnBody).toContain('gstack/SKILL.md');
expect(fnBody).toContain('node_modules');
expect(fnBody).toContain('browse/dist');
expect(fnBody).toContain('browse/bin');
expect(fnBody).toContain('gstack-upgrade/SKILL.md');
Expand Down