openprototype 1.8.0 → 1.8.2

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/bin/cli.js CHANGED
@@ -135,6 +135,27 @@ const LAN_ADDRESS_CLICK = ` document.getElementById('copyAddressBtn').addEventL
135
135
  showToast(err.message || '局域网地址读取失败');
136
136
  }
137
137
  });`;
138
+ const FUZZY_VERSION_MATCH_CALL = 'fuzzyVersionMatch(prdVer, currentVer)';
139
+ const EXACT_VERSION_MATCH_CALL = 'versionSearchMatch(prdVer, currentVer)';
140
+ const FUZZY_VERSION_MATCH_HELPER = `function fuzzyVersionMatch(version, keyword) {
141
+ const source = normalizeVersionSearchText(version);
142
+ const target = normalizeVersionSearchText(keyword);
143
+ if (!target) return true;
144
+ if (source.indexOf(target) !== -1) return true;
145
+
146
+ let index = 0;
147
+ for (const char of target) {
148
+ index = source.indexOf(char, index);
149
+ if (index === -1) return false;
150
+ index++;
151
+ }
152
+ return true;
153
+ }`;
154
+ const EXACT_VERSION_MATCH_HELPER = `function versionSearchMatch(version, keyword) {
155
+ const source = normalizeVersionSearchText(version);
156
+ const target = normalizeVersionSearchText(keyword);
157
+ return !!target && source === target;
158
+ }`;
138
159
  const LEGACY_LAN_ADDRESS_MARK = 'openprototype:lan-address:start';
139
160
  const LEGACY_LAN_ADDRESS_BLOCK = `<!-- openprototype:lan-address:start -->
140
161
  <script>
@@ -298,6 +319,30 @@ function patchShellLanAddress(projectRoot) {
298
319
  return patched;
299
320
  }
300
321
 
322
+ /** 把旧产品壳的版本模糊匹配迁移为忽略格式差异后的完整匹配。 */
323
+ function patchShellVersionSearch(projectRoot) {
324
+ let patched = 0;
325
+ for (const shell of listProductShells(projectRoot)) {
326
+ const rel = path.relative(projectRoot, shell);
327
+ let html = fs.readFileSync(shell, 'utf8');
328
+ if (html.includes(EXACT_VERSION_MATCH_CALL) && html.includes(EXACT_VERSION_MATCH_HELPER)) {
329
+ info(C.dim(' 跳过(版本搜索已是精确匹配): ') + rel);
330
+ continue;
331
+ }
332
+ if (!html.includes(FUZZY_VERSION_MATCH_CALL) || !html.includes(FUZZY_VERSION_MATCH_HELPER)) {
333
+ info(C.dim(' 跳过(版本搜索逻辑不是已知旧版本): ') + rel);
334
+ continue;
335
+ }
336
+ html = html
337
+ .replace(FUZZY_VERSION_MATCH_CALL, EXACT_VERSION_MATCH_CALL)
338
+ .replace(FUZZY_VERSION_MATCH_HELPER, EXACT_VERSION_MATCH_HELPER);
339
+ fs.writeFileSync(shell, html);
340
+ ok('已迁移版本精确搜索 ' + rel);
341
+ patched++;
342
+ }
343
+ return patched;
344
+ }
345
+
301
346
  /** 新项目 package.json 里本框架的依赖版本(已发布 npm,语义化版本管理) */
302
347
  function kitDependencySpec() {
303
348
  const pkg = readJson(path.join(PKG_ROOT, 'package.json'), {});
@@ -381,6 +426,7 @@ async function cmdInit() {
381
426
 
382
427
  patchShellOnboarding(root);
383
428
  patchShellLanAddress(root);
429
+ patchShellVersionSearch(root);
384
430
 
385
431
  // 合并 package.json 脚本(不覆盖用户已有脚本)
386
432
  const pkgPath = path.join(root, 'package.json');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openprototype",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "本地原型工作台:左侧树形导航 + 中间原型预览 + 右侧 AI Agent(OpenCode)。PRD 与 HTML/JS 原型协作,含自动化检查。",
5
5
  "keywords": [
6
6
  "prototype",
@@ -756,29 +756,31 @@ function loadVersionCache() { try { return JSON.parse(navStorage.getItem(VER_CAC
756
756
  function saveVersionCache() { navStorage.setItem(VER_CACHE_KEY, JSON.stringify(versionCache)); }
757
757
  versionCache = loadVersionCache();
758
758
 
759
- function comparePrdVersions(left, right) {
760
- const leftParts = String(left || '').replace(/^v/i, '').split('.');
761
- const rightParts = String(right || '').replace(/^v/i, '').split('.');
762
- const length = Math.max(leftParts.length, rightParts.length);
763
- for (let index = 0; index < length; index += 1) {
764
- const leftPart = leftParts[index] || '0';
765
- const rightPart = rightParts[index] || '0';
766
- const leftNumber = /^\d+$/.test(leftPart) ? Number(leftPart) : null;
767
- const rightNumber = /^\d+$/.test(rightPart) ? Number(rightPart) : null;
768
- const comparison = leftNumber !== null && rightNumber !== null
769
- ? leftNumber - rightNumber
770
- : leftPart.localeCompare(rightPart, undefined, { numeric: true, sensitivity: 'base' });
771
- if (comparison !== 0) return comparison;
759
+ function extractPrdHistoryLatestVersion(text) {
760
+ const lines = String(text || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
761
+ let latestVersion = null;
762
+
763
+ for (let index = 0; index < lines.length; index += 1) {
764
+ if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
765
+
766
+ const tableLines = [];
767
+ while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
768
+ tableLines.push(lines[index]);
769
+ index += 1;
770
+ }
771
+ index -= 1;
772
+
773
+ if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
774
+ const headerCell = tableLines[0].split('|')[1] || '';
775
+ if (!headerCell.includes('版本')) continue;
776
+
777
+ tableLines.slice(2).forEach(row => {
778
+ const version = (row.split('|')[1] || '').trim();
779
+ if (version) latestVersion = version;
780
+ });
772
781
  }
773
- return 0;
774
- }
775
782
 
776
- function extractPrdHistoryMaxVersion(text) {
777
- const plainText = String(text || '').replace(/<[^>]+>/g, '');
778
- const versions = [...plainText.matchAll(/^\|\s*(v\d+(?:\.[0-9a-z]+)+)\s*\|/gim)].map(match => match[1]);
779
- return versions.length
780
- ? versions.reduce((maxVersion, version) => comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion)
781
- : null;
783
+ return latestVersion;
782
784
  }
783
785
 
784
786
  async function fetchPageVersion(htmlPath) {
@@ -787,7 +789,7 @@ async function fetchPageVersion(htmlPath) {
787
789
  const res = await fetch(mdPath, { cache: 'no-cache' });
788
790
  if (!res.ok) return null;
789
791
  const text = await res.text();
790
- return extractPrdHistoryMaxVersion(text);
792
+ return extractPrdHistoryLatestVersion(text);
791
793
  } catch { return null; }
792
794
  }
793
795
 
@@ -807,7 +809,7 @@ function applyVersionBadge(path, ver) {
807
809
  function refreshVersionMatch(row) {
808
810
  const currentVer = (document.getElementById('versionInput').value || '').trim();
809
811
  const prdVer = row.dataset.prdVersion || '';
810
- const isMatch = currentVer && prdVer && fuzzyVersionMatch(prdVer, currentVer);
812
+ const isMatch = currentVer && prdVer && versionSearchMatch(prdVer, currentVer);
811
813
  row.classList.toggle('version-match', isMatch);
812
814
  const badge = row.querySelector('.version-badge');
813
815
  if (badge) badge.classList.toggle('match', isMatch);
@@ -969,19 +971,10 @@ function normalizeVersionSearchText(text) {
969
971
  return normalizeSearchText(text).replace(/[._-]/g, '');
970
972
  }
971
973
 
972
- function fuzzyVersionMatch(version, keyword) {
974
+ function versionSearchMatch(version, keyword) {
973
975
  const source = normalizeVersionSearchText(version);
974
976
  const target = normalizeVersionSearchText(keyword);
975
- if (!target) return true;
976
- if (source.indexOf(target) !== -1) return true;
977
-
978
- let index = 0;
979
- for (const char of target) {
980
- index = source.indexOf(char, index);
981
- if (index === -1) return false;
982
- index++;
983
- }
984
- return true;
977
+ return !!target && source === target;
985
978
  }
986
979
 
987
980
  function renderVersionHistory() {
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  // 页面可在引入本模块前声明这些全局以覆盖默认行为;未声明时使用默认值。
7
- // “当前版本”优先读取主 PRD 历史记录中的最大版本;PRD_OVERVIEW_VERSION 仅作兼容兜底。
7
+ // “当前版本”优先读取主 PRD 版本记录表的最后一条;PRD_OVERVIEW_VERSION 仅作兼容兜底。
8
8
  // PRD_WORKSPACE_MAP 配置多文档工作区。
9
9
  var PRD_BASE_PATH = typeof PRD_BASE_PATH !== 'undefined' ? PRD_BASE_PATH : './';
10
10
  var PRD_FILE_MAP = typeof PRD_FILE_MAP !== 'undefined' ? PRD_FILE_MAP : {};
@@ -434,41 +434,36 @@ function getPrdDisplayName(filePath) {
434
434
  return (filePath || '').split('/').pop().replace(/\.md(?:#.*)?$/i, '').replace(/_/g, ' ');
435
435
  }
436
436
 
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
- }
437
+ function getPrdHistoryLatestVersion(content) {
438
+ var lines = String(content || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
439
+ var latestVersion = '';
454
440
 
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]);
441
+ for (var index = 0; index < lines.length; index += 1) {
442
+ if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
443
+
444
+ var tableLines = [];
445
+ while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
446
+ tableLines.push(lines[index]);
447
+ index += 1;
448
+ }
449
+ index -= 1;
450
+
451
+ if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
452
+ var headerCell = tableLines[0].split('|')[1] || '';
453
+ if (headerCell.indexOf('版本') === -1) continue;
454
+
455
+ tableLines.slice(2).forEach(function(row) {
456
+ var version = (row.split('|')[1] || '').trim();
457
+ if (version) latestVersion = version;
458
+ });
462
459
  }
463
- if (!versions.length) return '';
464
- return versions.reduce(function(maxVersion, version) {
465
- return comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion;
466
- });
460
+
461
+ return latestVersion;
467
462
  }
468
463
 
469
464
  function getPrdOverviewVersion(rootContent) {
470
- var historyMaxVersion = getPrdHistoryMaxVersion(rootContent);
471
- if (historyMaxVersion) return historyMaxVersion;
465
+ var historyLatestVersion = getPrdHistoryLatestVersion(rootContent);
466
+ if (historyLatestVersion) return historyLatestVersion;
472
467
  if (prdOverviewVersion) return prdOverviewVersion;
473
468
  if (typeof PRD_OVERVIEW_VERSION === 'undefined') return '';
474
469
  return String(PRD_OVERVIEW_VERSION || '').trim();
@@ -756,29 +756,31 @@ function loadVersionCache() { try { return JSON.parse(navStorage.getItem(VER_CAC
756
756
  function saveVersionCache() { navStorage.setItem(VER_CACHE_KEY, JSON.stringify(versionCache)); }
757
757
  versionCache = loadVersionCache();
758
758
 
759
- function comparePrdVersions(left, right) {
760
- const leftParts = String(left || '').replace(/^v/i, '').split('.');
761
- const rightParts = String(right || '').replace(/^v/i, '').split('.');
762
- const length = Math.max(leftParts.length, rightParts.length);
763
- for (let index = 0; index < length; index += 1) {
764
- const leftPart = leftParts[index] || '0';
765
- const rightPart = rightParts[index] || '0';
766
- const leftNumber = /^\d+$/.test(leftPart) ? Number(leftPart) : null;
767
- const rightNumber = /^\d+$/.test(rightPart) ? Number(rightPart) : null;
768
- const comparison = leftNumber !== null && rightNumber !== null
769
- ? leftNumber - rightNumber
770
- : leftPart.localeCompare(rightPart, undefined, { numeric: true, sensitivity: 'base' });
771
- if (comparison !== 0) return comparison;
759
+ function extractPrdHistoryLatestVersion(text) {
760
+ const lines = String(text || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
761
+ let latestVersion = null;
762
+
763
+ for (let index = 0; index < lines.length; index += 1) {
764
+ if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
765
+
766
+ const tableLines = [];
767
+ while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
768
+ tableLines.push(lines[index]);
769
+ index += 1;
770
+ }
771
+ index -= 1;
772
+
773
+ if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
774
+ const headerCell = tableLines[0].split('|')[1] || '';
775
+ if (!headerCell.includes('版本')) continue;
776
+
777
+ tableLines.slice(2).forEach(row => {
778
+ const version = (row.split('|')[1] || '').trim();
779
+ if (version) latestVersion = version;
780
+ });
772
781
  }
773
- return 0;
774
- }
775
782
 
776
- function extractPrdHistoryMaxVersion(text) {
777
- const plainText = String(text || '').replace(/<[^>]+>/g, '');
778
- const versions = [...plainText.matchAll(/^\|\s*(v\d+(?:\.[0-9a-z]+)+)\s*\|/gim)].map(match => match[1]);
779
- return versions.length
780
- ? versions.reduce((maxVersion, version) => comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion)
781
- : null;
783
+ return latestVersion;
782
784
  }
783
785
 
784
786
  async function fetchPageVersion(htmlPath) {
@@ -787,7 +789,7 @@ async function fetchPageVersion(htmlPath) {
787
789
  const res = await fetch(mdPath, { cache: 'no-cache' });
788
790
  if (!res.ok) return null;
789
791
  const text = await res.text();
790
- return extractPrdHistoryMaxVersion(text);
792
+ return extractPrdHistoryLatestVersion(text);
791
793
  } catch { return null; }
792
794
  }
793
795
 
@@ -807,7 +809,7 @@ function applyVersionBadge(path, ver) {
807
809
  function refreshVersionMatch(row) {
808
810
  const currentVer = (document.getElementById('versionInput').value || '').trim();
809
811
  const prdVer = row.dataset.prdVersion || '';
810
- const isMatch = currentVer && prdVer && fuzzyVersionMatch(prdVer, currentVer);
812
+ const isMatch = currentVer && prdVer && versionSearchMatch(prdVer, currentVer);
811
813
  row.classList.toggle('version-match', isMatch);
812
814
  const badge = row.querySelector('.version-badge');
813
815
  if (badge) badge.classList.toggle('match', isMatch);
@@ -969,19 +971,10 @@ function normalizeVersionSearchText(text) {
969
971
  return normalizeSearchText(text).replace(/[._-]/g, '');
970
972
  }
971
973
 
972
- function fuzzyVersionMatch(version, keyword) {
974
+ function versionSearchMatch(version, keyword) {
973
975
  const source = normalizeVersionSearchText(version);
974
976
  const target = normalizeVersionSearchText(keyword);
975
- if (!target) return true;
976
- if (source.indexOf(target) !== -1) return true;
977
-
978
- let index = 0;
979
- for (const char of target) {
980
- index = source.indexOf(char, index);
981
- if (index === -1) return false;
982
- index++;
983
- }
984
- return true;
977
+ return !!target && source === target;
985
978
  }
986
979
 
987
980
  function renderVersionHistory() {