@mysterycode-liwen/dsh-credential-vault 1.4.0 → 1.4.1

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 (3) hide show
  1. package/README.md +12 -5
  2. package/client.js +133 -35
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -72,7 +72,7 @@ dsh plugin --profile desktop why @mysterycode-liwen/dsh-credential-vault
72
72
  - **密码生成器**:在账号密码字段旁点「⚙ 生成」,用加密安全随机数(Web Crypto)生成强密码,可设置长度与字符类型、避开易混淆字符,并实时显示强度;可直接填入表单或复制。(仅账号密码类提供,API Key / 其他类不显示)
73
73
  - **健康审计**:点「🛡 健康审计」扫描全部凭据,列出弱密码 / 空密钥、重复使用、已过期 / 即将到期等问题并按严重程度排序,点击条目可直接跳转编辑。
74
74
  - 登录网址 / Base URL 字段旁提供「访问」按钮,默认用 DeepSeek Harness 内置浏览器打开。
75
- - 导入 / 导出:可把全部凭据导出为 **JSON 备份 / CSV(Excel、WPS 可直接打开)/ Markdown 表格**三种格式,或从这三种格式的文件恢复;导入时自动识别格式,并可选「合并(跳过重复 ID)」或「替换全部」。JSON 保留全部字段,CSV 与 Markdown 便于查看、编辑和版本管理。
75
+ - 导入 / 导出:可把全部凭据导出为 **JSON 备份 / CSV(Excel、WPS 可直接打开)/ Markdown 卡片**三种格式,或从这三种格式的文件恢复;导入时自动识别格式,并可选「合并(跳过重复 ID)」或「替换全部」。JSON 保留全部字段;CSV 用中文表头、常用列在前;Markdown 每条凭据一张中文卡片,方便阅读。三种格式均可无损导回。
76
76
  - 设置页:访问密码开关、设置 / 修改密码、密保问题重置、闲置自动锁定(可开关、可选时长)、插件版本与检查更新。
77
77
 
78
78
  ## Agent 工具 / Agent tool
@@ -111,9 +111,9 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
111
111
 
112
112
  **导出该选哪种格式?Excel 打开 CSV 会乱码吗?**
113
113
  - **JSON**:字段最完整,换机器 / 完整备份首选。
114
- - **CSV**:带 UTF-8 BOM,Excel / WPS 双击即可正确显示中文;适合表格查看与批量编辑。
115
- - **Markdown**:可读表格,方便贴到文档或做版本管理。
116
- 导入时会自动识别这三种格式,无需手动选择。
114
+ - **CSV**:带 UTF-8 BOM,Excel / WPS 双击即可正确显示中文;中文表头、常用列在前,ID / 时间戳等放在最后,适合表格查看与批量编辑。
115
+ - **Markdown**:每条凭据一张卡片、中文标签两列表,空字段自动省略,方便阅读、贴到文档或做版本管理;完整数据以 HTML 注释内嵌,导入时无损还原。
116
+ 导入时会自动识别这三种格式(也兼容旧版英文表头的 CSV 与宽表格 Markdown),无需手动选择。
117
117
 
118
118
  **支持多设备同步吗?**
119
119
  不支持,也不打算支持——本插件的定位就是「不上云的本机保险箱」。
@@ -123,6 +123,13 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
123
123
 
124
124
  ## 更新日志 / Changelog
125
125
 
126
+ ### 1.4.1 — 2026-11-22
127
+
128
+ - **可读性改进**:Markdown 导出由超宽表格改为每条凭据一张卡片、中文标签两列表、空字段省略、类型显示为「账号 / API Key / 其他」,一目了然。
129
+ - CSV 导出改为中文表头、常用列在前,类型中文化,时间戳转为易读的 ISO 格式。
130
+ - 两种格式在保持可读的同时仍可无损导回(Markdown 以 HTML 注释内嵌完整数据);导入兼容旧版英文表头 CSV 与宽表格 Markdown。
131
+ - 自动识别逻辑同步更新,新增「无注释的手改卡片」回退解析。
132
+
126
133
  ### 1.4.0 — 2026-11-22
127
134
 
128
135
  - 导入 / 导出支持三种格式:**JSON 备份**(完整字段)、**CSV**(UTF-8 BOM,Excel / WPS 双击即开)、**Markdown 表格**(可读、易复制与版本管理)。
@@ -148,7 +155,7 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
148
155
  npm run check # 发布前自检:client.js 的模块 id 与 cordis.patch.yml 的 name 必须等于包名
149
156
  npm pack --dry-run # 核对实际打包的文件清单
150
157
  npm publish # publishConfig.access = public;会先自动跑一次 npm run check,不一致则中止
151
- git tag v1.4.0 && git push --tags
158
+ git tag v1.4.1 && git push --tags
152
159
  ```
153
160
 
154
161
  `client.js` 里 `window.__ModuleLoader__.load({ id })` 的 `id` **必须等于 `package.json` 的 `name`**:DSH 按包名去浏览器模块表里查找,不一致时浏览器端不会挂载,表现为侧边栏入口与设置页整块消失(Host 端仍然正常)。改包名或改 scope 时,三处要同步:`package.json` 的 `name`、`client.js` 的 `id`、`cordis.patch.yml` 的 `name`。
package/client.js CHANGED
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
15
15
  // whatever port the Web GUI is on.
16
16
  var API = 'dsh-credential-vault/';
17
17
  /** Plugin version shown in Settings; keep in sync with package.json on release. */
18
- var VERSION = '1.4.0';
18
+ var VERSION = '1.4.1';
19
19
 
20
20
  // Compare two semver-ish strings: -1 (left older), 0 (equal), 1 (left newer).
21
21
  // Used to decide "update available" against THIS client's version, so the
@@ -115,8 +115,8 @@ window.__ModuleLoader__.load({
115
115
  importInvalid: 'Invalid backup file', importEmpty: 'No credentials in this file',
116
116
  importDetected: 'Detected format', fmtJson: 'JSON', fmtCsv: 'CSV', fmtMd: 'Markdown',
117
117
  exportFormat: 'Export format', exportJson: 'JSON backup', exportJsonHint: 'Full fidelity — restores every field exactly (recommended).',
118
- exportCsv: 'CSV for Excel / WPS', exportCsvHint: 'Opens directly in spreadsheets. UTF-8 with BOM.',
119
- exportMd: 'Markdown', exportMdHint: 'Readable table — easy to view, copy and version.',
118
+ exportCsv: 'CSV for Excel / WPS', exportCsvHint: 'Chinese headers, readable order, UTF-8 with BOM.',
119
+ exportMd: 'Markdown cards', exportMdHint: 'One card per entry with Chinese labels — clean and readable.',
120
120
  genButton: 'Generate password', genField: 'Generate a password for this field',
121
121
  genTitle: 'Password generator', genHint: 'Generates a strong random password using your browser’s cryptographic random source. Nothing is stored or sent anywhere.',
122
122
  genLength: 'Length', genUpper: 'Uppercase (A–Z)', genLower: 'Lowercase (a–z)', genDigits: 'Digits (0–9)',
@@ -218,8 +218,8 @@ window.__ModuleLoader__.load({
218
218
  importInvalid: '备份文件无效', importEmpty: '文件中没有凭据',
219
219
  importDetected: '识别到的格式', fmtJson: 'JSON', fmtCsv: 'CSV', fmtMd: 'Markdown',
220
220
  exportFormat: '导出格式', exportJson: 'JSON 备份', exportJsonHint: '完整保真,可精确恢复全部字段(推荐)。',
221
- exportCsv: 'CSV(Excel / WPS)', exportCsvHint: '可用表格软件直接打开,UTF-8 BOM 编码。',
222
- exportMd: 'Markdown 表格', exportMdHint: '可读表格,方便查看、复制与版本管理。',
221
+ exportCsv: 'CSV(Excel / WPS)', exportCsvHint: '中文表头、常用列在前,UTF-8 BOM 编码。',
222
+ exportMd: 'Markdown 卡片', exportMdHint: '每条凭据一张卡片、中文标签,一目了然。',
223
223
  genButton: '生成密码', genField: '为此字段生成密码',
224
224
  genTitle: '密码生成器', genHint: '使用浏览器的加密随机源生成高强度随机密码,不会存储或上传任何数据。',
225
225
  genLength: '长度', genUpper: '大写字母 (A–Z)', genLower: '小写字母 (a–z)', genDigits: '数字 (0–9)',
@@ -654,6 +654,20 @@ window.__ModuleLoader__.load({
654
654
  }
655
655
  var EXPORT_COLS = ['id', 'title', 'category', 'username', 'password', 'url', 'provider', 'apiKey', 'endpoint', 'expiry', 'content', 'notes', 'createdAt', 'updatedAt'];
656
656
 
657
+ // ---- Human-readable labels ------------------------------------------------
658
+ // CSV/Markdown use Chinese labels for people; every label maps back to its
659
+ // exact field name so an exported file still round-trips without data loss.
660
+ var FIELD_LABELS = {
661
+ id: 'ID', title: '标题', category: '类型', username: '用户名', password: '密码',
662
+ url: '网址', provider: '服务商', apiKey: 'API Key', endpoint: '接口地址',
663
+ expiry: '有效期', content: '内容', notes: '备注', createdAt: '创建时间', updatedAt: '更新时间'
664
+ };
665
+ var LABEL_FIELDS = {};
666
+ Object.keys(FIELD_LABELS).forEach(function (k) { LABEL_FIELDS[FIELD_LABELS[k]] = k; });
667
+ var CATEGORY_LABELS = { account: '账号', apikey: 'API Key', other: '其他' };
668
+ var LABEL_CATEGORIES = {};
669
+ Object.keys(CATEGORY_LABELS).forEach(function (k) { LABEL_CATEGORIES[CATEGORY_LABELS[k]] = k; });
670
+
657
671
  // CSV helpers (RFC 4180): quote fields containing comma / quote / newline,
658
672
  // double embedded quotes. The file carries a UTF-8 BOM so Excel/WPS show
659
673
  // Chinese characters correctly when opened by double-click.
@@ -661,11 +675,24 @@ window.__ModuleLoader__.load({
661
675
  var s = v == null ? '' : String(v);
662
676
  return /[",\r\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
663
677
  }
678
+ function csvDate(v) {
679
+ if (v == null || v === '') return '';
680
+ var d = new Date(Number(v));
681
+ return isNaN(d.getTime()) ? String(v) : d.toISOString();
682
+ }
683
+ // CSV shows the fields people actually read first; technical columns
684
+ // (ID / timestamps) go last. Import maps by header label, so order is safe.
685
+ var CSV_COLS = ['title', 'category', 'username', 'password', 'url', 'provider',
686
+ 'apiKey', 'endpoint', 'expiry', 'content', 'notes', 'id', 'createdAt', 'updatedAt'];
664
687
  function buildCsv(arr) {
665
- var lines = [EXPORT_COLS.map(csvEscape).join(',')];
688
+ var lines = [CSV_COLS.map(function (c) { return csvEscape(FIELD_LABELS[c] || c); }).join(',')];
666
689
  arr.forEach(function (e) {
667
690
  var n = normalize(e);
668
- lines.push(EXPORT_COLS.map(function (c) { return csvEscape(n[c]); }).join(','));
691
+ lines.push(CSV_COLS.map(function (c) {
692
+ var v = (c === 'createdAt' || c === 'updatedAt') ? csvDate(n[c]) : n[c];
693
+ if (c === 'category') v = CATEGORY_LABELS[v] || v;
694
+ return csvEscape(v);
695
+ }).join(','));
669
696
  });
670
697
  return '\uFEFF' + lines.join('\r\n');
671
698
  }
@@ -693,7 +720,9 @@ window.__ModuleLoader__.load({
693
720
  function parseCsv(text) {
694
721
  var rows = csvParse(text);
695
722
  if (rows.length < 2) throw new Error('shape');
696
- var header = rows[0].map(function (x) { return String(x).trim(); });
723
+ var rawHeader = rows[0].map(function (x) { return String(x).trim(); });
724
+ // Accept both the new Chinese header and the legacy English one.
725
+ var header = rawHeader.map(function (h) { return LABEL_FIELDS[h] || h; });
697
726
  if (header.indexOf('title') === -1) throw new Error('shape');
698
727
  var out = [];
699
728
  for (var r = 1; r < rows.length; r++) {
@@ -701,16 +730,22 @@ window.__ModuleLoader__.load({
701
730
  if (cells.length === 1 && !String(cells[0]).trim()) continue;
702
731
  var e = {};
703
732
  header.forEach(function (h, i2) { if (h) e[h] = cells[i2] != null ? cells[i2] : ''; });
733
+ if (e.category) e.category = LABEL_CATEGORIES[e.category] || e.category;
704
734
  ['createdAt', 'updatedAt'].forEach(function (k) {
705
- if (e[k] != null && e[k] !== '' && /^\d+$/.test(String(e[k]))) e[k] = Number(e[k]);
735
+ var v = e[k];
736
+ if (v != null && v !== '') {
737
+ if (/^\d+$/.test(String(v))) e[k] = Number(v);
738
+ else { var ms = Date.parse(v); if (!isNaN(ms)) e[k] = ms; }
739
+ }
706
740
  });
707
741
  out.push(normalize(e));
708
742
  }
709
743
  return out;
710
744
  }
711
745
 
712
- // Markdown table helpers. Cell text is escaped so pipes, backslashes and
713
- // newlines survive a round-trip; on import they are decoded back exactly.
746
+ // Markdown card helpers. Each credential is a small card with a Chinese
747
+ // two-column table; an embedded HTML comment keeps the full original data
748
+ // so import stays lossless even though the visible part is human-friendly.
714
749
  function mdEscape(v) {
715
750
  return String(v == null ? '' : v)
716
751
  .replace(/\\/g, '\\\\').replace(/\|/g, '\\|')
@@ -719,6 +754,7 @@ window.__ModuleLoader__.load({
719
754
  function mdDecode(s) {
720
755
  var out = '', i = 0;
721
756
  while (i < s.length) {
757
+ if (s.substr(i, 4) === '<br>') { out += '\n'; i += 4; continue; }
722
758
  if (s.charAt(i) === '\\' && i + 1 < s.length) {
723
759
  var c = s.charAt(i + 1);
724
760
  if (c === 'n') { out += '\n'; i += 2; continue; }
@@ -740,45 +776,104 @@ window.__ModuleLoader__.load({
740
776
  if (s.charAt(i) === '|') { cells.push(cur); cur = ''; i++; continue; }
741
777
  cur += s.charAt(i); i++;
742
778
  }
743
- // The trailing '|' was stripped above, so the final cell is still in cur.
744
779
  cells.push(cur);
745
- // buildMarkdown pads each cell with one space on either side of '|';
746
- // strip exactly one such padding space, preserving any intentional ones.
747
780
  return cells.map(function (x) { return mdDecode(x.replace(/^ /, '').replace(/ $/, '')); });
748
781
  }
782
+ // Cell text for the visible card table: escape pipes/backslashes, and show
783
+ // real newlines as <br> so multi-line notes stay readable in a table.
784
+ function mdCell(v) {
785
+ return String(v == null ? '' : v)
786
+ .replace(/\\/g, '\\\\').replace(/\|/g, '\\|')
787
+ .replace(/\r/g, '').replace(/\n/g, '<br>');
788
+ }
749
789
  function buildMarkdown(arr) {
750
- var lines = ['# Credential Vault / 凭据保险箱', '', 'Exported: ' + new Date().toISOString(), '',
751
- '| ' + EXPORT_COLS.join(' | ') + ' |',
752
- '| ' + EXPORT_COLS.map(function () { return '---'; }).join(' | ') + ' |'];
753
- arr.forEach(function (e) {
790
+ var lines = ['# 凭据保险箱 / Credential Vault', '',
791
+ '导出时间:' + new Date().toISOString() + ' · 共 ' + arr.length + ' 条', '',
792
+ '> 每条凭据下方的 HTML 注释保存了完整原始数据(含 ID、时间戳等),导入时优先读取以保证无损还原。请勿删除这些注释。', ''];
793
+ arr.forEach(function (e, i) {
754
794
  var n = normalize(e);
755
- lines.push('| ' + EXPORT_COLS.map(function (c) { return mdEscape(n[c]); }).join(' | ') + ' |');
795
+ lines.push('## ' + (i + 1) + '. ' + mdCell(n.title || '(无标题)'));
796
+ lines.push('');
797
+ // Encode < and > so the JSON can never terminate the HTML comment early.
798
+ var data = JSON.stringify(n).replace(/</g, '\\u003c').replace(/>/g, '\\u003e');
799
+ lines.push('<!-- cv:' + data + ' -->');
800
+ lines.push('');
801
+ lines.push('| 字段 | 内容 |');
802
+ lines.push('| --- | --- |');
803
+ EXPORT_COLS.forEach(function (c) {
804
+ if (c === 'id' || c === 'title' || c === 'createdAt' || c === 'updatedAt') return;
805
+ var v = n[c];
806
+ if (v == null || v === '') return;
807
+ var label = FIELD_LABELS[c] || c;
808
+ if (c === 'category') v = CATEGORY_LABELS[v] || v;
809
+ lines.push('| ' + label + ' | ' + mdCell(v) + ' |');
810
+ });
811
+ lines.push('');
812
+ lines.push('---');
813
+ lines.push('');
756
814
  });
757
815
  return lines.join('\n');
758
816
  }
759
817
  function parseMarkdown(text) {
760
818
  var lines = String(text || '').replace(/^\uFEFF/, '').split(/\r?\n/);
819
+ // Preferred path: the embedded <!-- cv:{...} --> comment is lossless.
820
+ var fromComment = [];
821
+ lines.forEach(function (line) {
822
+ var m = /<!--\s*cv:(\{[\s\S]*?\})\s*-->/.exec(line);
823
+ if (m) { try { fromComment.push(normalize(JSON.parse(m[1]))); } catch (e) {} }
824
+ });
825
+ if (fromComment.length) return fromComment;
826
+
827
+ // Legacy wide table from earlier exports: keep supporting old files.
761
828
  var hIdx = -1;
762
829
  for (var i = 0; i < lines.length - 1; i++) {
763
830
  if (/^\s*\|/.test(lines[i]) && /title/.test(lines[i]) &&
764
831
  /^\s*\|/.test(lines[i + 1]) && /-/.test(lines[i + 1])) { hIdx = i; break; }
765
832
  }
766
- if (hIdx < 0) throw new Error('shape');
767
- var header = mdSplitRow(lines[hIdx]);
768
- if (header.indexOf('title') === -1) throw new Error('shape');
769
- var out = [];
770
- for (var r = hIdx + 2; r < lines.length; r++) {
771
- var line = lines[r];
772
- if (!/^\s*\|/.test(line)) continue;
773
- var cells = mdSplitRow(line);
774
- var e = {};
775
- header.forEach(function (h, i2) { if (h) e[h] = cells[i2] != null ? cells[i2] : ''; });
776
- ['createdAt', 'updatedAt'].forEach(function (k) {
777
- if (e[k] != null && e[k] !== '' && /^\d+$/.test(String(e[k]))) e[k] = Number(e[k]);
778
- });
779
- out.push(normalize(e));
833
+ if (hIdx >= 0) {
834
+ var header = mdSplitRow(lines[hIdx]).map(function (h) { return LABEL_FIELDS[h] || h; });
835
+ if (header.indexOf('title') !== -1) {
836
+ var out = [];
837
+ for (var r = hIdx + 2; r < lines.length; r++) {
838
+ var line = lines[r];
839
+ if (!/^\s*\|/.test(line)) continue;
840
+ var cells = mdSplitRow(line);
841
+ var e = {};
842
+ header.forEach(function (h, i2) { if (h) e[h] = cells[i2] != null ? cells[i2] : ''; });
843
+ ['createdAt', 'updatedAt'].forEach(function (k) {
844
+ if (e[k] != null && e[k] !== '' && /^\d+$/.test(String(e[k]))) e[k] = Number(e[k]);
845
+ });
846
+ out.push(normalize(e));
847
+ }
848
+ return out;
849
+ }
780
850
  }
781
- return out;
851
+
852
+ // Fallback: hand-edited cards whose comment was removed — read 字段/内容 tables.
853
+ var cards = [], curCard = null, inTable = false;
854
+ lines.forEach(function (line) {
855
+ var h = /^##\s+(?:\d+\.\s*)?(.*)$/.exec(line);
856
+ if (h) {
857
+ curCard = { title: h[1].trim() === '(无标题)' ? '' : h[1].trim(), fields: {} };
858
+ cards.push(curCard); inTable = false; return;
859
+ }
860
+ if (!curCard) return;
861
+ if (/^\|\s*字段\s*\|\s*内容\s*\|?\s*$/.test(line)) { inTable = true; return; }
862
+ if (inTable && /^\s*\|/.test(line)) {
863
+ var cells = mdSplitRow(line);
864
+ if (cells.length >= 2 && !/^-+$/.test(cells[0].replace(/\s/g, ''))) {
865
+ var key = LABEL_FIELDS[cells[0].trim()] || cells[0].trim();
866
+ curCard.fields[key] = cells.slice(1).join(' ');
867
+ }
868
+ } else if (!line.trim()) { inTable = false; }
869
+ });
870
+ return cards.map(function (c, i) {
871
+ var e = { id: 'import-' + Date.now() + '-' + i, title: c.title };
872
+ Object.keys(c.fields).forEach(function (k) {
873
+ e[k] = k === 'category' ? (LABEL_CATEGORIES[c.fields[k]] || c.fields[k]) : c.fields[k];
874
+ });
875
+ return normalize(e);
876
+ });
782
877
  }
783
878
 
784
879
  // Auto-detect the format and return { entries, fmt } or throw a known error.
@@ -787,12 +882,15 @@ window.__ModuleLoader__.load({
787
882
  var t = s.trim();
788
883
  if (!t) throw new Error('empty');
789
884
  if (t.charAt(0) === '{' || t.charAt(0) === '[') return { entries: parseBackup(t), fmt: 'json' };
885
+ if (/<!--\s*cv:/.test(s) || /\|\s*字段\s*\|/.test(s)) return { entries: parseMarkdown(t), fmt: 'md' };
790
886
  var lines = t.split(/\r?\n/);
791
887
  for (var li = 0; li < lines.length; li++) {
792
888
  if (/^\s*\|/.test(lines[li]) && /title/.test(lines[li])) return { entries: parseMarkdown(t), fmt: 'md' };
793
889
  }
794
890
  var first = lines[0] || '';
795
- if (first.indexOf(',') !== -1 && /\bid\b/.test(first) && /title/.test(first)) return { entries: parseCsv(t), fmt: 'csv' };
891
+ if (first.indexOf(',') !== -1 &&
892
+ (/\bid\b/.test(first) || /ID/.test(first)) &&
893
+ (/title/.test(first) || /标题/.test(first))) return { entries: parseCsv(t), fmt: 'csv' };
796
894
  throw new Error('parse');
797
895
  }
798
896
  function exportBackup(arr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysterycode-liwen/dsh-credential-vault",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "DeepSeek Harness 侧边栏凭据保险箱:本地保存账号密码、API Key 与恢复码,支持访问密码、密保重置、闲置自动锁定,并提供默认脱敏的 Agent 读取工具。",