@lincyaw/studio 0.2.0-rc.14 → 0.2.0-rc.17

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/README.md CHANGED
@@ -11,7 +11,7 @@ pnpm add -g @lincyaw/presmium
11
11
  presmium studio [dir] [--port <n>] [--host <addr>]
12
12
  ```
13
13
 
14
- Studio is included with Presmium. In a project with `pnpm add -D @lincyaw/presmium`, use `pnpm exec presmium studio`. The separate `presmium-studio` command remains available when this package is installed directly; `@lincyaw/presmium` is its required peer host.
14
+ Studio is included with Presmium. In a project with `pnpm add -D @lincyaw/presmium`, use `pnpm exec presmium studio`. The separate `presmium-studio` command remains available when this package is installed directly; it runs the `presmium` command on PATH (install it with `pnpm add -g @lincyaw/presmium`).
15
15
 
16
16
  `dir` is a workspace root (`presmium.workspace.yaml`) or a deck's directory, as for `presmium serve`. The workbench listens on 127.0.0.1, port 4320 by default (a free port when that one is in use); `--host <addr>` makes it listen on one address of the machine on the local network instead, with no login.
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/studio",
3
- "version": "0.2.0-rc.14",
3
+ "version": "0.2.0-rc.17",
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": {
@@ -38,12 +38,9 @@
38
38
  "dependencies": {
39
39
  "@deepseek-ai/dsh": "0.2.1-alpha.4",
40
40
  "jiti": "^2.7.0",
41
- "@lincyaw/dsh": "0.2.0-rc.14"
42
- },
43
- "peerDependencies": {
44
- "@lincyaw/presmium": "^1.0.0-rc.15"
41
+ "@lincyaw/dsh": "0.2.0-rc.17"
45
42
  },
46
43
  "devDependencies": {
47
- "@lincyaw/cli": "1.0.0-rc.15"
44
+ "@lincyaw/cli": "1.0.0-rc.18"
48
45
  }
49
46
  }
package/src/messages.ts CHANGED
@@ -18,6 +18,7 @@ export interface StudioMessages {
18
18
  serviceEnded: string
19
19
  appEnded: string
20
20
  modelVariables(variables: readonly string[], unset: string[]): string
21
+ presmiumMissing: string
21
22
  }
22
23
 
23
24
  export const STUDIO_MESSAGES: Record<Locale, StudioMessages> = {
@@ -42,6 +43,7 @@ presmium-studio-<散列>.log(每个安装一个)保存在 $XDG_STATE_HOME/pr
42
43
  -h, --help 显示本说明`,
43
44
  badPort: value => `--port 需要 0 到 65535 之间的端口号,而不是“${value}”。`,
44
45
  badUrl: (option, value) => `${option} 需要一个完整的网址,例如 https://studio.example.com/,而不是“${value}”。`,
46
+ presmiumMissing: 'presmium-studio 找不到 presmium 命令。Presmium Studio 随 Presmium 一起安装:请运行 pnpm add -g @lincyaw/presmium,然后用 presmium studio 启动。',
45
47
  unexpectedArgument: argument => `多余的参数“${argument}”。只能给出一个目录。`,
46
48
  notDirectory: dir => `${dir} 不是目录。请给出工作区的根目录或一份文稿所在的目录。`,
47
49
  log: file => `presmium studio: 日志在 ${file}`,
@@ -79,6 +81,7 @@ Options:
79
81
  -h, --help show this help`,
80
82
  badPort: value => `--port takes a port number from 0 to 65535, not “${value}”.`,
81
83
  badUrl: (option, value) => `${option} takes a full address, such as https://studio.example.com/, not “${value}”.`,
84
+ presmiumMissing: 'presmium-studio can’t find the presmium command. Presmium Studio comes with Presmium: run pnpm add -g @lincyaw/presmium, then start it with presmium studio.',
82
85
  unexpectedArgument: argument => `Unexpected argument “${argument}”. Give one directory.`,
83
86
  notDirectory: dir => `${dir} is not a directory. Give the workspace root, or the directory of a document.`,
84
87
  log: file => `presmium studio: log ${file}`,
package/src/studio.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { createHash, randomBytes } from 'node:crypto'
2
- import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs'
2
+ import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs'
3
3
  import { createRequire } from 'node:module'
4
4
  import { createServer, isIP } from 'node:net'
5
5
  import type { AddressInfo } from 'node:net'
6
6
  import { homedir } from 'node:os'
7
- import { dirname, join, resolve } from 'node:path'
7
+ import { delimiter, dirname, join, resolve } from 'node:path'
8
8
  import { fileURLToPath } from 'node:url'
9
9
  import { bracketIPv6, dshBin, inheritedEnv, isLauncherVariable, launchArgs, launchEnv, launchNode, launchWorkspaceServer, WEB_READY, writeProfile } from '@lincyaw/dsh/launch'
10
10
  import type { LaunchedProcess } from '@lincyaw/dsh/launch'
@@ -81,9 +81,36 @@ function installProfile(home: string, bundle: string): string {
81
81
  return name
82
82
  }
83
83
 
84
- /** The `presmium` command of this Studio's host package. */
85
- function presmiumBin(): string {
86
- return join(dirname(createRequire(join(PACKAGE_DIR, 'package.json')).resolve('@lincyaw/presmium/package.json')), 'bin', 'presmium.mjs')
84
+ /**
85
+ * The `presmium` command a Studio started by itself (`presmium-studio`) runs: `@lincyaw/presmium` where it can be
86
+ * resolved from here, else the one on PATH. `presmium studio` passes its own instead; Studio does not depend on it, which
87
+ * would make the two packages depend on each other.
88
+ */
89
+ function presmiumBin(env: NodeJS.ProcessEnv, missing: string): string {
90
+ try {
91
+ return join(dirname(createRequire(join(PACKAGE_DIR, 'package.json')).resolve('@lincyaw/presmium/package.json')), 'bin', 'presmium.mjs')
92
+ } catch {}
93
+ const names = process.platform === 'win32' ? ['presmium.cmd', 'presmium'] : ['presmium']
94
+ for (const dir of (env.PATH ?? '').split(delimiter).filter(Boolean)) {
95
+ for (const name of names) {
96
+ const script = existsSync(join(dir, name)) ? nodeScript(join(dir, name)) : undefined
97
+ if (script) return script
98
+ }
99
+ }
100
+ throw new Error(missing)
101
+ }
102
+
103
+ /** The Node script a command runs: the file itself (an npm link), or the target a pnpm shim names. */
104
+ function nodeScript(command: string): string | undefined {
105
+ try {
106
+ const file = realpathSync(command)
107
+ const head = readFileSync(file, 'utf8').slice(0, 4096)
108
+ if (/\.[cm]?js$/.test(file) || /^#!.*\bnode\b/.test(head)) return file
109
+ const target = /cmd-shim-target=(.+)$/m.exec(head)?.[1]?.trim()
110
+ return target && existsSync(target) ? target : undefined
111
+ } catch {
112
+ return undefined
113
+ }
87
114
  }
88
115
 
89
116
  const WILDCARD = /^(?:0\.0\.0\.0|::|(?:0+:){7}0+|::ffff:0\.0\.0\.0)$/i
@@ -168,7 +195,7 @@ export async function startStudio(options: StudioOptions): Promise<Studio> {
168
195
 
169
196
  try {
170
197
  const server = launchWorkspaceServer({
171
- presmium: options.presmium ?? presmiumBin(),
198
+ presmium: options.presmium ?? presmiumBin(env, t.presmiumMissing),
172
199
  dir: resolve(options.dir),
173
200
  serviceToken,
174
201
  ...options.previewPort ? { port: options.previewPort } : {},