@lincyaw/studio 0.2.0-rc.100 → 0.2.0-rc.101
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/package.json +4 -4
- package/src/studio.ts +24 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/studio",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.101",
|
|
4
4
|
"description": "presmium studio: Presmium's workbench on DeepSeek Harness in one command, with the workspace service of a directory (experimental)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@deepseek-ai/dsh": "0.2.1-alpha.4",
|
|
40
40
|
"http-proxy-3": "2.0.1",
|
|
41
41
|
"jiti": "^2.7.0",
|
|
42
|
-
"@lincyaw/dsh": "0.2.0-rc.
|
|
43
|
-
"@lincyaw/kernel": "1.0.0-rc.
|
|
42
|
+
"@lincyaw/dsh": "0.2.0-rc.101",
|
|
43
|
+
"@lincyaw/kernel": "1.0.0-rc.102"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@lincyaw/cli": "1.0.0-rc.
|
|
46
|
+
"@lincyaw/cli": "1.0.0-rc.102"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/studio.ts
CHANGED
|
@@ -170,12 +170,12 @@ function freePort(listenAddress: string, port: number): Promise<number | undefin
|
|
|
170
170
|
})
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
async function choosePort(listenAddress: string, port: number | undefined): Promise<number> {
|
|
173
|
+
async function choosePort(listenAddress: string, port: number | undefined, preferred?: number): Promise<number> {
|
|
174
174
|
if (port) {
|
|
175
175
|
if (await freePort(listenAddress, port) === undefined) throw new Error(STUDIO_MESSAGES[systemLocale()].portInUse(port, listenAddress))
|
|
176
176
|
return port
|
|
177
177
|
}
|
|
178
|
-
const chosen = (port === undefined ? await freePort(listenAddress, DEFAULT_PORT) : undefined) ?? await freePort(listenAddress, 0)
|
|
178
|
+
const chosen = (port === undefined ? (preferred ? await freePort(listenAddress, preferred) : undefined) ?? await freePort(listenAddress, DEFAULT_PORT) : undefined) ?? await freePort(listenAddress, 0)
|
|
179
179
|
if (chosen === undefined) throw new Error(STUDIO_MESSAGES[systemLocale()].noFreePort(listenAddress))
|
|
180
180
|
return chosen
|
|
181
181
|
}
|
|
@@ -234,7 +234,19 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
234
234
|
movedFrom = previewPort
|
|
235
235
|
previewPort = 0
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const home = studioHome(env)
|
|
238
|
+
mkdirSync(home, { recursive: true, mode: 0o700 })
|
|
239
|
+
// Preserve the browser origin (and its caches/return state) when the default port is held by another app.
|
|
240
|
+
const portFile = options.port === undefined && listenAddress === undefined && !options.publicUrl
|
|
241
|
+
? join(home, 'ports', `${createHash('sha256').update(realpathSync(options.dir)).digest('hex').slice(0, 32)}.json`) : undefined
|
|
242
|
+
let preferredPort: number | undefined
|
|
243
|
+
if (portFile) {
|
|
244
|
+
try {
|
|
245
|
+
const saved = JSON.parse(readFileSync(portFile, 'utf8')) as { port?: unknown }
|
|
246
|
+
if (typeof saved.port === 'number' && Number.isInteger(saved.port) && saved.port > 0 && saved.port <= 65535) preferredPort = saved.port
|
|
247
|
+
} catch { /* A missing preference uses the normal default/free-port selection. */ }
|
|
248
|
+
}
|
|
249
|
+
const port = await choosePort(boundAddress, options.port, preferredPort)
|
|
238
250
|
const dshAddress = wildcard ? '127.0.0.1' : boundAddress
|
|
239
251
|
const dshPort = wildcard ? await choosePort(dshAddress, undefined) : port
|
|
240
252
|
const hosts = wildcard ? networkHosts() : []
|
|
@@ -245,8 +257,6 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
245
257
|
? [...hosts.map(host => httpOrigin(host, port)), httpOrigin('127.0.0.1', port), `http://localhost:${port}`]
|
|
246
258
|
: [httpOrigin(boundAddress, port), ...boundAddress === '127.0.0.1' ? [`http://localhost:${port}`] : []]
|
|
247
259
|
|
|
248
|
-
const home = studioHome(env)
|
|
249
|
-
mkdirSync(home, { recursive: true, mode: 0o700 })
|
|
250
260
|
const bundle = bundleDir()
|
|
251
261
|
const profile = installProfile(home, bundle)
|
|
252
262
|
writeProfile(home, profile, 'web', bundle)
|
|
@@ -344,6 +354,15 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
|
|
|
344
354
|
})
|
|
345
355
|
started.push(dsh)
|
|
346
356
|
const backend = (await dsh.ready(WEB_READY))[1]!
|
|
357
|
+
if (portFile) {
|
|
358
|
+
try {
|
|
359
|
+
const content = `${JSON.stringify({ port })}\n`
|
|
360
|
+
if (!existsSync(portFile) || readFileSync(portFile, 'utf8') !== content) {
|
|
361
|
+
mkdirSync(dirname(portFile), { recursive: true, mode: 0o700 })
|
|
362
|
+
writeFileSync(portFile, content, { mode: 0o600 })
|
|
363
|
+
}
|
|
364
|
+
} catch { /* Failure to retain a preferred port must not prevent opening the workspace. */ }
|
|
365
|
+
}
|
|
347
366
|
if (wildcard) proxy = await startProxy({ host: boundAddress, port, target: `http://${authority(dshAddress, dshPort)}` })
|
|
348
367
|
dsh.stopBuffering()
|
|
349
368
|
const address = studioUrl(backend, options.publicUrl, primaryHost, port)
|