@lincyaw/studio 0.2.0-rc.55 → 0.2.0-rc.57

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/studio",
3
- "version": "0.2.0-rc.55",
3
+ "version": "0.2.0-rc.57",
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,9 +39,9 @@
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.55"
42
+ "@lincyaw/dsh": "0.2.0-rc.57"
43
43
  },
44
44
  "devDependencies": {
45
- "@lincyaw/cli": "1.0.0-rc.56"
45
+ "@lincyaw/cli": "1.0.0-rc.58"
46
46
  }
47
47
  }
package/src/cli.ts CHANGED
@@ -64,6 +64,7 @@ export async function main(argv: string[], options: MainOptions = {}): Promise<n
64
64
  for (const url of studio.networkUrls) process.stdout.write(`network ${url}\n`)
65
65
  process.stdout.write(`mcp ${studio.mcp.url}\n`)
66
66
  process.stderr.write(`${t.mcpToken(studio.mcp.tokenFile)}\n`)
67
+ if (studio.mcp.movedFrom) process.stderr.write(`${t.previewPortMoved(studio.mcp.movedFrom, studio.mcp.url)}\n`)
67
68
  process.stderr.write(`${t.log(studio.log)}\n`)
68
69
  if (values.host && values.host !== '127.0.0.1' && values.host !== '::1' && !values['public-url']) {
69
70
  process.stderr.write(`${studio.networkUrls.length
package/src/messages.ts CHANGED
@@ -14,6 +14,7 @@ export interface StudioMessages {
14
14
  ended(how: string, log: string): string
15
15
  portInUse(port: number, address: string): string
16
16
  previewPortInUse(port: number, address: string): string
17
+ previewPortMoved(port: number, url: string): string
17
18
  mcpToken(file: string): string
18
19
  badMcpToken(file: string): string
19
20
  noFreePort(address: string): string
@@ -43,7 +44,7 @@ presmium-studio-<散列>.log(每个安装一个)保存在 $XDG_STATE_HOME/pr
43
44
  它的主机受信任,打印的网址用它。代理需保留 Host 并转发 WebSocket
44
45
  --preview-url <网址> 同样情况下预览所在的地址,由代理转发到工作区服务;可以带路径,
45
46
  此时它必须与 Studio 不同源,否则预览中文稿的代码能读到 Studio 的会话
46
- --preview-port <端口> 工作区服务与 HTTP MCP 的固定端口(默认 4321);0 为随机端口
47
+ --preview-port <端口> 工作区服务与 HTTP MCP 的固定端口(默认 4321,被占用时换一个空闲端口);0 为随机端口
47
48
  -h, --help 显示本说明`,
48
49
  badPort: value => `--port 需要 0 到 65535 之间的端口号,而不是“${value}”。`,
49
50
  badUrl: (option, value) => `${option} 需要一个完整的网址,例如 https://studio.example.com/,而不是“${value}”。`,
@@ -56,6 +57,7 @@ presmium-studio-<散列>.log(每个安装一个)保存在 $XDG_STATE_HOME/pr
56
57
  ended: (how, log) => `presmium studio: ${how}。日志在 ${log}`,
57
58
  portInUse: (port, address) => `${address} 的端口 ${port} 已被占用。请用 --port 指定另一个端口。`,
58
59
  previewPortInUse: (port, address) => `${address} 的工作区与 MCP 端口 ${port} 已被占用。请停止占用它的服务,或用 --preview-port 指定另一个固定端口。`,
60
+ previewPortMoved: (port, url) => `presmium studio: 端口 ${port} 已被占用,这次的 MCP 地址是 ${url}。按默认地址配置的 MCP 客户端这次连不上;需要固定地址时,用 --preview-port 指定一个空闲端口。`,
59
61
  mcpToken: file => `presmium studio: MCP 客户端使用 HTTP(Streamable HTTP),从 ${file} 读取访问令牌,设置 Authorization: Bearer <访问令牌>;同一目录重启与升级后保持不变。`,
60
62
  badMcpToken: file => `MCP 访问令牌文件 ${file} 无效。请移走该文件后重试,并在客户端更新访问令牌。`,
61
63
  noFreePort: address => `${address} 上没有空闲的端口。请停止占用端口的服务后重试。`,
@@ -85,7 +87,7 @@ Options:
85
87
  --preview-url <url> in that case, the address of the previews, forwarded to the workspace service; it
86
88
  may have a path, and should be another origin than Studio’s, or the documents’ code in
87
89
  previews can read Studio’s session
88
- --preview-port <n> fixed workspace-service and HTTP MCP port (default: 4321); 0 requests a random port
90
+ --preview-port <n> fixed workspace-service and HTTP MCP port (default: 4321, or a free one when that is in use); 0 requests a random port
89
91
  -h, --help show this help`,
90
92
  badPort: value => `--port takes a port number from 0 to 65535, not “${value}”.`,
91
93
  badUrl: (option, value) => `${option} takes a full address, such as https://studio.example.com/, not “${value}”.`,
@@ -98,6 +100,7 @@ Options:
98
100
  ended: (how, log) => `presmium studio: ${how}; the log is ${log}`,
99
101
  portInUse: (port, address) => `Port ${port} of ${address} is in use. Give another with --port.`,
100
102
  previewPortInUse: (port, address) => `Workspace and MCP port ${port} of ${address} is in use. Stop the service using it, or choose another fixed port with --preview-port.`,
103
+ previewPortMoved: (port, url) => `presmium studio: port ${port} is in use, so the MCP address is ${url} this time. MCP clients set up with the usual address cannot reach it; for a fixed address, choose a free port with --preview-port.`,
101
104
  mcpToken: file => `presmium studio: MCP clients use HTTP (Streamable HTTP); read the access token from ${file} and set Authorization: Bearer <value>. It stays the same for this directory across restarts and upgrades.`,
102
105
  badMcpToken: file => `MCP access token file ${file} is invalid. Move it aside and retry, then update the access token in your clients.`,
103
106
  noFreePort: address => `There is no free port on ${address}. Stop a service that uses one, then retry.`,
package/src/studio.ts CHANGED
@@ -31,7 +31,7 @@ export interface StudioOptions {
31
31
  */
32
32
  publicUrl?: string
33
33
  previewUrl?: string
34
- /** The workspace service and HTTP MCP port (default: 4321). Zero explicitly requests a free port. */
34
+ /** The workspace service and HTTP MCP port. Without it Studio uses 4321, or a free port when 4321 is in use; zero requests a free port. */
35
35
  previewPort?: number
36
36
  env?: NodeJS.ProcessEnv
37
37
  presmium?: string
@@ -43,7 +43,8 @@ export interface Studio {
43
43
  url: string
44
44
  networkUrls: string[]
45
45
  workspaceServerUrl: string
46
- mcp: { url: string, tokenFile: string }
46
+ /** `movedFrom` is the default port when it was in use and the MCP address differs from the usual one. */
47
+ mcp: { url: string, tokenFile: string, movedFrom?: number }
47
48
  root: string
48
49
  home: string
49
50
  log: string
@@ -221,8 +222,14 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
221
222
  }
222
223
  const boundAddress = listenAddress ?? '127.0.0.1'
223
224
  const wildcard = WILDCARD.test(boundAddress)
224
- const previewPort = options.previewPort ?? DEFAULT_PREVIEW_PORT
225
- if (previewPort !== 0 && await freePort(boundAddress, previewPort) === undefined) throw new Error(t.previewPortInUse(previewPort, boundAddress))
225
+ // External MCP clients keep the default address, so it is preferred; an explicit port must be free.
226
+ let previewPort = options.previewPort ?? DEFAULT_PREVIEW_PORT
227
+ let movedFrom: number | undefined
228
+ if (previewPort !== 0 && await freePort(boundAddress, previewPort) === undefined) {
229
+ if (options.previewPort !== undefined) throw new Error(t.previewPortInUse(previewPort, boundAddress))
230
+ movedFrom = previewPort
231
+ previewPort = 0
232
+ }
226
233
  const port = await choosePort(boundAddress, options.port)
227
234
  const dshAddress = wildcard ? '127.0.0.1' : boundAddress
228
235
  const dshPort = wildcard ? await choosePort(dshAddress, undefined) : port
@@ -312,7 +319,7 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
312
319
  url: address,
313
320
  networkUrls,
314
321
  workspaceServerUrl: url,
315
- mcp: { url: mcpUrl.href, tokenFile },
322
+ mcp: { url: mcpUrl.href, tokenFile, ...movedFrom ? { movedFrom } : {} },
316
323
  root,
317
324
  home,
318
325
  log: log.file,