@wendongfly/myhi 1.3.106 → 1.3.108

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/dist/chat.html CHANGED
@@ -298,8 +298,22 @@
298
298
  .mem-file-header:hover { background: var(--border); }
299
299
  .mem-file-header .arrow { transition: transform 0.15s; font-size: 0.6rem; }
300
300
  .mem-file-header .arrow.open { transform: rotate(90deg); }
301
- .mem-file-body { display: none; padding: 0.5rem 0.6rem; background: var(--bg); font-family: 'SF Mono','Consolas',monospace; font-size: 0.72rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--text2); max-height: 300px; overflow-y: auto; }
301
+ .mem-file-body { display: none; padding: 0.55rem 0.7rem; background: var(--bg); font-size: 0.8rem; line-height: 1.6; word-break: break-word; color: var(--text2); max-height: 52vh; overflow-y: auto; }
302
302
  .mem-file-body.open { display: block; }
303
+ /* markdown 渲染样式(记忆正文,隐藏了 frontmatter) */
304
+ .mem-file-body.md h1, .mem-file-body.md h2, .mem-file-body.md h3 { font-size: 0.88rem; margin: 0.5rem 0 0.3rem; color: var(--text); }
305
+ .mem-file-body.md ul, .mem-file-body.md ol { margin: 0.3rem 0; padding-left: 1.2rem; }
306
+ .mem-file-body.md li { margin: 0.15rem 0; }
307
+ .mem-file-body.md p { margin: 0.35rem 0; }
308
+ .mem-file-body.md code { background: var(--surface2); padding: 0.05rem 0.3rem; border-radius: 4px; font-size: 0.75rem; font-family: 'SF Mono','Consolas',monospace; }
309
+ .mem-file-body.md pre { background: var(--surface2); padding: 0.5rem 0.6rem; border-radius: 6px; overflow-x: auto; }
310
+ .mem-file-body.md pre code { background: none; padding: 0; }
311
+ .mem-file-body.md a { color: var(--blue); }
312
+ .mem-file-body.md strong { color: var(--text); }
313
+ .mem-title { color: var(--blue); font-weight: 600; }
314
+ .mem-desc { display: block; color: var(--muted); font-size: 0.68rem; font-weight: 400; margin-top: 0.12rem; line-height: 1.4; white-space: normal; }
315
+ /* PC 上记忆面板加宽,别挤在窄底 sheet 里 */
316
+ @media (min-width: 900px) { #memory-sheet .action-sheet-box { max-width: 820px; } }
303
317
  .slash-inp { width: 100%; padding: 0.65rem 0.8rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 0.9rem; outline: none; }
304
318
  .slash-inp:focus { border-color: var(--purple); }
305
319
 
@@ -3534,38 +3548,89 @@
3534
3548
  });
3535
3549
 
3536
3550
  // ── Claude 记忆查看 ──────────────────────────────
3537
- window.showMemory = async function() {
3551
+ let _memScope = 'project'; // 默认只看本项目
3552
+ window.showMemory = async function(scope) {
3553
+ if (scope) _memScope = scope;
3538
3554
  const container = document.getElementById('memory-content');
3539
3555
  container.innerHTML = '<div style="text-align:center;color:var(--muted);padding:2rem 0">加载中...</div>';
3540
3556
  document.getElementById('memory-sheet').classList.add('open');
3541
3557
 
3558
+ const segBtn = (val, label) =>
3559
+ `<button onclick="showMemory('${val}')" style="flex:1;padding:0.4rem;border-radius:7px;cursor:pointer;font-size:0.76rem;` +
3560
+ `border:1px solid ${_memScope===val?'var(--purple)':'var(--border)'};` +
3561
+ `background:${_memScope===val?'var(--purple)':'var(--bg)'};color:${_memScope===val?'#fff':'var(--muted)'}">${label}</button>`;
3562
+ const makeBar = () => {
3563
+ const bar = document.createElement('div');
3564
+ bar.style.cssText = 'display:flex;gap:0.4rem;margin-bottom:0.55rem';
3565
+ bar.innerHTML = segBtn('project', '本项目') + segBtn('all', '全部(含全局/其它项目)');
3566
+ return bar;
3567
+ };
3568
+
3542
3569
  try {
3543
- const resp = await fetch(`/api/memory?sessionId=${SESSION_ID}`);
3570
+ const resp = await fetch(`/api/memory?sessionId=${SESSION_ID}&scope=${_memScope}`);
3544
3571
  const data = await resp.json();
3545
3572
  const files = data.files || [];
3546
3573
 
3574
+ container.innerHTML = '';
3575
+ container.appendChild(makeBar());
3576
+
3547
3577
  if (files.length === 0) {
3548
- container.innerHTML = '<div style="text-align:center;color:var(--muted);padding:2rem 0">暂无记忆文件</div>';
3578
+ const e = document.createElement('div');
3579
+ e.style.cssText = 'text-align:center;color:var(--muted);padding:1.5rem 0';
3580
+ e.textContent = _memScope === 'project' ? '本项目暂无记忆文件' : '暂无记忆文件';
3581
+ container.appendChild(e);
3549
3582
  return;
3550
3583
  }
3551
3584
 
3552
- container.innerHTML = '';
3553
- for (const f of files) {
3554
- const card = document.createElement('div');
3555
- card.className = 'mem-file';
3556
- const header = document.createElement('div');
3557
- header.className = 'mem-file-header';
3558
- header.innerHTML = `<span class="arrow">▶</span> ${escHtml(f.name)}`;
3559
- const body = document.createElement('div');
3560
- body.className = 'mem-file-body';
3561
- body.textContent = f.content;
3562
- header.onclick = () => { body.classList.toggle('open'); header.querySelector('.arrow').classList.toggle('open'); };
3563
- card.appendChild(header);
3564
- card.appendChild(body);
3565
- container.appendChild(card);
3566
- }
3585
+ // 拆掉开头的 --- frontmatter --- ,提取 description,正文单独渲染 markdown
3586
+ const parseFM = (content) => {
3587
+ const m = content.match(/^?---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
3588
+ if (!m) return { desc: '', body: content };
3589
+ const dm = m[1].match(/^description:\s*(.+)$/m);
3590
+ return { desc: dm ? dm[1].trim() : '', body: content.slice(m[0].length) };
3591
+ };
3592
+ const cleanName = (n) => n.replace(/^.*\//, '').replace(/\.md$/i, '');
3593
+
3594
+ // 搜索框
3595
+ const search = document.createElement('input');
3596
+ search.className = 'slash-inp';
3597
+ search.placeholder = '搜索记忆(文件名 / 内容)…';
3598
+ search.style.cssText = 'margin-bottom:0.5rem;width:100%;box-sizing:border-box';
3599
+ const listWrap = document.createElement('div');
3600
+ container.appendChild(search);
3601
+ container.appendChild(listWrap);
3602
+
3603
+ const renderList = (kw) => {
3604
+ kw = (kw || '').trim().toLowerCase();
3605
+ listWrap.innerHTML = '';
3606
+ let shown = 0;
3607
+ for (const f of files) {
3608
+ if (kw && !(f.name.toLowerCase().includes(kw) || (f.content || '').toLowerCase().includes(kw))) continue;
3609
+ shown++;
3610
+ const { desc, body: md } = parseFM(f.content || '');
3611
+ const card = document.createElement('div');
3612
+ card.className = 'mem-file';
3613
+ const header = document.createElement('div');
3614
+ header.className = 'mem-file-header';
3615
+ header.innerHTML = `<span class="arrow">▶</span><span style="flex:1;min-width:0"><span class="mem-title">${escHtml(cleanName(f.name))}</span>${desc ? '<span class="mem-desc">' + escHtml(desc) + '</span>' : ''}</span>`;
3616
+ const body = document.createElement('div');
3617
+ body.className = 'mem-file-body md';
3618
+ body.innerHTML = renderMarkdown(md.trim());
3619
+ header.onclick = () => { body.classList.toggle('open'); header.querySelector('.arrow').classList.toggle('open'); };
3620
+ card.appendChild(header); card.appendChild(body);
3621
+ listWrap.appendChild(card);
3622
+ }
3623
+ if (!shown) listWrap.innerHTML = '<div style="color:var(--muted);text-align:center;padding:1.2rem 0;font-size:0.8rem">没有匹配的记忆</div>';
3624
+ };
3625
+ search.addEventListener('input', () => renderList(search.value));
3626
+ renderList('');
3567
3627
  } catch (e) {
3568
- container.innerHTML = `<div style="text-align:center;color:var(--red);padding:2rem 0">加载失败: ${escHtml(e.message)}</div>`;
3628
+ container.innerHTML = '';
3629
+ container.appendChild(makeBar());
3630
+ const err = document.createElement('div');
3631
+ err.style.cssText = 'text-align:center;color:var(--red);padding:1.5rem 0';
3632
+ err.textContent = '加载失败: ' + e.message;
3633
+ container.appendChild(err);
3569
3634
  }
3570
3635
  };
3571
3636