openprototype 1.0.1 → 1.1.0
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 +6 -4
- package/README.zh-CN.md +6 -4
- package/bin/cli.js +153 -6
- package/lib/config.js +6 -0
- package/lib/service-manager.js +452 -0
- package/package.json +3 -1
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.html +25 -0
- package/product/demo/pc/customer//350/256/242/345/215/225/order_list.md +18 -0
- package/product/demo/pc/index.html +267 -22
- package/product/demo/pc/nav-tree.json +11 -2
- package/proto-kit.config.json +3 -0
- package/runtime/server.js +177 -15
- package/runtime/service-runner.js +138 -0
- package/runtime/shared/common/prd-panel.js +55 -5
- package/runtime/shell/agent-panel.css +65 -0
- package/runtime/shell/agent-panel.js +62 -20
- package/scripts/check/service-smoke-test.js +172 -0
- package/scripts/check/sync-nav-tree.js +30 -1
- package/scripts/postinstall.js +52 -0
- package/templates/product-shell/index.html +267 -22
package/runtime/server.js
CHANGED
|
@@ -18,6 +18,11 @@ const path = require('path');
|
|
|
18
18
|
const { spawn } = require('child_process');
|
|
19
19
|
const { loadConfig } = require('../lib/config');
|
|
20
20
|
|
|
21
|
+
function resolveArg(name) {
|
|
22
|
+
const i = process.argv.indexOf(name);
|
|
23
|
+
return i !== -1 && process.argv[i + 1] ? process.argv[i + 1] : '';
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
function resolvePortArg(fallback) {
|
|
22
27
|
const i = process.argv.indexOf('--port');
|
|
23
28
|
if (i !== -1 && process.argv[i + 1]) return Number(process.argv[i + 1]);
|
|
@@ -30,9 +35,15 @@ function resolveHostArg(fallback) {
|
|
|
30
35
|
return fallback;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
const EXPLICIT_ROOT = resolveArg('--root');
|
|
39
|
+
const SERVICE_ID = resolveArg('--service-id') || process.env.OPENPROTOTYPE_SERVICE_ID || '';
|
|
40
|
+
const STARTED_AT = new Date().toISOString();
|
|
41
|
+
let PACKAGE_VERSION = 'unknown';
|
|
42
|
+
try { PACKAGE_VERSION = require('../package.json').version || PACKAGE_VERSION; } catch {}
|
|
43
|
+
|
|
44
|
+
let CONFIG = loadConfig(EXPLICIT_ROOT || undefined);
|
|
34
45
|
// 当前目录没有 proto-kit.config.json 时(例如直接跑本包自带 demo),回退用本包自己的配置
|
|
35
|
-
if (!CONFIG.hasConfigFile) {
|
|
46
|
+
if (!EXPLICIT_ROOT && !CONFIG.hasConfigFile) {
|
|
36
47
|
const pkgConfig = loadConfig(__dirname);
|
|
37
48
|
if (pkgConfig.hasConfigFile) CONFIG = pkgConfig;
|
|
38
49
|
}
|
|
@@ -146,7 +157,7 @@ function handleSavePrd(req, res) {
|
|
|
146
157
|
});
|
|
147
158
|
}
|
|
148
159
|
|
|
149
|
-
// ──
|
|
160
|
+
// ── 导航树管理(创建 / 排序)────────────────────
|
|
150
161
|
const NAME_SEGMENT_RE = /^[A-Za-z0-9_\-一-龥]+$/;
|
|
151
162
|
|
|
152
163
|
function assertValidSegment(name, label) {
|
|
@@ -173,13 +184,6 @@ function resolveParentDir(rootDir, parent) {
|
|
|
173
184
|
return { dir, rel: segments.join('/') };
|
|
174
185
|
}
|
|
175
186
|
|
|
176
|
-
function compareNavNodes(a, b) {
|
|
177
|
-
const aIsFolder = !!a.children;
|
|
178
|
-
const bIsFolder = !!b.children;
|
|
179
|
-
if (aIsFolder !== bIsFolder) return aIsFolder ? -1 : 1;
|
|
180
|
-
return (a.name || a.file).localeCompare(b.name || b.file, 'zh-Hans-CN');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
187
|
function loadNavTree(rootDir) {
|
|
184
188
|
const file = path.join(rootDir, 'nav-tree.json');
|
|
185
189
|
if (!fs.existsSync(file)) return [];
|
|
@@ -199,13 +203,128 @@ function ensureNavFolder(tree, relParent) {
|
|
|
199
203
|
if (!node) {
|
|
200
204
|
node = { name, children: [] };
|
|
201
205
|
level.push(node);
|
|
202
|
-
level.sort(compareNavNodes);
|
|
203
206
|
}
|
|
204
207
|
level = node.children;
|
|
205
208
|
}
|
|
206
209
|
return level;
|
|
207
210
|
}
|
|
208
211
|
|
|
212
|
+
function getNavLevel(tree, relParent) {
|
|
213
|
+
let level = tree;
|
|
214
|
+
if (!relParent) return level;
|
|
215
|
+
for (const name of relParent.split('/')) {
|
|
216
|
+
const node = level.find((item) => item.children && item.name === name);
|
|
217
|
+
if (!node) throw new Error('导航树中不存在指定父目录');
|
|
218
|
+
level = node.children;
|
|
219
|
+
}
|
|
220
|
+
return level;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function resolveReorderParent(rootDir, parent) {
|
|
224
|
+
const relParent = String(parent || '').replace(/^\/+|\/+$/g, '');
|
|
225
|
+
const dir = path.resolve(rootDir, ...relParent.split('/').filter(Boolean));
|
|
226
|
+
if (dir !== rootDir && !dir.startsWith(rootDir + path.sep)) throw new Error('父目录超出产品范围');
|
|
227
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) throw new Error('父目录不存在');
|
|
228
|
+
return relParent;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function navNodeKey(node) {
|
|
232
|
+
return node.file ? `file:${node.file}` : `folder:${node.name}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function resolvePageFile(rootDir, inputPath) {
|
|
236
|
+
const relPath = String(inputPath || '').replace(/^\/+|\/+$/g, '');
|
|
237
|
+
const segments = relPath.split('/').filter(Boolean);
|
|
238
|
+
const fileName = segments.pop();
|
|
239
|
+
if (!fileName || !fileName.toLowerCase().endsWith('.html')) {
|
|
240
|
+
throw new Error('仅允许移动 .html 页面');
|
|
241
|
+
}
|
|
242
|
+
const pageName = fileName.slice(0, -'.html'.length);
|
|
243
|
+
assertValidSegment(pageName, '页面名');
|
|
244
|
+
segments.forEach((seg) => assertValidSegment(seg, '页面目录名'));
|
|
245
|
+
const parent = segments.join('/');
|
|
246
|
+
const dir = path.join(rootDir, ...segments);
|
|
247
|
+
const file = path.join(dir, fileName);
|
|
248
|
+
if (file !== rootDir && !file.startsWith(rootDir + path.sep)) throw new Error('页面路径超出产品范围');
|
|
249
|
+
if (!fs.existsSync(file) || !fs.statSync(file).isFile()) throw new Error('源页面不存在');
|
|
250
|
+
return { dir, parent, file, fileName, pageName, relPath: [...segments, fileName].join('/') };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function saveNavTreeAtomically(rootDir, tree) {
|
|
254
|
+
const file = path.join(rootDir, 'nav-tree.json');
|
|
255
|
+
const tempFile = path.join(rootDir, `.nav-tree-${process.pid}-${Date.now()}.tmp`);
|
|
256
|
+
try {
|
|
257
|
+
fs.writeFileSync(tempFile, JSON.stringify(tree, null, 2) + '\n');
|
|
258
|
+
fs.renameSync(tempFile, file);
|
|
259
|
+
} finally {
|
|
260
|
+
if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function handleMovePage(req, res) {
|
|
265
|
+
readJsonBody(req, 64 * 1024, (parseErr, data) => {
|
|
266
|
+
const moved = [];
|
|
267
|
+
try {
|
|
268
|
+
if (parseErr) throw parseErr;
|
|
269
|
+
const rootDir = resolveProductRootDir(data.base);
|
|
270
|
+
const source = resolvePageFile(rootDir, data.sourcePath);
|
|
271
|
+
const { dir: targetDir, rel: targetFolder } = resolveParentDir(rootDir, data.targetFolder);
|
|
272
|
+
if (source.parent === targetFolder) throw new Error('页面已在目标文件夹中');
|
|
273
|
+
|
|
274
|
+
const bundleNames = [`${source.pageName}.html`, `${source.pageName}.js`, `${source.pageName}.md`];
|
|
275
|
+
const conflicts = bundleNames.filter((name) => fs.existsSync(path.join(targetDir, name)));
|
|
276
|
+
if (conflicts.length) throw new Error(`目标文件夹已存在同名文件:${conflicts.join('、')}`);
|
|
277
|
+
|
|
278
|
+
const bundle = bundleNames
|
|
279
|
+
.map((name) => ({ source: path.join(source.dir, name), target: path.join(targetDir, name), name }))
|
|
280
|
+
.filter((item) => fs.existsSync(item.source) && fs.statSync(item.source).isFile());
|
|
281
|
+
if (!bundle.some((item) => item.name === source.fileName)) throw new Error('源页面不存在');
|
|
282
|
+
|
|
283
|
+
const tree = loadNavTree(rootDir);
|
|
284
|
+
const sourceLevel = getNavLevel(tree, source.parent);
|
|
285
|
+
const sourceIndex = sourceLevel.findIndex((node) => node.file === source.fileName && node.path === source.relPath);
|
|
286
|
+
if (sourceIndex < 0) throw new Error('导航树中不存在源页面,请刷新后重试');
|
|
287
|
+
const sourceNode = sourceLevel[sourceIndex];
|
|
288
|
+
const targetLevel = getNavLevel(tree, targetFolder);
|
|
289
|
+
const targetPath = targetFolder ? `${targetFolder}/${source.fileName}` : source.fileName;
|
|
290
|
+
|
|
291
|
+
bundle.forEach((item) => {
|
|
292
|
+
fs.renameSync(item.source, item.target);
|
|
293
|
+
moved.push(item);
|
|
294
|
+
});
|
|
295
|
+
sourceLevel.splice(sourceIndex, 1);
|
|
296
|
+
targetLevel.push({
|
|
297
|
+
file: source.fileName,
|
|
298
|
+
path: targetPath,
|
|
299
|
+
...(sourceNode.title ? { title: sourceNode.title } : {})
|
|
300
|
+
});
|
|
301
|
+
saveNavTreeAtomically(rootDir, tree);
|
|
302
|
+
|
|
303
|
+
console.log(`[200] POST /api/move-page -> ${source.relPath} => ${targetPath}`);
|
|
304
|
+
sendJson(res, 200, {
|
|
305
|
+
ok: true,
|
|
306
|
+
sourcePath: source.relPath,
|
|
307
|
+
path: targetPath,
|
|
308
|
+
movedFiles: moved.map((item) => targetFolder ? `${targetFolder}/${item.name}` : item.name)
|
|
309
|
+
});
|
|
310
|
+
} catch (err) {
|
|
311
|
+
const rollbackErrors = [];
|
|
312
|
+
moved.reverse().forEach((item) => {
|
|
313
|
+
try {
|
|
314
|
+
if (fs.existsSync(item.target) && !fs.existsSync(item.source)) fs.renameSync(item.target, item.source);
|
|
315
|
+
} catch (rollbackErr) {
|
|
316
|
+
rollbackErrors.push(rollbackErr.message);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const errorMessage = rollbackErrors.length
|
|
320
|
+
? `${err.message};回滚失败:${rollbackErrors.join('、')}`
|
|
321
|
+
: err.message;
|
|
322
|
+
console.log(`[400] POST /api/move-page -> ${errorMessage}`);
|
|
323
|
+
sendJson(res, 400, { ok: false, error: errorMessage });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
209
328
|
function todayString() {
|
|
210
329
|
const now = new Date();
|
|
211
330
|
const pad = (n) => String(n).padStart(2, '0');
|
|
@@ -295,7 +414,7 @@ function handleCreatePage(req, res) {
|
|
|
295
414
|
const { dir: parentDir, rel: parentRel } = resolveParentDir(rootDir, data.parent);
|
|
296
415
|
const name = String(data.name || '').trim().replace(/\.html$/i, '');
|
|
297
416
|
assertValidSegment(name, '页面名');
|
|
298
|
-
const title =
|
|
417
|
+
const title = name;
|
|
299
418
|
const htmlFile = path.join(parentDir, `${name}.html`);
|
|
300
419
|
const mdFile = path.join(parentDir, `${name}.md`);
|
|
301
420
|
if (fs.existsSync(htmlFile)) throw new Error('同名页面已存在');
|
|
@@ -305,8 +424,7 @@ function handleCreatePage(req, res) {
|
|
|
305
424
|
const tree = loadNavTree(rootDir);
|
|
306
425
|
const children = ensureNavFolder(tree, parentRel);
|
|
307
426
|
if (!children.some((n) => n.file === `${name}.html`)) {
|
|
308
|
-
children.push({ file: `${name}.html`, path: relPath });
|
|
309
|
-
children.sort(compareNavNodes);
|
|
427
|
+
children.push({ file: `${name}.html`, path: relPath, title });
|
|
310
428
|
}
|
|
311
429
|
saveNavTree(rootDir, tree);
|
|
312
430
|
console.log(`[200] POST /api/create-page -> ${htmlFile}`);
|
|
@@ -318,6 +436,36 @@ function handleCreatePage(req, res) {
|
|
|
318
436
|
});
|
|
319
437
|
}
|
|
320
438
|
|
|
439
|
+
function handleReorderNav(req, res) {
|
|
440
|
+
readJsonBody(req, 64 * 1024, (parseErr, data) => {
|
|
441
|
+
try {
|
|
442
|
+
if (parseErr) throw parseErr;
|
|
443
|
+
const rootDir = resolveProductRootDir(data.base);
|
|
444
|
+
const parentRel = resolveReorderParent(rootDir, data.parent);
|
|
445
|
+
const orderedKeys = Array.isArray(data.orderedKeys) ? data.orderedKeys.map(String) : [];
|
|
446
|
+
const tree = loadNavTree(rootDir);
|
|
447
|
+
const level = getNavLevel(tree, parentRel);
|
|
448
|
+
const currentKeys = level.map(navNodeKey);
|
|
449
|
+
const uniqueKeys = new Set(orderedKeys);
|
|
450
|
+
if (
|
|
451
|
+
orderedKeys.length !== currentKeys.length ||
|
|
452
|
+
uniqueKeys.size !== orderedKeys.length ||
|
|
453
|
+
currentKeys.some((key) => !uniqueKeys.has(key))
|
|
454
|
+
) {
|
|
455
|
+
throw new Error('排序节点与当前导航树不一致,请刷新后重试');
|
|
456
|
+
}
|
|
457
|
+
const nodesByKey = new Map(level.map((node) => [navNodeKey(node), node]));
|
|
458
|
+
level.splice(0, level.length, ...orderedKeys.map((key) => nodesByKey.get(key)));
|
|
459
|
+
saveNavTree(rootDir, tree);
|
|
460
|
+
console.log(`[200] POST /api/reorder-nav -> ${rootDir} (${parentRel || '根目录'})`);
|
|
461
|
+
sendJson(res, 200, { ok: true });
|
|
462
|
+
} catch (err) {
|
|
463
|
+
console.log(`[400] POST /api/reorder-nav -> ${err.message}`);
|
|
464
|
+
sendJson(res, 400, { ok: false, error: err.message });
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
321
469
|
// ── PRD 标红提取 ───────────────────────────────────────
|
|
322
470
|
function normalizeRedMarkedContent(text) {
|
|
323
471
|
return String(text || '')
|
|
@@ -784,11 +932,25 @@ const server = http.createServer(async (req, res) => {
|
|
|
784
932
|
return res.end('Bad Request');
|
|
785
933
|
}
|
|
786
934
|
|
|
935
|
+
if (req.method === 'GET' && urlPath === '/api/health') {
|
|
936
|
+
if (!requireLoopback(req, res)) return;
|
|
937
|
+
return sendJson(res, 200, {
|
|
938
|
+
ok: true,
|
|
939
|
+
serviceId: SERVICE_ID,
|
|
940
|
+
version: PACKAGE_VERSION,
|
|
941
|
+
pid: process.pid,
|
|
942
|
+
port: PORT,
|
|
943
|
+
startedAt: STARTED_AT
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
|
|
787
947
|
if (await handleAgentApi(req, res, urlPath)) return;
|
|
788
948
|
|
|
789
949
|
if (req.method === 'POST' && urlPath === '/api/save-prd') return requireLoopback(req, res) && handleSavePrd(req, res);
|
|
790
950
|
if (req.method === 'POST' && urlPath === '/api/create-folder') return requireLoopback(req, res) && handleCreateFolder(req, res);
|
|
791
951
|
if (req.method === 'POST' && urlPath === '/api/create-page') return requireLoopback(req, res) && handleCreatePage(req, res);
|
|
952
|
+
if (req.method === 'POST' && urlPath === '/api/reorder-nav') return requireLoopback(req, res) && handleReorderNav(req, res);
|
|
953
|
+
if (req.method === 'POST' && urlPath === '/api/move-page') return requireLoopback(req, res) && handleMovePage(req, res);
|
|
792
954
|
if (req.method === 'POST' && urlPath === '/api/build-update-page-prompt') return requireLoopback(req, res) && handleBuildUpdatePagePrompt(req, res);
|
|
793
955
|
if (req.method === 'POST' && urlPath === '/api/update-page-from-prd') return requireLoopback(req, res) && handleUpdatePageFromPrd(req, res);
|
|
794
956
|
|
|
@@ -814,7 +976,7 @@ const server = http.createServer(async (req, res) => {
|
|
|
814
976
|
});
|
|
815
977
|
|
|
816
978
|
server.on('error', (err) => {
|
|
817
|
-
if (err.code === 'EADDRINUSE') console.error(`端口 ${PORT}
|
|
979
|
+
if (err.code === 'EADDRINUSE') console.error(`端口 ${PORT} 已被占用。若常驻服务已启动,请使用 openprototype service status;否则请关闭占用进程或修改 proto-kit.config.json。`);
|
|
818
980
|
else console.error('服务器错误:', err);
|
|
819
981
|
process.exit(1);
|
|
820
982
|
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
const { spawn } = require('child_process');
|
|
8
|
+
|
|
9
|
+
function argValue(name) {
|
|
10
|
+
const index = process.argv.indexOf(name);
|
|
11
|
+
return index !== -1 && process.argv[index + 1] ? process.argv[index + 1] : '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const manifestPath = argValue('--manifest');
|
|
15
|
+
if (!manifestPath) process.exit(1);
|
|
16
|
+
|
|
17
|
+
let manifest;
|
|
18
|
+
try {
|
|
19
|
+
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
20
|
+
} catch {
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fs.mkdirSync(path.dirname(manifest.logPath), { recursive: true });
|
|
25
|
+
try {
|
|
26
|
+
const stat = fs.statSync(manifest.logPath);
|
|
27
|
+
if (stat.size > 5 * 1024 * 1024) {
|
|
28
|
+
const previous = manifest.logPath + '.1';
|
|
29
|
+
try { fs.unlinkSync(previous); } catch {}
|
|
30
|
+
fs.renameSync(manifest.logPath, previous);
|
|
31
|
+
}
|
|
32
|
+
} catch {}
|
|
33
|
+
|
|
34
|
+
const logFd = fs.openSync(manifest.logPath, 'a');
|
|
35
|
+
function log(message) {
|
|
36
|
+
fs.writeSync(logFd, `[${new Date().toISOString()}] ${message}\n`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log = (...args) => log(util.format(...args));
|
|
40
|
+
console.info = (...args) => log(util.format(...args));
|
|
41
|
+
console.warn = (...args) => log(`WARN ${util.format(...args)}`);
|
|
42
|
+
console.error = (...args) => log(`ERROR ${util.format(...args)}`);
|
|
43
|
+
|
|
44
|
+
const requiredPaths = [manifest.projectRoot, manifest.configPath, manifest.serverPath];
|
|
45
|
+
if (requiredPaths.some((target) => !fs.existsSync(target))) {
|
|
46
|
+
log('项目或 openprototype 包已不存在,服务停止。运行 service prune 可清理系统注册。');
|
|
47
|
+
fs.closeSync(logFd);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let missingChecks = 0;
|
|
52
|
+
let serverChild = null;
|
|
53
|
+
let restartTimer = null;
|
|
54
|
+
let shuttingDown = false;
|
|
55
|
+
|
|
56
|
+
function stopServerChild() {
|
|
57
|
+
shuttingDown = true;
|
|
58
|
+
if (restartTimer) clearTimeout(restartTimer);
|
|
59
|
+
restartTimer = null;
|
|
60
|
+
if (serverChild && !serverChild.killed) {
|
|
61
|
+
try { serverChild.kill(); } catch {}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pathTimer = setInterval(() => {
|
|
66
|
+
if (requiredPaths.every((target) => fs.existsSync(target))) {
|
|
67
|
+
missingChecks = 0;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
missingChecks += 1;
|
|
71
|
+
if (missingChecks >= 3) {
|
|
72
|
+
log('连续检测到项目或包路径失效,停止服务。');
|
|
73
|
+
stopServerChild();
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
}, 30000);
|
|
77
|
+
|
|
78
|
+
process.on('exit', () => {
|
|
79
|
+
clearInterval(pathTimer);
|
|
80
|
+
if (restartTimer) clearTimeout(restartTimer);
|
|
81
|
+
try { fs.closeSync(logFd); } catch {}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
process.on('SIGINT', () => {
|
|
85
|
+
stopServerChild();
|
|
86
|
+
process.exit(0);
|
|
87
|
+
});
|
|
88
|
+
process.on('SIGTERM', () => {
|
|
89
|
+
stopServerChild();
|
|
90
|
+
process.exit(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
function startWindowsServer() {
|
|
94
|
+
if (shuttingDown) return;
|
|
95
|
+
const env = Object.assign({}, process.env, { OPENPROTOTYPE_SERVICE_ID: manifest.serviceId });
|
|
96
|
+
const args = [manifest.serverPath, '--root', manifest.projectRoot, '--service-id', manifest.serviceId];
|
|
97
|
+
log(`启动 openprototype ${manifest.packageVersion},项目:${manifest.projectRoot}`);
|
|
98
|
+
serverChild = spawn(manifest.nodePath, args, {
|
|
99
|
+
cwd: manifest.projectRoot,
|
|
100
|
+
env,
|
|
101
|
+
stdio: ['ignore', logFd, logFd],
|
|
102
|
+
windowsHide: true
|
|
103
|
+
});
|
|
104
|
+
serverChild.once('error', (err) => {
|
|
105
|
+
log(`启动失败:${err.stack || err.message}`);
|
|
106
|
+
serverChild = null;
|
|
107
|
+
scheduleWindowsRestart();
|
|
108
|
+
});
|
|
109
|
+
serverChild.once('exit', (code, signal) => {
|
|
110
|
+
serverChild = null;
|
|
111
|
+
if (shuttingDown) return;
|
|
112
|
+
log(`服务器进程退出(code=${code}, signal=${signal || 'none'}),2 秒后重启。`);
|
|
113
|
+
scheduleWindowsRestart();
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function scheduleWindowsRestart() {
|
|
118
|
+
if (shuttingDown || restartTimer) return;
|
|
119
|
+
restartTimer = setTimeout(() => {
|
|
120
|
+
restartTimer = null;
|
|
121
|
+
startWindowsServer();
|
|
122
|
+
}, 2000);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
process.chdir(manifest.projectRoot);
|
|
127
|
+
if (process.platform === 'win32') {
|
|
128
|
+
startWindowsServer();
|
|
129
|
+
} else {
|
|
130
|
+
process.env.OPENPROTOTYPE_SERVICE_ID = manifest.serviceId;
|
|
131
|
+
process.argv.push('--root', manifest.projectRoot, '--service-id', manifest.serviceId);
|
|
132
|
+
log(`启动 openprototype ${manifest.packageVersion},项目:${manifest.projectRoot}`);
|
|
133
|
+
require(manifest.serverPath);
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
log(`启动失败:${err.stack || err.message}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// 页面可在引入本模块前声明这些全局以覆盖默认行为;未声明时使用默认值。
|
|
7
|
-
// PRD_OVERVIEW_VERSION
|
|
7
|
+
// “当前版本”优先读取主 PRD 历史记录中的最大版本;PRD_OVERVIEW_VERSION 仅作兼容兜底。
|
|
8
|
+
// PRD_WORKSPACE_MAP 配置多文档工作区。
|
|
8
9
|
var PRD_BASE_PATH = typeof PRD_BASE_PATH !== 'undefined' ? PRD_BASE_PATH : './';
|
|
9
10
|
var PRD_FILE_MAP = typeof PRD_FILE_MAP !== 'undefined' ? PRD_FILE_MAP : {};
|
|
10
11
|
var PRD_CACHE = typeof PRD_CACHE !== 'undefined' ? PRD_CACHE : {};
|
|
@@ -185,6 +186,11 @@ function ensurePrdPanelDom() {
|
|
|
185
186
|
document.body.appendChild(prdFloatBtn);
|
|
186
187
|
}
|
|
187
188
|
|
|
189
|
+
var legacyPrdBtn = document.getElementById('openPrd');
|
|
190
|
+
if (legacyPrdBtn) {
|
|
191
|
+
legacyPrdBtn.style.display = 'none';
|
|
192
|
+
}
|
|
193
|
+
|
|
188
194
|
var prdPanel = document.getElementById('prdPanel');
|
|
189
195
|
if (!prdPanel) {
|
|
190
196
|
prdPanel = document.createElement('div');
|
|
@@ -212,7 +218,10 @@ function initPrdPanel() {
|
|
|
212
218
|
|
|
213
219
|
var prdFloatBtn = document.getElementById('prdFloatBtn');
|
|
214
220
|
if (prdFloatBtn) {
|
|
215
|
-
prdFloatBtn.addEventListener('click',
|
|
221
|
+
prdFloatBtn.addEventListener('click', function(event) {
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
togglePrdPanel();
|
|
224
|
+
});
|
|
216
225
|
}
|
|
217
226
|
|
|
218
227
|
var prdPanelCloseBtn = document.getElementById('prdPanelCloseBtn');
|
|
@@ -331,6 +340,7 @@ var prdWorkspaceTabs = [];
|
|
|
331
340
|
var prdEditMode = false;
|
|
332
341
|
var prdWorkspaceRootPath = '';
|
|
333
342
|
var prdOverviewMarkdown = '';
|
|
343
|
+
var prdOverviewVersion = '';
|
|
334
344
|
var prdOverviewBuildToken = 0;
|
|
335
345
|
var PRD_OVERVIEW_PATH = './__openprototype_current_version__.md';
|
|
336
346
|
|
|
@@ -424,7 +434,42 @@ function getPrdDisplayName(filePath) {
|
|
|
424
434
|
return (filePath || '').split('/').pop().replace(/\.md(?:#.*)?$/i, '').replace(/_/g, ' ');
|
|
425
435
|
}
|
|
426
436
|
|
|
427
|
-
function
|
|
437
|
+
function comparePrdVersions(left, right) {
|
|
438
|
+
var leftParts = String(left || '').replace(/^v/i, '').split('.');
|
|
439
|
+
var rightParts = String(right || '').replace(/^v/i, '').split('.');
|
|
440
|
+
var length = Math.max(leftParts.length, rightParts.length);
|
|
441
|
+
|
|
442
|
+
for (var index = 0; index < length; index += 1) {
|
|
443
|
+
var leftPart = leftParts[index] || '0';
|
|
444
|
+
var rightPart = rightParts[index] || '0';
|
|
445
|
+
var leftNumber = /^\d+$/.test(leftPart) ? Number(leftPart) : null;
|
|
446
|
+
var rightNumber = /^\d+$/.test(rightPart) ? Number(rightPart) : null;
|
|
447
|
+
var comparison = leftNumber !== null && rightNumber !== null
|
|
448
|
+
? leftNumber - rightNumber
|
|
449
|
+
: leftPart.localeCompare(rightPart, undefined, { numeric: true, sensitivity: 'base' });
|
|
450
|
+
if (comparison !== 0) return comparison;
|
|
451
|
+
}
|
|
452
|
+
return 0;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function getPrdHistoryMaxVersion(content) {
|
|
456
|
+
var plainText = String(content || '').replace(/<[^>]+>/g, '');
|
|
457
|
+
var pattern = /^\|\s*(v\d+(?:\.[0-9a-z]+)+)\s*\|/gim;
|
|
458
|
+
var versions = [];
|
|
459
|
+
var match;
|
|
460
|
+
while ((match = pattern.exec(plainText)) !== null) {
|
|
461
|
+
versions.push(match[1]);
|
|
462
|
+
}
|
|
463
|
+
if (!versions.length) return '';
|
|
464
|
+
return versions.reduce(function(maxVersion, version) {
|
|
465
|
+
return comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function getPrdOverviewVersion(rootContent) {
|
|
470
|
+
var historyMaxVersion = getPrdHistoryMaxVersion(rootContent);
|
|
471
|
+
if (historyMaxVersion) return historyMaxVersion;
|
|
472
|
+
if (prdOverviewVersion) return prdOverviewVersion;
|
|
428
473
|
if (typeof PRD_OVERVIEW_VERSION === 'undefined') return '';
|
|
429
474
|
return String(PRD_OVERVIEW_VERSION || '').trim();
|
|
430
475
|
}
|
|
@@ -544,7 +589,7 @@ function buildPrdOverviewMarkdown(tabs, contents, version) {
|
|
|
544
589
|
}
|
|
545
590
|
|
|
546
591
|
function renderPrdOverview() {
|
|
547
|
-
var version =
|
|
592
|
+
var version = prdOverviewVersion;
|
|
548
593
|
var contentEl = document.getElementById('prdPanelContent');
|
|
549
594
|
var titleEl = document.getElementById('prdPanelTitle');
|
|
550
595
|
var fileNameEl = document.getElementById('prdPanelFileName');
|
|
@@ -567,13 +612,17 @@ function renderPrdOverview() {
|
|
|
567
612
|
|
|
568
613
|
function preparePrdOverview(rootPath, options) {
|
|
569
614
|
options = options || {};
|
|
570
|
-
var version = getPrdOverviewVersion();
|
|
571
615
|
var realTabs = prdWorkspaceTabs.filter(function(tab) {
|
|
572
616
|
return !isPrdOverviewPath(tab.path);
|
|
573
617
|
});
|
|
574
618
|
var contentOverrides = options.contentOverrides || {};
|
|
575
619
|
var buildToken = ++prdOverviewBuildToken;
|
|
576
620
|
var normalizedRootPath = normalizePrdPath(rootPath);
|
|
621
|
+
var rootContent = Object.prototype.hasOwnProperty.call(contentOverrides, normalizedRootPath)
|
|
622
|
+
? contentOverrides[normalizedRootPath]
|
|
623
|
+
: '';
|
|
624
|
+
var version = getPrdOverviewVersion(rootContent);
|
|
625
|
+
prdOverviewVersion = version;
|
|
577
626
|
|
|
578
627
|
if (!version || !realTabs.length) {
|
|
579
628
|
prdOverviewMarkdown = '';
|
|
@@ -842,6 +891,7 @@ function updatePrdContent() {
|
|
|
842
891
|
prdOverviewBuildToken += 1;
|
|
843
892
|
prdWorkspaceRootPath = '';
|
|
844
893
|
prdOverviewMarkdown = '';
|
|
894
|
+
prdOverviewVersion = '';
|
|
845
895
|
|
|
846
896
|
if (!prdFileName) {
|
|
847
897
|
prdContentEl.innerHTML = '<div class="error" style="padding:20px;color:var(--text-secondary);">当前页面暂无对应的PRD文档</div>';
|
|
@@ -342,6 +342,7 @@
|
|
|
342
342
|
width: 100%;
|
|
343
343
|
height: 28px;
|
|
344
344
|
margin-top: 6px;
|
|
345
|
+
padding: 0 8px;
|
|
345
346
|
border: 1px solid #d8dfe9;
|
|
346
347
|
border-radius: 4px;
|
|
347
348
|
background: #fff;
|
|
@@ -350,6 +351,70 @@
|
|
|
350
351
|
font-size: 10px;
|
|
351
352
|
}
|
|
352
353
|
|
|
354
|
+
.agent-question {
|
|
355
|
+
padding: 8px 0;
|
|
356
|
+
border-top: 1px solid #f0e4c4;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.agent-request-title + .agent-question {
|
|
360
|
+
border-top: 0;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.agent-question-header {
|
|
364
|
+
margin-bottom: 3px;
|
|
365
|
+
color: #9a6700;
|
|
366
|
+
font-size: 10px;
|
|
367
|
+
font-weight: 600;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.agent-question-options {
|
|
371
|
+
display: grid;
|
|
372
|
+
gap: 5px;
|
|
373
|
+
margin-top: 7px;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.agent-question-option {
|
|
377
|
+
display: flex;
|
|
378
|
+
gap: 7px;
|
|
379
|
+
align-items: flex-start;
|
|
380
|
+
padding: 7px 8px;
|
|
381
|
+
border: 1px solid #e1e6ee;
|
|
382
|
+
border-radius: 5px;
|
|
383
|
+
background: #fff;
|
|
384
|
+
cursor: pointer;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.agent-question-option:has(.agent-question-choice:checked) {
|
|
388
|
+
border-color: #1677ff;
|
|
389
|
+
background: #f0f7ff;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.agent-question-choice {
|
|
393
|
+
flex: 0 0 auto;
|
|
394
|
+
margin: 2px 0 0;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
.agent-question-option-label {
|
|
398
|
+
color: #20242d;
|
|
399
|
+
font-size: 10px;
|
|
400
|
+
font-weight: 600;
|
|
401
|
+
line-height: 1.4;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.agent-question-option-desc {
|
|
405
|
+
margin-top: 1px;
|
|
406
|
+
color: #7b8492;
|
|
407
|
+
font-size: 9px;
|
|
408
|
+
line-height: 1.4;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.agent-question-error {
|
|
412
|
+
min-height: 14px;
|
|
413
|
+
color: #d4380d;
|
|
414
|
+
font-size: 9px;
|
|
415
|
+
line-height: 1.4;
|
|
416
|
+
}
|
|
417
|
+
|
|
353
418
|
.agent-composer {
|
|
354
419
|
flex: 0 0 auto;
|
|
355
420
|
padding: 10px 12px 12px;
|