dsh-lifecard 0.2.1 → 0.2.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/lib/client.js CHANGED
@@ -144,6 +144,37 @@ function humanizeIssue(issue) {
144
144
  return `「${fieldLabel(field)}」这一项写法不太对,点「改这张卡」能就地改。`
145
145
  }
146
146
 
147
+ /**
148
+ * 这一份材料是不是真的能读。
149
+ *
150
+ * 存材料时会先写临时文件再改名。改名那一步如果被什么打断(程序崩了、
151
+ * 磁盘满了),就会留下 `.妈妈.md.bak-1234` 这种残骸。它一直被当成材料摆在
152
+ * 列表里:用户看到两份「妈妈」,点开其中一份是空的,还以为自己写丢了。
153
+ * 备份和点开头的临时文件都不该出现在材料列表里。
154
+ */
155
+ function isRealMaterial(m) {
156
+ const name = String(m?.name ?? '').trim()
157
+ if (name === '') return false
158
+ if (name.startsWith('.')) return false
159
+ return !/\.(bak|tmp)-/.test(name)
160
+ }
161
+
162
+ /**
163
+ * 读不了的那几个文件,用名字点出来(最多三个)。
164
+ *
165
+ * 只报一个数字(「有 4 个文件读不了」)等于没说:用户不知道是那几张重要的,
166
+ * 还是早就想删的草稿,只能一个抽屉一个抽屉去翻。名字后面多的用「还有 N 个」收。
167
+ */
168
+ function unreadableNames(errors) {
169
+ const names = (Array.isArray(errors) ? errors : [])
170
+ .map((e) => String(cardNameFromPath(e?.path ?? '')))
171
+ .filter((n) => n !== '' && n !== '一张卡')
172
+ const uniq = [...new Set(names)]
173
+ if (uniq.length === 0) return ''
174
+ const head = uniq.slice(0, 3).map((n) => `「${n}」`).join('、')
175
+ return uniq.length > 3 ? `${head},还有 ${uniq.length - 3} 个` : head
176
+ }
177
+
147
178
  /** `people/妈妈.card.md` → `妈妈`。界面上不摆文件路径。 */
148
179
  function cardNameFromPath(rel) {
149
180
  const base = String(rel ?? '').split('/').pop() ?? ''
@@ -280,6 +311,86 @@ const CSS = `
280
311
  .lc-row { display: flex; align-items: center; gap: 9px; }
281
312
  .lc-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
282
313
 
314
+ /* 门:鼠标放上去才露出「删掉」;删掉之后变成一块灰黑的死门,放上去露出「装回来」 */
315
+ .lc-door { position: relative; }
316
+ .lc-door-x {
317
+ position: absolute; top: 8px; right: 8px;
318
+ width: 24px; height: 24px; border-radius: 999px;
319
+ display: inline-flex; align-items: center; justify-content: center;
320
+ border: 1px solid var(--lc-line-strong); background: var(--lc-panel);
321
+ color: var(--lc-danger); font-size: 13px; line-height: 1; cursor: pointer;
322
+ opacity: 0; transition: opacity .14s; padding: 0;
323
+ }
324
+ .lc-door:hover .lc-door-x, .lc-door-x:focus-visible { opacity: 1; }
325
+ .lc-door-x:hover { background: var(--lc-danger-soft); border-color: var(--lc-danger); }
326
+ .lc-door-dead {
327
+ flex: 1 1 30%; min-width: 156px; min-height: 260px; position: relative;
328
+ display: flex; align-items: center; justify-content: center;
329
+ border: 1px dashed var(--lc-line-strong); border-radius: 16px;
330
+ background: #2b2b2b; box-sizing: border-box; cursor: default;
331
+ }
332
+ .lc-door-dead .lc-door-dead-icon { color: #6f6f6f; opacity: .9; }
333
+ .lc-door-dead .lc-door-back {
334
+ position: absolute; inset: 0; display: flex; flex-direction: column;
335
+ align-items: center; justify-content: center; gap: 8px;
336
+ opacity: 0; pointer-events: none; transition: opacity .14s;
337
+ background: rgba(20, 20, 20, .72); border-radius: 16px; color: #f0f0f0;
338
+ }
339
+ .lc-door-dead:hover .lc-door-back, .lc-door-dead:focus-within .lc-door-back { opacity: 1; pointer-events: auto; }
340
+ .lc-door-back-btn {
341
+ width: 56px; height: 56px; border-radius: 999px; border: 1px solid #8a8a8a;
342
+ background: #3a3a3a; color: #f0f0f0; cursor: pointer;
343
+ display: inline-flex; align-items: center; justify-content: center;
344
+ }
345
+ .lc-door-back-btn:hover { background: #4a4a4a; border-color: #c8c8c8; }
346
+ .lc-door-dead-name {
347
+ color: #9a9a9a; font-size: 13.5px; font-weight: 600; margin-top: 8px; letter-spacing: .04em;
348
+ }
349
+
350
+ /* 门框里那道内嵌的门板:让一块色块看起来是「一扇门」而不是一张卡 */
351
+ .lc-door-panel {
352
+ position: absolute; inset: 10px 10px 46px 10px; border-radius: 10px;
353
+ border: 1px solid rgba(0, 0, 0, .10);
354
+ box-shadow: inset 0 2px 6px rgba(255, 255, 255, .55), inset 0 -10px 22px rgba(0, 0, 0, .06);
355
+ pointer-events: none;
356
+ }
357
+ .lc-door-jamb {
358
+ position: absolute; left: 10px; right: 10px; bottom: 40px; height: 6px;
359
+ border-radius: 0 0 8px 8px; background: rgba(0, 0, 0, .10);
360
+ box-shadow: 0 2px 0 rgba(255, 255, 255, .5);
361
+ pointer-events: none;
362
+ }
363
+ /* 门的按动感:悬停抬一点,按下去真的往下沉 */
364
+ .lc-door {
365
+ /* 顶上是门楣,底下是门槛:上圆下平,才像个门洞而不是一张卡 */
366
+ border-radius: 18px 18px 8px 8px;
367
+ transition: transform .12s ease, box-shadow .16s ease, border-color .16s ease;
368
+ will-change: transform;
369
+ }
370
+ /* 铰链:门板靠左那一条竖线,让人一眼看出这是一扇能推开的门 */
371
+ .lc-door-hinge {
372
+ position: absolute; left: 14px; top: 14px; bottom: 52px; width: 2px;
373
+ border-radius: 2px; background: rgba(0, 0, 0, .09);
374
+ box-shadow: 1px 0 0 rgba(255, 255, 255, .55);
375
+ pointer-events: none;
376
+ }
377
+ .lc-door:hover { transform: translateY(-2px); box-shadow: 0 16px 30px rgba(0, 0, 0, .16); }
378
+ .lc-door:active { transform: translateY(1px) scale(.992); box-shadow: 0 6px 14px rgba(0, 0, 0, .12), inset 0 2px 6px rgba(0, 0, 0, .10); }
379
+ .lc-door:focus-visible { outline: 2px solid var(--lc-accent); outline-offset: 2px; }
380
+ /* 按钮立体 + 按下去的下沉动效(所有按钮一起变,不用逐处改) */
381
+ .lc-btn {
382
+ box-shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 2px 4px rgba(0, 0, 0, .10), 0 1px 0 rgba(0, 0, 0, .06);
383
+ transition: transform .1s ease, box-shadow .14s ease, background .14s ease, border-color .14s ease;
384
+ }
385
+ .lc-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 4px 8px rgba(0, 0, 0, .12); }
386
+ .lc-btn:active:not(:disabled) {
387
+ transform: translateY(1px);
388
+ box-shadow: inset 0 2px 5px rgba(0, 0, 0, .16), 0 0 0 rgba(0, 0, 0, 0);
389
+ }
390
+ /* 卡面:悬停抬起来一点,翻面靠内层 transform */
391
+ .lc-fcard { transition: transform .16s ease; }
392
+ .lc-fcard:hover { transform: translateY(-2px); }
393
+
283
394
  /* 按钮:颜色即语义 */
284
395
  .lc-btn {
285
396
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
@@ -486,6 +597,9 @@ const CSS = `
486
597
 
487
598
  /* 关系选项:一片一片能点的词,比下拉框好点——一屏就能看见父亲母亲爷爷都在 */
488
599
  .lc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
600
+ /* 上一题留下的选项:只是给人回看的,不要长得像能点的按钮 */
601
+ .lc-opt-past { opacity: .72; cursor: default; }
602
+ .lc-opt-past:hover { background: inherit; }
489
603
  .lc-chip {
490
604
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--lc-line-strong);
491
605
  background: var(--lc-panel); color: inherit; font-family: inherit; font-size: 14.5px;
@@ -729,6 +843,192 @@ const SECTIONS_REL = [
729
843
 
730
844
  const VIEWS = { doors: 'doors', novel: 'novel', book: 'book', game: 'game', career: 'career', tavern: 'tavern', tavernChat: 'tavernChat', home: 'home', card: 'card', interview: 'interview', import: 'import', analyze: 'analyze', doctor: 'doctor', setup: 'setup', newCard: 'newCard', world: 'world', memory: 'memory', jobs: 'jobs' }
731
845
 
846
+ // ── 开一个新会话去问 ──────────────────────────────────────────────
847
+ //
848
+ // 以前「聊着建」「接着聊」进的是插件自己的访谈页:插件里演一套问法,问答
849
+ // 再由插件拆成卡里的字段。同一套问法在外面(/lifecard-interview 那个 skill)
850
+ // 还有一份,两边慢慢就会走样——这边补了新的问法,那边不知道;用户在哪边问,
851
+ // 得到的东西也不一样。
852
+ //
853
+ // 现在只留一条路:开一个新会话,把 skill 和一句意图摆进它的输入框,用户按
854
+ // 回车才开始问。插件不替用户说话,也不再自己演示一遍。访谈页的代码还留着
855
+ // 当参考(还有它自己的测试),但已经没有入口进得去——入口就是下面这个
856
+ // openInterviewSession。
857
+ //
858
+ // 宿主那边给的是 `uiWorkspace.startSession(workspaceId?, options)`,options
859
+ // 里的 prompt 落在新会话的输入框里,不会自动发送。
860
+ let HOST = null
861
+ // 开新会话最终要走的两样东西:宿主的远程会话控制器(建会话 + 发第一句)和
862
+ // 客户端的 uiWorkspace(把新会话切到眼前)。两者都用 ctx.inject 等就绪,
863
+ // 拿不到就退回草稿法(host 版本不同,能力不同,路不能断)。
864
+ let REMOTE_SESSION = null
865
+ let UI_WORKSPACE = null
866
+
867
+ /** 三扇门各用哪一套预设。串了就会拿「记录一个真人」的问法去问虚构角色。 */
868
+ const DOOR_PRESET = { real: 'lc-real', tavern: 'lc-tavern', novel: 'lc-novel' }
869
+
870
+ /** 摆进新会话输入框的那段话。 */
871
+ function interviewPrompt({ about, mode, ask } = {}) {
872
+ const name = String(about === undefined || about === null ? '' : about).trim()
873
+ const lines = [
874
+ '/lifecard-interview',
875
+ // 一句话说清要做什么。补卡的时候带上「写过的别再问」——不然它会把
876
+ // 已经写好的部分从头再问一遍,用户得答第二遍。
877
+ name === '' ? '帮我建一张新的人物卡' : `帮我补一补「${name}」这张卡,已经写过的就别再问了`,
878
+ ]
879
+ // 虚构角色要说清是虚构的,不然它会照「记录一个真人」来问,
880
+ // 连生日、住址这种只对真人有意义的东西也问出来。
881
+ if (mode === 'tavern') lines.push('这是酒馆里要演的一个虚构角色。')
882
+ if (mode === 'novel') lines.push('这是小说里的一个虚构角色。')
883
+ const extra = String(ask === undefined || ask === null ? '' : ask).trim()
884
+ if (extra !== '') lines.push(extra)
885
+ return lines.join('\n')
886
+ }
887
+
888
+ /**
889
+ * 开一个新会话,输入框里摆好 skill 和一句意图。
890
+ *
891
+ * 拿不到 uiWorkspace(老版本宿主,或者它被禁用了)时不静默失败:把那段话
892
+ * 原样交回去,界面上让用户自己复制到新对话里。功能可以降级,路不能断。
893
+ */
894
+ function openInterviewSession({ about, mode, ask } = {}) {
895
+ const prompt = interviewPrompt({ about, mode, ask })
896
+ const preset = DOOR_PRESET[mode === 'tavern' ? 'tavern' : mode === 'novel' ? 'novel' : 'real']
897
+ // 这条路要等网络,是异步的;下面几条退路有同步的,调用方两种都接。
898
+ return openInterviewSessionByServer(prompt, preset)
899
+ }
900
+
901
+ /**
902
+ * 正路:让后台建会话、把第一句发出去,客户端再把那个会话切到眼前。
903
+ *
904
+ * 后台一定拿得到宿主的会话服务(sessionController);客户端那侧不一定——
905
+ * 真机上 uiWorkspace 有时根本不在插件的作用域里,只能看到「这个版本不支持」。
906
+ * 所以「建」这一步交给后台,「切到眼前」这一步才用客户端的 uiWorkspace。
907
+ */
908
+ async function openInterviewSessionByServer(prompt, preset) {
909
+ let made = null
910
+ try {
911
+ made = await call('session.open', { preset, text: prompt })
912
+ } catch (e) {
913
+ made = null
914
+ }
915
+ const id = String(made?.sessionId ?? '')
916
+ if (made?.ok === true && id !== '') {
917
+ const focused = focusSession(id)
918
+ const applied = String(made?.agentPreset ?? '').trim()
919
+ const notes = []
920
+ if (applied !== '' && applied !== preset) {
921
+ notes.push(`这台机器没认「${preset}」这套预设(现在跑的是「${applied}」),去顶部切一下。`)
922
+ }
923
+ if (made?.sent !== true) notes.push('新对话建好了,但第一句没能自动发出去,进去后自己发一下。')
924
+ if (focused !== true) notes.push('新对话在左边的会话列表里,点开它——第一句我已经替你发出去了。')
925
+ return { ok: true, prompt, preset, sessionId: id, note: notes.length === 0 ? undefined : notes.join(' ') }
926
+ }
927
+
928
+ // 第二条:客户端自己也能建会话(有的宿主把远程能力也暴露给前端)。
929
+ const remote = pickRemoteSession()
930
+ if (remote !== null) return openInterviewSessionVia(remote, prompt, preset)
931
+
932
+ // 第三条:老宿主只有「摆草稿」这一种能力。
933
+ return openInterviewSessionDraft(prompt, preset)
934
+ }
935
+
936
+ /** 把某个会话切到眼前。切不动就说没能切动(会话已经建好了,用户点一下也能进去)。 */
937
+ function focusSession(sessionId) {
938
+ const ui = UI_WORKSPACE !== null ? UI_WORKSPACE : (HOST === null || HOST === undefined ? undefined : HOST.get?.('uiWorkspace', false))
939
+ if (ui === undefined || ui === null || typeof ui.openSession !== 'function') return false
940
+ try {
941
+ ui.openSession(sessionId)
942
+ return true
943
+ } catch (e) {
944
+ return false
945
+ }
946
+ }
947
+
948
+ /** 自己建会话再发第一句(异步)。 */
949
+ async function openInterviewSessionVia(remote, prompt, preset) {
950
+ {
951
+ try {
952
+ const created = await remote.create({ agentPreset: preset })
953
+ const id = String(created === undefined || created === null ? '' : created.sessionId ?? '')
954
+ if (id === '') return { ok: false, prompt, preset, reason: '新会话没建起来,再点一次试试' }
955
+ if (UI_WORKSPACE !== null && typeof UI_WORKSPACE.openSession === 'function') {
956
+ // 打不开也不要紧:会话已经建好、话也发出去了,它在会话列表里等着。
957
+ try { UI_WORKSPACE.openSession(id) } catch (e) { /* 忽略 */ }
958
+ }
959
+ await remote.prompt({ sessionId: id, mode: 'queue', content: [{ type: 'text', text: prompt }] })
960
+ const applied = String(created === undefined || created === null ? '' : created.agentPreset ?? '').trim()
961
+ if (applied !== '' && applied !== preset) {
962
+ return {
963
+ ok: true,
964
+ prompt,
965
+ preset,
966
+ sessionId: id,
967
+ note: `会话开好了,但这台机器没认「${preset}」这套预设(现在跑的是「${applied}」)。在顶部把预设切成它对的那一套再聊。`,
968
+ }
969
+ }
970
+ return { ok: true, prompt, preset, sessionId: id }
971
+ } catch (e) {
972
+ // 远程那条路没走通,别让用户白点一次:退回摆草稿,把理由一并说清。
973
+ const draft = openInterviewSessionDraft(prompt, preset)
974
+ if (draft.ok === true) {
975
+ return { ...draft, note: `新会话没直接开起来(${humanizeError(e)}),改成把那句话摆进输入框了,按回车就开始。` }
976
+ }
977
+ return { ok: false, prompt, preset, reason: humanizeError(e) }
978
+ }
979
+ }
980
+ }
981
+
982
+ /** 找一个真的能用 startSession 的东西。宿主版本不同,服务可能挂在几个不同的地方。 */
983
+ function pickUiWorkspace() {
984
+ const got = []
985
+ const push = (v) => { if (v !== undefined && v !== null) got.push(v) }
986
+ push(UI_WORKSPACE)
987
+ try { push(HOST?.get?.('uiWorkspace', false)) } catch (e) { /* 没有就算了 */ }
988
+ try { push(HOST?.uiWorkspace) } catch (e) { /* 没有就算了 */ }
989
+ for (const one of got) if (typeof one?.startSession === 'function') return one
990
+ return null
991
+ }
992
+
993
+ /** 找一个真的能建会话 / 发消息的东西。 */
994
+ function pickRemoteSession() {
995
+ const got = []
996
+ const push = (v) => { if (v !== undefined && v !== null) got.push(v) }
997
+ push(REMOTE_SESSION)
998
+ try { push(HOST?.get?.('remote.session', false)) } catch (e) { /* 没有就算了 */ }
999
+ try { push(HOST?.remote?.session) } catch (e) { /* 没有就算了 */ }
1000
+ for (const one of got) if (typeof one?.create === 'function' && typeof one?.prompt === 'function') return one
1001
+ return null
1002
+ }
1003
+
1004
+ /** 老宿主的退路:把话摆进新会话的输入框,用户自己按回车。 */
1005
+ function openInterviewSessionDraft(prompt, preset) {
1006
+ const ui = pickUiWorkspace()
1007
+ if (ui === null) {
1008
+ // 真没法开的时候,把「查到了什么」一起说出去:不然用户只会看到一句
1009
+ // 「这个版本不支持」,我也没法判断到底是哪一层缺东西。
1010
+ const hasRemote = pickRemoteSession() !== null
1011
+ return {
1012
+ ok: false,
1013
+ prompt,
1014
+ reason: `这个版本没法从这里直接开对话(能建会话:${hasRemote === true ? '有' : '没有'};能开新对话:没有)。把下面这句复制到新对话里也一样能用。`,
1015
+ }
1016
+ }
1017
+ try {
1018
+ const started = ui.startSession(undefined, {
1019
+ prompt,
1020
+ agentPreset: preset,
1021
+ whenDraftExists: 'replace',
1022
+ clearPreviousDraft: false,
1023
+ })
1024
+ // 有的实现给的是 promise:开不出来也别让界面一直等着。
1025
+ if (started !== undefined && started !== null && typeof started.catch === 'function') started.catch(() => {})
1026
+ return { ok: true, prompt, preset }
1027
+ } catch (e) {
1028
+ return { ok: false, prompt, reason: humanizeError(e) }
1029
+ }
1030
+ }
1031
+
732
1032
  /**
733
1033
  * tab 组件。接收宿主给的 props(ctx / store / scope / tab / visible)。
734
1034
  * 只用到 `visible`,其余一律不碰——插件不该依赖宿主内部状态。
@@ -1006,6 +1306,43 @@ function LifeCardTab(props) {
1006
1306
  }, [pins])
1007
1307
 
1008
1308
 
1309
+ /**
1310
+ * 把一扇门收起来 / 装回来。
1311
+ *
1312
+ * 只动界面:卡、世界书、写的书、说过的场次一个字节不碰,
1313
+ * 所以「删掉」随时能反悔——这也是为什么用收起而不是真删文件。
1314
+ */
1315
+ const hideDoor = async (which) => {
1316
+ const one = DOORS.find((d) => d.id === which)
1317
+ if (one === undefined) return
1318
+ const ask = typeof window !== 'undefined' && typeof window.confirm === 'function' ? window.confirm : () => true
1319
+ const yes = ask(`把「${one.title}」这扇门收起来?\n\n里面的东西都不会删——卡、世界书、写过的书都还在原处。想用的时候在这块灰门上点一下就能装回来。`)
1320
+ if (yes !== true) return
1321
+ try {
1322
+ const r = await call('door.set', { id: which, hidden: true })
1323
+ if (r?.ok !== true) {
1324
+ setError(r?.error ?? '这扇门没能收起来,再点一次。')
1325
+ return
1326
+ }
1327
+ setDoorsOverride(Array.isArray(r.hidden_doors) ? r.hidden_doors : [])
1328
+ } catch (e) {
1329
+ setError(humanizeError(e))
1330
+ }
1331
+ }
1332
+
1333
+ const showDoor = async (which) => {
1334
+ try {
1335
+ const r = await call('door.set', { id: which, hidden: false })
1336
+ if (r?.ok !== true) {
1337
+ setError(r?.error ?? '这扇门没能装回来,再点一次。')
1338
+ return
1339
+ }
1340
+ setDoorsOverride(Array.isArray(r.hidden_doors) ? r.hidden_doors : [])
1341
+ } catch (e) {
1342
+ setError(humanizeError(e))
1343
+ }
1344
+ }
1345
+
1009
1346
  useEffect(() => {
1010
1347
  let gone = false
1011
1348
  call('features.list', {})
@@ -1019,6 +1356,15 @@ function LifeCardTab(props) {
1019
1356
  loadPins()
1020
1357
  }, [view, loadPins])
1021
1358
 
1359
+ // 用户自己在界面上收起来的门。
1360
+ //
1361
+ // 这里用「本地覆盖」而不是再挂一个 effect 去同步 state:刚点完要立刻变灰,
1362
+ // 等 refresh 回来之前界面不能还是老样子;拿到服务端结果后就以服务端为准。
1363
+ const [doorsOverride, setDoorsOverride] = useState(null)
1364
+ const hiddenDoors = doorsOverride !== null
1365
+ ? doorsOverride
1366
+ : (Array.isArray(state?.hidden_doors) ? state.hidden_doors : [])
1367
+
1022
1368
  // 门自己的那两屏直接说了算;其余屏(聊着建、卡片、分析…)沿用上次选的门。
1023
1369
  const mode = (view === VIEWS.novel || view === VIEWS.book || view === VIEWS.game) ? 'novel' : (view === VIEWS.tavern || view === VIEWS.tavernChat) ? 'tavern' : door
1024
1370
  // 回到酒馆那两屏就重新拿一遍说过的场次:刚说完、刚删完再回来,
@@ -1027,11 +1373,50 @@ function LifeCardTab(props) {
1027
1373
  if (view !== VIEWS.tavern && view !== VIEWS.tavernChat) return
1028
1374
  let gone = false
1029
1375
  call('tavern.list', {})
1030
- .then((r) => { if (!gone && r?.ok === true && Array.isArray(r.items)) setChats(r.items) })
1031
- .catch(() => { /* 取不到就空着,不影响开新的一场 */ })
1376
+ .then((r) => {
1377
+ if (gone) return
1378
+ // 读不出来的场次以前是「安静消失」:列表看着少了几场,用户只会以为
1379
+ // 自己记错了。后台早就把读不出来的份数报回来了(bad),这里要说出来。
1380
+ if (r?.ok !== true) {
1381
+ setChatsNote(String(r?.error ?? '').trim() === '' ? '说过的场次没读出来' : String(r.error))
1382
+ return
1383
+ }
1384
+ if (Array.isArray(r.items)) setChats(r.items)
1385
+ const bad = Number(r.bad ?? 0)
1386
+ setChatsNote(bad > 0 ? `有 ${bad} 场读不出来,可能文件坏了。别的场次不受影响。` : null)
1387
+ })
1388
+ .catch(() => { if (!gone) setChatsNote('说过的场次没读出来') })
1032
1389
  return () => { gone = true }
1033
1390
  }, [view])
1034
1391
 
1392
+ // 开不了新会话的时候,把那句话留在界面上让用户自己复制(见 openInterviewSession)。
1393
+ // 这几个 hook 追加在最后:hook 的顺序就是测试里各屏 presets 的槽位,插在中间
1394
+ // 会把后面每一个槽都错开一格。
1395
+ const [handoff, setHandoff] = useState(null)
1396
+ const [chatsNote, setChatsNote] = useState(null)
1397
+ const startInterview = useCallback((opts) => {
1398
+ const started = openInterviewSession(opts === undefined || opts === null ? {} : opts)
1399
+ const settle = (result) => {
1400
+ const done = result === undefined || result === null ? { ok: false, prompt: '', reason: '没能开成新会话' } : result
1401
+ if (done.ok === true) {
1402
+ setHandoff(null)
1403
+ // 预设没被认下来时它自己会带一句 note,那话比我编的「摆好了」有用。
1404
+ flash(done.note !== undefined ? String(done.note) : '已经在新对话里开始问了', done.note === undefined ? 'ok' : 'warn')
1405
+ return
1406
+ }
1407
+ // 不静默:把「为什么没开成」和「该复制什么」一起摆出来。
1408
+ setHandoff(done)
1409
+ }
1410
+ // openInterviewSession 现在是异步的(要先建会话、再把第一句发出去),
1411
+ // 但同步的返回(老宿主那条退路)也要照旧能用。
1412
+ if (started !== undefined && started !== null && typeof started.then === 'function') {
1413
+ setBusy('interview')
1414
+ started.then((r) => { setBusy(''); settle(r) }).catch((e) => { setBusy(''); settle({ ok: false, prompt: '', reason: humanizeError(e) }) })
1415
+ return
1416
+ }
1417
+ settle(started)
1418
+ }, [flash])
1419
+
1035
1420
  /** 打开一本书,进到那一屏。 */
1036
1421
  const openBook = (book) => {
1037
1422
  setActiveBook({ id: book?.id ?? '', title: book?.title ?? '' })
@@ -1051,6 +1436,28 @@ function LifeCardTab(props) {
1051
1436
  } catch (e) { setError(humanizeError(e)) }
1052
1437
  }
1053
1438
 
1439
+ /**
1440
+ * 从书架上拿掉一整本书。
1441
+ *
1442
+ * `novel.delete` 后台一直都有,界面从来没接过——书写歪了、试写了一本不想留的,
1443
+ * 用户只能在文件管理器里翻目录,而界面上那本书永远挂在书架上。
1444
+ * 确认要说清「章也一起没」:这一下是连目录一起删,不是收起来。
1445
+ */
1446
+ const deleteBook = async (book) => {
1447
+ const title = String(book?.title ?? book?.id ?? '').trim()
1448
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1449
+ ? window.confirm(`把《${title}》这本书拿掉?\n\n已经写好的章也一起删,删了就真没了。\n只想先别看它的话,留着不动就行——书架上多一本不碍事。`)
1450
+ : true
1451
+ if (ok !== true) return
1452
+ try {
1453
+ const r = await call('novel.delete', { id: String(book?.id ?? '') })
1454
+ if (r?.ok !== true) { setError(r?.error ?? '这本书没能删掉'); return }
1455
+ const fresh = await call('novel.books', {})
1456
+ if (fresh?.ok === true && Array.isArray(fresh.books)) setBooks(fresh.books)
1457
+ flash(`拿掉了《${title}》`)
1458
+ } catch (e) { setError(humanizeError(e)) }
1459
+ }
1460
+
1054
1461
  const pickDoor = (next) => {
1055
1462
  setDoor(next)
1056
1463
  setError(null)
@@ -1065,20 +1472,61 @@ function LifeCardTab(props) {
1065
1472
  /**
1066
1473
  * 删一张卡。
1067
1474
  *
1068
- * 先问一句:删卡是不可逆的(后台只写墓碑,界面上收不回来)。
1069
- * 问的时候要说清「哪些东西会跟着没」——关系史、口癖这些都在卡里,
1070
- * 而材料是另一份文件,不会跟着删。
1475
+ * 先问一句,并且要说清「删了以后它去哪了」:不是烧掉,是从列表里撤下去,
1476
+ * 原文还留在磁盘上——首页下面「已经撤掉的」里能找回来,也能彻底删掉。
1477
+ * 以前这里写的是「界面上收不回来」,那句话现在是错的,别改回去。
1478
+ * 材料是另一份文件,不跟着删。
1071
1479
  */
1072
1480
  const deleteCard = async (card) => {
1073
1481
  const name = String(card?.name ?? '').trim() === '' ? '这张卡' : `「${card.name}」`
1074
1482
  const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1075
- ? window.confirm(`确定删掉${name}吗?\n\n卡里写的东西(关系史、口癖、能力…)一起删掉,界面上收不回来。\n材料是另一份文件,不受影响。`)
1483
+ ? window.confirm(`确定删掉${name}吗?\n\n删掉之后,列表和 AI 都看不见它了;想反悔,去下面「已经撤掉的」里点「放回来」。\n材料是另一份文件,不受影响。`)
1076
1484
  : true
1077
1485
  if (ok !== true) return
1078
1486
  try {
1079
1487
  const r = await call('card.delete', { path: card?.path, reason: '用户在列表里删掉' })
1080
1488
  if (r?.ok !== true) { setError(r?.error ?? '没删掉'); return }
1081
- flash(`删掉了${name}`, 'ok')
1489
+ flash(`删掉了${name}。要反悔就去下面「已经撤掉的」里点「放回来」`, 'ok')
1490
+ await refresh()
1491
+ } catch (e) { setError(humanizeError(e)) }
1492
+ }
1493
+
1494
+ /** 撤掉的那张卡的称呼:卡上没名字就按文件名给一个,界面上不摆路径。 */
1495
+ const withdrawnName = (item) => (String(item?.name ?? '').trim() === '' ? cardNameFromPath(item?.path) : String(item.name))
1496
+
1497
+ /**
1498
+ * 把一张撤掉的卡放回来。
1499
+ *
1500
+ * 原文一直在磁盘上,所以这一步不发「重建」,只是让它重新出现在列表里。
1501
+ * 不弹确认:这是往回走的那一步,点错了再删一次就行。
1502
+ */
1503
+ const restoreCard = async (card) => {
1504
+ if (card?.path === undefined) return
1505
+ try {
1506
+ const r = await call('card.restore', { path: card.path })
1507
+ if (r?.ok !== true) { setError(r?.error ?? '没能放回来'); return }
1508
+ flash(`「${withdrawnName(card)}」放回来了`, 'ok')
1509
+ await refresh()
1510
+ } catch (e) { setError(humanizeError(e)) }
1511
+ }
1512
+
1513
+ /**
1514
+ * 彻底删掉一张撤掉的卡:原文一起删,删了没法反悔。
1515
+ *
1516
+ * 和「删掉」是两件不同的事,所以文案不能只写「确定删除」——
1517
+ * 用户得知道这一次是连磁盘上的原文都没了。
1518
+ */
1519
+ const purgeCard = async (card) => {
1520
+ if (card?.path === undefined) return
1521
+ const name = `「${withdrawnName(card)}」`
1522
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1523
+ ? window.confirm(`确定把${name}彻底删掉吗?\n\n磁盘上的原文一起删,删了就真没了。\n(只是想让它先别出现?点「放回来」就行,不用删。)`)
1524
+ : true
1525
+ if (ok !== true) return
1526
+ try {
1527
+ const r = await call('card.purge', { path: card.path })
1528
+ if (r?.ok !== true) { setError(r?.error ?? '没删掉'); return }
1529
+ flash(`彻底删掉了${name}`, 'ok')
1082
1530
  await refresh()
1083
1531
  } catch (e) { setError(humanizeError(e)) }
1084
1532
  }
@@ -1239,7 +1687,7 @@ function LifeCardTab(props) {
1239
1687
  })
1240
1688
  }
1241
1689
  // 门还没选:先问「你要用哪个」。选完才进首页,首页再按门决定露出什么。
1242
- if (view === VIEWS.doors) return h(DoorsView, { state, features, onPick: pickDoor })
1690
+ if (view === VIEWS.doors) return h(DoorsView, { state, features, hidden: hiddenDoors, onPick: pickDoor, onHide: hideDoor, onShow: showDoor })
1243
1691
  if (view === VIEWS.tavernChat) {
1244
1692
  return h(TavernView, {
1245
1693
  chat,
@@ -1273,8 +1721,12 @@ function LifeCardTab(props) {
1273
1721
  state, listing, preset: interviewFor, onRecorded: refresh, flash, mode,
1274
1722
  onDone: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home); refresh() },
1275
1723
  onAnalyze: (about) => {
1276
- const list = Array.isArray(about?.materials) ? about.materials.filter((x) => typeof x === 'string' && x !== '') : []
1277
- setMaterialFor(list.length > 0 ? list : null)
1724
+ // 这一场一路记下来的材料。空清单要照着「一份不读」传下去:
1725
+ // 折成 null 就是「全读」,用户刚聊完一个虚构角色,一点「开始读」
1726
+ // 就把别人的材料一起读了。null 只留给「没指定」——那时候才全读。
1727
+ const raw = about?.materials
1728
+ const list = Array.isArray(raw) ? raw.filter((x) => typeof x === 'string' && x !== '') : null
1729
+ setMaterialFor(list)
1278
1730
  setInterviewFor(about ?? null)
1279
1731
  setView(VIEWS.analyze)
1280
1732
  },
@@ -1284,6 +1736,8 @@ function LifeCardTab(props) {
1284
1736
  // about 是个字符串,这个人还没建卡也能分析——分析结果会进提案,
1285
1737
  // 采纳时才建卡。
1286
1738
  return h(MemoryView, {
1739
+ mode,
1740
+ onStartInterview: startInterview,
1287
1741
  onBack: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home) },
1288
1742
  onDone: (about) => {
1289
1743
  // 只认那份刚写出来的材料。不带 path 的话分析页不勾任何材料,
@@ -1314,7 +1768,7 @@ function LifeCardTab(props) {
1314
1768
  // 直接退回首页,用户点了没反应,还以为坏了。现在把清单单独摊开。
1315
1769
  return activeCard === null
1316
1770
  ? proposal === null
1317
- ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
1771
+ ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1318
1772
  : h('div', { className: 'lc-pad lc-stack' },
1319
1773
  proposal.about === undefined || String(proposal.about).trim() === ''
1320
1774
  ? null
@@ -1355,9 +1809,10 @@ function LifeCardTab(props) {
1355
1809
  } catch (e) { setError(humanizeError(e)) }
1356
1810
  },
1357
1811
  onDeleted: async () => { setActiveCard(null); setView(VIEWS.home); await refresh() },
1358
- onInterview: (preset) => { setInterviewFor(preset); setView(VIEWS.interview) },
1812
+ // 补卡不再进插件里的访谈页,改成开一个新会话(见 openInterviewSession)。
1813
+ mode,
1814
+ onStartInterview: startInterview,
1359
1815
  onAnalyze: () => { setInterviewFor({ id: activeCard.data?.id, name: activeCard.data?.name }); setView(VIEWS.analyze) },
1360
- onTavern: mode === 'tavern' ? (preset) => startTavern(preset) : undefined,
1361
1816
  })
1362
1817
  case VIEWS.newCard:
1363
1818
  return h(NewCardView, {
@@ -1375,7 +1830,7 @@ function LifeCardTab(props) {
1375
1830
  })
1376
1831
  case VIEWS.world:
1377
1832
  return activeWorld === null
1378
- ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
1833
+ ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1379
1834
  : h(WorldView, {
1380
1835
  world: activeWorld,
1381
1836
  listing,
@@ -1400,7 +1855,7 @@ function LifeCardTab(props) {
1400
1855
  case VIEWS.jobs:
1401
1856
  return h(JobsView, { onBack: () => setView(VIEWS.home), flash })
1402
1857
  default:
1403
- return h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook })
1858
+ return h(HomeView, { state, listing, mode, onStartInterview: startInterview, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1404
1859
  }
1405
1860
  }
1406
1861
 
@@ -1415,6 +1870,31 @@ function LifeCardTab(props) {
1415
1870
  h('div', { style: { whiteSpace: 'pre-wrap' } }, humanizeError(error)),
1416
1871
  h('div', { style: { marginTop: 6 } }, h(Btn, { size: 'sm', onClick: () => setError(null) }, '知道了'))))
1417
1872
  : null,
1873
+ // 开不了新会话时(老版本宿主)退化成这样:话摆在这儿,用户自己复制过去。
1874
+ // 不静默失败——点了没反应,比说清「这一步要你手动搬一下」更让人困惑。
1875
+ handoff === null || handoff.ok === true ? null : h('div', { style: { padding: '10px 12px 0' }, 'data-interview-handoff': '1' },
1876
+ h(Note, { tone: 'warn', icon: 'warning' },
1877
+ h('div', null, '这个版本不支持直接开会话,把下面这句复制到新对话里:'),
1878
+ h('textarea', {
1879
+ readOnly: true,
1880
+ rows: 3,
1881
+ spellCheck: false,
1882
+ className: 'lc-input',
1883
+ value: String(handoff.prompt ?? ''),
1884
+ style: { marginTop: 8, width: '100%', resize: 'vertical', boxSizing: 'border-box' },
1885
+ onFocus: (e) => {
1886
+ try { e?.target?.select?.() } catch (err) { /* 选不中也还能手动复制 */ }
1887
+ },
1888
+ }),
1889
+ h('div', { className: 'lc-row', style: { marginTop: 8 } },
1890
+ h(Btn, {
1891
+ size: 'sm',
1892
+ icon: 'check',
1893
+ onClick: () => {
1894
+ try { globalThis?.navigator?.clipboard?.writeText?.(String(handoff.prompt ?? '')) } catch (err) { /* 复制不了就手动选 */ }
1895
+ },
1896
+ }, '复制'),
1897
+ h(Btn, { size: 'sm', onClick: () => setHandoff(null) }, '知道了')))),
1418
1898
  body(),
1419
1899
  ),
1420
1900
  )
@@ -1497,19 +1977,22 @@ const DOORS = [
1497
1977
  id: 'real', icon: 'people', tone: 'interview',
1498
1978
  title: '真实人物记录',
1499
1979
  desc: '身边的人:他做过什么、怎么说话、你们之间发生过什么。',
1500
- bullets: ['聊着建,把他说的话记下来', '贴材料,让 AI 读出能核实的内容', '找工作:贴招聘说明、练面试'],
1980
+ bullets: ['聊一聊,它会问你几个具体的问题', '贴材料,让 AI 读出能核实的内容', '找工作:贴招聘说明、练面试'],
1981
+ modules: ['人物卡', '访谈记录', '材料与建议', '简历与规划'],
1501
1982
  },
1502
1983
  {
1503
1984
  id: 'novel', icon: 'book', tone: 'import',
1504
1985
  title: '写小说',
1505
1986
  desc: '虚构的角色和世界:先把人立起来,再一章一章往下写。',
1506
- bullets: ['立角色:性格、口癖、绝不会做的事', '写世界:地方、规矩、里面还有谁'],
1987
+ bullets: ['立角色:性格、口癖、绝不会做的事', '写世界:地方、规矩、里面还有谁', '一章一章往下写,能导出整本'],
1988
+ modules: ['角色卡', '世界书', '书架与章节', '文字模拟游戏', '写作预设'],
1507
1989
  },
1508
1990
  {
1509
1991
  id: 'tavern', icon: 'chat', tone: 'analyze',
1510
1992
  title: '酒馆',
1511
1993
  desc: '拿一张角色卡,和 TA 你一句一句地演。',
1512
- bullets: ['挑一张角色卡就开演', '拿现实里的人来演也行(复制一份,原卡不动)'],
1994
+ bullets: ['挑一张角色卡就开演', '拿现实里的人来演也行(复制一份,原卡不动)', '演到一半能收个尾,把这段备忘接着用'],
1995
+ modules: ['角色卡', '会话存档', '演法与语气预设'],
1513
1996
  },
1514
1997
  ]
1515
1998
 
@@ -1524,12 +2007,16 @@ const DOORS = [
1524
2007
  * 顶上一条门楣色块、中间竖着写门名、底部一道门槛写着「推门进去」。
1525
2008
  * 三扇并排、各占三分之一宽、高度撑满;窄窗口自动换行。
1526
2009
  */
1527
- function DoorsView({ onPick, state, features }) {
2010
+ function DoorsView({ onPick, state, features, hidden, onHide, onShow }) {
1528
2011
  const workspace = String(state?.workspace ?? '')
1529
2012
  // 没装的门不摆出来。`features === null` 时全摆(还没问到,别闪一下少一扇)。
1530
- const doors = (features === null || features === undefined)
2013
+ const installed = (features === null || features === undefined)
1531
2014
  ? DOORS
1532
2015
  : DOORS.filter((d) => (d.id === 'real' ? true : d.id === 'novel' ? features.novel !== false : features.tavern !== false))
2016
+ // 用户自己收起来的门:不摆出来,改摆一块灰黑的死门(悬停能装回来)。
2017
+ const gone = Array.isArray(hidden) ? hidden : []
2018
+ const doors = installed.filter((d) => !gone.includes(d.id))
2019
+ const deadDoors = installed.filter((d) => gone.includes(d.id))
1533
2020
  const tint = {
1534
2021
  real: {
1535
2022
  fg: 'var(--lc-interview)', bg: 'var(--lc-interview-soft)', icon: 'people',
@@ -1641,14 +2128,57 @@ function DoorsView({ onPick, state, features }) {
1641
2128
  background: t.fg, opacity: .55,
1642
2129
  },
1643
2130
  }),
2131
+ // 门板与门缝:一块纯色方块看起来像色卡,加了这两层才像门。
2132
+ h('span', { className: 'lc-door-panel', 'aria-hidden': 'true' }),
2133
+ h('span', { className: 'lc-door-hinge', 'aria-hidden': 'true' }),
2134
+ h('span', { className: 'lc-door-jamb', 'aria-hidden': 'true' }),
2135
+ // ── 删掉这扇门:鼠标放上来才露出来(免得误点)──
2136
+ h('button', {
2137
+ type: 'button',
2138
+ className: 'lc-door-x',
2139
+ title: `把「${door.title}」这扇门收起来`,
2140
+ 'data-door-hide': door.id,
2141
+ onClick: (e) => {
2142
+ e?.stopPropagation?.()
2143
+ onHide?.(door.id)
2144
+ },
2145
+ // 叉容易看成「关闭」,用垃圾桶才一眼知道是「删掉/收起来」。
2146
+ }, h(Icon, { name: 'trash', size: 13 })),
1644
2147
  )
1645
2148
  }),
2149
+ // ── 收起来的门:一块灰黑的死门,鼠标放上去露出装回来的按钮 ──
2150
+ deadDoors.map((door) => h('div', {
2151
+ key: `dead-${door.id}`,
2152
+ className: 'lc-door-dead',
2153
+ 'data-door-dead': door.id,
2154
+ },
2155
+ h('div', { className: 'lc-door-dead-icon' }, h(Icon, { name: (tint[door.id] ?? tint.real).icon, size: 34 })),
2156
+ h('div', { className: 'lc-door-dead-name' }, door.title),
2157
+ h('div', {
2158
+ className: 'lc-door-back',
2159
+ },
2160
+ h('button', {
2161
+ type: 'button',
2162
+ className: 'lc-door-back-btn',
2163
+ title: `把「${door.title}」装回来`,
2164
+ 'data-door-show': door.id,
2165
+ onClick: () => onShow?.(door.id),
2166
+ }, h(Icon, { name: 'download', size: 26 })),
2167
+ h('div', { style: { fontSize: 13.5, fontWeight: 600 } }, '装回来'),
2168
+ // 分模块列清楚:装回来只是把门重新露出来,里面的东西一样不少。
2169
+ (door.modules ?? []).length === 0 ? null : h('div', {
2170
+ className: 'lc-door-dead-mods',
2171
+ style: { fontSize: 11.5, color: '#cfcfcf', textAlign: 'center', padding: '0 10px', lineHeight: 1.6 },
2172
+ }, (door.modules ?? []).join(' · ')),
2173
+ ),
2174
+ )),
1646
2175
  ),
1647
- workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } }, '档案就在你选的那个文件夹里'),
2176
+ workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } },
2177
+ '档案就在你选的那个文件夹里。想让它开口说话,聊天前先在顶部把预设切成「LC 酒馆 / LC 小说 / LC 现实」——那张卡接在预设后面,不切预设带不进去。'),
1648
2178
  )
1649
2179
  }
1650
2180
 
1651
- function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onProposal, busy, onDoDoctor, showMore, onMore, intro, onIntroDone, onMaterial, onDeleteMaterial, chats, onOpenChat, onForkCard, onDeleteCard, onEditCard, books, onOpenBook, onCreateBook, pinId, onPickPin }) {
2181
+ function HomeView({ state, listing, mode, onStartInterview, onOpen, onOpenWorld, onNavigate, onProposal, busy, onDoDoctor, showMore, onMore, intro, onIntroDone, onMaterial, onDeleteMaterial, chats, onOpenChat, onForkCard, onDeleteCard, onRestoreCard, onPurgeCard, onEditCard, books, onOpenBook, onCreateBook, onDeleteBook, chatsNote, pinId, onPickPin }) {
1652
2182
  // 这扇门是不是「真实人物记录」。写小说、酒馆那两扇门里不该出现
1653
2183
  // 「贴一份招聘说明」「从记忆里认人」这类动作——那是记录真人才用得上的。
1654
2184
  const isReal = mode !== 'novel' && mode !== 'tavern'
@@ -1657,6 +2187,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1657
2187
  const fictionActionTone = mode === 'tavern' ? 'analyze' : 'import'
1658
2188
  const [q, setQ] = useState('')
1659
2189
  const cards = listing?.cards ?? []
2190
+ // 「已经撤掉的」:删过的卡还留在磁盘上,列表接口单独把它们带回来。
2191
+ // 没有这一栏的时候,删掉的卡在界面上就彻底消失了——想反悔没入口,
2192
+ // 想清理也找不到那条路,用户只能去翻文件夹。
2193
+ const withdrawn = Array.isArray(listing?.withdrawn) ? listing.withdrawn : []
1660
2194
  const filtered = useMemo(() => {
1661
2195
  const needle = q.trim().toLowerCase()
1662
2196
  if (needle === '') return cards
@@ -1677,7 +2211,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1677
2211
  const isFiction = hit !== undefined && hit.kind === 'fictional'
1678
2212
  return isFiction === (mode !== 'real')
1679
2213
  })
1680
- const materials = listing?.materials ?? []
2214
+ // 备份文件和临时文件不是材料:存材料时是先写临时文件再改名,改名那一步
2215
+ // 被打断就会留下 `.妈妈.md.bak-1234`。它一直被当成一份材料摆在列表里,
2216
+ // 用户看到两份「妈妈」、点开其中一份是空的,还以为自己写丢了。
2217
+ const materials = (listing?.materials ?? []).filter(isRealMaterial)
1681
2218
  // 搜索也要筛材料:搜一个人的名字,上面卡筛掉了、下面材料还整整齐齐列着,
1682
2219
  // 看着像「搜到了这一份」,其实根本没筛。
1683
2220
  const shownMaterials = useMemo(() => {
@@ -1699,16 +2236,43 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1699
2236
  return allWorlds.filter((w) => `${w.name ?? ''} ${w.id ?? ''} ${w.genre ?? ''}`.toLowerCase().includes(needle))
1700
2237
  }, [allWorlds, q])
1701
2238
  const byKind = useMemo(() => {
2239
+
1702
2240
  const real = filtered.filter((c) => c.kind === 'real' || c.kind === 'self' || c.kind === 'hybrid')
1703
2241
  const fic = filtered.filter((c) => c.kind === 'fictional')
1704
2242
  const other = filtered.filter((c) => !['real', 'self', 'hybrid', 'fictional'].includes(c.kind))
1705
2243
  return { real, fic, other }
1706
2244
  }, [filtered])
2245
+
2246
+ // 右上角圆点:绿 = 这扇门现在用它,红 = 不用。再点一次绿的就取消。
2247
+ // 写成普通函数(不是 hook),这样不动 hook 槽位。
2248
+ const togglePin = (card) => {
2249
+ const id = String(card?.id ?? '')
2250
+ if (id === '') return
2251
+ onPickPin?.(String(pinId ?? '') === id ? '' : id)
2252
+ }
1707
2253
  // 酒馆那扇门里,现实里的人默认收起来:一进去先看见父母、同学、同事的一排卡,
1708
2254
  // 会让人不太舒服,也分不清哪些是拿来演的。想看的时候再展开。
1709
2255
  const [showRealForRole, setShowRealForRole] = useState(false)
1710
2256
  // 正在问「要不要复制一份来演」的那张卡
1711
2257
  const [forkAsk, setForkAsk] = useState(null)
2258
+ // 「已经撤掉的」默认收起来:它不该跟正常的卡抢位置,但入口必须看得见。
2259
+ const [showWithdrawn, setShowWithdrawn] = useState(false)
2260
+ // 搜索也要筛这一栏。只筛上面的卡、下面还整整齐齐列着撤掉的卡,
2261
+ // 看着像「搜到了」,其实没筛——上面材料那栏踩过同一个坑。
2262
+ const shownWithdrawn = useMemo(() => {
2263
+ const needle = q.trim().toLowerCase()
2264
+ if (needle === '') return withdrawn
2265
+ return withdrawn.filter((w) => `${w.name ?? ''} ${w.id ?? ''}`.toLowerCase().includes(needle))
2266
+ }, [withdrawn, q])
2267
+ const withdrawnBlock = shownWithdrawn.length === 0
2268
+ ? null
2269
+ : h(WithdrawnSection, {
2270
+ items: shownWithdrawn,
2271
+ open: showWithdrawn,
2272
+ onToggle: () => setShowWithdrawn(!showWithdrawn),
2273
+ onRestore: onRestoreCard,
2274
+ onPurge: onPurgeCard,
2275
+ })
1712
2276
 
1713
2277
  // 第一次进来时那段介绍。只出现一次,点过「知道了」就不再出现。
1714
2278
  // 刻意只有四五行:介绍写长了没人读,读的人也只想知道「这玩意儿干吗的、从哪儿下手」。
@@ -1733,7 +2297,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1733
2297
  // 「还没有档案」这句只在真的什么都没有时说。以前只看卡和世界书,
1734
2298
  // 于是刚把一段文字存成材料、还没建卡的人回首页会看到一片空白,
1735
2299
  // 以为刚才没存上,又贴一遍——材料就多出一份重复的。
1736
- if (cards.length === 0 && allWorlds.length === 0 && materials.length === 0 && proposals.length === 0) {
2300
+ if (cards.length === 0 && withdrawn.length === 0 && allWorlds.length === 0 && materials.length === 0 && proposals.length === 0) {
1737
2301
  // 同一个空库,三扇门该给三条不同的路:写小说的人不需要「访谈」,
1738
2302
  // 记录真人的人也不需要「先写一章」。
1739
2303
  return h('div', { className: 'lc-pad lc-stack' },
@@ -1743,17 +2307,19 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1743
2307
  h('h3', null, isReal ? '还没有档案' : '还什么都没有'),
1744
2308
  h('div', { className: 'lc-meta' }, '选一个开始的方式,随时可以换别的:'),
1745
2309
  ),
1746
- // 三扇门第一块都给「聊着建」:那是这个插件最好上手的入口。
1747
- // 差别只在说什么话——建真人问的是「他是我的什么人」,
1748
- // 建角色问的是「TA 一张嘴什么感觉」。
2310
+ // 三扇门第一块都是「聊一聊」:那是这个插件最好上手的入口。
2311
+ //
2312
+ // 点了之后开的不是插件里的访谈页,而是一个新会话——问法那一套东西
2313
+ // 在 /lifecard-interview 那个 skill 里,只有一份;这边再演一遍,
2314
+ // 两边早晚会不是同一个东西。
1749
2315
  h(Action, {
1750
2316
  tone: fictionActionTone,
1751
2317
  icon: 'chat',
1752
- title: isReal ? '陪我聊聊,边聊边建' : (mode === 'tavern' ? '聊着立一个能演的角色' : '聊着立一个小说角色'),
2318
+ title: '聊一聊(新开一个对话)',
1753
2319
  desc: isReal
1754
- ? '它会问几个具体的问题。答不上来就跳过,一句也不想说也行。'
1755
- : '先问 TA 怎么说话、什么情况下会变脸,比填空白表快。',
1756
- onClick: () => onNavigate(VIEWS.interview),
2320
+ ? '会在新对话里问,答完 AI 自己写进卡里。答不上来就跳过,一句也不想说也行。'
2321
+ : '会在新对话里问,答完 AI 自己写进卡里。先问 TA 怎么说话、什么情况下会变脸,比填空白表快。',
2322
+ onClick: () => onStartInterview({ about: '', mode }),
1757
2323
  }),
1758
2324
  h(Action, {
1759
2325
  tone: 'import', icon: 'import',
@@ -1777,6 +2343,17 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1777
2343
  : '小说片段、人物小传、你写的设定都行。读出来的东西先给你看,你点了才写进卡。',
1778
2344
  onClick: () => onNavigate(VIEWS.import),
1779
2345
  }),
2346
+ // 空库的时候也有话要说:说过的场次读不出来、有文件读不了,
2347
+ // 这些跟「有没有卡」无关,不能因为还没建档就当没这回事。
2348
+ mode === 'tavern' && String(chatsNote ?? '').trim() !== ''
2349
+ ? h(Note, { tone: 'warn', icon: 'warning' }, String(chatsNote))
2350
+ : null,
2351
+ (listing?.errors ?? []).length > 0
2352
+ ? h(Note, { tone: 'warn', icon: 'warning' },
2353
+ `有 ${listing.errors.length} 个文件读不了${unreadableNames(listing.errors) === '' ? '' : `(${unreadableNames(listing.errors)})`},没影响别的。`)
2354
+ : null,
2355
+ // 卡全删光的时候这一屏尤其重要:不给这一段,「还没有档案」就是死结。
2356
+ withdrawnBlock,
1780
2357
  )
1781
2358
  }
1782
2359
 
@@ -1788,7 +2365,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1788
2365
  ),
1789
2366
 
1790
2367
  h('div', { className: 'lc-row', style: { marginTop: 2 } },
1791
- h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onNavigate(VIEWS.interview) }, isReal ? '聊着建' : '聊着立一个人'),
2368
+ h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
1792
2369
  h(Btn, { tone: 'import', size: 'sm', icon: 'import', onClick: () => onNavigate(VIEWS.import) }, '导入'),
1793
2370
  isReal
1794
2371
  ? h(Btn, { tone: 'analyze', size: 'sm', icon: 'person', onClick: () => onNavigate(VIEWS.memory), title: '从你写过的记忆里认出身边的人' }, '从记忆里认人')
@@ -1806,6 +2383,8 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1806
2383
  ? h(Btn, { tone: 'analyze', size: 'sm', icon: 'spark', onClick: () => onNavigate(VIEWS.analyze) }, isReal ? `整理 ${materials.length} 份材料` : `读那 ${materials.length} 段材料`)
1807
2384
  : null,
1808
2385
  ),
2386
+ // 按钮上一句「新开一个对话」,总会有人以为点完还在这里问。
2387
+ h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里'),
1809
2388
 
1810
2389
  // 一眼看到「这里有多少东西」:以前首页只有标题和一排按钮,一大片空。
1811
2390
  // 数字本身就是内容,也让人知道还有多少没用起来。
@@ -1845,15 +2424,18 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1845
2424
  (books ?? []).length === 0
1846
2425
  ? h('div', { className: 'lc-meta', style: { lineHeight: 1.7 } },
1847
2426
  '还没有书。新建一本,让 AI 先想大纲,再一章一章写。')
1848
- : h('div', { className: 'lc-stack' }, (books ?? []).map((b) => h('button', {
2427
+ : h('div', { className: 'lc-stack' }, (books ?? []).map((b) => h('div', {
1849
2428
  key: b.id,
1850
2429
  className: 'lc-card-item',
1851
- type: 'button',
1852
- onClick: () => onOpenBook?.(b),
1853
- style: { textAlign: 'left', font: 'inherit', color: 'inherit', width: '100%' },
2430
+ style: { cursor: 'default' },
1854
2431
  },
1855
2432
  h('div', { className: 'lc-avatar', style: { background: 'var(--lc-import-soft)', color: 'var(--lc-import)' } }, h(Icon, { name: 'book', size: 14 })),
1856
- h('div', { className: 'lc-grow', style: { minWidth: 0 } },
2433
+ h('button', {
2434
+ className: 'lc-btn ghost',
2435
+ type: 'button',
2436
+ onClick: () => onOpenBook?.(b),
2437
+ style: { flex: 1, minWidth: 0, textAlign: 'left', font: 'inherit', color: 'inherit', background: 'transparent', border: 'none', padding: 0, cursor: 'pointer' },
2438
+ },
1857
2439
  h('div', { className: 'lc-ellipsis', style: { fontWeight: 650 } }, String(b.title ?? b.id)),
1858
2440
  h('div', { className: 'lc-meta' },
1859
2441
  [`${b.chapters ?? 0} 章`, `${Math.max(1, Math.round((b.words ?? 0) / 1000))} 千字`]
@@ -1861,6 +2443,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1861
2443
  .join(' · ')),
1862
2444
  String(b.idea ?? '').trim() === '' ? null : h('div', { className: 'lc-meta lc-ellipsis' }, String(b.idea)),
1863
2445
  ),
2446
+ // 书写歪了、试写一本不想留的:以前界面里没有任何出口,书永远挂在书架上。
2447
+ onDeleteBook === undefined
2448
+ ? null
2449
+ : h(Btn, { size: 'sm', ghost: true, icon: 'trash', onClick: () => onDeleteBook(b), title: `不要《${String(b.title ?? b.id)}》了` }, '不要这本了'),
1864
2450
  ))),
1865
2451
  h('div', { className: 'lc-row', style: { marginTop: 8 } },
1866
2452
  h(Btn, { size: 'sm', tone: 'import', icon: 'plus', onClick: () => onCreateBook?.() }, '新建一本书'),
@@ -1895,7 +2481,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1895
2481
  ? (isReal
1896
2482
  ? h('div', null,
1897
2483
  h(GroupTitle, { icon: 'people' }, `认识的人 · ${byKind.real.length}`),
1898
- h('div', { className: 'lc-stack' }, byKind.real.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
2484
+ h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 10, alignItems: 'stretch' } }, byKind.real.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard, pinned: String(pinId ?? '') === String(c.id ?? ''), onTogglePin: togglePin }))),
1899
2485
  )
1900
2486
  // 同一个文件夹里可能两样都有。这扇门不直接铺开真人,但也不能装作没有——
1901
2487
  // 用户会以为卡丢了。收起来一行,想看再展开,展开后是「复制一份来演」。
@@ -1927,28 +2513,21 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1927
2513
  ))
1928
2514
  : null,
1929
2515
 
1930
- // 「现在用哪张」:写小说、酒馆那两扇门里演谁 / 写谁不用每次现挑;
1931
- // 真实人物那扇门用它决定首页先给谁。存在这个文件夹的 config.json 里。
2516
+ // 「这扇门用哪张卡」:不再用下拉框挑,而是每张卡右上角一个圆点——
2517
+ // 绿色 = 这扇门用它,红色 = 不用。再点一下绿的就取消(等于「不挑卡」)。
2518
+ // 存在这个文件夹的 config.json 里。
1932
2519
  (() => {
1933
2520
  const pool = isReal ? byKind.real : byKind.fic
1934
2521
  if (pool.length === 0) return null
1935
- const label = isReal ? '这扇门先看谁' : (mode === 'tavern' ? '现在演谁' : '现在写谁')
1936
2522
  const chosen = String(pinId ?? '')
1937
2523
  const hit = chosen === '' ? undefined : pool.find((c) => String(c.id ?? '') === chosen)
1938
- // 空着也是一档:不挑卡。用户按一下下拉里的第一项就能取消选择,
1939
- // 之后写小说 / 演都从零开始,不读卡上的设定。
2524
+ const label = isReal ? '这扇门先看谁' : (mode === 'tavern' ? '现在演谁' : '现在写谁')
1940
2525
  return h('div', null,
1941
- h('div', { className: 'lc-row', style: { marginTop: 10, marginBottom: 2, gap: 8 } },
1942
- h('span', { className: 'lc-meta', style: { flexShrink: 0 } }, label),
1943
- h('select', {
1944
- className: 'lc-select',
1945
- value: chosen,
1946
- onChange: (e) => onPickPin?.(String(e?.target?.value ?? '')),
1947
- },
1948
- h('option', { value: '' }, '不挑卡(从零开始)'),
1949
- pool.map((c) => h('option', { key: c.path, value: String(c.id ?? '') }, String(c.name ?? '(还没起名字)'))),
1950
- ),
1951
- hit === undefined ? null : h('span', { className: 'lc-meta' }, '说「演他」「写他」就默认用这张'),
2526
+ h('div', { className: 'lc-row', style: { marginTop: 10, marginBottom: 2, gap: 8, flexWrap: 'wrap' } },
2527
+ h('span', { className: 'lc-meta', style: { flexShrink: 0 } }, `${label}:`),
2528
+ hit === undefined
2529
+ ? h('span', { className: 'lc-meta' }, '点卡右上角的圆点挑一张(绿 = 用它,红 = 不用)')
2530
+ : h('span', { className: 'lc-meta' }, `现在是「${String(hit.name ?? '')}」,点那个绿点可以取消`),
1952
2531
  ),
1953
2532
  chosen !== '' ? null : h('div', { className: 'lc-meta', style: { marginTop: 2 } },
1954
2533
  isReal
@@ -1962,17 +2541,19 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1962
2541
  byKind.fic.length > 0
1963
2542
  ? h('div', null,
1964
2543
  h(GroupTitle, { tone: 'interview', icon: 'book' }, `${isReal ? '虚构角色' : (mode === 'tavern' ? '可以拿来演的角色' : '角色')} · ${byKind.fic.length}`),
1965
- h('div', { className: 'lc-stack' }, byKind.fic.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
2544
+ h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 10, alignItems: 'stretch' } }, byKind.fic.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard, pinned: String(pinId ?? '') === String(c.id ?? ''), onTogglePin: togglePin }))),
1966
2545
  )
1967
2546
  : null,
1968
2547
 
1969
2548
  byKind.other.length > 0
1970
2549
  ? h('div', null,
1971
2550
  h(GroupTitle, { tone: 'analyze', icon: 'list' }, `其他 · ${byKind.other.length}`),
1972
- h('div', { className: 'lc-stack' }, byKind.other.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard }))),
2551
+ h('div', { className: 'lc-stack' }, byKind.other.map((c) => h(CardRow, { key: c.path, card: c, onOpen, photo: avatars[c.id], onDelete: onDeleteCard, onEdit: onEditCard, pinned: String(pinId ?? '') === String(c.id ?? ''), onTogglePin: togglePin }))),
1973
2552
  )
1974
2553
  : null,
1975
2554
 
2555
+ withdrawnBlock,
2556
+
1976
2557
  // 材料单独一栏。以前材料只在「更多工具」里报个数字,用户从记忆里提出来
1977
2558
  // 一堆东西之后回首页找不到——不知道存哪了,也没法看、没法删。
1978
2559
  !isReal || shownMaterials.length === 0
@@ -1993,7 +2574,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1993
2574
  ))),
1994
2575
  ),
1995
2576
 
1996
- q.trim() !== '' && filtered.length === 0 && worlds.length === 0 && shownMaterials.length === 0
2577
+ q.trim() !== '' && filtered.length === 0 && worlds.length === 0 && shownMaterials.length === 0 && shownWithdrawn.length === 0
1997
2578
  ? h('div', { className: 'lc-meta', style: { textAlign: 'center', padding: 12 } }, '没找到。换个词试试?')
1998
2579
  : null,
1999
2580
 
@@ -2023,7 +2604,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2023
2604
  h('div', { className: 'lc-meta' },
2024
2605
  `${p.accepted} 条可以采用`,
2025
2606
  (p.adopted ?? 0) > 0 ? ` · 已经写进去 ${p.adopted} 条` : '',
2026
- p.rejected > 0 ? ` · ${p.rejected} 条没能核实,已丢掉` : '',
2607
+ rejectedWords(p) === '' ? '' : ` · ${rejectedWords(p)}`,
2027
2608
  ' · ', shortDate(p.generated_at)),
2028
2609
  ),
2029
2610
  ))),
@@ -2036,7 +2617,13 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2036
2617
  : null,
2037
2618
 
2038
2619
  (listing?.errors ?? []).length > 0
2039
- ? h(Note, { tone: 'warn', icon: 'warning' }, `有 ${listing.errors.length} 个文件读不了,没影响别的。`)
2620
+ ? h(Note, { tone: 'warn', icon: 'warning' },
2621
+ `有 ${listing.errors.length} 个文件读不了${unreadableNames(listing.errors) === '' ? '' : `(${unreadableNames(listing.errors)})`},没影响别的。`)
2622
+ : null,
2623
+
2624
+ // 说过的场次里读不出来的那几场,得说出来:它们以前是安静消失的。
2625
+ mode === 'tavern' && String(chatsNote ?? '').trim() !== ''
2626
+ ? h(Note, { tone: 'warn', icon: 'warning' }, String(chatsNote))
2040
2627
  : null,
2041
2628
 
2042
2629
  // ── 收起来的「更多」──
@@ -2068,60 +2655,195 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2068
2655
  )
2069
2656
  }
2070
2657
 
2071
- function CardRow({ card, onOpen, photo, onDelete, onEdit }) {
2072
- // 整行是一个 button(点哪儿都能打开)。要再塞一个「删」进去,就不能
2073
- // 在 button 里放 button——浏览器会把它们当兄弟节点拆开,React 也会警告。
2074
- // 所以行改成 div,左边一块可点区域负责打开,右边单独一个真 button 负责删。
2075
- return h('div', { className: 'lc-card-item', style: { display: 'flex', alignItems: 'center', gap: 8, cursor: 'default' } },
2658
+ /**
2659
+ * 「已经撤掉的」这一块。
2660
+ *
2661
+ * 删过的卡并没有从磁盘上消失,只是不再出现在列表、导出和 AI 眼里。
2662
+ * 以前界面上完全没有这一栏,于是两种情况都没路走:
2663
+ * 删错了想找回来,找不到;想彻底清掉,也找不到。
2664
+ *
2665
+ * 这里把三条路一次摆出来:
2666
+ * - 看得见:标题里带张数,展开就是一条一行;
2667
+ * - 放回来:重新回到上面的列表,什么都不用重写;
2668
+ * - 彻底删掉:连磁盘上的原文一起删,删了就真没了,所以要点一次确认。
2669
+ *
2670
+ * 文案只说人话:不写路径、不写文件后缀、不写接口名。
2671
+ */
2672
+ function WithdrawnSection({ items, open, onToggle, onRestore, onPurge }) {
2673
+ const rows = Array.isArray(items) ? items : []
2674
+ if (rows.length === 0) return null
2675
+ return h('div', { 'data-withdrawn-section': '' },
2076
2676
  h('button', {
2677
+ className: 'lc-btn ghost sm',
2678
+ type: 'button',
2679
+ 'data-withdrawn-toggle': '',
2680
+ 'aria-expanded': open === true,
2681
+ onClick: onToggle,
2682
+ style: { width: '100%', justifyContent: 'flex-start' },
2683
+ },
2684
+ h('span', { style: { display: 'inline-flex', transform: open === true ? 'rotate(90deg)' : 'none', transition: 'transform .12s' } }, h(Icon, { name: 'chevron', size: 12 })),
2685
+ h('span', null, `已经撤掉的 · ${rows.length}`),
2686
+ h('span', { className: 'lc-meta', style: { marginLeft: 4 } }, '(看不见,但原文还在)'),
2687
+ h('span', { style: { flex: '1 1 auto' } }),
2688
+ h('span', { className: 'lc-meta' }, open === true ? '收起' : '展开'),
2689
+ ),
2690
+ open !== true
2691
+ ? null
2692
+ : h('div', { className: 'lc-stack', style: { marginTop: 8 } },
2693
+ h('div', { className: 'lc-meta', style: { lineHeight: 1.7 } },
2694
+ '「放回来」会让它回到上面的列表;「彻底删掉」会把磁盘上的原文一起删掉,删了就真没了。'),
2695
+ rows.map((item) => {
2696
+ const name = String(item?.name ?? '').trim() === '' ? cardNameFromPath(item?.path) : String(item.name)
2697
+ return h('div', {
2698
+ key: item?.path ?? name,
2699
+ className: 'lc-card-item',
2700
+ 'data-withdrawn-row': item?.path ?? '',
2701
+ style: { cursor: 'default' },
2702
+ },
2703
+ h('div', { className: 'lc-grow lc-ellipsis', style: { fontWeight: 600, minWidth: 0 } }, name),
2704
+ h('button', {
2705
+ type: 'button',
2706
+ className: 'lc-btn sm',
2707
+ 'data-withdrawn-restore': item?.path ?? '',
2708
+ title: `把「${name}」放回来`,
2709
+ onClick: () => onRestore?.(item),
2710
+ }, h(Icon, { name: 'back', size: 13 }), h('span', null, '放回来')),
2711
+ h('button', {
2712
+ type: 'button',
2713
+ className: 'lc-btn sm',
2714
+ 'data-withdrawn-purge': item?.path ?? '',
2715
+ title: `把「${name}」彻底删掉`,
2716
+ onClick: () => onPurge?.(item),
2717
+ }, h(Icon, { name: 'trash', size: 13 }), h('span', null, '彻底删掉')),
2718
+ )
2719
+ }),
2720
+ ),
2721
+ )
2722
+ }
2723
+
2724
+ function CardRow({ card, onOpen, photo, onDelete, onEdit, pinned, onTogglePin }) {
2725
+ // 「一张卡」而不是「一行字」:正面只有头像和名字,名字下面一个「详细信息」;
2726
+ // 直接点卡片,卡片翻过来露出背面的简介,再点一下翻回来。
2727
+ // 翻面用 CSS 3D(transform + backface-visibility),没有 JS 动画成本。
2728
+ const [flipped, setFlipped] = useState(false)
2729
+ const name = String(card.name ?? '').trim() === '' ? '(还没起名字)' : card.name
2730
+ const intro = String(card.intro ?? '').trim()
2731
+ const face = {
2732
+ position: 'absolute', inset: 0, borderRadius: 14, border: '1px solid var(--lc-line)',
2733
+ background: 'var(--lc-panel)', overflow: 'hidden', display: 'flex', flexDirection: 'column',
2734
+ backfaceVisibility: 'hidden', WebkitBackfaceVisibility: 'hidden',
2735
+ boxShadow: '0 10px 22px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .55)',
2736
+ }
2737
+ const iconBtn = (opts) => h('button', {
2738
+ type: 'button',
2739
+ title: opts.title,
2740
+ 'data-card-action': opts.act,
2741
+ onClick: (e) => { e?.stopPropagation?.(); opts.onClick() },
2742
+ style: {
2743
+ width: 26, height: 26, borderRadius: 9, padding: 0, cursor: 'pointer', flex: '0 0 auto',
2744
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
2745
+ border: '1px solid var(--lc-line)', background: 'rgba(255,255,255,.82)', color: 'var(--lc-ink-2)',
2746
+ boxShadow: '0 1px 0 rgba(255,255,255,.7), 0 2px 4px rgba(0,0,0,.08)',
2747
+ },
2748
+ }, h(Icon, { name: opts.icon, size: 13 }))
2749
+
2750
+ return h('div', {
2751
+ className: 'lc-fcard',
2752
+ style: { flex: '1 1 150px', maxWidth: 210, minWidth: 132, perspective: 900 },
2753
+ },
2754
+ h('div', {
2755
+ style: {
2756
+ position: 'relative', width: '100%', aspectRatio: '3 / 4',
2757
+ transformStyle: 'preserve-3d', transition: 'transform .42s cubic-bezier(.2, .7, .3, 1)',
2758
+ transform: flipped ? 'rotateY(180deg)' : 'none',
2759
+ },
2760
+ },
2761
+ // ── 正面:头像 + 名字 + 「详细信息」 ───────────────────────────────────
2762
+ h('div', {
2763
+ style: face,
2764
+ 'data-face': 'front',
2765
+ onClick: () => setFlipped(true),
2766
+ },
2767
+ h('div', { className: 'lc-row', style: { padding: '8px 8px 0 8px', gap: 6, alignItems: 'flex-start' } },
2768
+ onTogglePin === undefined ? null : h('button', {
2077
2769
  type: 'button',
2078
- className: 'lc-row',
2079
- onClick: () => onOpen(card),
2770
+ title: pinned === true
2771
+ ? `这扇门现在用的是「${name}」,点一下取消`
2772
+ : `点一下让这扇门用「${name}」`,
2773
+ 'aria-pressed': pinned === true,
2774
+ 'data-pinned': pinned === true ? 'yes' : 'no',
2775
+ onClick: (e) => { e?.stopPropagation?.(); onTogglePin(card) },
2080
2776
  style: {
2081
- flex: '1 1 auto', minWidth: 0, background: 'transparent', border: 0,
2082
- padding: 0, textAlign: 'left', cursor: 'pointer', font: 'inherit', color: 'inherit',
2083
- display: 'flex', alignItems: 'center', gap: 8,
2777
+ width: 24, height: 24, borderRadius: 12, padding: 0, cursor: 'pointer', flex: '0 0 auto',
2778
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
2779
+ border: pinned === true ? '1px solid var(--lc-doctor)' : '1px solid var(--lc-danger)',
2780
+ background: pinned === true ? 'var(--lc-doctor)' : 'var(--lc-danger-soft)',
2781
+ color: pinned === true ? '#ffffff' : 'var(--lc-danger)',
2084
2782
  },
2783
+ }, h(Icon, { name: pinned === true ? 'check' : 'x', size: 12 })),
2784
+ h('span', { style: { flex: '1 1 auto' } }),
2785
+ onEdit === undefined ? null : iconBtn({ act: 'edit', icon: 'pencil', title: `改「${name}」`, onClick: () => onEdit(card) }),
2786
+ onDelete === undefined ? null : iconBtn({ act: 'delete', icon: 'trash', title: `删掉「${name}」`, onClick: () => onDelete(card) }),
2787
+ ),
2788
+ h('div', {
2789
+ style: {
2790
+ flex: '1 1 auto', display: 'flex', flexDirection: 'column', alignItems: 'center',
2791
+ justifyContent: 'center', gap: 8, padding: '4px 10px 10px 10px', minHeight: 0,
2085
2792
  },
2086
- h(Avatar, { name: card.name, kind: card.kind, photo }),
2087
- h('div', { className: 'lc-grow' },
2088
- h('div', { className: 'lc-row' },
2089
- h('span', { style: { fontWeight: 600, flex: '0 1 auto', overflow: 'hidden', textOverflow: 'ellipsis' } }, card.name),
2090
- card.relation === undefined || card.relation === '' ? null : h('span', { className: 'lc-meta' }, card.relation),
2091
- h('span', { className: 'lc-grow' }),
2092
- card.issues?.some((i) => i.level === 'error')
2093
- ? h(Tag, { tone: 'err' }, '有问题')
2094
- : null,
2095
- ),
2096
- h('div', { className: 'lc-row', style: { marginTop: 3 } },
2097
- h(Bar, { value: card.coverage }),
2098
- // 「10%」以前只有一个数字,没人知道是什么。它是这张卡写全了多少:
2099
- // 关系、性格、说话习惯、做过的事……这些栏里填了几样。
2100
- h('span', { className: 'lc-meta', style: { flexShrink: 0 }, title: '这张卡写全了多少:性格、说话习惯、做过的事这些填了几样' }, `写全 ${card.coverage}%`),
2101
- ),
2102
- (card.tags ?? []).length > 0
2103
- ? h('div', { className: 'lc-wrap', style: { marginTop: 5 } }, card.tags.slice(0, 4).map((t) => h(Tag, { key: t }, t)))
2104
- : null,
2105
- ),
2793
+ },
2794
+ h(Avatar, { name, kind: card.kind, photo, big: true }),
2795
+ h('div', {
2796
+ style: {
2797
+ fontWeight: 700, fontSize: 15.5, textAlign: 'center', maxWidth: '100%',
2798
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
2799
+ },
2800
+ }, name),
2801
+ card.relation === undefined || card.relation === '' ? null : h('div', { className: 'lc-meta' }, card.relation),
2802
+ onOpen === undefined ? null : h('button', {
2803
+ type: 'button',
2804
+ className: 'lc-btn sm',
2805
+ 'data-card-open': card.id ?? '',
2806
+ title: `看「${name}」的详细信息`,
2807
+ onClick: (e) => { e?.stopPropagation?.(); onOpen(card) },
2808
+ style: { marginTop: 2, width: '100%' },
2809
+ }, '详细信息'),
2810
+ ),
2811
+ h('div', {
2812
+ className: 'lc-meta',
2813
+ style: { textAlign: 'center', padding: '0 8px 8px 8px', fontSize: 11.5 },
2814
+ }, '点卡片翻面'),
2815
+ ),
2816
+
2817
+ // ── 背面:简介 + 写全多少 + 标签 ───────────────────────────────────────
2818
+ h('div', {
2819
+ style: { ...face, transform: 'rotateY(180deg)' },
2820
+ 'data-face': 'back',
2821
+ onClick: () => setFlipped(false),
2822
+ },
2823
+ h('div', { className: 'lc-row', style: { padding: '8px 8px 0 8px', gap: 6, alignItems: 'flex-start' } },
2824
+ h('span', { style: { fontWeight: 700, fontSize: 13.5, flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, name),
2825
+ onDelete === undefined ? null : iconBtn({ act: 'delete-back', icon: 'trash', title: `删掉「${name}」`, onClick: () => onDelete(card) }),
2826
+ ),
2827
+ h('div', {
2828
+ style: {
2829
+ flex: '1 1 auto', minHeight: 0, overflow: 'hidden', padding: '6px 10px 0 10px',
2830
+ fontSize: 13, lineHeight: 1.65, color: 'var(--lc-ink-2)',
2831
+ },
2832
+ },
2833
+ intro === '' ? '这张卡还没写自述。' : intro,
2834
+ ),
2835
+ h('div', { style: { padding: '6px 10px 8px 10px' } },
2836
+ h('div', { className: 'lc-row', style: { gap: 6 } },
2837
+ h(Bar, { value: card.coverage }),
2838
+ h('span', { className: 'lc-meta', style: { flexShrink: 0 }, title: '这张卡写全了多少:性格、说话习惯、做过的事这些填了几样' }, `写全 ${card.coverage}%`),
2106
2839
  ),
2107
- // 列表里直接能删:以前必须先点开卡、滚到最底下才找得到「删掉这张卡」,
2108
- // 建错一张(比如「复制一份来演」试了几次)就得来回点好几屏。
2109
- // 「写全 10%」后面以前没有任何「去补它」的入口:要改这张卡,得先点开、
2110
- // 再在卡页上找「改这张卡」。一行一个铅笔,直接进修改。
2111
- onEdit === undefined ? null : h('button', {
2112
- type: 'button',
2113
- className: 'lc-btn ghost sm',
2114
- title: `改「${card.name ?? '这张卡'}」`,
2115
- onClick: (e) => { e?.stopPropagation?.(); onEdit(card) },
2116
- style: { flex: '0 0 auto' },
2117
- }, h(Icon, { name: 'pencil', size: 13 })),
2118
- onDelete === undefined ? null : h('button', {
2119
- type: 'button',
2120
- className: 'lc-btn ghost sm',
2121
- title: `删掉「${card.name ?? '这张卡'}」`,
2122
- onClick: (e) => { e?.stopPropagation?.(); onDelete(card) },
2123
- style: { flex: '0 0 auto' },
2124
- }, h(Icon, { name: 'trash', size: 13 })),
2840
+ (card.tags ?? []).length > 0
2841
+ ? h('div', { className: 'lc-wrap', style: { marginTop: 5 } }, card.tags.slice(0, 3).map((t) => h(Tag, { key: t }, t)))
2842
+ : null,
2843
+ h('div', { className: 'lc-meta', style: { marginTop: 5, textAlign: 'center' } }, '再点一下翻回正面'),
2844
+ ),
2845
+ ),
2846
+ ),
2125
2847
  )
2126
2848
  }
2127
2849
 
@@ -2349,6 +3071,28 @@ function GameView({ bookId, onBack, flash }) {
2349
3071
  } catch (e) { setErr(humanizeError(e)) }
2350
3072
  }
2351
3073
 
3074
+ /**
3075
+ * 删掉某一局存档。
3076
+ *
3077
+ * `game.delete` 后台一直都有,界面没接过——玩过几局之后,「之前玩到一半的」
3078
+ * 会一直往下堆,试一下就走的那几局也删不掉。
3079
+ */
3080
+ const removePlay = async (row) => {
3081
+ const said = String(row?.scene ?? '').trim() === '' ? '那一局' : String(row.scene)
3082
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3083
+ ? window.confirm(`把「${said}」这一局删掉?\n\n走了 ${Number(row?.turns ?? 0)} 步,删了就真没了,接不回来。\n已经写成某一章的内容不受影响,那些章还在。`)
3084
+ : true
3085
+ if (ok !== true) return
3086
+ setErr(null)
3087
+ try {
3088
+ const r = await call('game.delete', { book: bookId, id: String(row?.id ?? '') })
3089
+ if (r?.ok !== true) { setErr(r?.error ?? '这一局没删掉'); return }
3090
+ if (play !== null && play.id === row?.id) setPlay(null)
3091
+ await loadPlays()
3092
+ flash?.('删掉了那一局')
3093
+ } catch (e) { setErr(humanizeError(e)) }
3094
+ }
3095
+
2352
3096
  useEffect(() => {
2353
3097
  let gone = false
2354
3098
  loadPlays()
@@ -2399,10 +3143,11 @@ function GameView({ bookId, onBack, flash }) {
2399
3143
  ? null
2400
3144
  : h('div', { className: 'lc-stack', style: { gap: 6, marginTop: 10 } },
2401
3145
  h('div', { className: 'lc-fhint' }, `之前玩到一半的 · ${plays.length}`),
2402
- plays.map((row) => h(Btn, {
2403
- key: row.id, block: true, size: 'sm', icon: 'history',
2404
- onClick: () => open(row),
2405
- }, `${String(row.scene ?? '').trim() === '' ? '那一局' : String(row.scene)} · 走了 ${Number(row.turns ?? 0)} 步`)),
3146
+ plays.map((row) => h('div', { key: row.id, className: 'lc-row', style: { gap: 6 } },
3147
+ h(Btn, { block: true, size: 'sm', icon: 'history', onClick: () => open(row) },
3148
+ `${String(row.scene ?? '').trim() === '' ? '那一局' : String(row.scene)} · 走了 ${Number(row.turns ?? 0)} 步`),
3149
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', title: '删掉这一局', onClick: () => removePlay(row) }, '删掉这一局'),
3150
+ )),
2406
3151
  ),
2407
3152
  err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
2408
3153
  )
@@ -2491,16 +3236,31 @@ function CareerView({ onBack, flash }) {
2491
3236
  const [err, setErr] = useState(null)
2492
3237
  const [dirty, setDirty] = useState(false)
2493
3238
 
3239
+ /** 把读回来的东西摆到界面上。读不出来就照实说,别让它只停在转圈上。 */
3240
+ const applyRead = (r) => {
3241
+ if (r?.ok !== true) { setErr(r?.error ?? '你的简历这一份读不出来'); return }
3242
+ setProfile(buildCareerForm(r.profileSections ?? {}))
3243
+ setGoal(String(r.plan?.goal ?? ''))
3244
+ setHorizon(String(r.plan?.horizon ?? '1年'))
3245
+ }
3246
+
3247
+ /**
3248
+ * 读一次自己的简历。首次进来和「再试一次」走的是同一段。
3249
+ *
3250
+ * 以前「再试一次」只写了 `call('career.get', {})`,返回值被丢掉——点了以后
3251
+ * 界面还是空着转圈,跟没点一样,用户只能一直点下去。
3252
+ */
3253
+ const load = async () => {
3254
+ setErr(null)
3255
+ try {
3256
+ applyRead(await call('career.get', {}))
3257
+ } catch (e) { setErr(humanizeError(e)) }
3258
+ }
3259
+
2494
3260
  useEffect(() => {
2495
3261
  let gone = false
2496
3262
  call('career.get', {})
2497
- .then((r) => {
2498
- if (gone) return
2499
- if (r?.ok !== true) { setErr(r?.error ?? '你的简历这一份读不出来'); return }
2500
- setProfile(buildCareerForm(r.profileSections ?? {}))
2501
- setGoal(String(r.plan?.goal ?? ''))
2502
- setHorizon(String(r.plan?.horizon ?? '1年'))
2503
- })
3263
+ .then((r) => { if (!gone) applyRead(r) })
2504
3264
  .catch((e) => { if (!gone) setErr(humanizeError(e)) })
2505
3265
  return () => { gone = true }
2506
3266
  }, [])
@@ -2539,7 +3299,7 @@ function CareerView({ onBack, flash }) {
2539
3299
  ? h(Spinner)
2540
3300
  : h('div', { className: 'lc-stack' },
2541
3301
  h(Note, { tone: 'err', icon: 'warning' }, err),
2542
- h(Btn, { block: true, onClick: () => { setErr(null); call('career.get', {}) } }, '再试一次'),
3302
+ h(Btn, { block: true, onClick: () => { load() } }, '再试一次'),
2543
3303
  ),
2544
3304
  )
2545
3305
  }
@@ -2697,6 +3457,29 @@ function BookView({ bookId, onBack, flash }) {
2697
3457
  await openChapter(index)
2698
3458
  }
2699
3459
 
3460
+ /**
3461
+ * 删掉某一章。
3462
+ *
3463
+ * `novel.chapter.delete` 后台一直都有,界面从来没调过——写歪了一章,
3464
+ * 用户只能去文件夹里找那个文件。删的是正文本身,不是「收起来」。
3465
+ */
3466
+ const removeChapter = async (c) => {
3467
+ const n = Number(c?.index ?? 0)
3468
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3469
+ ? window.confirm(`把第 ${n} 章删掉?\n\n这一章的正文一起删,删了就真没了。别的章不受影响;大纲里那一行还在,你可以重写。`)
3470
+ : true
3471
+ if (ok !== true) return
3472
+ setErr(null)
3473
+ setBodyDirty(false)
3474
+ try {
3475
+ const r = await call('novel.chapter.delete', { id: bookId, index: n })
3476
+ if (r?.ok !== true) { setErr(r?.error ?? '这一章没删掉'); return }
3477
+ flash?.(`删掉了第 ${n} 章`)
3478
+ // 重新读一遍这本书:章列表少一条,正文换成还在的那一章。
3479
+ await load(n > 1 ? n - 1 : 0)
3480
+ } catch (e) { setErr(humanizeError(e)) }
3481
+ }
3482
+
2700
3483
  useEffect(() => { load(0) }, [bookId])
2701
3484
 
2702
3485
  const doPlan = async () => {
@@ -2836,6 +3619,28 @@ function BookView({ bookId, onBack, flash }) {
2836
3619
  : null,
2837
3620
  ),
2838
3621
 
3622
+ // ── 已经写过的章 ──
3623
+ // 以前这一块没有:写了几章之后想回头删掉某一章,界面上根本没有落脚的地方。
3624
+ chapters.length === 0
3625
+ ? null
3626
+ : h('div', { className: 'lc-sec' },
3627
+ h('div', { className: 'lc-row' },
3628
+ h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, `已经写过的章 · ${chapters.length}`)),
3629
+ h('span', { className: 'lc-meta' }, '点一章就能翻过去'),
3630
+ ),
3631
+ h('div', { className: 'lc-stack', style: { gap: 4, marginTop: 6 } },
3632
+ chapters.map((c) => h('div', { key: c.index, className: 'lc-row', style: { gap: 6 } },
3633
+ h(Btn, {
3634
+ size: 'sm', icon: 'book',
3635
+ tone: Number(c.index) === Number(chapterIndex) ? 'primary' : undefined,
3636
+ onClick: () => { goChapter(Number(c.index)) },
3637
+ }, `第 ${c.index} 章${String(c.title ?? '').trim() === '' ? '' : ` · ${String(c.title).slice(0, 16)}`}`),
3638
+ h('div', { className: 'lc-grow' }),
3639
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', onClick: () => removeChapter(c) }, '删掉这一章'),
3640
+ )),
3641
+ ),
3642
+ ),
3643
+
2839
3644
  // ── 第二段:写这一章 ──
2840
3645
  h('div', { className: 'lc-sec' },
2841
3646
  h('div', { className: 'lc-row' },
@@ -2926,6 +3731,10 @@ function TavernView({ chat, onChat, onBack, flash }) {
2926
3731
  // 「挑几句写进卡里」。同样排在最后。
2927
3732
  const [exBusy, setExBusy] = useState(false)
2928
3733
  const [exNote, setExNote] = useState('')
3734
+ // 这一张卡现在读不出来了(被删掉、被挪走、文件坏了)——后台照样回话,
3735
+ // 但它手上没有这张卡,演出来的就不是卡上那个人。以前这一句没人说,
3736
+ // 用户只会觉得「TA 今天怎么没性格了」。这一行排在最后,同上。
3737
+ const [cardWarn, setCardWarn] = useState('')
2929
3738
  const turns = Array.isArray(chat?.turns) ? chat.turns : []
2930
3739
  const rawName = String(chat?.card_name ?? '').trim()
2931
3740
  const name = rawName === '' ? 'TA' : rawName
@@ -2943,6 +3752,11 @@ function TavernView({ chat, onChat, onBack, flash }) {
2943
3752
  // 不然用户会以为自己那句话没发出去、再打一遍,最后文件里出现两份。
2944
3753
  if (Array.isArray(r?.turns)) onChat({ ...chat, turns: r.turns })
2945
3754
  if (r?.ok !== true) { setErr(r?.error ?? 'TA 没接上话,过一会儿再试一次'); return }
3755
+ // 后台在卡读不出来时会退化成空 persona 照样回话,并把原因放在 warning 里。
3756
+ // 不说的话,用户看到的只是「TA 变了个性格」,会以为是自己哪里点错了。
3757
+ setCardWarn(String(r?.warning ?? '').trim() === ''
3758
+ ? ''
3759
+ : '这张卡现在读不出来了,这一段没在照卡演。往上看一眼是不是刚删过或者挪过它。')
2946
3760
  setDraft('')
2947
3761
  } catch (e) {
2948
3762
  setErr(humanizeError(e))
@@ -3078,6 +3892,8 @@ function TavernView({ chat, onChat, onBack, flash }) {
3078
3892
  className: 'lc-stack',
3079
3893
  style: { gap: 7, maxHeight: '52vh', overflowY: 'auto', padding: '2px 1px' },
3080
3894
  }, turns.map(bubble)),
3895
+ // 紧贴在对话流末尾:这一段不是照卡演的,必须当场说,不能等用户自己发现。
3896
+ cardWarn === '' ? null : h(Note, { tone: 'warn', icon: 'warning' }, cardWarn),
3081
3897
  memoryText === '' ? null : h(Note, { icon: 'book' },
3082
3898
  h('div', { style: { fontWeight: 650, marginBottom: 3 } }, '前面这些已经收好了'),
3083
3899
  h('div', { style: { whiteSpace: 'pre-wrap' } }, memoryText),
@@ -3160,7 +3976,7 @@ function TavernView({ chat, onChat, onBack, flash }) {
3160
3976
  )
3161
3977
  }
3162
3978
 
3163
- function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onInterview, onAnalyze, worlds, onOpenWorld, onTavern, initialEditing }) {
3979
+ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onStartInterview, onAnalyze, worlds, onOpenWorld, initialEditing, mode }) {
3164
3980
  const [editing, setEditing] = useState(initialEditing === true)
3165
3981
  const [busy, setBusy] = useState('')
3166
3982
  const [err, setErr] = useState(null)
@@ -3279,7 +4095,7 @@ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, on
3279
4095
 
3280
4096
  memFlag === null
3281
4097
  ? null
3282
- : h('div', { className: 'lc-meta' }, `这条是从你写过的记忆里认出来的,当时只记了半句。还差:${memFlag.missing.join('、')}。点「接着聊」就会专门问这几样。`),
4098
+ : h('div', { className: 'lc-meta' }, `这条是从你写过的记忆里认出来的,当时只记了半句。还差:${memFlag.missing.join('、')}。点「聊一聊」就会专门问这几样。`),
3283
4099
 
3284
4100
  cov === undefined ? null : h('div', null,
3285
4101
  h('div', { className: 'lc-row' },
@@ -3296,13 +4112,22 @@ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, on
3296
4112
  // 主操作:三个指向明确的按钮
3297
4113
  h('div', { className: 'lc-row', style: { marginTop: 2 } },
3298
4114
  h(Btn, { tone: 'primary', icon: 'pencil', onClick: () => setEditing(true) }, '改这张卡'),
3299
- h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onInterview(buildPreset(data)) }, '接着聊'),
3300
- onTavern === undefined ? null : h(Btn, { tone: 'analyze', icon: 'mic', onClick: () => onTavern(buildPreset(data)) }, '和 TA 演一段'),
4115
+ // 补这张卡也不在插件里问:开一个新对话,把「补哪一张」说给它听。
4116
+ // 带上名字,新对话里才不用再问一遍「你说的是谁」。
4117
+ h(Btn, {
4118
+ tone: 'interview',
4119
+ icon: 'chat',
4120
+ onClick: () => onStartInterview({
4121
+ about: String(data?.name ?? '').trim(),
4122
+ mode,
4123
+
4124
+ }),
4125
+ }, '聊一聊(新开一个对话)'),
3301
4126
  h(Btn, { tone: 'analyze', size: 'sm', icon: 'spark', onClick: onAnalyze }, '读材料'),
3302
4127
  ),
3303
4128
 
3304
4129
  cov !== undefined && cov.empty.length > 0
3305
- ? h('div', { className: 'lc-meta' }, '「接着聊」会专门问还空着的那几样。')
4130
+ ? h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里。')
3306
4131
  : null,
3307
4132
 
3308
4133
  issues.length > 0
@@ -4247,7 +5072,7 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4247
5072
  h('span', { className: 'lc-grow' }),
4248
5073
  h('span', { className: 'lc-meta' }, `选了 ${checked} 条`),
4249
5074
  ),
4250
- h('div', { className: 'lc-meta' }, '每一条下面都引用了材料里的原话。它编不出来的——材料里找不到原文的,已经被丢掉了。'),
5075
+ h('div', { className: 'lc-meta' }, '每一条下面都引用了材料里的原话。它编不出来的——材料里找不到原文的、和前面那条重复的,都已经丢掉了。'),
4251
5076
  adoptedBefore > 0
4252
5077
  ? h('div', { className: 'lc-meta' }, `其中 ${adoptedBefore} 条之前已经写进卡了,不再列在这里。`)
4253
5078
  : null,
@@ -4266,7 +5091,7 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4266
5091
  ),
4267
5092
  ))),
4268
5093
  (proposal.rejected ?? []).length > 0
4269
- ? h(Note, { tone: 'warn', icon: 'warning' }, `有 ${proposal.rejected.length} 条在材料里找不到原话,已经丢掉了。`)
5094
+ ? h(Note, { tone: 'warn', icon: 'warning' }, `没有采用的有 ${proposal.rejected.length} 条:${rejectedWords(proposal)}。`)
4270
5095
  : null,
4271
5096
  // 名下还没有卡时不给采纳按钮。硬给的话点下去只会得到「找不到这张卡」,
4272
5097
  // 而用户刚刚才看完一整页建议——说清楚比给个坏按钮好。
@@ -4293,6 +5118,36 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4293
5118
  )
4294
5119
  }
4295
5120
 
5121
+ /**
5122
+ * 被丢掉的条目为什么被丢:引文对不上,还是和同一字段里另一条重复?
5123
+ * 提案里带的是完整 rejected(每条有 reason);分析结果和提案列表只带计数,
5124
+ * 后端会把计数拆成 rejectedDuplicate / rejectedQuote 两个数回传。
5125
+ * 拿不到原因的时候不许硬说成「找不到原话」——那是在冤枉用户。
5126
+ */
5127
+ function rejectedSplit(one) {
5128
+ const raw = one?.rejected
5129
+ if (Array.isArray(raw)) {
5130
+ const dup = raw.filter((r) => String(r?.reason ?? '').includes('重复')).length
5131
+ return { known: true, total: raw.length, dup, quote: raw.length - dup }
5132
+ }
5133
+ const total = Number(raw ?? 0) || 0
5134
+ if (one?.rejectedDuplicate !== undefined && one?.rejectedQuote !== undefined) {
5135
+ return { known: true, total, dup: Number(one.rejectedDuplicate) || 0, quote: Number(one.rejectedQuote) || 0 }
5136
+ }
5137
+ return { known: false, total, dup: 0, quote: total }
5138
+ }
5139
+
5140
+ /** 把「丢了几条、为什么丢」说成一句人话;一条都没丢时返回空串。 */
5141
+ function rejectedWords(one) {
5142
+ const split = rejectedSplit(one)
5143
+ if (!(split.total > 0)) return ''
5144
+ if (!split.known) return `${split.total} 条没能通过校验,已经丢掉(引文对不上,或者和前面那条重复)`
5145
+ const bits = []
5146
+ if (split.dup > 0) bits.push(`${split.dup} 条和前面那条重复,只留了一条`)
5147
+ if (split.quote > 0) bits.push(`${split.quote} 条在材料里找不到原话,已经丢掉`)
5148
+ return bits.join(';')
5149
+ }
5150
+
4296
5151
  /** 把字段名翻译成人话。 */
4297
5152
  function fieldLabel(field) {
4298
5153
  const table = {
@@ -4436,7 +5291,15 @@ function NewCardView({ state, onCreate, presetName }) {
4436
5291
  )
4437
5292
  }
4438
5293
 
4439
- // ── 访谈 ──────────────────────────────────────────────────────────
5294
+ // ── 访谈(已经不走了,留作参考)──────────────────────────────────
5295
+ //
5296
+ // 这一段是插件自己演的访谈:插件问、插件拆字段、插件写卡。现在所有入口
5297
+ // (首页的「聊一聊」、卡片页补信息、材料页)都改成开一个新对话,把
5298
+ // /lifecard-interview 那个 skill 带上——问法只有一份,两边不会走样。
5299
+ //
5300
+ // 所以:任何界面路径都进不到 InterviewView,VIEWS.interview 也没有入口了。
5301
+ // 代码和它的测试留着,是因为拆字段、写卡那些逻辑以后可能还要用;真要改
5302
+ // 访谈的问法,改的是 skill,不是这里。入口见 openInterviewSession。
4440
5303
 
4441
5304
  function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAnalyze, mode }) {
4442
5305
  // 这扇门建的是现实里的人,还是虚构的角色。两者的第一问本来就不该一样:
@@ -4482,6 +5345,10 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4482
5345
  // 不然分析页一条都不勾,而「一条都不勾」= 全读——别人的材料会被读进这张卡。
4483
5346
  const [materialPaths, setMaterialPaths] = useState([])
4484
5347
  const scrollRef = useRef(null)
5348
+ // 开局失败要收掉刚建的那张空卡。收不掉的时候(比如超过十分钟窗口)它不是
5349
+ // 一句道歉能了事的:列表里会留一张同名空卡,下次同名建卡就撞
5350
+ // 「已经有一张叫…」。所以得记下来,并给一个能点过去的地方。
5351
+ const [stuckCard, setStuckCard] = useState(null)
4485
5352
 
4486
5353
  // 宿主给什么就用什么;一个都没有(还没重启、旧版宿主)就用本地这份。
4487
5354
  const relations = (state?.relations?.length ?? 0) > 0 ? state.relations : RELATION_FALLBACK
@@ -4518,7 +5385,7 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4518
5385
  .split(/[、,,;;\s]+/)
4519
5386
  .map((s) => s.trim())
4520
5387
  .filter((s) => s !== '')
4521
- setBusy(true); setErr(null)
5388
+ setBusy(true); setErr(null); setStuckCard(null)
4522
5389
  try {
4523
5390
  const id = preset?.id ?? safeId(targetName)
4524
5391
  // 先按 id 精确匹配,再按名字兜底。顺序不能反:酒馆里「复制一份来演」
@@ -4582,10 +5449,21 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4582
5449
  // 问题没准备出来(多半是 AI 那边没响应)。这时候刚建的那张空卡要收回去:
4583
5450
  // 留着它就是列表里一张名字对、点开什么都没有的卡,用户下次还会再建一张。
4584
5451
  // 本来就有的卡不动——那张卡上有他自己写的东西。
5452
+ let leftover = false
4585
5453
  if (existing === undefined && typeof made?.path === 'string' && made.path !== '') {
4586
- try { await call('card.delete', { path: made.path, reason: '访谈没能开始,撤掉这次建的空卡' }) } catch (e) { /* 撤不掉也不该挡住这句话 */ }
5454
+ // 用 discard 而不是 delete:这张卡从没进过列表,写墓碑会占住名字,
5455
+ // 用户马上换个名字重来时就会撞上「这个名字被一张已经删掉的卡占着」。
5456
+ try {
5457
+ const dr = await call('card.discard', { path: made.path })
5458
+ // 收不掉就记一笔。以前这里连返回值都不看,界面只说「已经撤掉了」,
5459
+ // 用户回列表却看见一张空卡,还以为是新问题。
5460
+ if (dr?.ok !== true) leftover = true
5461
+ } catch (e) { leftover = true }
4587
5462
  }
4588
- setErr(`${p?.error ?? '没法准备问题'}。${existing === undefined ? '刚才建的那张空卡已经撤掉了,' : ''}过一会儿再点一次「开始」。`)
5463
+ setStuckCard(leftover ? { name: targetName } : null)
5464
+ setErr(leftover
5465
+ ? `${p?.error ?? '没法准备问题'}。刚才建的那张空卡没能收走,去列表里把它删掉再重试。`
5466
+ : `${p?.error ?? '没法准备问题'}。${existing === undefined ? '刚才建的那张空卡已经撤掉了,' : ''}过一会儿再点一次「开始」。`)
4589
5467
  setPhase('pick')
4590
5468
  return
4591
5469
  }
@@ -4601,6 +5479,10 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4601
5479
  }
4602
5480
 
4603
5481
  const advance = async (status, reason) => {
5482
+ // 正记着的时候再点一次,会把同一题记两遍、还多跳一题——
5483
+ // 用户看到的就是「答案和题目错位」。按键已经 disabled,
5484
+ // 但键盘回车和连点仍可能挤进来,所以这里再挡一道。
5485
+ if (busy === true) return
4604
5486
  if (current === null) return
4605
5487
  const q = current
4606
5488
  setBusy(true); setErr(null)
@@ -4613,6 +5495,7 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4613
5495
  status,
4614
5496
  reason,
4615
5497
  fills: q.fills,
5498
+ options: q.options,
4616
5499
  })
4617
5500
  // 记不下来就别往下走。以前这里不看结果:盘写不进去(文件夹被挪走、
4618
5501
  // 变成只读)时界面照样把这一问答进对话、照样跳下一题,用户答了半小时,
@@ -4633,14 +5516,14 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4633
5516
  setLog((prev) => [...prev, { role: 'bot', text: q.ask, options: q.options }, { role: 'me', text: status === 'skipped' ? (reason === 'sealed' ? '(这个不想说)' : '(跳过)') : '(以后再说)' }])
4634
5517
  }
4635
5518
  setAnswer('')
4636
- // 队列推进
4637
- const rest = queue.slice(1)
5519
+ // 队列推进:按「这一题不在队里了」来算,不靠 slice(1) 的位置假设
5520
+ const rest = queue.filter((item) => item.id !== q.id)
4638
5521
  if (rest.length === 0) {
4639
5522
  const p = await call('interview.plan', { about: aboutId, relation, limit: 3, kind: fiction ? 'fictional' : 'real' })
4640
5523
  // 没问着问题不等于问完了。以前这里不看结果:AI 没连上、模型抽风、
4641
5524
  // 文件夹读不出来,界面都会直接跳到结束页,还写「现在写满了 undefined%」。
4642
5525
  if (p?.ok !== true) {
4643
- setErr(`${p?.error ?? '想不出下一题'}。刚才那一句已经记下了,这里是没接上——过一会儿点「再问一题」接着来。`)
5526
+ setErr(`${p?.error ?? '想不出下一题'}。刚才那一句已经记下了,这里是没接上——过一会儿点下面「再问一题」接着来。`)
4644
5527
  return
4645
5528
  }
4646
5529
  setPlan(p)
@@ -4662,6 +5545,24 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4662
5545
  } finally { setBusy(false) }
4663
5546
  }
4664
5547
 
5548
+ // 队列走空了、但下一组问题没要到(模型没连上/抽风)时的退路。
5549
+ // 以前错误文案让人点「再问一题」,界面上根本没有这个按钮,
5550
+ // 用户只能重开一场或者干脆放弃。
5551
+ const askMore = async () => {
5552
+ if (busy === true) return
5553
+ setBusy(true); setErr(null)
5554
+ try {
5555
+ const p = await call('interview.plan', { about: aboutId, relation, limit: 3, kind: fiction ? 'fictional' : 'real' })
5556
+ if (p?.ok !== true) { setErr(p?.error ?? '这会儿想不出下一题,过一会儿再点一次。'); return }
5557
+ setPlan(p)
5558
+ setQueue(p.next ?? [])
5559
+ setCurrent((p.next ?? [])[0] ?? null)
5560
+ if ((p.next ?? []).length === 0) { setPhase('done'); await onRecorded() }
5561
+ } catch (e) {
5562
+ setErr(humanizeError(e))
5563
+ } finally { setBusy(false) }
5564
+ }
5565
+
4665
5566
  // 「结束这次访谈」是整场收工,不是「跳过」的另一个说法:输入框里已经写好的
4666
5567
  // 那句不会存进去。以前这个按钮挤在「跳过 / 不想说」旁边,手一滑整场就没了、
4667
5568
  // 写了一半的话跟着丢,结束页还说「你说的都记下来了」。现在它挪到顶上单独一格,
@@ -4778,6 +5679,16 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4778
5679
  : h('div', { className: 'lc-meta' },
4779
5680
  relations.find((r) => r.id === relation)?.hint ?? '随便点一个最贴的。这一句只决定先问什么,不决定他的身份。'),
4780
5681
  err === null ? null : h(Err, { text: err }),
5682
+ // 空卡没被收走:给一条能走的路,不是让人自己去列表里翻。
5683
+ stuckCard === null
5684
+ ? null
5685
+ : h('div', { className: 'lc-note' },
5686
+ h('div', { style: { lineHeight: 1.7 } },
5687
+ `「${String(stuckCard.name ?? '').trim() === '' ? '刚才建的那张卡' : String(stuckCard.name)}」那张空卡还在列表里。`),
5688
+ h('div', { className: 'lc-row', style: { marginTop: 8, gap: 6 } },
5689
+ h(Btn, { size: 'sm', icon: 'list', onClick: () => { setStuckCard(null); setErr(null); onDone() } }, '去列表里删掉它'),
5690
+ ),
5691
+ ),
4781
5692
  h(Btn, { tone: fiction ? fictionTone : 'interview', big: true, block: true, onClick: start, disabled: busy, icon: 'send' }, busy ? '准备中…' : '开始聊'),
4782
5693
  )
4783
5694
  }
@@ -4818,17 +5729,26 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4818
5729
  log.map((entry, n) => entry.role === 'bot'
4819
5730
  ? h('div', { key: n, className: 'lc-stack' },
4820
5731
  h('div', { className: 'lc-bubble bot' }, h('div', { style: { whiteSpace: 'pre-wrap' } }, entry.text)),
5732
+ // 已经答完的那几题,选项只留着让人回看,**不能再点**:
5733
+ // 它们属于上一题,点下去会把那句话填进「这一题」的答案框,
5734
+ // 于是记下来的答案和题对不上(用户说的「选项和上一题答案错位」)。
4821
5735
  (entry.options ?? []).length > 0
4822
5736
  ? h('div', { className: 'lc-stack', style: { marginTop: 4 } },
4823
- entry.options.map((opt, k) => h('button', {
4824
- key: k, className: 'lc-opt', type: 'button',
4825
- onClick: () => setAnswer(opt),
5737
+ entry.options.map((opt, k) => h('div', {
5738
+ key: k, className: 'lc-opt lc-opt-past',
5739
+ 'data-past-option': 'yes',
4826
5740
  }, h('span', { className: 'lc-opt-num' }, String(k + 1)), h('span', null, opt))))
4827
5741
  : null,
4828
5742
  )
4829
5743
  : h('div', { key: n, className: 'lc-bubble me' }, h('div', { style: { whiteSpace: 'pre-wrap' } }, entry.text))),
4830
5744
 
4831
5745
  current === null ? null : h('div', { className: 'lc-stack', style: { marginTop: 10 } },
5746
+ // 这一题的问题必须**在答题时就看得见**。以前只把问题写进日志气泡,
5747
+ // 而气泡是答完才追加的,于是用户在答「第 N 题」时,屏幕上最后一条
5748
+ // 还是「第 N-1 题」——答的什么、写进哪一题,全靠猜。
5749
+ h('div', { className: 'lc-bubble bot', 'data-current-ask': current.id },
5750
+ h('div', { style: { whiteSpace: 'pre-wrap' } }, String(current.ask ?? '')),
5751
+ h('div', { className: 'lc-meta', style: { marginTop: 4 } }, '这一题')),
4832
5752
  (current.options ?? []).length > 0
4833
5753
  ? h('div', { className: 'lc-meta' }, '选一个,或者直接在下面写自己的:')
4834
5754
  : null,
@@ -4839,7 +5759,14 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4839
5759
  ),
4840
5760
  ),
4841
5761
  h('div', { style: { padding: 10, borderTop: '1px solid var(--lc-line)', background: 'var(--lc-panel)' } },
4842
- err === null ? null : h('div', { style: { marginBottom: 6 } }, h(Err, { text: err })),
5762
+ err === null ? null : h('div', { style: { marginBottom: 6 } },
5763
+ h(Err, { text: err }),
5764
+ // 这一题已经记下了、下一组问题没要到:给一个真的能点的「再问一题」,
5765
+ // 而不是让人对着错误信息干等。
5766
+ queue.length <= 1
5767
+ ? h('div', { style: { marginTop: 6 } }, h(Btn, { size: 'sm', icon: 'chat', tone: 'primary', disabled: busy, onClick: askMore }, '再问一题'))
5768
+ : null,
5769
+ ),
4843
5770
  h('textarea', {
4844
5771
  className: 'lc-textarea', style: { minHeight: 62, marginBottom: 6 },
4845
5772
  value: answer, onChange: (e) => setAnswer(e.target.value),
@@ -4867,12 +5794,12 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
4867
5794
 
4868
5795
  const handleFiles = (fileList) => {
4869
5796
  const all = Array.from(fileList ?? [])
4870
- const files = all.filter((f) => /\.(png|json|charx|zip)$/i.test(f.name))
5797
+ const files = all.filter((f) => /\.(png|json|charx|zip|txt|md)$/i.test(f.name))
4871
5798
  // 以前过滤完直接就 return:拖进来的是一张 jpg 头像或一份 md 设定,
4872
5799
  // 界面上什么都不发生,用户只会以为这块坏了。
4873
5800
  setSkipNote(files.length > 0 || all.length === 0
4874
5801
  ? ''
4875
- : `这些认不出来:${all.map((f) => f.name).join('、')}。只认角色卡文件(.png / .json / .charx / .zip)。想贴一段文字,就切到上面「一段文字」。`)
5802
+ : `这些认不出来:${all.map((f) => f.name).join('、')}。只认角色卡文件(.png / .json / .charx / .zip / .txt)。想贴一段文字,就切到上面「一段文字」。`)
4876
5803
  if (files.length === 0) return
4877
5804
  onImport(files)
4878
5805
  }
@@ -4904,7 +5831,7 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
4904
5831
  h('h3', null, drag ? '松手就行' : '把文件拖到这里,或者点一下去选'),
4905
5832
  h('div', { className: 'lc-meta' }, '别人给你的角色卡都能读——图片也行,导出的文件也行。', h('br'), '可以一次选好几个。'),
4906
5833
  h('input', {
4907
- ref: inputRef, type: 'file', multiple: true, accept: '.png,.json,.charx,.zip',
5834
+ ref: inputRef, type: 'file', multiple: true, accept: '.png,.json,.charx,.zip,.txt,.md',
4908
5835
  style: { display: 'none' }, onChange: (e) => handleFiles(e.target.files),
4909
5836
  }),
4910
5837
  ),
@@ -4998,7 +5925,7 @@ function TextImport({ onAnalyze }) {
4998
5925
  * 直接建卡会造出一排空卡,看着像成功、其实什么也不能用。
4999
5926
  * 摆出来、标清楚每人缺什么,用户自己决定哪些值得现在做。
5000
5927
  */
5001
- function MemoryView({ onDone, onBack }) {
5928
+ function MemoryView({ onDone, onBack, mode, onStartInterview }) {
5002
5929
  const [scan, setScan] = useState(null)
5003
5930
  const [picked, setPicked] = useState(null) // null = 还没选过,等于全选
5004
5931
  const [busy, setBusy] = useState(false)
@@ -5063,7 +5990,12 @@ function MemoryView({ onDone, onBack }) {
5063
5990
  `${whereText}认出了 ${people.length} 个人。`),
5064
5991
 
5065
5992
  people.length === 0
5066
- ? h(Note, { tone: undefined, icon: 'person' }, '记忆里没有提到具体的人。可以先「陪我聊聊」,聊过的内容会变成材料。')
5993
+ ? h('div', { className: 'lc-stack' },
5994
+ h(Note, { tone: undefined, icon: 'person' }, '记忆里没有提到具体的人。可以先「聊一聊」,聊过的内容会变成材料。'),
5995
+ h('div', null,
5996
+ h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
5997
+ h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里'),
5998
+ ))
5067
5999
  : h('div', { className: 'lc-stack' },
5068
6000
  people.map((p) => {
5069
6001
  const key = peopleKey(p)
@@ -5150,7 +6082,8 @@ function peopleKey(p) {
5150
6082
  // ── 让 AI 读材料 ──────────────────────────────────────────────────
5151
6083
 
5152
6084
  function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMaterials, onBack, onNeedMaterial, onAppliedCard }) {
5153
- const materials = listing?.materials ?? []
6085
+ // 备份和临时文件不算材料(见 isRealMaterial):它们点开是空的,读也读不出东西。
6086
+ const materials = (listing?.materials ?? []).filter(isRealMaterial)
5154
6087
  const cards = listing?.cards ?? []
5155
6088
  // 从别的页带过来的人,可能只有一个名字:材料刚存下、卡还没建。
5156
6089
  // 这种也该直接开始读——读出来的东西先进「建议」,采纳时才建卡。
@@ -5161,9 +6094,17 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5161
6094
  // 带过来的材料可能是一份,也可能是好几份(访谈一路上记下来的)。
5162
6095
  // 不认数组的话会变成「[一份, 另一份]」被当成一个路径,一条都勾不上,
5163
6096
  // 而一条都不勾等于全读。
6097
+ // 「读哪些材料」分三种:null = 全读(默认),[] = 一份都不读,[路径…] = 只读这几份。
6098
+ // 以前用「长度 0 就是全读」来表示「还没选」,于是把最后一份也取消勾选以后,
6099
+ // 界面悄悄回到「全读」——用户以为自己刚取消了,下一次读的却是全部。
5164
6100
  const [chosen, setChosen] = useState(() => {
5165
- if (Array.isArray(presetMaterials)) return presetMaterials.filter((x) => typeof x === 'string' && x !== '')
5166
- return presetMaterials === undefined || presetMaterials === null ? [] : [presetMaterials]
6101
+ if (Array.isArray(presetMaterials)) {
6102
+ // 显式给了清单就照单办:空清单就是「一份不读」,还给它 []。
6103
+ // 折回 null 等于「全读」——一场什么都没记下的访谈会因此把
6104
+ // 别人的材料一起读进这张卡里。
6105
+ return presetMaterials.filter((x) => typeof x === 'string' && x !== '')
6106
+ }
6107
+ return presetMaterials === undefined || presetMaterials === null ? null : [presetMaterials]
5167
6108
  })
5168
6109
  const [busy, setBusy] = useState(false)
5169
6110
  const [err, setErr] = useState(null)
@@ -5251,16 +6192,20 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5251
6192
  // 那一份,还以为读的是全部。
5252
6193
  const toggleMaterial = (path) => {
5253
6194
  setChosen((prev) => {
5254
- if (prev.length === 0) return materials.map((m) => m.path).filter((p) => p !== path)
5255
- if (prev.includes(path)) return prev.filter((p) => p !== path)
5256
- const next = [...prev, path]
5257
- // 全勾回来时收回「一个都没选」的表示,界面才会如实显示「全读」
5258
- return next.length === materials.length ? [] : next
6195
+ // 收起态(全读)里点掉一份 = 从「全读」变成「只读剩下的那几份」。
6196
+ const now = prev === null ? materials.map((m) => m.path) : prev
6197
+ const next = now.includes(path) ? now.filter((p) => p !== path) : [...now, path]
6198
+ // 又全勾回来了:收回成「全读」,界面才如实显示
6199
+ return next.length === materials.length ? null : next
5259
6200
  })
5260
6201
  }
6202
+ // 一份都没选(不是「还没选」):这时候「开始读」得置灰,否则点下去要么读全部、
6203
+ // 要么后台报「选中的材料都不存在」,两种都不是用户想要的。
6204
+ const nothingChosen = chosen !== null && chosen.length === 0
5261
6205
 
5262
6206
  // 选了哪几份就按哪几份算字数:「一条都不勾 = 全读」。
5263
- const readChars = (chosen.length > 0 ? materials.filter((m) => chosen.includes(m.path)) : materials)
6207
+ const readChars = materials
6208
+ .filter((m) => chosen === null || chosen.includes(m.path))
5264
6209
  .reduce((sum, m) => sum + (Number(m.chars) || Number(m.size) || 0), 0)
5265
6210
  const longRead = readChars > 20000
5266
6211
 
@@ -5280,14 +6225,14 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5280
6225
  about,
5281
6226
  // about 可能是卡 id,也可能只是个名字(还没建卡)。两种都照实传。
5282
6227
  name: cards.find((c) => c.id === about)?.name ?? about,
5283
- materials: chosen.length > 0 ? chosen : undefined,
6228
+ materials: chosen === null ? undefined : chosen,
5284
6229
  concept: conceptForRun === null ? undefined : conceptForRun,
5285
6230
  // 这个人是真人还是虚构角色:采纳时如果卡还不存在,就按这个身份现建。
5286
6231
  kind: String(presetAbout?.kind ?? '').trim() === 'fictional' ? 'fictional' : 'real',
5287
6232
  })
5288
6233
  if (r.ok !== true) { setErr(r.error ?? '没跑成'); return }
5289
6234
  setResult(r)
5290
- flash(`读出了 ${r.accepted} 条${r.rejected > 0 ? `,${r.rejected} 条没能核实已丢掉` : ''}`)
6235
+ flash(`读出了 ${r.accepted} 条${r.rejected > 0 ? `,${rejectedWords(r)}` : ''}`)
5291
6236
  } catch (e) {
5292
6237
  // 「连不上后台」在等了几分钟之后出现,真实原因通常不是没启动,
5293
6238
  // 而是 AI 那边卡住了、连接被断开。说实话比说套话有用。
@@ -5383,9 +6328,14 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5383
6328
  ),
5384
6329
  ),
5385
6330
 
5386
- h(Field, { label: '读哪些材料', hint: chosen.length === 0 ? '一个都不选就是全读。' : `已选 ${chosen.length} 份。` },
6331
+ h(Field, {
6332
+ label: '读哪些材料',
6333
+ hint: nothingChosen
6334
+ ? '现在一份都没选。至少选一份,或者把要读的材料挑出来。'
6335
+ : chosen === null ? '不选 = 全读。' : `已选 ${chosen.length} 份。`,
6336
+ },
5387
6337
  h('div', { className: 'lc-stack' }, materials.map((m) => {
5388
- const on = chosen.includes(m.path) || chosen.length === 0
6338
+ const on = chosen === null || chosen.includes(m.path)
5389
6339
  return h('div', {
5390
6340
  key: m.path, className: 'lc-proposal-item' + (on ? ' on' : ''),
5391
6341
  onClick: () => toggleMaterial(m.path), role: 'button', tabIndex: 0,
@@ -5402,7 +6352,7 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5402
6352
  err === null ? null : h(Err, { text: err }),
5403
6353
 
5404
6354
  h('div', { className: 'lc-row' },
5405
- h(Btn, { tone: 'analyze', big: true, onClick: run, disabled: busy || about === '' || materials.length === 0, icon: 'spark' }, busy ? '正在读…' : '开始读'),
6355
+ h(Btn, { tone: 'analyze', big: true, onClick: run, disabled: busy || about === '' || materials.length === 0 || nothingChosen, icon: 'spark' }, busy ? '正在读…' : '开始读'),
5406
6356
  busy ? h(Spinner) : null,
5407
6357
  ),
5408
6358
  // 这一趟是真等:模型先在心里想一遍再写(实测小材料也要四十秒上下,
@@ -5417,7 +6367,7 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5417
6367
  result === null ? null : h('div', null,
5418
6368
  h(Note, { tone: 'ok', icon: 'check' },
5419
6369
  h('div', null, `读出了 ${result.accepted} 条。`),
5420
- result.rejected > 0 ? h('div', { className: 'lc-meta', style: { marginTop: 3 } }, `另有 ${result.rejected} 条在材料里找不到原句,已经丢掉——AI 编的东西进不来。`) : null,
6370
+ result.rejected > 0 ? h('div', { className: 'lc-meta', style: { marginTop: 3 } }, `另有 ${rejectedWords(result)}。`) : null,
5421
6371
  ),
5422
6372
  // 写小说和酒馆里,用户要的是「读完就有一张能用的角色卡」,
5423
6373
  // 不是再去访谈一遍——虚构角色本来就没有「他是我的什么人」这种问题,
@@ -6310,6 +7260,23 @@ const PANEL_ID = 'lifecard'
6310
7260
  const PANEL_ORDER = 35
6311
7261
 
6312
7262
  function apply(ctx) {
7263
+ // 留住宿主,供 openInterviewSession 开新会话用。
7264
+ // 必须在最前面:下面拿不到 betterSidebar 会提前 return,放后面就永远是 null。
7265
+ HOST = ctx
7266
+ // 开新会话的两样能力都是可选的:有就记下来,没有就一直是 null(走退路)。
7267
+ // 不写进 inject 导出数组——那会让缺服务的干净 profile 整个 apply 不执行。
7268
+ try {
7269
+ ctx.inject?.(['remote.session'], (scoped) => {
7270
+ const got = scoped.get?.('remote.session', false)
7271
+ if (got !== undefined && got !== null) REMOTE_SESSION = got
7272
+ })
7273
+ } catch (e) { /* 老宿主没有这个服务 */ }
7274
+ try {
7275
+ ctx.inject?.(['uiWorkspace'], (scoped) => {
7276
+ const got = scoped.get?.('uiWorkspace', false)
7277
+ if (got !== undefined && got !== null) UI_WORKSPACE = got
7278
+ })
7279
+ } catch (e) { /* 老宿主没有这个服务 */ }
6313
7280
  // 样式也算副作用:跟着插件一起上手、一起回收。
6314
7281
  ctx.effect(() => ensureStyle(document), 'lifecard: 样式')
6315
7282
 
@@ -6349,7 +7316,7 @@ function apply(ctx) {
6349
7316
  ctx.effect(() => sidebar.registerTab({
6350
7317
  id: 'lifecard',
6351
7318
  title: 'Life Cards',
6352
- description: '把你认识的人和虚构角色写成档案:聊着建、导入角色卡、或从材料里读出来',
7319
+ description: '把你认识的人和虚构角色写成档案:聊一聊、导入角色卡、或从材料里读出来',
6353
7320
  icon: () => h(TabIcon),
6354
7321
  order: 40,
6355
7322
  single: true,
@@ -6371,6 +7338,13 @@ const inject = ['slots']
6371
7338
  exports.apply = apply;
6372
7339
  exports.inject = inject;
6373
7340
  exports.LifeCardTab = LifeCardTab;
7341
+ // 测试专用口子:这两条路要等宿主服务就绪(ctx.inject)才分得清,
7342
+ // 假宿主里造不出 inject,所以允许测试直接把两个服务塞进来。
7343
+ exports.__openInterviewSession = openInterviewSession;
7344
+ exports.__setHostServices = (remote, ui) => {
7345
+ REMOTE_SESSION = remote === undefined ? null : remote;
7346
+ UI_WORKSPACE = ui === undefined ? null : ui;
7347
+ };
6374
7348
  return module.exports;
6375
7349
  }
6376
7350
  });