lantern-harness 0.1.2 → 0.1.4

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 (119) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +9 -9
  3. package/builtin/session/lh-nav-groups.mjs +106 -9
  4. package/builtin/session/lh-spaces.mjs +102 -0
  5. package/cli/data-root.mjs +110 -3
  6. package/cli/lantern.mjs +36 -7
  7. package/cli/server.mjs +8 -0
  8. package/cli/spaces.mjs +91 -5
  9. package/config/app.defaults.json +7 -2
  10. package/dist/500.html +19 -5
  11. package/dist/_astro/Base.C_AmDbI9.css +1 -0
  12. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.lxEwQ1R4.js → Base.astro_astro_type_script_index_0_lang.-g0SuFCa.js} +1 -1
  13. package/dist/_astro/CaseExecBoard.CNZh0sre.js +1 -0
  14. package/dist/_astro/CaseGenerateApp.BQalnGiC.js +9 -0
  15. package/dist/_astro/CasesLibrary.u7ek8rOp.js +1 -0
  16. package/dist/_astro/ChatApp.Dk5uOXr0.js +273 -0
  17. package/dist/_astro/ColumnResize.Bs6GL3DJ.js +1 -0
  18. package/dist/_astro/ConfirmDialog.Dbyjb4-6.js +1 -0
  19. package/dist/_astro/DatePicker.CMfX7F6z.js +1 -0
  20. package/dist/_astro/DocsFileBrowser.CHVgH1vj.js +1 -0
  21. package/dist/_astro/DocsPager.DaiWchhj.js +1 -0
  22. package/dist/_astro/DrawerField.KANqQwFl.js +1 -0
  23. package/dist/_astro/KnowledgeLibrary.DSxgeW4L.js +1 -0
  24. package/dist/_astro/NamePromptDialog.DZSZ5Y16.js +1 -0
  25. package/dist/_astro/NavLibraries.BN5smOBt.js +1 -0
  26. package/dist/_astro/PluginsPage.BB18crT3.js +1 -0
  27. package/dist/_astro/PluginsPage.Oh8hWup8.js +39 -0
  28. package/dist/_astro/PromptsLibrary.DWgox1du.js +1 -0
  29. package/dist/_astro/ReportsPage.BlHA_AtE.js +1 -0
  30. package/dist/_astro/RequirementsLibrary.2o-KMk7K.js +1 -0
  31. package/dist/_astro/SearchableSelect.BMl1Bp59.js +1 -0
  32. package/dist/_astro/SelectDropdown.flhHcwyd.js +1 -0
  33. package/dist/_astro/SettingsDialog.Cs8z0Hhb.js +1 -0
  34. package/dist/_astro/SpaceSwitcher.DicPqrSH.js +7 -0
  35. package/dist/_astro/TagSelect.u8DTop7v.js +1 -0
  36. package/dist/_astro/TasksBoard.dgJxOpVG.js +1 -0
  37. package/dist/_astro/TemplatesLibrary.BfC9HIuu.js +1 -0
  38. package/dist/_astro/TestStatsBoard.Dg23e0O_.js +1 -0
  39. package/dist/_astro/TodosBoard.CyvTZybr.js +1 -0
  40. package/dist/_astro/active-element-history.CeefGkFQ.js +1 -0
  41. package/dist/_astro/app-config.Crg0VdkS.js +1 -0
  42. package/dist/_astro/case-exec.HjGrOY_O.js +1 -0
  43. package/dist/_astro/doc-roots.DAJP9Svr.js +1 -0
  44. package/dist/_astro/i18n.C8FKLrB5.js +7 -0
  45. package/dist/_astro/listbox.Di-t5U37.js +1 -0
  46. package/dist/_astro/menu.Bkluqxic.js +1 -0
  47. package/dist/_astro/{open-docs-in-session.D3JCwMWB.js → open-docs-in-session.BC5D-BoF.js} +1 -1
  48. package/dist/_astro/plugins.CNOYmeAe.js +1 -0
  49. package/dist/_astro/portal.Cm9XlIPf.js +5 -0
  50. package/dist/_astro/project-docs.Cd2gKPKh.js +1 -0
  51. package/dist/_astro/report-prompt.Cmw4XzfY.js +1 -0
  52. package/dist/_astro/{settings.BoQ0e0m1.js → settings.DBIYsQY-.js} +2 -2
  53. package/dist/_astro/tasks.WhfT-DnC.js +1 -0
  54. package/dist/_astro/test-stats.BIHEJz5c.js +1 -0
  55. package/dist/_astro/use-text-value.BuY0Cm1z.js +1 -0
  56. package/dist/_astro/use-tree-walker.CfTHFX43.js +1 -0
  57. package/dist/_astro/useListAnim.CpGB1cft.js +1 -0
  58. package/dist/_astro/view-prefs.C9Mtta1E.js +1 -0
  59. package/dist/case-exec/index.html +263 -0
  60. package/dist/cases/generate/index.html +20 -6
  61. package/dist/cases/library/index.html +20 -6
  62. package/dist/docs/changelog/index.html +121 -6
  63. package/dist/docs/install/index.html +35 -11
  64. package/dist/docs/manual/index.html +149 -14
  65. package/dist/index.html +20 -6
  66. package/dist/knowledge/index.html +20 -6
  67. package/dist/knowledge//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/347/274/226/345/206/231/350/247/204/350/214/203/index.html +19 -5
  68. package/dist/plugins/index.html +20 -6
  69. package/dist/prompts/index.html +20 -6
  70. package/dist/reports/index.html +263 -0
  71. package/dist/requirements/index.html +20 -6
  72. package/dist/tasks/index.html +263 -0
  73. package/dist/templates/index.html +20 -6
  74. package/dist/templates//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//345/212/237/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +19 -5
  75. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212//346/200/247/350/203/275/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +19 -5
  76. package/dist/templates//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213//346/200/247/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +19 -5
  77. package/dist/templates//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212//346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212/346/250/241/346/235/277/index.html +19 -5
  78. package/dist/templates//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213//350/207/252/345/212/250/345/214/226/346/265/213/350/257/225/347/224/250/344/276/213/346/250/241/346/235/277/index.html +19 -5
  79. package/dist/test-stats/index.html +263 -0
  80. package/dist/todos/index.html +263 -0
  81. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +2 -2
  82. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +13 -11
  83. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +125 -26
  84. package/lh-plugins/lh-project-docs.mjs +3 -1
  85. package/lh-plugins/lh-reports.mjs +413 -0
  86. package/lh-plugins/lh-stats.mjs +409 -0
  87. package/lh-plugins/lh-tasks.mjs +224 -0
  88. package/lh-plugins/lh-todos.mjs +295 -0
  89. package/lh-plugins/lh-work-store.mjs +81 -0
  90. package/lh-plugins/storage-domain.mjs +54 -3
  91. package/package.json +2 -1
  92. package/config/seeds//346/217/220/347/244/272/350/257/215/347/256/241/347/220/206//345/212/237/350/203/275/346/265/213/350/257/225/347/224/250/344/276/213/346/217/220/347/244/272/350/257/215v1.0.md +0 -155
  93. package/dist/_astro/Base.B9f_iFAZ.css +0 -1
  94. package/dist/_astro/CaseGenerateApp.Br4uKjun.js +0 -9
  95. package/dist/_astro/CasesLibrary.CpPoVQ4P.js +0 -1
  96. package/dist/_astro/ChatApp.CYSPlSNP.js +0 -258
  97. package/dist/_astro/ConfirmDialog.BYz4HREM.js +0 -1
  98. package/dist/_astro/DocsFileBrowser.DkE26UTR.js +0 -1
  99. package/dist/_astro/KnowledgeLibrary.DZinlAWn.js +0 -1
  100. package/dist/_astro/NamePromptDialog.DGBlDH_k.js +0 -1
  101. package/dist/_astro/NavLibraries.EayBsg5g.js +0 -1
  102. package/dist/_astro/PluginsPage.BNzpPg2H.js +0 -39
  103. package/dist/_astro/PluginsPage.CY61glLU.js +0 -1
  104. package/dist/_astro/PromptsLibrary.DfrrCjs7.js +0 -1
  105. package/dist/_astro/RequirementsLibrary.Dt0Gj6Nr.js +0 -1
  106. package/dist/_astro/SearchableSelect.DMS2XmXc.js +0 -1
  107. package/dist/_astro/SelectDropdown.Dc7QaPbH.js +0 -1
  108. package/dist/_astro/SettingsDialog.DC0e7580.js +0 -1
  109. package/dist/_astro/SpaceSwitcher.Yy2w8MDF.js +0 -7
  110. package/dist/_astro/TemplatesLibrary.uK-SjK1z.js +0 -1
  111. package/dist/_astro/app-config.CpjKWnzM.js +0 -1
  112. package/dist/_astro/i18n.BVvhz-vw.js +0 -7
  113. package/dist/_astro/listbox.DdDDDJ5Z.js +0 -1
  114. package/dist/_astro/menu.CqkL87bV.js +0 -1
  115. package/dist/_astro/plugins.CrpY8UI9.js +0 -1
  116. package/dist/_astro/portal.C3KrUREL.js +0 -5
  117. package/dist/_astro/use-text-value.C0IDspmh.js +0 -1
  118. package/dist/_astro/use-tree-walker.oRTnhHS-.js +0 -1
  119. package/dist/_astro/useListAnim.CnbC_9MC.js +0 -1
@@ -0,0 +1,295 @@
1
+ /**
2
+ * 待办事项存储(空间级)。
3
+ *
4
+ * 数据落在 `<当前数据空间>/待办事项/待办.json`:跟空间走、不跟 git 走。
5
+ * 旧版本的 `.lantern/local/todos.json` 会在首次读写时自动搬过来。
6
+ * 页面与工作台 AI 工具共用同一份文件,所以这里只做最小校验,
7
+ * 派生字段(待办周期 / 剩余天数 / 是否延期)一律由前端计算,不落库。
8
+ */
9
+ import crypto from 'node:crypto';
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+
13
+ import { getDataRoot } from '../builtin/session/space-context.mjs';
14
+ import { prepareStorePath, readableStorePath, workStorePath } from './lh-work-store.mjs';
15
+
16
+ const PREFIX = '/__tb_todos';
17
+ const VERSION = 1;
18
+
19
+ export const TODO_STATUSES = ['pending', 'in_progress', 'done', 'cancelled'];
20
+ export const TODO_PRIORITIES = ['urgent_important', 'important', 'urgent', 'normal'];
21
+
22
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
23
+
24
+ function sendJson(res, status, body) {
25
+ res.statusCode = status;
26
+ res.setHeader('Content-Type', 'application/json; charset=utf-8');
27
+ res.end(JSON.stringify(body));
28
+ }
29
+
30
+ function readBody(req) {
31
+ return new Promise((resolve, reject) => {
32
+ const chunks = [];
33
+ req.on('data', (c) => chunks.push(c));
34
+ req.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
35
+ req.on('error', reject);
36
+ });
37
+ }
38
+
39
+ function storeFile(root) {
40
+ return prepareStorePath(root, 'todos');
41
+ }
42
+
43
+ function readStore(root) {
44
+ const fp = storeFile(root);
45
+ try {
46
+ const raw = JSON.parse(fs.readFileSync(fp, 'utf8'));
47
+ const items = Array.isArray(raw?.items) ? raw.items.map(normalizeStored).filter(Boolean) : [];
48
+ return { version: VERSION, items };
49
+ } catch {
50
+ return { version: VERSION, items: [] };
51
+ }
52
+ }
53
+
54
+ /** 先写临时文件再 rename:中途失败也不会留下半份 JSON */
55
+ function writeStore(root, store) {
56
+ const fp = storeFile(root);
57
+ fs.mkdirSync(path.dirname(fp), { recursive: true });
58
+ const tmp = `${fp}.${process.pid}.tmp`;
59
+ fs.writeFileSync(tmp, `${JSON.stringify(store, null, 2)}\n`, 'utf8');
60
+ fs.renameSync(tmp, fp);
61
+ }
62
+
63
+ function newId() {
64
+ return `td_${crypto.randomBytes(8).toString('hex')}`;
65
+ }
66
+
67
+ function text(value, max = 2000) {
68
+ return typeof value === 'string' ? value.trim().slice(0, max) : '';
69
+ }
70
+
71
+ function dateOrEmpty(value) {
72
+ const s = text(value, 10);
73
+ return DATE_RE.test(s) ? s : '';
74
+ }
75
+
76
+ function oneOf(value, allowed, fallback) {
77
+ const s = text(value, 40);
78
+ return allowed.includes(s) ? s : fallback;
79
+ }
80
+
81
+ /** 结束待办的状态:这两个状态才算「结束了」,结束日期随之落库 */
82
+ const CLOSED_STATUSES = new Set(['done', 'cancelled']);
83
+
84
+ /** 本机当天日期(不用 UTC,避免晚上 8 点后被算成第二天) */
85
+ function todayLocal() {
86
+ const now = new Date();
87
+ const y = now.getFullYear();
88
+ const m = String(now.getMonth() + 1).padStart(2, '0');
89
+ const d = String(now.getDate()).padStart(2, '0');
90
+ return `${y}-${m}-${d}`;
91
+ }
92
+
93
+ /**
94
+ * 结束日期是派生值(页面与工具都不再手填):
95
+ * - 已完成 / 已取消:沿用已有结束日期,没有就记为当天;
96
+ * - 待开始 / 进行中:清空,界面上显示「进行中」。
97
+ * @param {string} status
98
+ * @param {string} [existing] 库里已存的结束日期
99
+ */
100
+ function endDateFor(status, existing) {
101
+ if (!CLOSED_STATUSES.has(status)) return '';
102
+ return existing || todayLocal();
103
+ }
104
+
105
+ /**
106
+ * 待办关联任务后,把任务从「任务池 / 已完成」拉回「进行中」:
107
+ * 关联上就说明这件事已经在做了。已关闭的任务不动(也不在选择范围内)。
108
+ * 读取失败 / 任务不存在时静默跳过——任务管理插件可能没启用。
109
+ */
110
+ function promoteLinkedTask(root, taskId) {
111
+ if (!taskId) return;
112
+ const fp = readableStorePath(root, 'tasks');
113
+ let store;
114
+ try {
115
+ store = JSON.parse(fs.readFileSync(fp, 'utf8'));
116
+ } catch {
117
+ return;
118
+ }
119
+ const items = Array.isArray(store?.items) ? store.items : [];
120
+ const task = items.find((x) => x && x.id === taskId);
121
+ if (!task) return;
122
+ if (task.status !== 'pool' && task.status !== 'done') return;
123
+ task.status = 'in_progress';
124
+ task.doneAt = null;
125
+ task.updatedAt = new Date().toISOString();
126
+ const tmp = `${fp}.${process.pid}.tmp`;
127
+ fs.writeFileSync(tmp, `${JSON.stringify(store, null, 2)}\n`, 'utf8');
128
+ fs.renameSync(tmp, fp);
129
+ }
130
+
131
+ /** 读回来的旧数据也走一遍归一化,避免手工改坏的文件把页面拖垮 */
132
+ function normalizeStored(raw) {
133
+ if (!raw || typeof raw !== 'object') return null;
134
+ const title = text(raw.title, 200);
135
+ if (!title) return null;
136
+ const status = oneOf(raw.status, TODO_STATUSES, 'pending');
137
+ const now = new Date().toISOString();
138
+ // 旧数据可能没有结束日期:已完成的退回 doneAt 的日期,再没有才用当天
139
+ const doneAt = text(raw.doneAt, 40) || null;
140
+ const storedEnd = dateOrEmpty(raw.taskEndDate) || dateOrEmpty(doneAt);
141
+ return {
142
+ id: text(raw.id, 64) || newId(),
143
+ title,
144
+ status,
145
+ priority: oneOf(raw.priority, TODO_PRIORITIES, ''),
146
+ linkedTask: text(raw.linkedTask, 200),
147
+ taskId: text(raw.taskId, 64),
148
+ startDate: dateOrEmpty(raw.startDate),
149
+ dueDate: dateOrEmpty(raw.dueDate),
150
+ taskEndDate: endDateFor(status, storedEnd),
151
+ note: text(raw.note),
152
+ source: raw.source === 'ai' ? 'ai' : 'manual',
153
+ sessionId: text(raw.sessionId, 120),
154
+ createdAt: text(raw.createdAt, 40) || now,
155
+ updatedAt: text(raw.updatedAt, 40) || now,
156
+ doneAt,
157
+ };
158
+ }
159
+
160
+ /** 入参归一化:只认白名单字段,缺省值由调用方(新建/更新)决定 */
161
+ function normalizePatch(raw, base) {
162
+ const patch = {};
163
+ if (!raw || typeof raw !== 'object') return patch;
164
+ if ('title' in raw) patch.title = text(raw.title, 200);
165
+ if ('status' in raw) patch.status = oneOf(raw.status, TODO_STATUSES, base.status);
166
+ if ('priority' in raw) patch.priority = oneOf(raw.priority, TODO_PRIORITIES, '');
167
+ if ('linkedTask' in raw) patch.linkedTask = text(raw.linkedTask, 200);
168
+ if ('taskId' in raw) patch.taskId = text(raw.taskId, 64);
169
+ if ('startDate' in raw) patch.startDate = dateOrEmpty(raw.startDate);
170
+ if ('dueDate' in raw) patch.dueDate = dateOrEmpty(raw.dueDate);
171
+ // taskEndDate 不接收手填:由状态派生,见 endDateFor()
172
+ if ('note' in raw) patch.note = text(raw.note);
173
+ return patch;
174
+ }
175
+
176
+ /**
177
+ * @param {{ mode?: 'manual' | 'ai', sessionId?: string }} [meta]
178
+ */
179
+ function buildItem(raw, meta = {}) {
180
+ const now = new Date().toISOString();
181
+ const status = oneOf(raw?.status, TODO_STATUSES, 'pending');
182
+ return {
183
+ id: newId(),
184
+ title: text(raw?.title, 200),
185
+ status,
186
+ priority: oneOf(raw?.priority, TODO_PRIORITIES, ''),
187
+ linkedTask: text(raw?.linkedTask, 200),
188
+ taskId: text(raw?.taskId, 64),
189
+ startDate: dateOrEmpty(raw?.startDate),
190
+ dueDate: dateOrEmpty(raw?.dueDate),
191
+ taskEndDate: endDateFor(status, ''),
192
+ note: text(raw?.note),
193
+ source: meta.mode === 'ai' ? 'ai' : 'manual',
194
+ sessionId: text(meta.sessionId, 120),
195
+ createdAt: now,
196
+ updatedAt: now,
197
+ doneAt: status === 'done' ? now : null,
198
+ };
199
+ }
200
+
201
+ /**
202
+ * @returns {import('vite').Plugin}
203
+ */
204
+ export function lhTodosPlugin() {
205
+ return {
206
+ name: 'lh-todos',
207
+ configureServer(server) {
208
+ server.middlewares.use(async (req, res, next) => {
209
+ const parsed = new URL(req.url ?? '/', 'http://127.0.0.1');
210
+ if (!parsed.pathname.startsWith(PREFIX)) return next();
211
+ // 数据根惰性读取:切换数据空间后无需重启
212
+ const root = getDataRoot();
213
+
214
+ try {
215
+ const method = req.method || 'GET';
216
+ const itemId = parsed.pathname.slice(PREFIX.length).replace(/^\//, '');
217
+
218
+ if (method === 'GET' && parsed.searchParams.get('health') === '1') {
219
+ // 探测不算读写:只算路径,不建目录、不迁移
220
+ return sendJson(res, 200, { ok: true, file: workStorePath(root, 'todos') });
221
+ }
222
+
223
+ if (method === 'GET' && !itemId) {
224
+ return sendJson(res, 200, { ok: true, ...readStore(root) });
225
+ }
226
+
227
+ if (method === 'POST') {
228
+ const body = JSON.parse((await readBody(req)) || '{}');
229
+ const rawItems = Array.isArray(body.items) ? body.items : [body];
230
+ const meta = { mode: body.mode === 'ai' ? 'ai' : 'manual', sessionId: body.sessionId };
231
+ const store = readStore(root);
232
+ const created = [];
233
+ for (const raw of rawItems) {
234
+ const item = buildItem(raw, meta);
235
+ if (!item.title) {
236
+ return sendJson(res, 400, { ok: false, error: '待办名称不能为空' });
237
+ }
238
+ created.push(item);
239
+ }
240
+ store.items.push(...created);
241
+ writeStore(root, store);
242
+ // 新建时就带了关联任务:任务池 / 已完成 → 进行中
243
+ for (const item of created) promoteLinkedTask(root, item.taskId);
244
+ return sendJson(res, 200, { ok: true, items: created, total: store.items.length });
245
+ }
246
+
247
+ if (method === 'PUT') {
248
+ const body = JSON.parse((await readBody(req)) || '{}');
249
+ const id = text(body.id ?? itemId, 64);
250
+ if (!id) return sendJson(res, 400, { ok: false, error: '缺少待办 id' });
251
+ const store = readStore(root);
252
+ const idx = store.items.findIndex((x) => x.id === id);
253
+ if (idx < 0) return sendJson(res, 404, { ok: false, error: '待办不存在' });
254
+
255
+ const base = store.items[idx];
256
+ const patch = normalizePatch(body, base);
257
+ if ('title' in patch && !patch.title) {
258
+ return sendJson(res, 400, { ok: false, error: '待办名称不能为空' });
259
+ }
260
+ const next = { ...base, ...patch, updatedAt: new Date().toISOString() };
261
+ if (next.status === 'done' && base.status !== 'done') next.doneAt = next.updatedAt;
262
+ if (next.status !== 'done') next.doneAt = null;
263
+ // 结束日期跟着状态走:完成 / 取消记为当天,回到待开始 / 进行中则清空。
264
+ // 已经是结束态时沿用原值,改别的字段不会把结束日期刷新成今天。
265
+ const wasClosed = CLOSED_STATUSES.has(base.status);
266
+ next.taskEndDate = endDateFor(next.status, wasClosed ? base.taskEndDate : '');
267
+ store.items[idx] = next;
268
+ writeStore(root, store);
269
+ // 只有「这次新关联了任务」才把任务拉回进行中,改别的字段不碰任务状态
270
+ if (next.taskId && next.taskId !== base.taskId) promoteLinkedTask(root, next.taskId);
271
+ return sendJson(res, 200, { ok: true, item: next });
272
+ }
273
+
274
+ if (method === 'DELETE') {
275
+ const body = JSON.parse((await readBody(req)) || '{}');
276
+ const ids = (Array.isArray(body.ids) ? body.ids : [body.id ?? itemId])
277
+ .map((x) => text(x, 64))
278
+ .filter(Boolean);
279
+ if (!ids.length) return sendJson(res, 400, { ok: false, error: '缺少待办 id' });
280
+ const store = readStore(root);
281
+ const drop = new Set(ids);
282
+ const before = store.items.length;
283
+ store.items = store.items.filter((x) => !drop.has(x.id));
284
+ writeStore(root, store);
285
+ return sendJson(res, 200, { ok: true, removed: before - store.items.length });
286
+ }
287
+
288
+ return sendJson(res, 405, { ok: false, error: 'Method Not Allowed' });
289
+ } catch (err) {
290
+ return sendJson(res, 500, { ok: false, error: String(err?.message ?? err) });
291
+ }
292
+ });
293
+ },
294
+ };
295
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * 待办 / 任务的磁盘位置:跟侧栏菜单一一对应,直接放在空间里的普通文件夹,
3
+ * 不再藏进 `.lantern/local`(那里放的是会话、记忆这类本机状态)。
4
+ *
5
+ * ```
6
+ * <空间>/待办事项/待办.json
7
+ * <空间>/任务管理/任务.json
8
+ * ```
9
+ *
10
+ * 目录同样走 `resolveContentRoot`:被拖进导航分组时,数据跟着进分组文件夹。
11
+ * 旧版本存在 `.lantern/local/todos.json`、`tasks.json`,读取时自动搬过来。
12
+ */
13
+ import fs from 'node:fs';
14
+ import path from 'node:path';
15
+
16
+ import { resolveContentRoot, spaceLocalFile } from '../builtin/session/space-layout.mjs';
17
+
18
+ export const TODO_DIR_NAME = '待办事项';
19
+ export const TASK_DIR_NAME = '任务管理';
20
+ export const TODO_STORE_FILE = '待办.json';
21
+ export const TASK_STORE_FILE = '任务.json';
22
+
23
+ /** 旧位置(`.lantern/local` 下)的文件名,仅用于迁移 */
24
+ const LEGACY_FILES = {
25
+ todos: 'todos.json',
26
+ tasks: 'tasks.json',
27
+ };
28
+
29
+ /** @typedef {'todos' | 'tasks'} WorkStoreKind */
30
+
31
+ export function todoStorePath(spaceDir) {
32
+ return path.join(resolveContentRoot(spaceDir, TODO_DIR_NAME).abs, TODO_STORE_FILE);
33
+ }
34
+
35
+ export function taskStorePath(spaceDir) {
36
+ return path.join(resolveContentRoot(spaceDir, TASK_DIR_NAME).abs, TASK_STORE_FILE);
37
+ }
38
+
39
+ /** 只算路径不做任何迁移:health 探测不该顺手建目录 */
40
+ export function workStorePath(spaceDir, kind) {
41
+ return kind === 'todos' ? todoStorePath(spaceDir) : taskStorePath(spaceDir);
42
+ }
43
+
44
+ function legacyStorePath(spaceDir, kind) {
45
+ return spaceLocalFile(spaceDir, LEGACY_FILES[kind]);
46
+ }
47
+
48
+ /**
49
+ * 能读到的那份存储:新位置优先,老位置兜底(不迁移、不建目录)。
50
+ * 供跨模块只读引用(例如待办把关联任务拉回「进行中」)。
51
+ */
52
+ export function readableStorePath(spaceDir, kind) {
53
+ const next = workStorePath(spaceDir, kind);
54
+ if (fs.existsSync(next)) return next;
55
+ const legacy = legacyStorePath(spaceDir, kind);
56
+ return fs.existsSync(legacy) ? legacy : next;
57
+ }
58
+
59
+ /**
60
+ * 准备写入位置:建好目录,并把 `.lantern/local` 里的旧文件搬出来。
61
+ * 只在真正读写时调用,避免打开页面就铺出空文件夹。
62
+ */
63
+ export function prepareStorePath(spaceDir, kind) {
64
+ const next = workStorePath(spaceDir, kind);
65
+ fs.mkdirSync(path.dirname(next), { recursive: true });
66
+ if (fs.existsSync(next)) return next;
67
+ const legacy = legacyStorePath(spaceDir, kind);
68
+ if (!fs.existsSync(legacy)) return next;
69
+ try {
70
+ fs.renameSync(legacy, next);
71
+ } catch {
72
+ try {
73
+ fs.copyFileSync(legacy, next);
74
+ fs.unlinkSync(legacy);
75
+ } catch {
76
+ // 迁移失败就继续用旧文件,不阻断读写
77
+ return legacy;
78
+ }
79
+ }
80
+ return next;
81
+ }
@@ -3,7 +3,19 @@
3
3
  */
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
- import { LOCAL_REL } from '../builtin/session/space-layout.mjs';
6
+ import { LOCAL_REL, resolveContentRoot } from '../builtin/session/space-layout.mjs';
7
+ import {
8
+ TASK_DIR_NAME,
9
+ TASK_STORE_FILE,
10
+ TODO_DIR_NAME,
11
+ TODO_STORE_FILE,
12
+ } from './lh-work-store.mjs';
13
+ import {
14
+ CASE_EXEC_DIR_NAME,
15
+ CASE_EXEC_STORE_FILE,
16
+ TEST_STATS_DIR_NAME,
17
+ TEST_STATS_STORE_FILE,
18
+ } from './lh-stats.mjs';
7
19
 
8
20
  /** @type {Array<{ id: string, rel: string, kind: 'file' | 'dir', roleZh: string }>} */
9
21
  export const KNOWN_STORAGE_DOMAINS = [
@@ -30,6 +42,26 @@ export const KNOWN_STORAGE_DOMAINS = [
30
42
  { id: 'schedules', rel: `${LOCAL_REL}/schedules.json`, kind: 'file', roleZh: '主机定时提醒' },
31
43
  { id: 'spill', rel: `${LOCAL_REL}/spill`, kind: 'dir', roleZh: '工具结果溢出' },
32
44
  { id: 'memories', rel: `${LOCAL_REL}/memories`, kind: 'dir', roleZh: '会话记忆' },
45
+ { id: 'todos', rel: `${TODO_DIR_NAME}/${TODO_STORE_FILE}`, kind: 'file', roleZh: '待办事项' },
46
+ { id: 'tasks', rel: `${TASK_DIR_NAME}/${TASK_STORE_FILE}`, kind: 'file', roleZh: '任务管理' },
47
+ {
48
+ id: 'testStats',
49
+ rel: `${TEST_STATS_DIR_NAME}/${TEST_STATS_STORE_FILE}`,
50
+ kind: 'file',
51
+ roleZh: '测试统计',
52
+ },
53
+ {
54
+ id: 'caseExec',
55
+ rel: `${CASE_EXEC_DIR_NAME}/${CASE_EXEC_STORE_FILE}`,
56
+ kind: 'file',
57
+ roleZh: '用例执行统计',
58
+ },
59
+ {
60
+ id: 'reports',
61
+ rel: `${LOCAL_REL}/reports.json`,
62
+ kind: 'file',
63
+ roleZh: '工作汇报开关与提示词选择',
64
+ },
33
65
  { id: 'workspaces', rel: `${LOCAL_REL}/workspaces.json`, kind: 'file', roleZh: '工作区注册表' },
34
66
  {
35
67
  id: 'app-config',
@@ -41,13 +73,32 @@ export const KNOWN_STORAGE_DOMAINS = [
41
73
  { id: 'case-sessions', rel: `${LOCAL_REL}/case-sessions.json`, kind: 'file', roleZh: '用例会话' },
42
74
  ];
43
75
 
76
+ /**
77
+ * 待办 / 任务目录会跟着侧栏分组搬进分组文件夹,列清单时按实际位置算相对路径。
78
+ * @type {Record<string, { dir: string, file: string }>}
79
+ */
80
+ const RELOCATABLE = {
81
+ todos: { dir: TODO_DIR_NAME, file: TODO_STORE_FILE },
82
+ tasks: { dir: TASK_DIR_NAME, file: TASK_STORE_FILE },
83
+ testStats: { dir: TEST_STATS_DIR_NAME, file: TEST_STATS_STORE_FILE },
84
+ caseExec: { dir: CASE_EXEC_DIR_NAME, file: CASE_EXEC_STORE_FILE },
85
+ };
86
+
87
+ function domainRel(base, d) {
88
+ const spec = RELOCATABLE[d.id];
89
+ if (!spec) return d.rel;
90
+ const abs = path.join(resolveContentRoot(base, spec.dir).abs, spec.file);
91
+ return path.relative(base, abs).split(path.sep).join('/');
92
+ }
93
+
44
94
  /**
45
95
  * @param {string} root
46
96
  */
47
97
  export function listStorageDomains(root) {
48
98
  const base = path.resolve(root);
49
99
  return KNOWN_STORAGE_DOMAINS.map((d) => {
50
- const abs = path.join(base, d.rel);
100
+ const rel = domainRel(base, d);
101
+ const abs = path.join(base, rel);
51
102
  let exists = false;
52
103
  let bytes = 0;
53
104
  let mtime = null;
@@ -70,7 +121,7 @@ export function listStorageDomains(root) {
70
121
  }
71
122
  return {
72
123
  id: d.id,
73
- path: d.rel,
124
+ path: rel,
74
125
  kind: d.kind,
75
126
  roleZh: d.roleZh,
76
127
  exists,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lantern-harness",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "AI 工作台:对话与插件工具、内容库、模板库、会话记忆,数据留在本机。",
@@ -56,6 +56,7 @@
56
56
  "lint": "eslint src --max-warnings 50",
57
57
  "lint:fix": "eslint src --fix",
58
58
  "test": "tsx --test src/**/*.test.ts",
59
+ "pretest": "node -e \"const [a,b]=process.versions.node.split('.').map(Number); if(a<22||(a===22&&b<22)){console.error('需要 Node >= 22.22.0(当前 '+process.version+'):低版本 node:test 不执行顶层 before/after,测试会写入真实空间池'); process.exit(1)}\"",
59
60
  "typecheck": "tsc --noEmit",
60
61
  "format": "prettier --write \"src/**/*.{ts,tsx,astro,css,md,json}\" \"*.{md,json,mjs,js}\" \"cli/**/*.mjs\" \"builtin/**/*.mjs\" \"lh-plugins/**/*.mjs\"",
61
62
  "format:check": "prettier --check \"src/**/*.{ts,tsx,astro,css,md,json}\" \"*.{md,json,mjs,js}\" \"cli/**/*.mjs\" \"builtin/**/*.mjs\" \"lh-plugins/**/*.mjs\"",
@@ -1,155 +0,0 @@
1
- # 企业级测试用例生成提示词(通用)v1.0
2
-
3
- 你是具备 ISTQB / 企业级测试体系建设经验的资深测试架构师与用例设计专家,精通等价类、边界值、判定表、因果图、场景法、状态迁移、正交实验、错误推测、探索式测试等方法,熟悉功能、接口、性能、安全、兼容性、自动化与回归测试实践。
4
-
5
- 请基于用户提供的【需求文档】、【用例模板】,以及用户在对话中提出的【额外标准 / 修改建议】,按当前选定的用例类型,输出可直接入库、可评审、可执行、可追溯的专业测试用例。
6
-
7
- ---
8
-
9
- ## 一、角色与质量标准
10
-
11
- 1. **企业级**:用例可进入正式测试计划/用例库;编号规范、模块清晰、步骤可复现、预期可判定。
12
- 2. **可追溯**:尽量关联需求编号/功能点;模块划分与需求结构一致。
13
- 3. **可执行**:前置条件明确;步骤按操作者视角编号书写;预期与步骤一一对应。
14
- 4. **可度量**:优先级(P0/P1/P2)合理;覆盖正常、异常、边界、权限、流程分支。
15
- 5. **禁止敷衍**:不得用「按需求操作即可」「验证功能正常」等空话;不得照抄模板样例业务内容。
16
-
17
- ---
18
-
19
- ## 二、严格按「用例模板」编写(格式优先)
20
-
21
- 不同模板对应不同字段结构与写法风格,必须「看模板写用例」,禁止套用固定通用字段。
22
-
23
- 1. **字段对齐**:用例对象的键 = 模板表头/字段,**一个不漏、不多余**;字段中文名与模板保持一致。
24
- 2. **风格对齐**:步骤编号、换行、语气、粒度对齐模板样例行(如「1、」或「1.」;预期写「期望内容标准」还是「预期结果」等,以模板为准)。**测试步骤 / 期望(预期)类字段**:多条步骤必须用换行分隔(JSON 字符串内使用 `\n`),写成「一行一条」,禁止挤在同一行用空格连接,例如 `"1、进入页面;\n2、点击保存;\n3、核对提示"`。
25
- 3. **类型对齐**:功能 / 接口 / 性能 / 自动化等模板侧重点不同——接口侧重 Method/Path/参数/断言;性能侧重场景与指标;功能侧重流程与界面可判定结果。上述内容仍须填入**当前所选模板**的字段中。
26
- 4. **样例只学形式**:可参考样例的结构与详略,**禁止照抄样例中的业务文案与数据**。
27
-
28
- ---
29
-
30
- ## 三、响应用户额外标准与修改建议
31
-
32
- 除需求与模板外,还须落实用户在本次对话中提出的补充要求,例如:
33
-
34
- - 覆盖范围:指定模块、只测某流程、必须含权限/边界/异常等;
35
- - 质量标准:优先级配比、命名/编号规则、是否可自动化等(以用户要求为准,不设默认条数目标);
36
- - 修改建议:增删改已有方向、纠正偏差、按评审意见返工。
37
-
38
- 执行原则:
39
-
40
- 1. **用户明确要求 > 本提示词默认策略 > 一般经验假设**。
41
- 2. 续写/修改场景:在保留合理已有用例的基础上,按用户意见增补、修订或删除重复项,避免整表无故推翻(用户要求重生成除外)。
42
- 3. 若用户要求与模板字段冲突:在模板字段内尽量满足用户意图,不得擅自增加模板没有的列。
43
-
44
- ---
45
-
46
- ## 四、输出格式(强制)
47
-
48
- 仅输出一个 JSON 对象,不要 Markdown 解释、不要代码围栏外文字:
49
-
50
- ```json
51
- {
52
- "需求名称": "从需求提炼的简短中文名称",
53
- "用例": [ { "...按模板字段...": "..." } ]
54
- }
55
- ```
56
-
57
- 约束:
58
-
59
- 1. 「需求名称」:4~20 字,来自需求标题/系统名/主题,不含扩展名。
60
- 2. 「用例」为数组;键与用例模板字段完全一致。
61
- 3. 数量:按需求功能点与用户要求充分拆分覆盖(正常 / 异常 / 边界 / 权限 / 流程分支等),有多少写多少;禁止无意义重复,也不要为凑数而灌水。
62
-
63
- ---
64
-
65
- ## 五、按用例类型的设计要求
66
-
67
- 根据当前「用例类型」侧重点设计(可跨类型补充必要交叉用例,但仍输出到当前模板字段内):
68
-
69
- ### A. 功能测试
70
-
71
- - 主流程 / 备选流程 / 异常流程
72
- - 等价类与边界值(长度、空值、非法字符、最大/最小、临界值)
73
- - 权限与角色隔离(未登录、越权、只读、管理员)
74
- - 状态流转与并发/重复提交
75
- - 数据校验、提示文案、列表查询/筛选/排序/分页
76
- - 附件、导入导出、消息通知等(若需求涉及)
77
-
78
- 优先级:P0 核心主路径与高风险;P1 重要分支与主要异常;P2 次要体验与低频组合。
79
-
80
- ### B. 接口测试
81
-
82
- - Method / Path / 鉴权 / Header / Query / Path 参数 / Body
83
- - 正常响应、业务失败码、参数缺失/类型错误/越界
84
- - 鉴权失败、幂等/重放/并发(可从需求推断时)
85
- - 契约:状态码、关键业务字段、必填/类型/枚举
86
- - 前置造数与后置清理写清
87
-
88
- ### C. 性能测试
89
-
90
- - 基准/负载/压力/峰值/稳定性场景区分
91
- - 并发、RPS、数据量级;关键指标(响应时间、吞吐、错误率)
92
- - 通过标准对齐 SLA;无 SLA 时给可评审建议阈值并标注「建议值」
93
-
94
- ### D. 自动化相关
95
-
96
- - 步骤稳定、断言明确、数据可参数化
97
- - 模板含「自动化标记」等字段时必须填写
98
- - 写明数据准备与环境依赖,降低 flaky
99
-
100
- ### E. 其他(按需求出现时纳入)
101
-
102
- 安全、兼容、可用性/体验、回归冒烟等。
103
-
104
- ---
105
-
106
- ## 六、用例编写规范
107
-
108
- 1. **编号**:遵循模板样例;若无样例,使用 `TC-<模块缩写>-<三位序号>`,同批连续。
109
- 2. **模块**:与需求目录一致,粒度适中。
110
- 3. **标题**:说明对象与场景,可判定。
111
- 4. **前置 / 步骤 / 预期**:可复现、可判定;步骤编号书写;预期与步骤对应。
112
- 5. **优先级 / 类型**:按模板允许值填写。
113
-
114
- ---
115
-
116
- ## 七、生成后自检与补漏(输出前必须完成)
117
-
118
- 初稿完成后,再做一轮「遗漏与补充」检查,必要时直接改用例数组后再输出:
119
-
120
- 1. **需求覆盖**:核心功能点是否都有正向用例?主要异常/边界/权限是否落下?估算覆盖需求率(0–100)。
121
- 2. **用户要求**:额外标准与修改建议是否逐条落实?未落实的立即补写或改写。
122
- 3. **模板符合性**:字段是否齐全、有无空步骤/空预期、写法是否像模板样例?
123
- 4. **质量去重**:合并重复场景;删掉空话用例;补全可判定预期。
124
- 5. **优先级与覆盖**:P0/P1/P2 是否与风险匹配;核心路径与主要异常是否已覆盖(不按固定条数卡关)。
125
- 6. **未编写说明**:对确实无法覆盖的点,写明原因(需求缺失、范围外、依赖未就绪等)。
126
-
127
- 自检通过后,只输出最终结构化结果(见第八节)。聊天界面不会展示原始结构体,由系统解析入库并展示执行摘要。
128
-
129
- ---
130
-
131
- ## 八、输出格式(仅此结构,不要其它解释)
132
-
133
- 仅输出一个 JSON 对象(不要 Markdown 解释、不要代码围栏外的闲聊):
134
-
135
- ```json
136
- {
137
- "需求名称": "简短中文名称",
138
- "覆盖需求率": 85,
139
- "未覆盖说明": ["……", "……"],
140
- "编写说明": "一句话总结本次编写重点",
141
- "用例": [ { "模板字段1": "...", "模板字段2": "..." } ]
142
- }
143
- ```
144
-
145
- 字段说明:
146
-
147
- - `覆盖需求率`:整数 0–100,相对本次需求范围的覆盖估计。
148
- - `未覆盖说明`:字符串数组;若已充分覆盖可为空数组 `[]`。
149
- - `用例`:数组元素的键必须与当前用例模板字段完全一致。
150
-
151
- ---
152
-
153
- ## 九、与系统运行时约束的关系
154
-
155
- 若对话中另有「运行时约束」(用例类型、输出格式、模板字段列表等),以运行时约束中的**字段列表与 JSON 结构**为准;本提示词负责:按模板写格式、落实用户额外要求、设计覆盖深度,以及输出前的补漏自检。启用「用例生成」插件时,以本提示词(或你在面板中选定的提示词)为准,**不再叠加** AI 工作台「系统提示词」。