GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode/packages/opencode/script/run-workspace-server at dev · ildella/opencode

Expand file tree

/

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
/

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)
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.