FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
browsercode/packages/opencode/script/run-workspace-server at main · code2labgit/browsercode · GitHub
code2labgit
/
browsercode
Public
forked from
browser-use/browsercode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
browsercode
/
packages
/
opencode
/
script
/
run-workspace-server
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
106 lines (87 loc) · 2.74 KB
Breadcrumbs
browsercode
/
packages
/
opencode
/
script
/
run-workspace-server
Copy path
File metadata and controls
executable file
·
106 lines (87 loc) · 2.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bun
// This script runs a separate OpenCode server to be used as a remote
// workspace, simulating a remote environment but all local to make
// debugger easier
//
// *Important*: make sure you add the debug workspace plugin first.
// In `.opencode/opencode.jsonc` in the root of this project add:
//
// "plugin": ["../packages/opencode/src/control-plane/dev/debug-workspace-plugin.ts"]
//
// Afterwards, run `./packages/opencode/script/run-workspace-server`
import
{
stat
}
from
"node:fs/promises"
import
{
setTimeout
as
sleep
}
from
"node:timers/promises"
const
DEV_DATA_FILE
=
"/tmp/opencode-workspace-dev-data.json"
const
RESTART_POLL_INTERVAL
=
250
async
function
readData
(
)
{
return
await
Bun
.
file
(
DEV_DATA_FILE
)
.
json
(
)
}
async
function
readDataMtime
(
)
{
return
await
stat
(
DEV_DATA_FILE
)
.
then
(
(
info
)
=>
info
.
mtimeMs
)
.
catch
(
(
error
)
=>
{
if
(
typeof
error
===
"object"
&&
error
&&
"code"
in
error
&&
error
.
code
===
"ENOENT"
)
{
return
undefined
}
throw
error
}
)
}
async
function
readSnapshot
(
)
{
while
(
true
)
{
try
{
const
before
=
await
readDataMtime
(
)
if
(
before
===
undefined
)
{
await
sleep
(
RESTART_POLL_INTERVAL
)
continue
}
const
data
=
await
readData
(
)
const
after
=
await
readDataMtime
(
)
if
(
before
===
after
)
{
return
{
data
,
mtime
:
after
}
}
}
catch
(
error
)
{
if
(
typeof
error
===
"object"
&&
error
&&
"code"
in
error
&&
error
.
code
===
"ENOENT"
)
{
await
sleep
(
RESTART_POLL_INTERVAL
)
continue
}
throw
error
}
}
}
function
startDevServer
(
data
:
any
)
{
const
env
=
Object
.
fromEntries
(
Object
.
entries
(
data
.
env
??
{
}
)
.
filter
(
(
[
,
value
]
)
=>
value
!==
undefined
)
)
return
Bun
.
spawn
(
[
"bun"
,
"run"
,
"dev"
,
"serve"
,
"--port"
,
String
(
data
.
port
)
,
"--print-logs"
]
,
{
env
:
{
...
process
.
env
,
...
env
,
XDG_DATA_HOME
:
"/tmp/data"
,
}
,
stdin
:
"inherit"
,
stdout
:
"inherit"
,
stderr
:
"inherit"
,
}
)
}
async
function
waitForRestartSignal
(
mtime
:
number
,
signal
:
AbortSignal
)
{
while
(
!
signal
.
aborted
)
{
await
sleep
(
RESTART_POLL_INTERVAL
)
if
(
signal
.
aborted
)
return
false
if
(
(
await
readDataMtime
(
)
)
!==
mtime
)
return
true
}
return
false
}
while
(
true
)
{
const
{
data
,
mtime
}
=
await
readSnapshot
(
)
const
proc
=
startDevServer
(
data
)
const
restartAbort
=
new
AbortController
(
)
const
result
=
await
Promise
.
race
(
[
proc
.
exited
.
then
(
(
code
)
=>
(
{
type
:
"exit"
as
const
,
code
}
)
)
,
waitForRestartSignal
(
mtime
,
restartAbort
.
signal
)
.
then
(
(
restart
)
=>
(
{
type
:
"restart"
as
const
,
restart
}
)
)
,
]
)
restartAbort
.
abort
(
)
if
(
result
.
type
===
"restart"
&&
result
.
restart
)
{
proc
.
kill
(
)
await
proc
.
exited
continue
}
process
.
exit
(
result
.
code
)
}
Back
|
FazBrowse Home
|
New Git URL