dsh-xuyi-memory 1.0.0 → 1.0.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.
@@ -115,11 +115,22 @@ main.diary { display: block; position: relative; padding: 12px 0 70px; min-heigh
115
115
  box-shadow: var(--shadow); padding: 36px 42px 46px 46px; min-height: 62vh; }
116
116
  .sheet::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
117
117
  background: linear-gradient(#e6d6a4, #d3bf87); opacity: .55; border-radius: 4px 0 0 4px; }
118
- .desk { perspective: 1600px; }
119
- .sheet { transform-origin: left center; transition: transform .18s ease-in, opacity .18s ease-in; }
120
- .sheet.turn-out { transform: rotateY(-9deg) translateX(-6px); opacity: .3; }
121
- .sheet.turn-in { animation: turnIn .32s cubic-bezier(.2,.7,.3,1) both; }
122
- @keyframes turnIn { from { transform: rotateY(10deg); opacity: .15; } to { transform: none; opacity: 1; } }
118
+ /* 翻页:装订线在左边。往后翻(后一天)——当前页绕装订线掀起翻走,露出下面的新页;
119
+ 往前翻(前一天)——上一页从左边翻回来盖住当前页。翻起来时纸背光变暗一点。 */
120
+ .desk { perspective: 1800px; }
121
+ .leaf { z-index: 4; overflow: hidden; transform-origin: left center; backface-visibility: hidden;
122
+ pointer-events: none; will-change: transform; }
123
+ .leaf::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
124
+ background: linear-gradient(90deg, rgba(40,32,20,.02), rgba(40,32,20,.16) 70%, rgba(40,32,20,.24)); }
125
+ .leaf.turning-away { animation: leafAway .56s cubic-bezier(.45,.05,.35,1) forwards; }
126
+ .leaf.turning-away::after { animation: leafShade .56s ease-in forwards; }
127
+ .leaf.turning-back { animation: leafBack .56s cubic-bezier(.45,.05,.35,1) forwards; }
128
+ .leaf.turning-back::after { animation: leafShade .56s ease-out reverse forwards; }
129
+ @keyframes leafAway { from { transform: rotateY(0); box-shadow: var(--shadow); }
130
+ to { transform: rotateY(-108deg); box-shadow: 18px 10px 40px rgba(0,0,0,.18); } }
131
+ @keyframes leafBack { from { transform: rotateY(-108deg); box-shadow: 18px 10px 40px rgba(0,0,0,.18); }
132
+ to { transform: rotateY(0); box-shadow: var(--shadow); } }
133
+ @keyframes leafShade { from { opacity: 0; } to { opacity: 1; } }
123
134
  .page-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 26px;
124
135
  padding-top: 12px; border-top: 1px dashed var(--line); }
125
136
  .page-nav button { font: 13px var(--sans); color: var(--ink-2); background: transparent;
@@ -128,6 +139,19 @@ main.diary { display: block; position: relative; padding: 12px 0 70px; min-heigh
128
139
  .page-nav button:disabled { opacity: .35; cursor: default; }
129
140
  .page-nav .no { font-size: 12px; color: var(--ink-3); letter-spacing: .08em; }
130
141
  .sheet h2 { font-family: var(--hand); font-weight: 400; font-size: 25px; margin: 0 0 4px; letter-spacing: .06em; }
142
+ .day-pick { font: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0;
143
+ cursor: default; display: inline-flex; align-items: baseline; gap: 8px; }
144
+ .day-pick .caret { display: none; font-family: var(--sans); font-size: 13px; color: var(--ink-3); }
145
+ .day-menu { position: absolute; z-index: 6; top: 72px; left: 32px; width: min(300px, calc(100% - 56px));
146
+ max-height: 55vh; overflow: auto; background: #fffdf7; border: 1px solid var(--card-line); border-radius: 10px;
147
+ box-shadow: var(--shadow); padding: 6px; }
148
+ .day-menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; border: 0;
149
+ background: transparent; color: var(--ink-2); font: 14px var(--sans); padding: 8px 10px; border-radius: 8px;
150
+ cursor: pointer; text-align: left; }
151
+ .day-menu button:hover { background: rgba(127,120,105,.08); }
152
+ .day-menu button.on { background: rgba(35,38,45,.07); color: var(--ink); }
153
+ .day-menu button b { font-weight: 500; color: var(--ink); }
154
+ .day-menu .cnt { font-size: 12px; color: var(--ink-3); }
131
155
  .sheet .meta { color: var(--ink-3); font-size: 13px; margin-bottom: 20px; }
132
156
  .sheet .empty { color: var(--ink-3); font: 16px var(--hand); }
133
157
  .entry p { margin: 0 0 1.05em; font-family: var(--hand); font-size: 17.5px; line-height: 1.9;
@@ -156,11 +180,11 @@ details.raw[open] summary::before { content: "▾ "; }
156
180
  @media (max-width: 1180px) {
157
181
  :root { --note-w: clamp(118px, 15vw, 170px); }
158
182
  main.diary { padding: 8px 18px 60px; }
159
- /* 日期目录改成横排时换行,不要一条横向滚动条(真机看着像进度条,很丑)。 */
160
- .spine { position: static; width: auto; max-height: none; flex-direction: row; flex-wrap: wrap;
161
- overflow: visible; padding-bottom: 8px; }
162
- .spine::-webkit-scrollbar { display: none; }
163
- .spine button { flex: 0 0 auto; }
183
+ /* 日期目录不再堆在页面顶上(用户反馈:顶上一大摞日期很奇怪、把日记挤到下面):
184
+ 收进纸页标题——点「11 月 12 日 ▾」弹出日期列表。 */
185
+ .spine { display: none; }
186
+ .day-pick { cursor: pointer; }
187
+ .day-pick .caret { display: inline; }
164
188
  .desk { width: min(680px, calc(100vw - 2 * (var(--note-w) + 14px) - 36px)); }
165
189
  .sheet { padding: 30px 28px 38px 32px; }
166
190
  .page-notes .side { width: var(--note-w); gap: 18px; }
@@ -212,6 +236,13 @@ details.raw[open] summary::before { content: "▾ "; }
212
236
  .persona-editor label { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }
213
237
  .persona-editor textarea { min-height: 12em; }
214
238
  .persona-editor-actions { display: flex; flex-wrap: wrap; gap: 8px; }
239
+ .persona-confirm { border: 1px solid var(--center); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; background: var(--page); }
240
+ .persona-confirm p { margin: 0 0 8px; color: var(--ink); }
241
+ .own-list h4 { margin: 4px 0 6px; font-size: 14px; color: var(--ink); font-weight: 600; }
242
+ .own-item { border: 1px solid var(--card-line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; background: var(--page); }
243
+ .own-item.on { border-color: var(--center); box-shadow: inset 0 0 0 1px var(--center); }
244
+ .own-item p { margin: 0 0 6px; font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
245
+ .own-item .btn { padding: 3px 10px; font-size: 12px; margin: 0 6px 0 0; }
215
246
  .own { width: 100%; min-height: 76px; resize: vertical; box-sizing: border-box; border: 1px solid var(--line); border-radius: 10px;
216
247
  padding: 9px 12px; font: 14px/1.6 var(--sans); color: var(--ink); background: var(--page); margin-bottom: 8px; }
217
248
  .say { font-size: 13px; color: var(--ink-2); min-height: 1.4em; margin-top: 6px; }
@@ -437,6 +468,41 @@ function setBook(book) {
437
468
 
438
469
  const wait = ms => new Promise(done => setTimeout(done, ms));
439
470
  let flipping = false;
471
+ const TURN_MS = 560;
472
+
473
+ // 翻一页。forward:往后翻到更新的一天(当前页掀走,露出下面的新页);否则往前翻(上一页从左边翻回来)。
474
+ async function turnPage(sheet, forward, render) {
475
+ const still = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
476
+ if (still || !sheet.offsetWidth) { render(); return; }
477
+ const desk = sheet.parentElement;
478
+ const leafOf = html => {
479
+ const leaf = document.createElement('div');
480
+ leaf.className = 'sheet leaf';
481
+ leaf.setAttribute('aria-hidden', 'true');
482
+ leaf.style.cssText = `position:absolute;left:${sheet.offsetLeft}px;top:${sheet.offsetTop}px;`
483
+ + `width:${sheet.offsetWidth}px;height:${sheet.offsetHeight}px;margin:0;`;
484
+ leaf.innerHTML = html;
485
+ desk.appendChild(leaf);
486
+ return leaf;
487
+ };
488
+ if (forward) {
489
+ const leaf = leafOf(sheet.innerHTML); // 旧页盖在上面
490
+ render(); // 新页在下面
491
+ leaf.classList.add('turning-away');
492
+ await wait(TURN_MS);
493
+ leaf.remove();
494
+ } else {
495
+ const old = sheet.innerHTML;
496
+ render();
497
+ const fresh = sheet.innerHTML;
498
+ sheet.innerHTML = old; // 翻的时候下面还是旧页
499
+ const leaf = leafOf(fresh);
500
+ leaf.classList.add('turning-back');
501
+ await wait(TURN_MS);
502
+ leaf.remove();
503
+ render(); // 换成真正的新页(带上按钮事件)
504
+ }
505
+ }
440
506
 
441
507
  async function showDay(dateStr, animate = true) {
442
508
  const day = diaryData?.days.find(entry => entry.date === dateStr);
@@ -447,18 +513,15 @@ async function showDay(dateStr, animate = true) {
447
513
  const one = await api('api/diary?scope=' + encodeURIComponent(current) + '&date=' + dateStr);
448
514
  if (currentDay !== dateStr || one.error) return;
449
515
  const sheet = document.getElementById('sheet');
450
- const flip = animate && previous && previous !== dateStr && !flipping;
451
- if (flip) {
516
+ const render = () => renderDay(day, one.diary_text, one.diary_pending, one.diary_today, one.diary_hour);
517
+ const days = diaryData?.days ?? [];
518
+ const from = days.findIndex(entry => entry.date === previous), to = days.findIndex(entry => entry.date === dateStr);
519
+ if (animate && previous && previous !== dateStr && !flipping && from >= 0 && to >= 0) {
452
520
  flipping = true;
453
- sheet.classList.add('turn-out');
454
- await wait(180);
455
- }
456
- renderDay(day, one.diary_text, one.diary_pending, one.diary_today, one.diary_hour);
457
- if (flip) {
458
- sheet.classList.remove('turn-out');
459
- void sheet.offsetWidth;
460
- sheet.classList.add('turn-in');
461
- setTimeout(() => { sheet.classList.remove('turn-in'); flipping = false; }, 360);
521
+ try { await turnPage(sheet, to < from, render); } // 列表最新的在前:序号变小=往后翻到更新的一天
522
+ finally { flipping = false; }
523
+ } else {
524
+ render();
462
525
  }
463
526
  if (!one.diary_text && one.diary_pending) pollDay(dateStr, Date.now());
464
527
  }
@@ -469,6 +532,42 @@ const hourText = hour => {
469
532
  return (h >= 18 ? '晚上' : h >= 12 ? '下午' : '') + words[h > 12 ? h - 12 : h] + '点';
470
533
  };
471
534
 
535
+ // 窄窗口(嵌在 DSH 侧栏旁)没有左边的日期目录:点纸页标题弹出日期列表,选一天就翻过去。
536
+ function dayPicker(sheet, days, currentDate) {
537
+ const pick = sheet.querySelector('.day-pick');
538
+ if (!pick || days.length < 2) return;
539
+ const close = () => {
540
+ sheet.querySelector('.day-menu')?.remove();
541
+ pick.setAttribute('aria-expanded', 'false');
542
+ document.removeEventListener('click', outside, true);
543
+ document.removeEventListener('keydown', escape);
544
+ };
545
+ const outside = event => { if (!event.target.closest('.day-menu, .day-pick')) close(); };
546
+ const escape = event => { if (event.key === 'Escape') { close(); pick.focus(); } };
547
+ pick.onclick = () => {
548
+ if (getComputedStyle(document.getElementById('spine')).display !== 'none') return; // 宽窗口用左边的目录
549
+ if (sheet.querySelector('.day-menu')) { close(); return; }
550
+ const menu = document.createElement('div');
551
+ menu.className = 'day-menu';
552
+ menu.setAttribute('role', 'listbox');
553
+ for (const day of days) {
554
+ const button = document.createElement('button');
555
+ button.setAttribute('role', 'option');
556
+ button.classList.toggle('on', day.date === currentDate);
557
+ button.setAttribute('aria-selected', String(day.date === currentDate));
558
+ button.innerHTML = `<b>${esc(day.date.slice(5))}</b>`
559
+ + `<span class="cnt">${esc(day.weekday)}${day.label ? ' · ' + esc(day.label) : ''}</span>`;
560
+ button.onclick = () => { close(); if (day.date !== currentDate) showDay(day.date); };
561
+ menu.appendChild(button);
562
+ }
563
+ sheet.appendChild(menu);
564
+ pick.setAttribute('aria-expanded', 'true');
565
+ (menu.querySelector('.on') ?? menu.firstChild).focus();
566
+ document.addEventListener('click', outside, true);
567
+ document.addEventListener('keydown', escape);
568
+ };
569
+ }
570
+
472
571
  function renderDay(day, text, pending, isToday = false, hour = 22) {
473
572
  const [, month, date] = day.date.split('-').map(Number);
474
573
  const raw = day.entries.map(entry => `<li><time>${esc(entry.time)}</time><p>${esc(entry.text)}</p></li>`).join('');
@@ -486,11 +585,13 @@ function renderDay(day, text, pending, isToday = false, hour = 22) {
486
585
  <button data-go="newer" ${index > 0 ? '' : 'disabled'}>后一天 ›</button>
487
586
  </div>`;
488
587
  const sheet = document.getElementById('sheet');
489
- sheet.innerHTML = `<h2>${month} 月 ${date} 日</h2>`
588
+ sheet.innerHTML = `<h2><button class="day-pick" aria-haspopup="listbox" aria-expanded="false">`
589
+ + `${month} 月 ${date} 日<span class="caret">▾ 换一天</span></button></h2>`
490
590
  + `<div class="meta">${esc(day.weekday)} · 聊了 ${day.count} 句</div>`
491
591
  + `<div class="entry">${entry}</div>`
492
592
  + (raw ? `<details class="raw"><summary>那天的原话(${day.entries.length} 句)</summary><ol class="lines">${raw}</ol></details>` : '')
493
593
  + nav;
594
+ dayPicker(sheet, days, day.date);
494
595
  sheet.querySelectorAll('.page-nav button').forEach(button => {
495
596
  if (button.disabled) return;
496
597
  button.onclick = () => {
@@ -620,24 +721,40 @@ function renderPrepare(p) {
620
721
  }
621
722
 
622
723
  // 选TA的样子(人设 + 群里怎么回):设置页和引导共用。
724
+ // 换人设要先点「确定」:点一下预设不会马上覆盖。自己写的人设存在「我写的人设」里,换走也不丢。
623
725
  function personaBlock(box, sayId, { kicker = '', onSaved } = {}) {
624
726
  const s = setupState;
625
727
  const choices = s.presets ?? [];
728
+ const owns = s.own ?? [];
626
729
  const editorId = `${sayId}Editor`, detailSayId = `${sayId}Detail`;
730
+ const usingOwn = Boolean(s.persona?.configured && !s.persona?.name);
731
+ const inUse = o => usingOwn && s.persona?.own_id === o.id;
627
732
  const presets = choices.map((p, i) => `<div class="preset${s.persona?.name === p.name ? ' on' : ''}">`
628
733
  + `<button class="preset-choice" data-name="${esc(p.name)}"><b>${esc(p.label)}</b>${esc(p.description)}</button>`
629
734
  + (typeof p.systemPrompt === 'string' && p.systemPrompt.trim()
630
735
  ? `<button class="btn ghost preset-detail" data-detail="${i}" aria-label="查看${esc(p.label)}的详情" aria-expanded="false" aria-controls="${editorId}">查看详情</button>` : '')
631
736
  + '</div>').join('');
737
+ const ownItems = owns.map((o, i) => `<div class="own-item${inUse(o) ? ' on' : ''}">`
738
+ + `<p>${esc(o.preview)}${o.text.length > o.preview.length ? '……' : ''}</p>`
739
+ + `<button class="btn ghost" data-own-edit="${i}" aria-controls="${editorId}">查看/修改</button>`
740
+ + (inUse(o) ? '<span class="ok">正在用</span>'
741
+ : `<button class="btn ghost" data-own-use="${i}">用这份</button>`
742
+ + `<button class="btn ghost" data-own-forget="${i}">删掉</button>`)
743
+ + '</div>').join('');
632
744
  const saved = s.persona?.configured;
633
- const current = saved ? `已保存<b>${esc(s.persona.label)}</b>。`
745
+ const current = saved ? `正在用<b>${esc(s.persona.label)}</b>。`
746
+ + (s.persona.outdated ? `这个预设有新版了(不再默认你是男生),点一下「${esc(s.persona.label)}」就能更新。` : '')
634
747
  + (bindState?.phase === 'bound' ? '' : '绑定 QQ 后会使用这份人设。') : '';
635
748
  box.innerHTML = (kicker ? `<div class="wiz-kicker">${kicker}</div><h3>选TA的样子</h3>`
636
749
  : `<h3>TA的样子${saved ? '<span class="ok">✓ 已保存</span>' : ''}</h3>`)
637
750
  + `<p>${current}挑一个,或者自己写几句:TA是什么性格、跟你什么关系、说话什么样。</p>`
751
+ + '<div class="persona-confirm" data-confirm hidden><p data-question></p>'
752
+ + '<div class="persona-editor-actions"><button class="btn" data-yes>确定</button>'
753
+ + '<button class="btn ghost" data-no>取消</button></div></div>'
638
754
  + `<div class="presets">${presets}</div>`
755
+ + (owns.length ? `<div class="own-list"><h4>我写的人设</h4>${ownItems}</div>` : '')
639
756
  + `<div class="persona-editor" id="${editorId}" hidden>`
640
- + `<label for="${editorId}Text"></label><p>可以直接修改。改过的内容会作为自定义人设使用,原预设会保留。</p>`
757
+ + `<label for="${editorId}Text"></label><p data-editor-hint></p>`
641
758
  + `<textarea class="own" id="${editorId}Text" maxlength="4000"></textarea>`
642
759
  + '<div class="persona-editor-actions"><button class="btn" data-save-detail>保存并使用</button>'
643
760
  + '<button class="btn ghost" data-close-detail>取消</button></div>'
@@ -652,7 +769,31 @@ function personaBlock(box, sayId, { kicker = '', onSaved } = {}) {
652
769
  const editor = box.querySelector('.persona-editor');
653
770
  const editorText = editor.querySelector('textarea');
654
771
  const saveDetail = editor.querySelector('[data-save-detail]');
655
- let active = null, saving = false;
772
+ const confirmBox = box.querySelector('[data-confirm]');
773
+ let active = null, saving = false, pending = null;
774
+ const keepNote = usingOwn ? '你写的那份会一直留在「我写的人设」里,随时能换回来。' : '';
775
+ // 先问一句再动手:pending 是点「确定」后要做的事,点「取消」就什么都不改。
776
+ const ask = (question, action, revert = null) => {
777
+ if (saving) return;
778
+ pending?.revert?.();
779
+ pending = { action, revert };
780
+ confirmBox.querySelector('[data-question]').textContent = question;
781
+ confirmBox.hidden = false;
782
+ confirmBox.scrollIntoView?.({ block: 'nearest' });
783
+ confirmBox.querySelector('[data-yes]').focus();
784
+ };
785
+ confirmBox.querySelector('[data-no]').onclick = () => {
786
+ confirmBox.hidden = true;
787
+ pending?.revert?.();
788
+ pending = null;
789
+ say(sayId, '没改,还是原来的。');
790
+ };
791
+ confirmBox.querySelector('[data-yes]').onclick = () => {
792
+ const job = pending;
793
+ confirmBox.hidden = true;
794
+ pending = null;
795
+ job?.action();
796
+ };
656
797
  const choose = async (body, statusId = sayId) => {
657
798
  if (saving) return;
658
799
  if (!setupState.qq?.installed) { say(statusId, '先装 QQ 插件。', true); return; }
@@ -669,20 +810,58 @@ function personaBlock(box, sayId, { kicker = '', onSaved } = {}) {
669
810
  saving = saveDetail.disabled = false;
670
811
  }
671
812
  };
672
- box.querySelectorAll('[data-name]').forEach(button => { button.onclick = () => choose({ name: button.dataset.name }); });
813
+ const nameOf = body => body.name ? `「${choices.find(p => p.name === body.name)?.label ?? body.name}」` : '你写的这份人设';
814
+ const switchTo = (body, statusId = sayId) => {
815
+ if (saved && s.persona?.name && body.name === s.persona.name) {
816
+ if (!s.persona.outdated) { say(statusId, `现在用的就是「${s.persona.label}」。`); return; }
817
+ ask(`把「${s.persona.label}」更新成新版吗?新版不再默认你是男生,其他不变。`, () => choose(body, statusId));
818
+ return;
819
+ }
820
+ if (body.own && usingOwn && body.own === s.persona?.own_id) { say(statusId, '现在用的就是这份。'); return; }
821
+ ask(`把TA换成${nameOf(body)}吗?${saved ? `现在用的是「${s.persona.label}」。` : ''}${keepNote}`,
822
+ () => choose(body, statusId));
823
+ };
824
+ const openEditor = (title, hint, text, opener) => {
825
+ if (saving) return;
826
+ active?.setAttribute('aria-expanded', 'false');
827
+ active = opener;
828
+ active.setAttribute('aria-expanded', 'true');
829
+ editor.querySelector('label').textContent = title;
830
+ editor.querySelector('[data-editor-hint]').textContent = hint;
831
+ editorText.value = text;
832
+ say(detailSayId, '');
833
+ editor.hidden = false;
834
+ editorText.focus();
835
+ };
836
+ box.querySelectorAll('[data-name]').forEach(button => { button.onclick = () => switchTo({ name: button.dataset.name }); });
673
837
  box.querySelectorAll('[data-detail]').forEach(button => {
674
838
  button.onclick = () => {
675
- if (saving) return;
676
- if (active === button) { editorText.focus(); return; }
677
- active?.setAttribute('aria-expanded', 'false');
678
- active = button;
679
- active.setAttribute('aria-expanded', 'true');
680
839
  const preset = choices[button.dataset.detail];
681
- editor.querySelector('label').textContent = `${preset.label} · 完整设定`;
682
- editorText.value = preset.systemPrompt;
683
- say(detailSayId, '');
684
- editor.hidden = false;
685
- editorText.focus();
840
+ openEditor(`${preset.label} · 完整设定`, '可以直接修改。改过的内容会存进「我写的人设」,原预设也保留。',
841
+ preset.systemPrompt, button);
842
+ button.dataset.preset = preset.name;
843
+ };
844
+ });
845
+ box.querySelectorAll('[data-own-edit]').forEach(button => {
846
+ button.onclick = () => {
847
+ const own = owns[button.dataset.ownEdit];
848
+ openEditor('我写的人设', '改完点「保存并使用」。改之前那份也会留着。', own.text, button);
849
+ button.dataset.own = own.id;
850
+ };
851
+ });
852
+ box.querySelectorAll('[data-own-use]').forEach(button => {
853
+ button.onclick = () => switchTo({ own: owns[button.dataset.ownUse].id });
854
+ });
855
+ box.querySelectorAll('[data-own-forget]').forEach(button => {
856
+ button.onclick = () => {
857
+ const own = owns[button.dataset.ownForget];
858
+ ask(`删掉这份自己写的人设吗?删了就找不回来了。(${own.preview}……)`, async () => {
859
+ const { ok, data } = await setupPost('setup/forget-own', { own: own.id });
860
+ if (!ok) { say(sayId, data.error || '没删掉', true); return; }
861
+ await refreshSetup();
862
+ personaBlock(box, sayId, { kicker, onSaved });
863
+ say(sayId, '删掉了。');
864
+ });
686
865
  };
687
866
  });
688
867
  editor.querySelector('[data-close-detail]').onclick = () => {
@@ -697,19 +876,24 @@ function personaBlock(box, sayId, { kicker = '', onSaved } = {}) {
697
876
  if (!active) return;
698
877
  const text = editorText.value.trim();
699
878
  if (!text) { say(detailSayId, '人设内容不能为空。', true); editorText.focus(); return; }
700
- const preset = choices[active.dataset.detail];
701
- return choose(text === preset.systemPrompt.trim() ? { name: preset.name } : { text }, detailSayId);
879
+ const preset = choices.find(p => p.name === active.dataset.preset);
880
+ const own = owns.find(o => o.id === active.dataset.own);
881
+ const body = preset && text === preset.systemPrompt.trim() ? { name: preset.name }
882
+ : own && text === own.text.trim() ? { own: own.id } : { text };
883
+ switchTo(body, detailSayId);
702
884
  };
703
885
  box.querySelector('[data-own]').onclick = () => {
704
886
  const text = box.querySelector('[data-own-text]').value.trim();
705
887
  if (!text) { say(sayId, '先写几句。', true); return; }
706
- choose({ text });
888
+ switchTo({ text });
707
889
  };
708
890
  group.onchange = () => {
709
- // 现在用的是预设:按同一个预设重新保存(带上新的群聊设置);自己写的要重新点「用我写的」。
710
- if (active) say(detailSayId, '保存人设时会一起保存群聊设置。');
711
- else if (setupState.persona?.name) choose({ name: setupState.persona.name });
712
- else say(sayId, '选人设的时候会一起存这项。');
891
+ const was = group.value === 'all' ? 'mention' : 'all';
892
+ const label = group.value === 'all' ? '每条都可能接话' : '有人 @ TA才回';
893
+ const body = setupState.persona?.name ? { name: setupState.persona.name }
894
+ : setupState.persona?.own_id ? { own: setupState.persona.own_id } : null;
895
+ if (!body) { say(sayId, '选人设的时候会一起存这项。'); return; }
896
+ ask(`群里改成「${label}」吗?人设不变。`, () => choose(body), () => { group.value = was; });
713
897
  };
714
898
  }
715
899
 
package/py/xuyi/board.py CHANGED
@@ -205,7 +205,7 @@ def _note_seeds(store, scope, peer, events, superseded, today, limit, loops):
205
205
  gist = found[0]["值"] if found else _quote(recalled, 16)
206
206
  asked = _short(query.rstrip("??。!!"), 12)
207
207
  notes.append({"kind": "recall", "at": at[:16].replace("T", " "),
208
- "fact": f"他刚问你「{asked}」,你想起来:{gist}",
208
+ "fact": f"TA刚问你「{asked}」,你想起来:{gist}",
209
209
  "text": f"你问我「{asked}」——想起来啦:{gist}~", "quote": _quote(recalled),
210
210
  "event_id": recalled["event_id"]})
211
211
  if len([n for n in notes if n["kind"] == "recall"]) >= 3:
@@ -213,17 +213,17 @@ def _note_seeds(store, scope, peer, events, superseded, today, limit, loops):
213
213
  for family in (FAMILIES[0], FAMILIES[1]):
214
214
  for pair in family.suspected_pairs(peer, events, superseded):
215
215
  notes.append({"kind": "confirm",
216
- "fact": f"他先说「{pair['旧值']}」,后来说「{pair['新值']}」,到底哪个还没确认",
216
+ "fact": f"TA先说「{pair['旧值']}」,后来说「{pair['新值']}」,到底哪个还没确认",
217
217
  "text": f"你说过「{pair['旧值']}」,后来又说「{pair['新值']}」……到底是哪个呀?",
218
218
  "event_id": pair["新来源"]})
219
219
  for loop in loops[-3:]:
220
- notes.append({"kind": "followup", "fact": f"他提过想{loop['值']},还没下文",
220
+ notes.append({"kind": "followup", "fact": f"TA提过想{loop['值']},还没下文",
221
221
  "text": f"你说想{loop['值']},后来怎么样啦?找机会问问你~",
222
222
  "event_id": loop["来源"]["event_id"]})
223
223
  for row in upcoming(store, scope, today=today, events=events)[:2]:
224
224
  if row["date"]:
225
225
  when = "今天" if row["date"] == today.isoformat() else row["时间"]
226
- notes.append({"kind": "plan", "fact": f"{when}他和{row['who']}有约",
226
+ notes.append({"kind": "plan", "fact": f"{when}TA和{row['who']}有约",
227
227
  "text": f"{when}和{row['who']}有约,记得提醒你一下。",
228
228
  "event_id": row["event_id"]})
229
229
  # 今天聊过的事也要贴上(用户要的):不管有没有重点事实,都取今天最像"一件事"的一两句。
@@ -277,7 +277,7 @@ def pick_topics(candidates, limit=2, when="今天"):
277
277
  picked.append(said)
278
278
  topics.append({"kind": "topic",
279
279
  "at": (event.get("recorded_at") or "")[:16].replace("T", " "),
280
- "fact": f"他{when}提到:{said}",
280
+ "fact": f"TA{when}提到:{said}",
281
281
  "text": f"你说「{_short(said, 18)}」,我记着呢。",
282
282
  "event_id": event["event_id"]})
283
283
  if len(picked) >= limit:
@@ -57,7 +57,7 @@ def note_prompt(facts):
57
57
  lines = "\n".join(f"{i}. {fact['fact'].strip()}" for i, fact in enumerate(facts, 1))
58
58
  return (f"现在请你写便利贴。下面 {len(facts)} 条是你刚想起来的事。"
59
59
  "用你平时说话的口吻,一条写成一张便利贴上的短句。\n"
60
- "规矩:一条一张,一张一行。每张 15 到 35 个字——写清「他说的哪件事」加上「你的反应或答案」,"
60
+ "规矩:一条一张,一张一行。每张 15 到 35 个字——写清「对方说的哪件事」加上「你的反应或答案」,"
61
61
  "别只写一个词、一个名字或半句话;便利贴不是发消息,可以比聊天时多说几个字。"
62
62
  "只写纸条上的话,不编号、不加引号、不解释、不寒暄。\n\n" + lines)
63
63
 
@@ -103,8 +103,20 @@ def _placed(notes, facts):
103
103
  return out
104
104
 
105
105
 
106
+ def writing_voice(persona):
107
+ """写日记、写便利贴用的人设:只要人设本身,去掉「在 QQ 上怎么发消息」那段规矩
108
+ (每条要短、最多分三条发……),那些和写一篇日记是冲突的。"""
109
+ from .personas import persona_body
110
+ body = persona_body(persona or "")
111
+ if not body:
112
+ return ""
113
+ return (body + "\n\n(以上是你的人设。现在不是在 QQ 上发消息,而是你自己在写东西:"
114
+ "照着这个人设的性格、和对方的关系、说话方式来写,用你自己的视角。)")
115
+
116
+
106
117
  def request_notes(db_path, scope, facts, persona, now):
107
118
  """Return (cached model notes or None, whether a fresh request was just written)."""
119
+ persona = writing_voice(persona)
108
120
  if not facts or not persona:
109
121
  return None, False
110
122
  want = fingerprint(facts, persona)
@@ -143,7 +155,7 @@ def diary_length(count):
143
155
 
144
156
 
145
157
  def diary_prompt(day, weekday, messages):
146
- lines = "\n".join(f"[{m['time']}] {'他' if m['role'] == 'user' else '你'}:{m['text']}"
158
+ lines = "\n".join(f"[{m['time']}] {'对方' if m['role'] == 'user' else '你'}:{m['text']}"
147
159
  for m in messages)
148
160
  size = diary_length(len(messages))
149
161
  low, high = size["paragraphs"]
@@ -152,8 +164,9 @@ def diary_prompt(day, weekday, messages):
152
164
  "要求:\n"
153
165
  f"- 分成 {low} 到 {high} 段,每段两三句话,段与段之间空一行;"
154
166
  f"全文 {size['min']} 到 {size['max']} 字,无论如何不超过 {DIARY_MAX_CHARS} 字。\n"
155
- "- 不是流水账:只写这天里真正有内容的事(他说的事、你们的约定、他的心情、你记住的细节),"
156
- "寒暄、重复和没内容的话不要写。可以写细一点:他当时怎么说的、你心里怎么想。\n"
167
+ "- 不是流水账:只写这天里真正有内容的事(对方说的事、你们的约定、对方的心情、你记住的细节),"
168
+ "寒暄、重复和没内容的话不要写。可以写细一点:对方当时怎么说的、你心里怎么想。\n"
169
+ "- 提到对方时,用你平时对TA的称呼(名字、昵称);聊天里看不出性别,就不要用「他」「她」。\n"
157
170
  "- 不要编:只能写这些话里出现过的事,不要加没发生过的事。\n"
158
171
  "- 像晚上自己回想这一天,用你的第一人称写,不要标题、日期、署名、列表或任何格式符号。\n\n"
159
172
  + lines)
@@ -209,6 +222,7 @@ def request_diary(db_path, scope, day, messages, persona, now, allow_write=True)
209
222
  写完就定稿:这一天已经有正文,就不再管内容变没变、也不会重写(规则升级也不重写)。
210
223
  `allow_write=False` 用于"还没到写日记的时候"——只读缓存,不请模型。
211
224
  """
225
+ persona = writing_voice(persona)
212
226
  if not messages or not persona:
213
227
  return None, False
214
228
  request, reply = paths(db_path, scope, f"diary-{day}")
package/py/xuyi/cli.py CHANGED
@@ -26,6 +26,10 @@ def main():
26
26
  recall.add_argument('--sender',help='仅查询这个稳定发言人ID')
27
27
  recall.add_argument('--highlight-only',action='store_true',help='仅回忆有原话的当前重点')
28
28
  recall.add_argument('--related',action='store_true',help='无重点时按话题稀有实体回退一条相关旧话')
29
+ recall.add_argument('--about-me',action='store_true',help='无重点时,问的是用户自己的事就带上有共同词的原话')
30
+ recall.add_argument('--her',action='store_true',help='问她自己的喜好时,带上她以前对同一问题的回答(前后一致)')
31
+ recall.add_argument('--group',action='store_true',help='群里的自动提醒:只查本群,最多两条,写明是谁说的')
32
+ recall.add_argument('--speaker',help='群里正在说话的成员编号(问「我…」时只查这个人说过的话)')
29
33
  recall.add_argument('--focus',action='store_true',help='只返回与问题有实质共同词的证据(模型主动查询用)')
30
34
  recall.add_argument('--ordinal',action='store_true',help='编号事实清单中旧事实附上最新事实原文(序号冲突规则)')
31
35
  for name in ('get','forget'):
@@ -54,6 +58,8 @@ def main():
54
58
  persona_command=commands.add_parser('persona',help='打印人设预设全文(可粘贴进宿主人设配置)')
55
59
  persona_command.add_argument('name',nargs='?',help='预设名;用自己写的人设时省略,改用 --file')
56
60
  persona_command.add_argument('--file',help='自己写的人设文本文件(UTF-8)')
61
+ persona_command.add_argument('--own',help='用「我写的人设」里存过的那份(编号见 setup-state)')
62
+ persona_command.add_argument('--forget-own',help='从「我写的人设」里删掉一份(不影响正在用的人设)')
57
63
  persona_command.add_argument('--apply',action='store_true',help='直接写进宿主 QQ 配置(先自动备份)')
58
64
  persona_command.add_argument('--no-bubbles',action='store_true',help='不改发送方式(保持一整条、流式)')
59
65
  persona_command.add_argument('--profile',default=str(Path.home()/'.dsh/profiles/desktop'))
@@ -163,7 +169,12 @@ def main():
163
169
  from .personas import list_personas, persona_status
164
170
  from .board_bridge import DIARY_HOURS, diary_hour
165
171
  from .carry import health
166
- result={'persona':persona_status(args.profile),'presets':list_personas(include_prompt=True),
172
+ from .personas import list_own, keep_current_own
173
+ status=persona_status(args.profile)
174
+ # 现在用着自己写的人设:先存进「我写的人设」,页面上标「正在用」,以后换走也不丢。
175
+ status['own_id']=keep_current_own(store,args.profile)
176
+ result={'persona':status,'presets':list_personas(include_prompt=True),
177
+ 'own':list_own(store),
167
178
  'diary_hour':diary_hour(args.db),'diary_hours':list(DIARY_HOURS),
168
179
  'health':health(store)}
169
180
  elif args.command=='diary-due':
@@ -182,14 +193,25 @@ def main():
182
193
  raise MemoryError(str(exc)) from exc
183
194
  result={'diary_hour':diary_hour(args.db)}
184
195
  elif args.command=='persona':
185
- from .personas import load_persona, apply_persona, compose_prompt
186
- if bool(args.name)==bool(args.file):raise MemoryError('请给一个预设名,或用 --file 指定自己写的人设(二选一)')
187
- text=Path(args.file).read_text(encoding='utf-8') if args.file else None
188
- if args.apply:
196
+ from .personas import (load_persona, apply_persona, compose_prompt, save_own, load_own,
197
+ forget_own, keep_current_own)
198
+ if args.forget_own:
199
+ result={'forgotten':forget_own(store,args.forget_own)}
200
+ elif sum(map(bool,(args.name,args.file,args.own)))!=1:
201
+ raise MemoryError('请给一个预设名,或用 --file / --own 指定自己写的人设(三选一)')
202
+ else:
203
+ text=Path(args.file).read_text(encoding='utf-8') if args.file else (load_own(store,args.own) if args.own else None)
204
+ if args.forget_own:
205
+ pass
206
+ elif args.apply:
207
+ # 换之前先把现在用着的自己写的人设存好,换成预设也不会丢。
208
+ keep_current_own(store,args.profile)
189
209
  result=apply_persona(args.name,args.profile,text=text,bubbles=not args.no_bubbles,create=args.create,group_reply=args.group_reply)
210
+ if text is not None:
211
+ result['own_id']=save_own(store,text,used=True)
190
212
  result['提示']='重启 DeepSeek Harness 后生效'
191
213
  else:
192
- data=load_persona(args.name) if args.name else {'label':'自定义人设','systemPrompt':text}
214
+ data=load_persona(args.name) if args.name else {'label':'我写的人设','systemPrompt':text}
193
215
  result=dict(data,directPrompt=compose_prompt(data['systemPrompt']))
194
216
  elif args.command=='stats':
195
217
  from .stats import stats
@@ -224,7 +246,8 @@ def main():
224
246
  fallback=f'语义模型不可用,已改用词法检索:{exc}'
225
247
  counter=TokenizerCounter(args.tokenizer) if args.tokenizer else None
226
248
  result=Retriever(store,embedder,counter).recall(args.scope,args.query,args.budget,args.sender,
227
- highlight_only=args.highlight_only,related=args.related,ordinal=args.ordinal,focus=args.focus)
249
+ highlight_only=args.highlight_only,related=args.related,ordinal=args.ordinal,focus=args.focus,
250
+ about_me=args.about_me,her=args.her,group=args.group,speaker=args.speaker)
228
251
  if fallback and isinstance(result.get('warnings'),list):result['warnings'].insert(0,fallback)
229
252
  print(json.dumps(result,ensure_ascii=False,indent=2))
230
253
  except (MemoryError,OSError,sqlite3.Error,json.JSONDecodeError) as exc:
@@ -182,7 +182,7 @@ def _last_thread(store, scope, events, max_chars=40, current=None):
182
182
  # sides show what they were actually talking about and what she herself said.
183
183
  recent = [event for event in events if session_of(event) == previous
184
184
  and event["role"] in ("user", "assistant") and event["text"].strip()][-4:]
185
- exchange = [("他:" if event["role"] == "user" else "我:")
185
+ exchange = [("对方:" if event["role"] == "user" else "我:")
186
186
  + " ".join(event["text"].split())[:18] + ("…" if len(" ".join(event["text"].split())) > 18 else "")
187
187
  for event in recent]
188
188
  return {"摘要": summary, "来源": last_user, "最后几句": exchange, "结束于": recent[-1]["recorded_at"],