lantern-harness 0.1.36 → 0.1.38

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +9 -15
  3. package/builtin/session/lh-spaces.mjs +8 -2
  4. package/builtin/session/space-context.mjs +2 -2
  5. package/cli/data-root.mjs +2 -2
  6. package/cli/lantern.mjs +149 -24
  7. package/cli/user-config.mjs +108 -10
  8. package/dist/500.html +3 -3
  9. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.CvmRHkFv.js → Base.astro_astro_type_script_index_0_lang.C17uMscj.js} +1 -1
  10. package/dist/_astro/{CaseGenerateApp.BxkQ-HTK.js → CaseGenerateApp.fUXTG_NE.js} +1 -1
  11. package/dist/_astro/{CasesLibrary.BU1q0MvV.js → CasesLibrary.CVPhAnFf.js} +1 -1
  12. package/dist/_astro/{ChatApp.DXlSptIj.js → ChatApp.KceL1TNg.js} +1 -1
  13. package/dist/_astro/{DashboardBoard.BuyuI8WW.js → DashboardBoard.BTFyQf9w.js} +1 -1
  14. package/dist/_astro/{PluginsPage.Bxu1FEvU.js → PluginsPage.BFEwg0vr.js} +1 -1
  15. package/dist/_astro/PluginsPage.CPEoYrlx.js +1 -0
  16. package/dist/_astro/{PromptsLibrary.D3huSjPf.js → PromptsLibrary.CNLcQ66B.js} +1 -1
  17. package/dist/_astro/{ReqAnalysisBoard.DGrYx1I5.js → ReqAnalysisBoard.DaOV-2Z2.js} +1 -1
  18. package/dist/_astro/{SettingsDialog.C3qqpZPT.js → SettingsDialog.DFnXkw7a.js} +1 -1
  19. package/dist/_astro/app-version.BsRPDlqD.js +1 -0
  20. package/dist/_astro/{case-gen-run.BWQpCgpW.js → case-gen-run.BaUxa_BR.js} +1 -1
  21. package/dist/_astro/{req-analysis.BOz9djQo.js → req-analysis.ilj0McI3.js} +1 -1
  22. package/dist/_astro/{story-review.Bvz3alFd.js → story-review.Bsm2JWdj.js} +1 -1
  23. package/dist/case-exec/index.html +3 -3
  24. package/dist/cases/generate/index.html +4 -4
  25. package/dist/cases/library/index.html +4 -4
  26. package/dist/dashboard/index.html +4 -4
  27. package/dist/docs/changelog/index.html +63 -42
  28. package/dist/docs/install/index.html +19 -10
  29. package/dist/docs/manual/index.html +7 -4
  30. package/dist/knowledge/index.html +3 -3
  31. package/dist/life/kr-tasks/index.html +3 -3
  32. package/dist/life/kr-todos/index.html +3 -3
  33. package/dist/life/objectives/index.html +3 -3
  34. package/dist/life/reviews/index.html +3 -3
  35. package/dist/life/stages/index.html +3 -3
  36. package/dist/life/year-plans/index.html +3 -3
  37. package/dist/plugins/index.html +4 -4
  38. package/dist/pm/bugs/index.html +3 -3
  39. package/dist/pm/iterations/index.html +3 -3
  40. package/dist/pm/projects/detail/index.html +3 -3
  41. package/dist/pm/projects/index.html +3 -3
  42. package/dist/pm/requirements/index.html +3 -3
  43. package/dist/prompts/index.html +4 -4
  44. package/dist/reports/index.html +3 -3
  45. package/dist/requirement-analysis/index.html +4 -4
  46. package/dist/requirements/index.html +3 -3
  47. package/dist/tasks/index.html +3 -3
  48. package/dist/templates/index.html +3 -3
  49. package/dist/test-automation/index.html +3 -3
  50. package/dist/test-stats/index.html +3 -3
  51. package/dist/todos/index.html +3 -3
  52. package/dist/workbench/index.html +4 -4
  53. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +16 -6
  54. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +3 -1
  55. package/package.json +2 -2
  56. package/dist/_astro/PluginsPage.C_hLqPed.js +0 -1
  57. package/dist/_astro/app-version.BuvzE2YQ.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # 版本日志
2
2
 
3
+ ## [0.1.38] - 2026-11-03
4
+
5
+ 本地开发与产品服务可各自选择数据空间池根;选成同一路径即共用数据,`lantern init` 支持按作用域再初始化。
6
+
7
+ ### 新增
8
+
9
+ - **双池根配置**:`dataRoot` 供 `lantern web` / npx,`devDataRoot` 供 `pnpm dev`;未单独配置开发池根时回退产品池根,再没有则回退源码仓库根
10
+ - **`lantern init --scope`**:`both`(默认)/ `web` / `dev`,交互未带参数时也会询问作用域;`lantern status` 同时展示产品与开发池根
11
+
12
+ ### 修复
13
+
14
+ - **`pnpm dev` 写死仓库根**:开发服改为读取本机开发池根,空间管理扫描与业务数据可与产品服务指向同一目录(例如 iCloud 池根)
15
+
16
+ ### 优化
17
+
18
+ - **`pnpm start`**:不再强制 `--dir .`,与 init 记住的产品池根一致
19
+ - **`lantern init` 收尾提示**:按作用域(产品 / 开发 / 两者)与启动环境(源码 / 全局 / npx)显示对应下一步命令,不再一律写 `lantern web`
20
+
21
+ ## [0.1.37] - 2026-11-02
22
+
23
+ 仪表盘「测试统计」改按维度累加全部统计日数量,与测试统计页顶部合计口径一致。
24
+
25
+ ### 修复
26
+
27
+ - **仪表盘测试统计只显示最新一天**:柱状图按维度把所有统计日数量加总后再排序展示(最多 10 个维度),不再只取最新一条
28
+
3
29
  ## [0.1.36] - 2026-11-02
4
30
 
5
31
  工作汇报支持删除与卡片选中;本期数据改回起止 / 统计日期筛选,用例执行按项目基线注入;写汇报不再挂到已归档会话;待办分组头胶囊与整行悬停对齐。
@@ -21,7 +47,6 @@
21
47
 
22
48
  - **本期工作数据筛选**:待办 / 任务看计划起止(无则创建日),测试统计看统计日期,用例执行看统计日期或起止与区间相交;不用修改时间
23
49
  - **分组头整行可点**:待办与人生管理分组行任意位置展开 / 收起
24
- - **操作手册 / 提示词示例**:同步删除、选中、筛选、基线与跳转口径
25
50
 
26
51
  ## [0.1.35] - 2026-11-01
27
52
 
package/README.md CHANGED
@@ -30,32 +30,26 @@ npx lantern-harness
30
30
 
31
31
  执行后会安装全局短命令 `lantern`,之后用 `lantern init` / `lantern web` 操作即可。升级有两种方式:终端执行 `lantern update`(在跑的服务会自动停掉、装完重新拉起),或在页面「设置 → 通用 → 平台版本」点「检查更新 / 更新并重启」——有新版本时侧栏版本号旁会出现小圆点,但**不会在后台自动升级**,点按钮才装。`npx` 模式下的页面更新会先装到全局,再用全局 `lantern` 启动。
32
32
 
33
- 2、 初始化数据空间(首次必做;可再次执行以更换数据空间):
33
+ 2、 初始化数据空间池根(首次必做;可再次执行以更换):
34
34
 
35
35
  ```bash
36
- lantern init
36
+ lantern init # 默认同时写入产品与开发池根
37
+ lantern init --scope=web # 仅 lantern web / npx
38
+ lantern init --scope=dev # 仅 pnpm dev
37
39
  ```
38
40
 
39
- 按序号选择数据空间:
40
-
41
- ```text
42
- 选择数据目录:
43
- 1) 打开系统文件夹选择器
44
- 2) 当前目录(当前终端所在位置)
45
- 3) 自定义路径(手输)
46
- 请输入 1 / 2 / 3(默认 1):
47
- ```
41
+ 按序号选择目录后再选作用域。`dataRoot` 与 `devDataRoot` 路径相同则共用数据,不同则分离;未单独配置开发池根时 `pnpm dev` 回退产品池根。
48
42
 
49
43
  3、 常用命令:
50
44
 
51
45
  ```bash
52
- lantern init # 选择并记住数据空间
46
+ lantern init # 选择并记住池根(可加 --scope)
53
47
  lantern web # 启动本地 Web 服务
54
48
  lantern stop # 停止服务
55
49
  lantern restart # 重启服务
56
- lantern status # 运行状态、端口、数据空间
50
+ lantern status # 运行状态、端口、产品/开发池根
57
51
  lantern open # 在浏览器中打开工作台
58
- lantern path # 显示当前数据空间路径
52
+ lantern path # 显示产品池根路径
59
53
  lantern config # 显示配置文件地址
60
54
  lantern logs # 查看服务日志
61
55
  lantern doctor # 检查运行环境与配置是否正常
@@ -89,7 +83,7 @@ git clone https://github.com/yychuiyan/lantern-harness.git
89
83
  cd lantern-harness
90
84
  ```
91
85
 
92
- 2、 开发模式(热更新,含本地落盘 API):
86
+ 2、 开发模式(热更新,含本地落盘 API;池根见上文 `lantern init --scope=dev`):
93
87
 
94
88
  ```bash
95
89
  pnpm install
@@ -44,7 +44,7 @@ import {
44
44
  setRegistryRoot,
45
45
  spaceSize,
46
46
  } from '../../cli/spaces.mjs';
47
- import { loadRunState, saveRunState } from '../../cli/user-config.mjs';
47
+ import { loadRunState, resolveRuntimeSpacesRoot, saveRunState } from '../../cli/user-config.mjs';
48
48
  import { closeAllBashSessions } from './bash-session.mjs';
49
49
  import { closeAllPwshSessions } from './pwsh-session.mjs';
50
50
  import { hasRunningSessions } from './session-runs.mjs';
@@ -230,8 +230,14 @@ export function lhSpacesPlugin() {
230
230
  return {
231
231
  name: 'lh-spaces',
232
232
  configureServer(server) {
233
+ // Vite 项目根 ≠ 数据池根:优先本机 devDataRoot / dataRoot,否则回退仓库根
234
+ const resolved = resolveRuntimeSpacesRoot({
235
+ role: 'dev',
236
+ fallback: server.config.root,
237
+ });
238
+ const spacesRoot = resolved.ok ? resolved.dataRoot : server.config.root;
233
239
  // 首次进入确定基准根;已切换过的空间不会被覆盖
234
- ensureSpaceContext(server.config.root);
240
+ ensureSpaceContext(spacesRoot);
235
241
  // 注册表按池根分区:先告诉它当前是哪个数据目录,才能只认自己的空间与激活项
236
242
  setRegistryRoot(getBaseRoot());
237
243
  // 新进程里 activeRoot 默认是公共空间:按注册表回到用户上次选的空间
@@ -4,7 +4,7 @@
4
4
  * 单空间时代各插件在 configureServer 里把 root 抓进闭包,导致切换空间只能重启进程;
5
5
  * 这里改为惰性读取(每个请求调用 getDataRoot()),切换只需 setActiveRoot()。
6
6
  *
7
- * - baseRoot(池根):打包运行 = lantern 记住的数据目录;本地 astro dest 为仓库根
7
+ * - baseRoot(池根):产品 = config.dataRoot;开发 = config.devDataRoot(可回退 dataRoot / 仓库根)
8
8
  * - activeRoot:当前生效的空间目录;未切换时 = 公共空间路径
9
9
  *
10
10
  * 路径口径全部来自 `space-layout.mjs`,本模块只管「当前是哪个」。
@@ -33,7 +33,7 @@ export function ensureSpaceContext(root) {
33
33
  return activeRoot;
34
34
  }
35
35
 
36
- /** 池根(dev = 仓库根,打包 = lantern 记住的数据目录) */
36
+ /** 池根(由 ensureSpaceContext 在启动时写入) */
37
37
  export function getBaseRoot() {
38
38
  return baseRoot || process.cwd();
39
39
  }
package/cli/data-root.mjs CHANGED
@@ -5,8 +5,8 @@
5
5
  * / `builtin/session/lh-spaces.mjs`)都要用,但这几个模块之间不能互相 import(会成环)。
6
6
  *
7
7
  * 两个层级要分清(命名与相对路径统一来自 `builtin/session/space-layout.mjs`):
8
- * - 池根(spaces root):用户选中的文件夹;打包模式 = lantern 记住的目录,dev = 仓库根
9
- * - 空间目录:用户数据目录下直接是「公共空间」;源码仓库根则在 `空间池/` 里
8
+ * - 池根(spaces root):用户选中的文件夹;产品 = dataRoot,开发 = devDataRoot(可同可异)
9
+ * - 空间目录:用户数据目录下直接是「公共空间」;池根若是本仓库则在 `空间池/` 里
10
10
  */
11
11
  import fs from 'node:fs';
12
12
  import path from 'node:path';
package/cli/lantern.mjs CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  import { prepareSpaceDir, prepareSpacesRoot, startLocalServer } from './server.mjs';
30
30
  import {
31
31
  clearDataRootFromConfig,
32
+ clearDevDataRootFromConfig,
32
33
  clearRunState,
33
34
  ensureLogFile,
34
35
  getConfigPath,
@@ -36,10 +37,12 @@ import {
36
37
  isPidAlive,
37
38
  loadRunState,
38
39
  loadUserConfig,
40
+ normalizeDataRootScope,
39
41
  printDataRootUnavailable,
40
42
  resolveConfiguredDataRoot,
43
+ resolveRuntimeSpacesRoot,
44
+ saveDataRootForScope,
41
45
  saveRunState,
42
- saveUserConfig,
43
46
  } from './user-config.mjs';
44
47
  import {
45
48
  copySpace,
@@ -130,13 +133,16 @@ function printHelp() {
130
133
  console.log(`${APP_NAME} · lantern
131
134
 
132
135
  用法:
133
- lantern init 选择并记住数据空间
136
+ lantern init 选择并记住数据空间池根
137
+ lantern init --scope=both 同时写入产品与本地开发池根(默认)
138
+ lantern init --scope=web 仅产品(lantern web / npx)
139
+ lantern init --scope=dev 仅本地开发(pnpm dev)
134
140
  lantern web 后台启动本地 Web 服务
135
141
  lantern stop 停止服务
136
142
  lantern restart 重启服务
137
- lantern status 运行状态、端口、数据空间
143
+ lantern status 运行状态、端口、产品/开发池根
138
144
  lantern open 在浏览器中打开工作台
139
- lantern path 显示当前数据空间路径
145
+ lantern path 显示产品池根路径
140
146
  lantern config 显示配置文件地址
141
147
  lantern logs 查看服务日志
142
148
  lantern doctor 检查运行环境与配置
@@ -146,7 +152,7 @@ function printHelp() {
146
152
  lantern update 更新到最新版本(自动重启在跑的服务)
147
153
  lantern update <版本> 更新到指定版本(自动重启在跑的服务)
148
154
  lantern uninstall 卸载本机 lantern(保留数据空间)
149
- lantern wipe 删除当前数据空间(需确认)
155
+ lantern wipe 删除当前产品池根目录(需确认)
150
156
 
151
157
  数据空间:
152
158
  lantern space list 列出全部数据空间与当前项
@@ -168,8 +174,9 @@ function printHelp() {
168
174
  lantern acp 以 ACP 子集供外部编排驱动无 UI Agent
169
175
 
170
176
  说明:
171
- 首次请执行 lantern init;之后 lantern web 使用已记住的数据空间。
172
- 若数据空间被移动/重命名/删除,请重新 lantern init 初始化或选择已有数据空间。
177
+ 首次请执行 lantern init;产品服务读 dataRoot,pnpm dev 读 devDataRoot
178
+ (未单独配置时回退 dataRoot)。两边路径相同则共用同一份数据。
179
+ 若池根被移动/重命名/删除,请重新 lantern init(可加 --scope)。
173
180
  `);
174
181
  }
175
182
 
@@ -202,13 +209,11 @@ async function promptDataRoot() {
202
209
 
203
210
  /** @param {string | null | undefined} dirOverride */
204
211
  function requireDataRoot(dirOverride) {
205
- if (dirOverride) {
206
- const dataRoot = path.resolve(dirOverride);
207
- if (!fs.existsSync(dataRoot)) fs.mkdirSync(dataRoot, { recursive: true });
208
- setRegistryRoot(dataRoot);
209
- return dataRoot;
210
- }
211
- const result = resolveConfiguredDataRoot();
212
+ const result = resolveRuntimeSpacesRoot({
213
+ role: 'web',
214
+ dir: dirOverride,
215
+ mkdir: Boolean(dirOverride),
216
+ });
212
217
  if (!result.ok) {
213
218
  printDataRootUnavailable(result);
214
219
  process.exit(1);
@@ -218,6 +223,33 @@ function requireDataRoot(dirOverride) {
218
223
  return result.dataRoot;
219
224
  }
220
225
 
226
+ /**
227
+ * @param {string | null | undefined} scopeFlag
228
+ * @returns {Promise<'both'|'web'|'dev'>}
229
+ */
230
+ async function promptOrResolveScope(scopeFlag) {
231
+ const fromFlag = scopeFlag ? normalizeDataRootScope(scopeFlag) : null;
232
+ if (fromFlag) return fromFlag;
233
+ if (scopeFlag) {
234
+ throw new Error(`未知 --scope:${scopeFlag}(可用 both / web / dev)`);
235
+ }
236
+ if (!process.stdin.isTTY) return 'both';
237
+ const rl = readline.createInterface({ input, output });
238
+ try {
239
+ console.log('');
240
+ console.log('此池根用于:');
241
+ console.log(' 1) 仅产品(lantern web / npx)');
242
+ console.log(' 2) 仅本地开发(pnpm dev)');
243
+ console.log(' 3) 两者(路径相同则共用数据)');
244
+ const ans = (await rl.question('请输入 1 / 2 / 3(默认 3):')).trim() || '3';
245
+ const scope = normalizeDataRootScope(ans);
246
+ if (!scope) throw new Error('请输入 1 / 2 / 3');
247
+ return scope;
248
+ } finally {
249
+ rl.close();
250
+ }
251
+ }
252
+
221
253
  function getServerOpts() {
222
254
  const cfg = loadUserConfig();
223
255
  return {
@@ -235,24 +267,92 @@ function getAliveRun() {
235
267
  return state;
236
268
  }
237
269
 
238
- async function cmdInit() {
270
+ /** @param {{ scope?: string|null }} [opts] */
271
+ async function cmdInit(opts = {}) {
239
272
  const spacesRoot = await promptDataRoot();
240
273
  if (!fs.existsSync(spacesRoot)) {
241
274
  fs.mkdirSync(spacesRoot, { recursive: true });
242
275
  }
276
+ const scope = await promptOrResolveScope(opts.scope);
243
277
  prepareSpacesRoot(spacesRoot);
244
- saveUserConfig({ dataRoot: spacesRoot, host: '127.0.0.1', port: 4321 });
278
+ saveDataRootForScope(spacesRoot, scope, { host: '127.0.0.1', port: 4321 });
245
279
  // 换数据目录后注册表要按新池根分区,别把上一个目录的空间与激活项带过来
246
280
  setRegistryRoot(spacesRoot);
281
+ const cfg = loadUserConfig();
247
282
  console.log('');
248
283
  console.log('数据目录已关联:');
249
284
  console.log(` ${spacesRoot}`);
285
+ console.log(
286
+ ` 作用域:${scope === 'both' ? '产品 + 本地开发' : scope === 'web' ? '仅产品' : '仅本地开发'}`,
287
+ );
288
+ if (cfg.dataRoot) console.log(` 产品池根:${cfg.dataRoot}`);
289
+ if (cfg.devDataRoot) console.log(` 开发池根:${cfg.devDataRoot}`);
250
290
  console.log(` 公共空间:${displaySpacePath(publicSpacePath(spacesRoot), spacesRoot)}`);
251
291
  console.log(` 配置:${getConfigPath()}`);
252
- console.log('接下来可执行:lantern web');
292
+ printInitNextSteps(scope);
253
293
  console.log('');
254
294
  }
255
295
 
296
+ /** 当前 CLI 从哪启动:npx 缓存 / 源码仓库 / 全局安装 */
297
+ function detectCliContext() {
298
+ if (isNpxRun()) return 'npx';
299
+ try {
300
+ const pkg = JSON.parse(fs.readFileSync(PKG_JSON, 'utf8'));
301
+ if (
302
+ pkg?.name === 'lantern-harness' &&
303
+ (fs.existsSync(path.join(PKG_ROOT, '.git')) ||
304
+ fs.existsSync(path.join(PKG_ROOT, 'pnpm-lock.yaml')))
305
+ ) {
306
+ return 'source';
307
+ }
308
+ } catch {
309
+ /* ignore */
310
+ }
311
+ try {
312
+ const cwdPkg = path.join(process.cwd(), 'package.json');
313
+ if (fs.existsSync(cwdPkg)) {
314
+ const pkg = JSON.parse(fs.readFileSync(cwdPkg, 'utf8'));
315
+ if (pkg?.name === 'lantern-harness') return 'source';
316
+ }
317
+ } catch {
318
+ /* ignore */
319
+ }
320
+ return 'global';
321
+ }
322
+
323
+ /**
324
+ * 按 init 作用域 + 启动环境提示下一步命令。
325
+ * @param {'both'|'web'|'dev'} scope
326
+ */
327
+ function printInitNextSteps(scope) {
328
+ const ctx = detectCliContext();
329
+ const wantWeb = scope === 'web' || scope === 'both';
330
+ const wantDev = scope === 'dev' || scope === 'both';
331
+ /** @type {string[]} */
332
+ const lines = [];
333
+
334
+ if (wantWeb) {
335
+ if (ctx === 'npx') {
336
+ lines.push('lantern web # 全局 lantern 已安装时启动产品服务');
337
+ } else if (ctx === 'source') {
338
+ lines.push('lantern web # 全局命令');
339
+ lines.push('pnpm start # 或在本仓库前台跑产品服务');
340
+ } else {
341
+ lines.push('lantern web');
342
+ }
343
+ }
344
+ if (wantDev) {
345
+ if (ctx === 'source') {
346
+ lines.push('pnpm dev # 本地开发(读开发池根)');
347
+ } else {
348
+ lines.push('pnpm dev # 需在源码仓库目录执行');
349
+ }
350
+ }
351
+
352
+ console.log('接下来可执行:');
353
+ for (const line of lines) console.log(` ${line}`);
354
+ }
355
+
256
356
  async function runForegroundServer(dataRoot) {
257
357
  const { host, port } = getServerOpts();
258
358
  const {
@@ -394,20 +494,35 @@ async function cmdRestart() {
394
494
 
395
495
  function cmdStatus() {
396
496
  const cfg = loadUserConfig();
397
- const resolved = resolveConfiguredDataRoot();
497
+ const web = resolveRuntimeSpacesRoot({ role: 'web' });
498
+ const dev = resolveRuntimeSpacesRoot({ role: 'dev', fallback: PKG_ROOT });
398
499
  const run = getAliveRun();
399
500
  console.log(`版本:${readPkgVersion()}`);
400
501
  console.log(`配置:${getConfigPath()}`);
401
- if (!resolved.ok) {
402
- if (resolved.reason === 'missing_config') {
403
- console.log('数据空间:未配置');
502
+ if (!web.ok) {
503
+ if (web.reason === 'missing_config') {
504
+ console.log('产品池根:未配置');
404
505
  console.log(' → 请使用 lantern init 初始化或选择已有数据空间');
405
506
  } else {
406
- console.log(`数据空间:不可用(${resolved.dataRoot})`);
507
+ console.log(`产品池根:不可用(${web.dataRoot})`);
407
508
  console.log(' → 请重新 lantern init:初始化或选择已有数据空间');
408
509
  }
409
510
  } else {
410
- console.log(`数据空间:${resolved.dataRoot}`);
511
+ console.log(`产品池根:${web.dataRoot}`);
512
+ }
513
+ if (cfg.devDataRoot) {
514
+ console.log(
515
+ `开发池根:${cfg.devDataRoot}${dev.ok && dev.source === 'fallback' ? '(不可用,dev 将回退仓库根)' : ''}`,
516
+ );
517
+ } else if (web.ok) {
518
+ console.log(`开发池根:未单独配置(回退产品池根)`);
519
+ } else {
520
+ console.log(`开发池根:未配置(pnpm dev 回退仓库根)`);
521
+ }
522
+ if (web.ok && cfg.devDataRoot && path.resolve(cfg.devDataRoot) === path.resolve(web.dataRoot)) {
523
+ console.log('池根关系:产品与开发相同(共用数据)');
524
+ } else if (cfg.devDataRoot && web.ok) {
525
+ console.log('池根关系:产品与开发不同');
411
526
  }
412
527
  console.log(`监听:${cfg.host || '127.0.0.1'}:${Number(cfg.port) || 4321}`);
413
528
  if (run) {
@@ -967,7 +1082,11 @@ async function cmdWipe() {
967
1082
 
968
1083
  fs.rmSync(resolved, { recursive: true, force: true });
969
1084
  forgetRegistryRoot(resolved);
1085
+ const cfg = loadUserConfig();
970
1086
  clearDataRootFromConfig();
1087
+ if (cfg.devDataRoot && path.resolve(cfg.devDataRoot) === resolved) {
1088
+ clearDevDataRootFromConfig();
1089
+ }
971
1090
  console.log('数据空间已删除,配置中的关联已清除。');
972
1091
  console.log('如需继续使用,请使用 lantern init 初始化或选择已有数据空间。');
973
1092
  }
@@ -980,6 +1099,8 @@ function parseArgv(argv) {
980
1099
  foreground: false,
981
1100
  help: false,
982
1101
  dir: null,
1102
+ /** init:both | web | dev */
1103
+ scope: null,
983
1104
  purge: false,
984
1105
  yes: false,
985
1106
  use: false,
@@ -1015,6 +1136,10 @@ function parseArgv(argv) {
1015
1136
  flags.dir = argv[++i];
1016
1137
  if (!flags.dir) throw new Error('--dir 需要路径参数');
1017
1138
  } else if (a.startsWith('--dir=')) flags.dir = a.slice('--dir='.length);
1139
+ else if (a === '--scope') {
1140
+ flags.scope = argv[++i];
1141
+ if (!flags.scope) throw new Error('--scope 需要 both|web|dev');
1142
+ } else if (a.startsWith('--scope=')) flags.scope = a.slice('--scope='.length);
1018
1143
  else if (a === '--access') {
1019
1144
  flags.access = argv[++i];
1020
1145
  if (!flags.access) throw new Error('--access 需要 readonly|readwrite|full');
@@ -1062,7 +1187,7 @@ async function main() {
1062
1187
  try {
1063
1188
  switch (cmd) {
1064
1189
  case 'init':
1065
- await cmdInit();
1190
+ await cmdInit({ scope: flags.scope });
1066
1191
  break;
1067
1192
  case 'web':
1068
1193
  await cmdStart({ foreground: flags.foreground, dir: flags.dir });
@@ -70,7 +70,7 @@ function ensureDir(dir) {
70
70
  }
71
71
 
72
72
  /**
73
- * @returns {{ dataRoot?: string, host?: string, port?: number }}
73
+ * @returns {{ dataRoot?: string, devDataRoot?: string, host?: string, port?: number }}
74
74
  */
75
75
  export function loadUserConfig() {
76
76
  const p = getConfigPath();
@@ -84,7 +84,7 @@ export function loadUserConfig() {
84
84
  }
85
85
 
86
86
  /**
87
- * @param {{ dataRoot?: string, host?: string, port?: number }} patch
87
+ * @param {{ dataRoot?: string, devDataRoot?: string, host?: string, port?: number }} patch
88
88
  */
89
89
  export function saveUserConfig(patch) {
90
90
  const dir = getUserConfigDir();
@@ -92,12 +92,45 @@ export function saveUserConfig(patch) {
92
92
  const cur = loadUserConfig();
93
93
  const next = { ...cur, ...patch };
94
94
  if (next.dataRoot) next.dataRoot = path.resolve(next.dataRoot);
95
+ if (next.devDataRoot) next.devDataRoot = path.resolve(next.devDataRoot);
95
96
  if (next.port != null) next.port = Number(next.port) || 4321;
96
97
  if (next.host != null) next.host = String(next.host || '127.0.0.1');
97
98
  fs.writeFileSync(getConfigPath(), `${JSON.stringify(next, null, 2)}\n`, 'utf8');
98
99
  return next;
99
100
  }
100
101
 
102
+ /** init 作用域:产品 web / 本地开发 / 两者 */
103
+ export const DATA_ROOT_SCOPES = /** @type {const} */ (['both', 'web', 'dev']);
104
+
105
+ /**
106
+ * @param {string} raw
107
+ * @returns {'both'|'web'|'dev'|null}
108
+ */
109
+ export function normalizeDataRootScope(raw) {
110
+ const s = String(raw || '')
111
+ .trim()
112
+ .toLowerCase();
113
+ if (s === 'both' || s === 'all' || s === '两者' || s === '3') return 'both';
114
+ if (s === 'web' || s === 'product' || s === '产品' || s === '1') return 'web';
115
+ if (s === 'dev' || s === 'develop' || s === '开发' || s === '2') return 'dev';
116
+ return null;
117
+ }
118
+
119
+ /**
120
+ * 按作用域写入池根。
121
+ * @param {string} spacesRoot
122
+ * @param {'both'|'web'|'dev'} scope
123
+ * @param {{ host?: string, port?: number }} [extra]
124
+ */
125
+ export function saveDataRootForScope(spacesRoot, scope, extra = {}) {
126
+ const abs = path.resolve(spacesRoot);
127
+ /** @type {{ dataRoot?: string, devDataRoot?: string, host?: string, port?: number }} */
128
+ const patch = { ...extra };
129
+ if (scope === 'web' || scope === 'both') patch.dataRoot = abs;
130
+ if (scope === 'dev' || scope === 'both') patch.devDataRoot = abs;
131
+ return saveUserConfig(patch);
132
+ }
133
+
101
134
  export function clearDataRootFromConfig() {
102
135
  const cur = loadUserConfig();
103
136
  delete cur.dataRoot;
@@ -105,6 +138,14 @@ export function clearDataRootFromConfig() {
105
138
  fs.writeFileSync(getConfigPath(), `${JSON.stringify(cur, null, 2)}\n`, 'utf8');
106
139
  }
107
140
 
141
+ /** 清除开发池根配置 */
142
+ export function clearDevDataRootFromConfig() {
143
+ const cur = loadUserConfig();
144
+ delete cur.devDataRoot;
145
+ ensureDir(getUserConfigDir());
146
+ fs.writeFileSync(getConfigPath(), `${JSON.stringify(cur, null, 2)}\n`, 'utf8');
147
+ }
148
+
108
149
  /**
109
150
  * @returns {{ pid?: number, url?: string, host?: string, port?: number, dataRoot?: string, startedAt?: string } | null}
110
151
  */
@@ -156,19 +197,76 @@ export function isPidAlive(pid) {
156
197
  }
157
198
 
158
199
  /**
159
- * 校验已配置的数据空间是否可用。
160
- * @returns {{ ok: true, dataRoot: string } | { ok: false, reason: 'missing_config' | 'missing_path', dataRoot?: string }}
200
+ * 校验已配置的产品池根是否可用。
201
+ * @returns {{ ok: true, dataRoot: string, source?: string } | { ok: false, reason: 'missing_config' | 'missing_path', dataRoot?: string }}
161
202
  */
162
203
  export function resolveConfiguredDataRoot() {
204
+ return resolveRuntimeSpacesRoot({ role: 'web' });
205
+ }
206
+
207
+ /**
208
+ * 解析运行时池根。
209
+ * 优先级:`--dir` > 对应配置字段(dev 缺省回退 dataRoot)> fallback(仅开发入口)。
210
+ *
211
+ * @param {{
212
+ * role?: 'web'|'dev',
213
+ * dir?: string|null,
214
+ * fallback?: string|null,
215
+ * mkdir?: boolean,
216
+ * }} [opts]
217
+ * @returns {{
218
+ * ok: true, dataRoot: string, source: 'dir'|'dataRoot'|'devDataRoot'|'fallback'
219
+ * } | {
220
+ * ok: false, reason: 'missing_config'|'missing_path', dataRoot?: string
221
+ * }}
222
+ */
223
+ export function resolveRuntimeSpacesRoot(opts = {}) {
224
+ const role = opts.role === 'dev' ? 'dev' : 'web';
225
+
226
+ if (opts.dir) {
227
+ const dataRoot = path.resolve(opts.dir);
228
+ if (opts.mkdir && !fs.existsSync(dataRoot)) {
229
+ fs.mkdirSync(dataRoot, { recursive: true });
230
+ }
231
+ if (!fs.existsSync(dataRoot) || !fs.statSync(dataRoot).isDirectory()) {
232
+ return { ok: false, reason: 'missing_path', dataRoot };
233
+ }
234
+ return { ok: true, dataRoot, source: 'dir' };
235
+ }
236
+
163
237
  const cfg = loadUserConfig();
164
- const dataRoot = cfg.dataRoot ? path.resolve(cfg.dataRoot) : '';
165
- if (!dataRoot) {
166
- return { ok: false, reason: 'missing_config' };
238
+ /** @type {{ path: string, source: 'dataRoot'|'devDataRoot' }[]} */
239
+ const candidates = [];
240
+ if (role === 'dev') {
241
+ if (cfg.devDataRoot) {
242
+ candidates.push({ path: path.resolve(cfg.devDataRoot), source: 'devDataRoot' });
243
+ }
244
+ if (cfg.dataRoot) {
245
+ candidates.push({ path: path.resolve(cfg.dataRoot), source: 'dataRoot' });
246
+ }
247
+ } else if (cfg.dataRoot) {
248
+ candidates.push({ path: path.resolve(cfg.dataRoot), source: 'dataRoot' });
249
+ }
250
+
251
+ let lastMissing = '';
252
+ for (const c of candidates) {
253
+ if (fs.existsSync(c.path) && fs.statSync(c.path).isDirectory()) {
254
+ return { ok: true, dataRoot: c.path, source: c.source };
255
+ }
256
+ lastMissing = c.path;
167
257
  }
168
- if (!fs.existsSync(dataRoot) || !fs.statSync(dataRoot).isDirectory()) {
169
- return { ok: false, reason: 'missing_path', dataRoot };
258
+
259
+ if (lastMissing) {
260
+ if (role === 'dev' && opts.fallback) {
261
+ return { ok: true, dataRoot: path.resolve(opts.fallback), source: 'fallback' };
262
+ }
263
+ return { ok: false, reason: 'missing_path', dataRoot: lastMissing };
264
+ }
265
+
266
+ if (role === 'dev' && opts.fallback) {
267
+ return { ok: true, dataRoot: path.resolve(opts.fallback), source: 'fallback' };
170
268
  }
171
- return { ok: true, dataRoot };
269
+ return { ok: false, reason: 'missing_config' };
172
270
  }
173
271
 
174
272
  export function printDataRootUnavailable(result) {