dsh-lifecard 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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`,其余一律不碰——插件不该依赖宿主内部状态。
@@ -912,6 +1212,10 @@ function LifeCardTab(props) {
912
1212
  // 首页那几个按钮是「从头开始」的意思:上一次打开的是谁,到这一页就作废。
913
1213
  // 不这样清,刚看完某人的卡再回首页点「整理 N 份材料」,那一页会默默
914
1214
  // 还选着刚才那个人。
1215
+ // 书那一屏(BookView)自己知道手头有没有没存的正文和剧本。顶栏的返回和换门
1216
+ // 都在外面这一层,直接切屏的话那一屏就卸载了,谁也来不及问一句——
1217
+ // 人写了一段正文点顶上那个返回,字就没了,屏幕上连个提示都没有。
1218
+ // 所以 BookView 挂载时把「先收好再走」这个函数放在这里,外面切屏前先调它。
915
1219
  const go = useCallback((next) => {
916
1220
  // 离开那一屏就把带过去的东西清掉:不留着上一次的「整理谁」「读哪一份材料」,
917
1221
  // 也不留着「这张建议卡属于谁」。以前 pendingAbout 只写不清——点过一次
@@ -1006,6 +1310,43 @@ function LifeCardTab(props) {
1006
1310
  }, [pins])
1007
1311
 
1008
1312
 
1313
+ /**
1314
+ * 把一扇门收起来 / 装回来。
1315
+ *
1316
+ * 只动界面:卡、世界书、写的书、说过的场次一个字节不碰,
1317
+ * 所以「删掉」随时能反悔——这也是为什么用收起而不是真删文件。
1318
+ */
1319
+ const hideDoor = async (which) => {
1320
+ const one = DOORS.find((d) => d.id === which)
1321
+ if (one === undefined) return
1322
+ const ask = typeof window !== 'undefined' && typeof window.confirm === 'function' ? window.confirm : () => true
1323
+ const yes = ask(`把「${one.title}」这扇门收起来?\n\n里面的东西都不会删——卡、世界书、写过的书都还在原处。想用的时候在这块灰门上点一下就能装回来。`)
1324
+ if (yes !== true) return
1325
+ try {
1326
+ const r = await call('door.set', { id: which, hidden: true })
1327
+ if (r?.ok !== true) {
1328
+ setError(r?.error ?? '这扇门没能收起来,再点一次。')
1329
+ return
1330
+ }
1331
+ setDoorsOverride(Array.isArray(r.hidden_doors) ? r.hidden_doors : [])
1332
+ } catch (e) {
1333
+ setError(humanizeError(e))
1334
+ }
1335
+ }
1336
+
1337
+ const showDoor = async (which) => {
1338
+ try {
1339
+ const r = await call('door.set', { id: which, hidden: false })
1340
+ if (r?.ok !== true) {
1341
+ setError(r?.error ?? '这扇门没能装回来,再点一次。')
1342
+ return
1343
+ }
1344
+ setDoorsOverride(Array.isArray(r.hidden_doors) ? r.hidden_doors : [])
1345
+ } catch (e) {
1346
+ setError(humanizeError(e))
1347
+ }
1348
+ }
1349
+
1009
1350
  useEffect(() => {
1010
1351
  let gone = false
1011
1352
  call('features.list', {})
@@ -1019,6 +1360,15 @@ function LifeCardTab(props) {
1019
1360
  loadPins()
1020
1361
  }, [view, loadPins])
1021
1362
 
1363
+ // 用户自己在界面上收起来的门。
1364
+ //
1365
+ // 这里用「本地覆盖」而不是再挂一个 effect 去同步 state:刚点完要立刻变灰,
1366
+ // 等 refresh 回来之前界面不能还是老样子;拿到服务端结果后就以服务端为准。
1367
+ const [doorsOverride, setDoorsOverride] = useState(null)
1368
+ const hiddenDoors = doorsOverride !== null
1369
+ ? doorsOverride
1370
+ : (Array.isArray(state?.hidden_doors) ? state.hidden_doors : [])
1371
+
1022
1372
  // 门自己的那两屏直接说了算;其余屏(聊着建、卡片、分析…)沿用上次选的门。
1023
1373
  const mode = (view === VIEWS.novel || view === VIEWS.book || view === VIEWS.game) ? 'novel' : (view === VIEWS.tavern || view === VIEWS.tavernChat) ? 'tavern' : door
1024
1374
  // 回到酒馆那两屏就重新拿一遍说过的场次:刚说完、刚删完再回来,
@@ -1027,11 +1377,71 @@ function LifeCardTab(props) {
1027
1377
  if (view !== VIEWS.tavern && view !== VIEWS.tavernChat) return
1028
1378
  let gone = false
1029
1379
  call('tavern.list', {})
1030
- .then((r) => { if (!gone && r?.ok === true && Array.isArray(r.items)) setChats(r.items) })
1031
- .catch(() => { /* 取不到就空着,不影响开新的一场 */ })
1380
+ .then((r) => {
1381
+ if (gone) return
1382
+ // 读不出来的场次以前是「安静消失」:列表看着少了几场,用户只会以为
1383
+ // 自己记错了。后台早就把读不出来的份数报回来了(bad),这里要说出来。
1384
+ if (r?.ok !== true) {
1385
+ setChatsNote(String(r?.error ?? '').trim() === '' ? '说过的场次没读出来' : String(r.error))
1386
+ return
1387
+ }
1388
+ if (Array.isArray(r.items)) setChats(r.items)
1389
+ const bad = Number(r.bad ?? 0)
1390
+ setChatsNote(bad > 0 ? `有 ${bad} 场读不出来,可能文件坏了。别的场次不受影响。` : null)
1391
+ })
1392
+ .catch(() => { if (!gone) setChatsNote('说过的场次没读出来') })
1032
1393
  return () => { gone = true }
1033
1394
  }, [view])
1034
1395
 
1396
+ // 开不了新会话的时候,把那句话留在界面上让用户自己复制(见 openInterviewSession)。
1397
+ // 这几个 hook 追加在最后:hook 的顺序就是测试里各屏 presets 的槽位,插在中间
1398
+ // 会把后面每一个槽都错开一格。
1399
+ const [handoff, setHandoff] = useState(null)
1400
+ const [chatsNote, setChatsNote] = useState(null)
1401
+ // 书那一屏(BookView)自己知道手头有没有没存的正文和剧本。顶栏的返回和换门
1402
+ // 都在外面这一层,直接切屏的话那一屏就卸载了,谁也来不及问一句。
1403
+ // 所以 BookView 挂载时把「先收好再走」这个函数放在这里,切屏前先调它。
1404
+ //
1405
+ // 这三个 hook 必须排在 App 所有 hook 的最后:测试(render-all、doors-test)
1406
+ // 是按序号把预置状态摆进 hookStore 的,插在中间会把后面每个槽位都顶歪。
1407
+ const bookFlush = useRef(null)
1408
+ // 手头干净时同步返回 true:切屏不该为了「没东西要存」多等一帧。
1409
+ // 真有没存的东西才返回一个 promise,那时候等一下是对的。
1410
+ const leaveBook = useCallback(() => {
1411
+ const f = bookFlush.current
1412
+ if (typeof f !== 'function') return true
1413
+ return f()
1414
+ }, [])
1415
+ // 顶栏返回、换门都走这里:先请那一屏把没存的收好,收好了再走。
1416
+ const leaveThen = useCallback((next) => {
1417
+ const r = leaveBook()
1418
+ if (r === true) { next(); return }
1419
+ Promise.resolve(r).then((ok) => { if (ok === true) next() }).catch(() => null)
1420
+ }, [leaveBook])
1421
+
1422
+ const startInterview = useCallback((opts) => {
1423
+ const started = openInterviewSession(opts === undefined || opts === null ? {} : opts)
1424
+ const settle = (result) => {
1425
+ const done = result === undefined || result === null ? { ok: false, prompt: '', reason: '没能开成新会话' } : result
1426
+ if (done.ok === true) {
1427
+ setHandoff(null)
1428
+ // 预设没被认下来时它自己会带一句 note,那话比我编的「摆好了」有用。
1429
+ flash(done.note !== undefined ? String(done.note) : '已经在新对话里开始问了', done.note === undefined ? 'ok' : 'warn')
1430
+ return
1431
+ }
1432
+ // 不静默:把「为什么没开成」和「该复制什么」一起摆出来。
1433
+ setHandoff(done)
1434
+ }
1435
+ // openInterviewSession 现在是异步的(要先建会话、再把第一句发出去),
1436
+ // 但同步的返回(老宿主那条退路)也要照旧能用。
1437
+ if (started !== undefined && started !== null && typeof started.then === 'function') {
1438
+ setBusy('interview')
1439
+ started.then((r) => { setBusy(''); settle(r) }).catch((e) => { setBusy(''); settle({ ok: false, prompt: '', reason: humanizeError(e) }) })
1440
+ return
1441
+ }
1442
+ settle(started)
1443
+ }, [flash])
1444
+
1035
1445
  /** 打开一本书,进到那一屏。 */
1036
1446
  const openBook = (book) => {
1037
1447
  setActiveBook({ id: book?.id ?? '', title: book?.title ?? '' })
@@ -1051,6 +1461,28 @@ function LifeCardTab(props) {
1051
1461
  } catch (e) { setError(humanizeError(e)) }
1052
1462
  }
1053
1463
 
1464
+ /**
1465
+ * 从书架上拿掉一整本书。
1466
+ *
1467
+ * `novel.delete` 后台一直都有,界面从来没接过——书写歪了、试写了一本不想留的,
1468
+ * 用户只能在文件管理器里翻目录,而界面上那本书永远挂在书架上。
1469
+ * 确认要说清「章也一起没」:这一下是连目录一起删,不是收起来。
1470
+ */
1471
+ const deleteBook = async (book) => {
1472
+ const title = String(book?.title ?? book?.id ?? '').trim()
1473
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1474
+ ? window.confirm(`把《${title}》这本书拿掉?\n\n已经写好的章也一起删,删了就真没了。\n只想先别看它的话,留着不动就行——书架上多一本不碍事。`)
1475
+ : true
1476
+ if (ok !== true) return
1477
+ try {
1478
+ const r = await call('novel.delete', { id: String(book?.id ?? '') })
1479
+ if (r?.ok !== true) { setError(r?.error ?? '这本书没能删掉'); return }
1480
+ const fresh = await call('novel.books', {})
1481
+ if (fresh?.ok === true && Array.isArray(fresh.books)) setBooks(fresh.books)
1482
+ flash(`拿掉了《${title}》`)
1483
+ } catch (e) { setError(humanizeError(e)) }
1484
+ }
1485
+
1054
1486
  const pickDoor = (next) => {
1055
1487
  setDoor(next)
1056
1488
  setError(null)
@@ -1065,20 +1497,61 @@ function LifeCardTab(props) {
1065
1497
  /**
1066
1498
  * 删一张卡。
1067
1499
  *
1068
- * 先问一句:删卡是不可逆的(后台只写墓碑,界面上收不回来)。
1069
- * 问的时候要说清「哪些东西会跟着没」——关系史、口癖这些都在卡里,
1070
- * 而材料是另一份文件,不会跟着删。
1500
+ * 先问一句,并且要说清「删了以后它去哪了」:不是烧掉,是从列表里撤下去,
1501
+ * 原文还留在磁盘上——首页下面「已经撤掉的」里能找回来,也能彻底删掉。
1502
+ * 以前这里写的是「界面上收不回来」,那句话现在是错的,别改回去。
1503
+ * 材料是另一份文件,不跟着删。
1071
1504
  */
1072
1505
  const deleteCard = async (card) => {
1073
1506
  const name = String(card?.name ?? '').trim() === '' ? '这张卡' : `「${card.name}」`
1074
1507
  const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1075
- ? window.confirm(`确定删掉${name}吗?\n\n卡里写的东西(关系史、口癖、能力…)一起删掉,界面上收不回来。\n材料是另一份文件,不受影响。`)
1508
+ ? window.confirm(`确定删掉${name}吗?\n\n删掉之后,列表和 AI 都看不见它了;想反悔,去下面「已经撤掉的」里点「放回来」。\n材料是另一份文件,不受影响。`)
1076
1509
  : true
1077
1510
  if (ok !== true) return
1078
1511
  try {
1079
1512
  const r = await call('card.delete', { path: card?.path, reason: '用户在列表里删掉' })
1080
1513
  if (r?.ok !== true) { setError(r?.error ?? '没删掉'); return }
1081
- flash(`删掉了${name}`, 'ok')
1514
+ flash(`删掉了${name}。要反悔就去下面「已经撤掉的」里点「放回来」`, 'ok')
1515
+ await refresh()
1516
+ } catch (e) { setError(humanizeError(e)) }
1517
+ }
1518
+
1519
+ /** 撤掉的那张卡的称呼:卡上没名字就按文件名给一个,界面上不摆路径。 */
1520
+ const withdrawnName = (item) => (String(item?.name ?? '').trim() === '' ? cardNameFromPath(item?.path) : String(item.name))
1521
+
1522
+ /**
1523
+ * 把一张撤掉的卡放回来。
1524
+ *
1525
+ * 原文一直在磁盘上,所以这一步不发「重建」,只是让它重新出现在列表里。
1526
+ * 不弹确认:这是往回走的那一步,点错了再删一次就行。
1527
+ */
1528
+ const restoreCard = async (card) => {
1529
+ if (card?.path === undefined) return
1530
+ try {
1531
+ const r = await call('card.restore', { path: card.path })
1532
+ if (r?.ok !== true) { setError(r?.error ?? '没能放回来'); return }
1533
+ flash(`「${withdrawnName(card)}」放回来了`, 'ok')
1534
+ await refresh()
1535
+ } catch (e) { setError(humanizeError(e)) }
1536
+ }
1537
+
1538
+ /**
1539
+ * 彻底删掉一张撤掉的卡:原文一起删,删了没法反悔。
1540
+ *
1541
+ * 和「删掉」是两件不同的事,所以文案不能只写「确定删除」——
1542
+ * 用户得知道这一次是连磁盘上的原文都没了。
1543
+ */
1544
+ const purgeCard = async (card) => {
1545
+ if (card?.path === undefined) return
1546
+ const name = `「${withdrawnName(card)}」`
1547
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
1548
+ ? window.confirm(`确定把${name}彻底删掉吗?\n\n磁盘上的原文一起删,删了就真没了。\n(只是想让它先别出现?点「放回来」就行,不用删。)`)
1549
+ : true
1550
+ if (ok !== true) return
1551
+ try {
1552
+ const r = await call('card.purge', { path: card.path })
1553
+ if (r?.ok !== true) { setError(r?.error ?? '没删掉'); return }
1554
+ flash(`彻底删掉了${name}`, 'ok')
1082
1555
  await refresh()
1083
1556
  } catch (e) { setError(humanizeError(e)) }
1084
1557
  }
@@ -1188,7 +1661,15 @@ function LifeCardTab(props) {
1188
1661
  // 顶部返回一律当成「回首页」:上次打开的是谁、刚才点的是哪份材料、
1189
1662
  // 看的是哪本世界书,到这里都作废。不这样清,从 A 的卡退回来再点别人的
1190
1663
  // 材料,分析页会默默还认着 A,读出来的东西全记到 A 名下。
1191
- canBack ? h('button', { className: 'lc-btn ghost sm', onClick: () => { go(VIEWS.home); setError(null); setProposal(null); setActiveWorld(null) }, title: '回到列表', type: 'button' }, h(Icon, { name: 'back', size: 14 })) : null,
1664
+ canBack ? h('button', {
1665
+ className: 'lc-btn ghost sm',
1666
+ onClick: () => {
1667
+ // 先问这一屏有没有没存的东西(书那一屏会自己存);存不上就留在原地。
1668
+ leaveThen(() => { go(VIEWS.home); setError(null); setProposal(null); setActiveWorld(null) })
1669
+ },
1670
+ title: '回到列表',
1671
+ type: 'button',
1672
+ }, h(Icon, { name: 'back', size: 14 })) : null,
1192
1673
  h('div', { className: 'lc-grow lc-ellipsis' },
1193
1674
  h('div', { className: 'lc-title lc-ellipsis' }, titles[view] ?? 'Life Cards'),
1194
1675
  mode === 'real' && view !== VIEWS.doors
@@ -1203,7 +1684,10 @@ function LifeCardTab(props) {
1203
1684
  ? null
1204
1685
  : h('button', {
1205
1686
  className: 'lc-btn ghost sm',
1206
- onClick: () => { setView(VIEWS.doors); setError(null); setProposal(null); setActiveWorld(null); setActiveCard(null) },
1687
+ onClick: () => {
1688
+ // 换门也是离开这一屏,一样先把没存的收好。
1689
+ leaveThen(() => { setView(VIEWS.doors); setError(null); setProposal(null); setActiveWorld(null); setActiveCard(null) })
1690
+ },
1207
1691
  title: '换成另一扇门',
1208
1692
  type: 'button',
1209
1693
  }, '换门'),
@@ -1239,7 +1723,7 @@ function LifeCardTab(props) {
1239
1723
  })
1240
1724
  }
1241
1725
  // 门还没选:先问「你要用哪个」。选完才进首页,首页再按门决定露出什么。
1242
- if (view === VIEWS.doors) return h(DoorsView, { state, features, onPick: pickDoor })
1726
+ if (view === VIEWS.doors) return h(DoorsView, { state, features, hidden: hiddenDoors, onPick: pickDoor, onHide: hideDoor, onShow: showDoor })
1243
1727
  if (view === VIEWS.tavernChat) {
1244
1728
  return h(TavernView, {
1245
1729
  chat,
@@ -1273,8 +1757,12 @@ function LifeCardTab(props) {
1273
1757
  state, listing, preset: interviewFor, onRecorded: refresh, flash, mode,
1274
1758
  onDone: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home); refresh() },
1275
1759
  onAnalyze: (about) => {
1276
- const list = Array.isArray(about?.materials) ? about.materials.filter((x) => typeof x === 'string' && x !== '') : []
1277
- setMaterialFor(list.length > 0 ? list : null)
1760
+ // 这一场一路记下来的材料。空清单要照着「一份不读」传下去:
1761
+ // 折成 null 就是「全读」,用户刚聊完一个虚构角色,一点「开始读」
1762
+ // 就把别人的材料一起读了。null 只留给「没指定」——那时候才全读。
1763
+ const raw = about?.materials
1764
+ const list = Array.isArray(raw) ? raw.filter((x) => typeof x === 'string' && x !== '') : null
1765
+ setMaterialFor(list)
1278
1766
  setInterviewFor(about ?? null)
1279
1767
  setView(VIEWS.analyze)
1280
1768
  },
@@ -1284,6 +1772,8 @@ function LifeCardTab(props) {
1284
1772
  // about 是个字符串,这个人还没建卡也能分析——分析结果会进提案,
1285
1773
  // 采纳时才建卡。
1286
1774
  return h(MemoryView, {
1775
+ mode,
1776
+ onStartInterview: startInterview,
1287
1777
  onBack: () => { setInterviewFor(null); setMaterialFor(null); setView(VIEWS.home) },
1288
1778
  onDone: (about) => {
1289
1779
  // 只认那份刚写出来的材料。不带 path 的话分析页不勾任何材料,
@@ -1314,7 +1804,7 @@ function LifeCardTab(props) {
1314
1804
  // 直接退回首页,用户点了没反应,还以为坏了。现在把清单单独摊开。
1315
1805
  return activeCard === null
1316
1806
  ? 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 })
1807
+ ? 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
1808
  : h('div', { className: 'lc-pad lc-stack' },
1319
1809
  proposal.about === undefined || String(proposal.about).trim() === ''
1320
1810
  ? null
@@ -1355,9 +1845,10 @@ function LifeCardTab(props) {
1355
1845
  } catch (e) { setError(humanizeError(e)) }
1356
1846
  },
1357
1847
  onDeleted: async () => { setActiveCard(null); setView(VIEWS.home); await refresh() },
1358
- onInterview: (preset) => { setInterviewFor(preset); setView(VIEWS.interview) },
1848
+ // 补卡不再进插件里的访谈页,改成开一个新会话(见 openInterviewSession)。
1849
+ mode,
1850
+ onStartInterview: startInterview,
1359
1851
  onAnalyze: () => { setInterviewFor({ id: activeCard.data?.id, name: activeCard.data?.name }); setView(VIEWS.analyze) },
1360
- onTavern: mode === 'tavern' ? (preset) => startTavern(preset) : undefined,
1361
1852
  })
1362
1853
  case VIEWS.newCard:
1363
1854
  return h(NewCardView, {
@@ -1375,7 +1866,7 @@ function LifeCardTab(props) {
1375
1866
  })
1376
1867
  case VIEWS.world:
1377
1868
  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 })
1869
+ ? 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
1870
  : h(WorldView, {
1380
1871
  world: activeWorld,
1381
1872
  listing,
@@ -1391,6 +1882,7 @@ function LifeCardTab(props) {
1391
1882
  return h(BookView, {
1392
1883
  bookId: String(activeBook?.id ?? ''),
1393
1884
  flash,
1885
+ flushRef: bookFlush,
1394
1886
  onBack: () => { setActiveBook(null); setView(VIEWS.novel) },
1395
1887
  })
1396
1888
  case VIEWS.doctor:
@@ -1400,7 +1892,7 @@ function LifeCardTab(props) {
1400
1892
  case VIEWS.jobs:
1401
1893
  return h(JobsView, { onBack: () => setView(VIEWS.home), flash })
1402
1894
  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 })
1895
+ 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
1896
  }
1405
1897
  }
1406
1898
 
@@ -1415,6 +1907,31 @@ function LifeCardTab(props) {
1415
1907
  h('div', { style: { whiteSpace: 'pre-wrap' } }, humanizeError(error)),
1416
1908
  h('div', { style: { marginTop: 6 } }, h(Btn, { size: 'sm', onClick: () => setError(null) }, '知道了'))))
1417
1909
  : null,
1910
+ // 开不了新会话时(老版本宿主)退化成这样:话摆在这儿,用户自己复制过去。
1911
+ // 不静默失败——点了没反应,比说清「这一步要你手动搬一下」更让人困惑。
1912
+ handoff === null || handoff.ok === true ? null : h('div', { style: { padding: '10px 12px 0' }, 'data-interview-handoff': '1' },
1913
+ h(Note, { tone: 'warn', icon: 'warning' },
1914
+ h('div', null, '这个版本不支持直接开会话,把下面这句复制到新对话里:'),
1915
+ h('textarea', {
1916
+ readOnly: true,
1917
+ rows: 3,
1918
+ spellCheck: false,
1919
+ className: 'lc-input',
1920
+ value: String(handoff.prompt ?? ''),
1921
+ style: { marginTop: 8, width: '100%', resize: 'vertical', boxSizing: 'border-box' },
1922
+ onFocus: (e) => {
1923
+ try { e?.target?.select?.() } catch (err) { /* 选不中也还能手动复制 */ }
1924
+ },
1925
+ }),
1926
+ h('div', { className: 'lc-row', style: { marginTop: 8 } },
1927
+ h(Btn, {
1928
+ size: 'sm',
1929
+ icon: 'check',
1930
+ onClick: () => {
1931
+ try { globalThis?.navigator?.clipboard?.writeText?.(String(handoff.prompt ?? '')) } catch (err) { /* 复制不了就手动选 */ }
1932
+ },
1933
+ }, '复制'),
1934
+ h(Btn, { size: 'sm', onClick: () => setHandoff(null) }, '知道了')))),
1418
1935
  body(),
1419
1936
  ),
1420
1937
  )
@@ -1497,19 +2014,22 @@ const DOORS = [
1497
2014
  id: 'real', icon: 'people', tone: 'interview',
1498
2015
  title: '真实人物记录',
1499
2016
  desc: '身边的人:他做过什么、怎么说话、你们之间发生过什么。',
1500
- bullets: ['聊着建,把他说的话记下来', '贴材料,让 AI 读出能核实的内容', '找工作:贴招聘说明、练面试'],
2017
+ bullets: ['聊一聊,它会问你几个具体的问题', '贴材料,让 AI 读出能核实的内容', '找工作:贴招聘说明、练面试'],
2018
+ modules: ['人物卡', '访谈记录', '材料与建议', '简历与规划'],
1501
2019
  },
1502
2020
  {
1503
2021
  id: 'novel', icon: 'book', tone: 'import',
1504
2022
  title: '写小说',
1505
2023
  desc: '虚构的角色和世界:先把人立起来,再一章一章往下写。',
1506
- bullets: ['立角色:性格、口癖、绝不会做的事', '写世界:地方、规矩、里面还有谁'],
2024
+ bullets: ['立角色:性格、口癖、绝不会做的事', '写世界:地方、规矩、里面还有谁', '一章一章往下写,能导出整本'],
2025
+ modules: ['角色卡', '世界书', '书架与章节', '文字模拟游戏', '写作预设'],
1507
2026
  },
1508
2027
  {
1509
2028
  id: 'tavern', icon: 'chat', tone: 'analyze',
1510
2029
  title: '酒馆',
1511
2030
  desc: '拿一张角色卡,和 TA 你一句一句地演。',
1512
- bullets: ['挑一张角色卡就开演', '拿现实里的人来演也行(复制一份,原卡不动)'],
2031
+ bullets: ['挑一张角色卡就开演', '拿现实里的人来演也行(复制一份,原卡不动)', '演到一半能收个尾,把这段备忘接着用'],
2032
+ modules: ['角色卡', '会话存档', '演法与语气预设'],
1513
2033
  },
1514
2034
  ]
1515
2035
 
@@ -1524,12 +2044,16 @@ const DOORS = [
1524
2044
  * 顶上一条门楣色块、中间竖着写门名、底部一道门槛写着「推门进去」。
1525
2045
  * 三扇并排、各占三分之一宽、高度撑满;窄窗口自动换行。
1526
2046
  */
1527
- function DoorsView({ onPick, state, features }) {
2047
+ function DoorsView({ onPick, state, features, hidden, onHide, onShow }) {
1528
2048
  const workspace = String(state?.workspace ?? '')
1529
2049
  // 没装的门不摆出来。`features === null` 时全摆(还没问到,别闪一下少一扇)。
1530
- const doors = (features === null || features === undefined)
2050
+ const installed = (features === null || features === undefined)
1531
2051
  ? DOORS
1532
2052
  : DOORS.filter((d) => (d.id === 'real' ? true : d.id === 'novel' ? features.novel !== false : features.tavern !== false))
2053
+ // 用户自己收起来的门:不摆出来,改摆一块灰黑的死门(悬停能装回来)。
2054
+ const gone = Array.isArray(hidden) ? hidden : []
2055
+ const doors = installed.filter((d) => !gone.includes(d.id))
2056
+ const deadDoors = installed.filter((d) => gone.includes(d.id))
1533
2057
  const tint = {
1534
2058
  real: {
1535
2059
  fg: 'var(--lc-interview)', bg: 'var(--lc-interview-soft)', icon: 'people',
@@ -1641,14 +2165,57 @@ function DoorsView({ onPick, state, features }) {
1641
2165
  background: t.fg, opacity: .55,
1642
2166
  },
1643
2167
  }),
2168
+ // 门板与门缝:一块纯色方块看起来像色卡,加了这两层才像门。
2169
+ h('span', { className: 'lc-door-panel', 'aria-hidden': 'true' }),
2170
+ h('span', { className: 'lc-door-hinge', 'aria-hidden': 'true' }),
2171
+ h('span', { className: 'lc-door-jamb', 'aria-hidden': 'true' }),
2172
+ // ── 删掉这扇门:鼠标放上来才露出来(免得误点)──
2173
+ h('button', {
2174
+ type: 'button',
2175
+ className: 'lc-door-x',
2176
+ title: `把「${door.title}」这扇门收起来`,
2177
+ 'data-door-hide': door.id,
2178
+ onClick: (e) => {
2179
+ e?.stopPropagation?.()
2180
+ onHide?.(door.id)
2181
+ },
2182
+ // 叉容易看成「关闭」,用垃圾桶才一眼知道是「删掉/收起来」。
2183
+ }, h(Icon, { name: 'trash', size: 13 })),
1644
2184
  )
1645
2185
  }),
2186
+ // ── 收起来的门:一块灰黑的死门,鼠标放上去露出装回来的按钮 ──
2187
+ deadDoors.map((door) => h('div', {
2188
+ key: `dead-${door.id}`,
2189
+ className: 'lc-door-dead',
2190
+ 'data-door-dead': door.id,
2191
+ },
2192
+ h('div', { className: 'lc-door-dead-icon' }, h(Icon, { name: (tint[door.id] ?? tint.real).icon, size: 34 })),
2193
+ h('div', { className: 'lc-door-dead-name' }, door.title),
2194
+ h('div', {
2195
+ className: 'lc-door-back',
2196
+ },
2197
+ h('button', {
2198
+ type: 'button',
2199
+ className: 'lc-door-back-btn',
2200
+ title: `把「${door.title}」装回来`,
2201
+ 'data-door-show': door.id,
2202
+ onClick: () => onShow?.(door.id),
2203
+ }, h(Icon, { name: 'download', size: 26 })),
2204
+ h('div', { style: { fontSize: 13.5, fontWeight: 600 } }, '装回来'),
2205
+ // 分模块列清楚:装回来只是把门重新露出来,里面的东西一样不少。
2206
+ (door.modules ?? []).length === 0 ? null : h('div', {
2207
+ className: 'lc-door-dead-mods',
2208
+ style: { fontSize: 11.5, color: '#cfcfcf', textAlign: 'center', padding: '0 10px', lineHeight: 1.6 },
2209
+ }, (door.modules ?? []).join(' · ')),
2210
+ ),
2211
+ )),
1646
2212
  ),
1647
- workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } }, '档案就在你选的那个文件夹里'),
2213
+ workspace === '' ? null : h('div', { className: 'lc-meta', style: { flex: '0 0 auto', paddingTop: 10 } },
2214
+ '档案就在你选的那个文件夹里。想让它开口说话,聊天前先在顶部把预设切成「LC 酒馆 / LC 小说 / LC 现实」——那张卡接在预设后面,不切预设带不进去。'),
1648
2215
  )
1649
2216
  }
1650
2217
 
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 }) {
2218
+ 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
2219
  // 这扇门是不是「真实人物记录」。写小说、酒馆那两扇门里不该出现
1653
2220
  // 「贴一份招聘说明」「从记忆里认人」这类动作——那是记录真人才用得上的。
1654
2221
  const isReal = mode !== 'novel' && mode !== 'tavern'
@@ -1657,6 +2224,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1657
2224
  const fictionActionTone = mode === 'tavern' ? 'analyze' : 'import'
1658
2225
  const [q, setQ] = useState('')
1659
2226
  const cards = listing?.cards ?? []
2227
+ // 「已经撤掉的」:删过的卡还留在磁盘上,列表接口单独把它们带回来。
2228
+ // 没有这一栏的时候,删掉的卡在界面上就彻底消失了——想反悔没入口,
2229
+ // 想清理也找不到那条路,用户只能去翻文件夹。
2230
+ const withdrawn = Array.isArray(listing?.withdrawn) ? listing.withdrawn : []
1660
2231
  const filtered = useMemo(() => {
1661
2232
  const needle = q.trim().toLowerCase()
1662
2233
  if (needle === '') return cards
@@ -1677,7 +2248,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1677
2248
  const isFiction = hit !== undefined && hit.kind === 'fictional'
1678
2249
  return isFiction === (mode !== 'real')
1679
2250
  })
1680
- const materials = listing?.materials ?? []
2251
+ // 备份文件和临时文件不是材料:存材料时是先写临时文件再改名,改名那一步
2252
+ // 被打断就会留下 `.妈妈.md.bak-1234`。它一直被当成一份材料摆在列表里,
2253
+ // 用户看到两份「妈妈」、点开其中一份是空的,还以为自己写丢了。
2254
+ const materials = (listing?.materials ?? []).filter(isRealMaterial)
1681
2255
  // 搜索也要筛材料:搜一个人的名字,上面卡筛掉了、下面材料还整整齐齐列着,
1682
2256
  // 看着像「搜到了这一份」,其实根本没筛。
1683
2257
  const shownMaterials = useMemo(() => {
@@ -1699,16 +2273,43 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1699
2273
  return allWorlds.filter((w) => `${w.name ?? ''} ${w.id ?? ''} ${w.genre ?? ''}`.toLowerCase().includes(needle))
1700
2274
  }, [allWorlds, q])
1701
2275
  const byKind = useMemo(() => {
2276
+
1702
2277
  const real = filtered.filter((c) => c.kind === 'real' || c.kind === 'self' || c.kind === 'hybrid')
1703
2278
  const fic = filtered.filter((c) => c.kind === 'fictional')
1704
2279
  const other = filtered.filter((c) => !['real', 'self', 'hybrid', 'fictional'].includes(c.kind))
1705
2280
  return { real, fic, other }
1706
2281
  }, [filtered])
2282
+
2283
+ // 右上角圆点:绿 = 这扇门现在用它,红 = 不用。再点一次绿的就取消。
2284
+ // 写成普通函数(不是 hook),这样不动 hook 槽位。
2285
+ const togglePin = (card) => {
2286
+ const id = String(card?.id ?? '')
2287
+ if (id === '') return
2288
+ onPickPin?.(String(pinId ?? '') === id ? '' : id)
2289
+ }
1707
2290
  // 酒馆那扇门里,现实里的人默认收起来:一进去先看见父母、同学、同事的一排卡,
1708
2291
  // 会让人不太舒服,也分不清哪些是拿来演的。想看的时候再展开。
1709
2292
  const [showRealForRole, setShowRealForRole] = useState(false)
1710
2293
  // 正在问「要不要复制一份来演」的那张卡
1711
2294
  const [forkAsk, setForkAsk] = useState(null)
2295
+ // 「已经撤掉的」默认收起来:它不该跟正常的卡抢位置,但入口必须看得见。
2296
+ const [showWithdrawn, setShowWithdrawn] = useState(false)
2297
+ // 搜索也要筛这一栏。只筛上面的卡、下面还整整齐齐列着撤掉的卡,
2298
+ // 看着像「搜到了」,其实没筛——上面材料那栏踩过同一个坑。
2299
+ const shownWithdrawn = useMemo(() => {
2300
+ const needle = q.trim().toLowerCase()
2301
+ if (needle === '') return withdrawn
2302
+ return withdrawn.filter((w) => `${w.name ?? ''} ${w.id ?? ''}`.toLowerCase().includes(needle))
2303
+ }, [withdrawn, q])
2304
+ const withdrawnBlock = shownWithdrawn.length === 0
2305
+ ? null
2306
+ : h(WithdrawnSection, {
2307
+ items: shownWithdrawn,
2308
+ open: showWithdrawn,
2309
+ onToggle: () => setShowWithdrawn(!showWithdrawn),
2310
+ onRestore: onRestoreCard,
2311
+ onPurge: onPurgeCard,
2312
+ })
1712
2313
 
1713
2314
  // 第一次进来时那段介绍。只出现一次,点过「知道了」就不再出现。
1714
2315
  // 刻意只有四五行:介绍写长了没人读,读的人也只想知道「这玩意儿干吗的、从哪儿下手」。
@@ -1733,7 +2334,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1733
2334
  // 「还没有档案」这句只在真的什么都没有时说。以前只看卡和世界书,
1734
2335
  // 于是刚把一段文字存成材料、还没建卡的人回首页会看到一片空白,
1735
2336
  // 以为刚才没存上,又贴一遍——材料就多出一份重复的。
1736
- if (cards.length === 0 && allWorlds.length === 0 && materials.length === 0 && proposals.length === 0) {
2337
+ if (cards.length === 0 && withdrawn.length === 0 && allWorlds.length === 0 && materials.length === 0 && proposals.length === 0) {
1737
2338
  // 同一个空库,三扇门该给三条不同的路:写小说的人不需要「访谈」,
1738
2339
  // 记录真人的人也不需要「先写一章」。
1739
2340
  return h('div', { className: 'lc-pad lc-stack' },
@@ -1743,17 +2344,19 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1743
2344
  h('h3', null, isReal ? '还没有档案' : '还什么都没有'),
1744
2345
  h('div', { className: 'lc-meta' }, '选一个开始的方式,随时可以换别的:'),
1745
2346
  ),
1746
- // 三扇门第一块都给「聊着建」:那是这个插件最好上手的入口。
1747
- // 差别只在说什么话——建真人问的是「他是我的什么人」,
1748
- // 建角色问的是「TA 一张嘴什么感觉」。
2347
+ // 三扇门第一块都是「聊一聊」:那是这个插件最好上手的入口。
2348
+ //
2349
+ // 点了之后开的不是插件里的访谈页,而是一个新会话——问法那一套东西
2350
+ // 在 /lifecard-interview 那个 skill 里,只有一份;这边再演一遍,
2351
+ // 两边早晚会不是同一个东西。
1749
2352
  h(Action, {
1750
2353
  tone: fictionActionTone,
1751
2354
  icon: 'chat',
1752
- title: isReal ? '陪我聊聊,边聊边建' : (mode === 'tavern' ? '聊着立一个能演的角色' : '聊着立一个小说角色'),
2355
+ title: '聊一聊(新开一个对话)',
1753
2356
  desc: isReal
1754
- ? '它会问几个具体的问题。答不上来就跳过,一句也不想说也行。'
1755
- : '先问 TA 怎么说话、什么情况下会变脸,比填空白表快。',
1756
- onClick: () => onNavigate(VIEWS.interview),
2357
+ ? '会在新对话里问,答完 AI 自己写进卡里。答不上来就跳过,一句也不想说也行。'
2358
+ : '会在新对话里问,答完 AI 自己写进卡里。先问 TA 怎么说话、什么情况下会变脸,比填空白表快。',
2359
+ onClick: () => onStartInterview({ about: '', mode }),
1757
2360
  }),
1758
2361
  h(Action, {
1759
2362
  tone: 'import', icon: 'import',
@@ -1777,6 +2380,17 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1777
2380
  : '小说片段、人物小传、你写的设定都行。读出来的东西先给你看,你点了才写进卡。',
1778
2381
  onClick: () => onNavigate(VIEWS.import),
1779
2382
  }),
2383
+ // 空库的时候也有话要说:说过的场次读不出来、有文件读不了,
2384
+ // 这些跟「有没有卡」无关,不能因为还没建档就当没这回事。
2385
+ mode === 'tavern' && String(chatsNote ?? '').trim() !== ''
2386
+ ? h(Note, { tone: 'warn', icon: 'warning' }, String(chatsNote))
2387
+ : null,
2388
+ (listing?.errors ?? []).length > 0
2389
+ ? h(Note, { tone: 'warn', icon: 'warning' },
2390
+ `有 ${listing.errors.length} 个文件读不了${unreadableNames(listing.errors) === '' ? '' : `(${unreadableNames(listing.errors)})`},没影响别的。`)
2391
+ : null,
2392
+ // 卡全删光的时候这一屏尤其重要:不给这一段,「还没有档案」就是死结。
2393
+ withdrawnBlock,
1780
2394
  )
1781
2395
  }
1782
2396
 
@@ -1788,7 +2402,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1788
2402
  ),
1789
2403
 
1790
2404
  h('div', { className: 'lc-row', style: { marginTop: 2 } },
1791
- h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onNavigate(VIEWS.interview) }, isReal ? '聊着建' : '聊着立一个人'),
2405
+ h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
1792
2406
  h(Btn, { tone: 'import', size: 'sm', icon: 'import', onClick: () => onNavigate(VIEWS.import) }, '导入'),
1793
2407
  isReal
1794
2408
  ? h(Btn, { tone: 'analyze', size: 'sm', icon: 'person', onClick: () => onNavigate(VIEWS.memory), title: '从你写过的记忆里认出身边的人' }, '从记忆里认人')
@@ -1806,6 +2420,8 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1806
2420
  ? h(Btn, { tone: 'analyze', size: 'sm', icon: 'spark', onClick: () => onNavigate(VIEWS.analyze) }, isReal ? `整理 ${materials.length} 份材料` : `读那 ${materials.length} 段材料`)
1807
2421
  : null,
1808
2422
  ),
2423
+ // 按钮上一句「新开一个对话」,总会有人以为点完还在这里问。
2424
+ h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里'),
1809
2425
 
1810
2426
  // 一眼看到「这里有多少东西」:以前首页只有标题和一排按钮,一大片空。
1811
2427
  // 数字本身就是内容,也让人知道还有多少没用起来。
@@ -1845,15 +2461,18 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1845
2461
  (books ?? []).length === 0
1846
2462
  ? h('div', { className: 'lc-meta', style: { lineHeight: 1.7 } },
1847
2463
  '还没有书。新建一本,让 AI 先想大纲,再一章一章写。')
1848
- : h('div', { className: 'lc-stack' }, (books ?? []).map((b) => h('button', {
2464
+ : h('div', { className: 'lc-stack' }, (books ?? []).map((b) => h('div', {
1849
2465
  key: b.id,
1850
2466
  className: 'lc-card-item',
1851
- type: 'button',
1852
- onClick: () => onOpenBook?.(b),
1853
- style: { textAlign: 'left', font: 'inherit', color: 'inherit', width: '100%' },
2467
+ style: { cursor: 'default' },
1854
2468
  },
1855
2469
  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 } },
2470
+ h('button', {
2471
+ className: 'lc-btn ghost',
2472
+ type: 'button',
2473
+ onClick: () => onOpenBook?.(b),
2474
+ style: { flex: 1, minWidth: 0, textAlign: 'left', font: 'inherit', color: 'inherit', background: 'transparent', border: 'none', padding: 0, cursor: 'pointer' },
2475
+ },
1857
2476
  h('div', { className: 'lc-ellipsis', style: { fontWeight: 650 } }, String(b.title ?? b.id)),
1858
2477
  h('div', { className: 'lc-meta' },
1859
2478
  [`${b.chapters ?? 0} 章`, `${Math.max(1, Math.round((b.words ?? 0) / 1000))} 千字`]
@@ -1861,6 +2480,10 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1861
2480
  .join(' · ')),
1862
2481
  String(b.idea ?? '').trim() === '' ? null : h('div', { className: 'lc-meta lc-ellipsis' }, String(b.idea)),
1863
2482
  ),
2483
+ // 书写歪了、试写一本不想留的:以前界面里没有任何出口,书永远挂在书架上。
2484
+ onDeleteBook === undefined
2485
+ ? null
2486
+ : h(Btn, { size: 'sm', ghost: true, icon: 'trash', onClick: () => onDeleteBook(b), title: `不要《${String(b.title ?? b.id)}》了` }, '不要这本了'),
1864
2487
  ))),
1865
2488
  h('div', { className: 'lc-row', style: { marginTop: 8 } },
1866
2489
  h(Btn, { size: 'sm', tone: 'import', icon: 'plus', onClick: () => onCreateBook?.() }, '新建一本书'),
@@ -1895,7 +2518,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1895
2518
  ? (isReal
1896
2519
  ? h('div', null,
1897
2520
  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 }))),
2521
+ 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
2522
  )
1900
2523
  // 同一个文件夹里可能两样都有。这扇门不直接铺开真人,但也不能装作没有——
1901
2524
  // 用户会以为卡丢了。收起来一行,想看再展开,展开后是「复制一份来演」。
@@ -1927,28 +2550,21 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1927
2550
  ))
1928
2551
  : null,
1929
2552
 
1930
- // 「现在用哪张」:写小说、酒馆那两扇门里演谁 / 写谁不用每次现挑;
1931
- // 真实人物那扇门用它决定首页先给谁。存在这个文件夹的 config.json 里。
2553
+ // 「这扇门用哪张卡」:不再用下拉框挑,而是每张卡右上角一个圆点——
2554
+ // 绿色 = 这扇门用它,红色 = 不用。再点一下绿的就取消(等于「不挑卡」)。
2555
+ // 存在这个文件夹的 config.json 里。
1932
2556
  (() => {
1933
2557
  const pool = isReal ? byKind.real : byKind.fic
1934
2558
  if (pool.length === 0) return null
1935
- const label = isReal ? '这扇门先看谁' : (mode === 'tavern' ? '现在演谁' : '现在写谁')
1936
2559
  const chosen = String(pinId ?? '')
1937
2560
  const hit = chosen === '' ? undefined : pool.find((c) => String(c.id ?? '') === chosen)
1938
- // 空着也是一档:不挑卡。用户按一下下拉里的第一项就能取消选择,
1939
- // 之后写小说 / 演都从零开始,不读卡上的设定。
2561
+ const label = isReal ? '这扇门先看谁' : (mode === 'tavern' ? '现在演谁' : '现在写谁')
1940
2562
  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' }, '说「演他」「写他」就默认用这张'),
2563
+ h('div', { className: 'lc-row', style: { marginTop: 10, marginBottom: 2, gap: 8, flexWrap: 'wrap' } },
2564
+ h('span', { className: 'lc-meta', style: { flexShrink: 0 } }, `${label}:`),
2565
+ hit === undefined
2566
+ ? h('span', { className: 'lc-meta' }, '点卡右上角的圆点挑一张(绿 = 用它,红 = 不用)')
2567
+ : h('span', { className: 'lc-meta' }, `现在是「${String(hit.name ?? '')}」,点那个绿点可以取消`),
1952
2568
  ),
1953
2569
  chosen !== '' ? null : h('div', { className: 'lc-meta', style: { marginTop: 2 } },
1954
2570
  isReal
@@ -1962,17 +2578,19 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1962
2578
  byKind.fic.length > 0
1963
2579
  ? h('div', null,
1964
2580
  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 }))),
2581
+ 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
2582
  )
1967
2583
  : null,
1968
2584
 
1969
2585
  byKind.other.length > 0
1970
2586
  ? h('div', null,
1971
2587
  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 }))),
2588
+ 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
2589
  )
1974
2590
  : null,
1975
2591
 
2592
+ withdrawnBlock,
2593
+
1976
2594
  // 材料单独一栏。以前材料只在「更多工具」里报个数字,用户从记忆里提出来
1977
2595
  // 一堆东西之后回首页找不到——不知道存哪了,也没法看、没法删。
1978
2596
  !isReal || shownMaterials.length === 0
@@ -1993,7 +2611,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
1993
2611
  ))),
1994
2612
  ),
1995
2613
 
1996
- q.trim() !== '' && filtered.length === 0 && worlds.length === 0 && shownMaterials.length === 0
2614
+ q.trim() !== '' && filtered.length === 0 && worlds.length === 0 && shownMaterials.length === 0 && shownWithdrawn.length === 0
1997
2615
  ? h('div', { className: 'lc-meta', style: { textAlign: 'center', padding: 12 } }, '没找到。换个词试试?')
1998
2616
  : null,
1999
2617
 
@@ -2023,7 +2641,7 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2023
2641
  h('div', { className: 'lc-meta' },
2024
2642
  `${p.accepted} 条可以采用`,
2025
2643
  (p.adopted ?? 0) > 0 ? ` · 已经写进去 ${p.adopted} 条` : '',
2026
- p.rejected > 0 ? ` · ${p.rejected} 条没能核实,已丢掉` : '',
2644
+ rejectedWords(p) === '' ? '' : ` · ${rejectedWords(p)}`,
2027
2645
  ' · ', shortDate(p.generated_at)),
2028
2646
  ),
2029
2647
  ))),
@@ -2036,7 +2654,13 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2036
2654
  : null,
2037
2655
 
2038
2656
  (listing?.errors ?? []).length > 0
2039
- ? h(Note, { tone: 'warn', icon: 'warning' }, `有 ${listing.errors.length} 个文件读不了,没影响别的。`)
2657
+ ? h(Note, { tone: 'warn', icon: 'warning' },
2658
+ `有 ${listing.errors.length} 个文件读不了${unreadableNames(listing.errors) === '' ? '' : `(${unreadableNames(listing.errors)})`},没影响别的。`)
2659
+ : null,
2660
+
2661
+ // 说过的场次里读不出来的那几场,得说出来:它们以前是安静消失的。
2662
+ mode === 'tavern' && String(chatsNote ?? '').trim() !== ''
2663
+ ? h(Note, { tone: 'warn', icon: 'warning' }, String(chatsNote))
2040
2664
  : null,
2041
2665
 
2042
2666
  // ── 收起来的「更多」──
@@ -2068,60 +2692,195 @@ function HomeView({ state, listing, mode, onOpen, onOpenWorld, onNavigate, onPro
2068
2692
  )
2069
2693
  }
2070
2694
 
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' } },
2695
+ /**
2696
+ * 「已经撤掉的」这一块。
2697
+ *
2698
+ * 删过的卡并没有从磁盘上消失,只是不再出现在列表、导出和 AI 眼里。
2699
+ * 以前界面上完全没有这一栏,于是两种情况都没路走:
2700
+ * 删错了想找回来,找不到;想彻底清掉,也找不到。
2701
+ *
2702
+ * 这里把三条路一次摆出来:
2703
+ * - 看得见:标题里带张数,展开就是一条一行;
2704
+ * - 放回来:重新回到上面的列表,什么都不用重写;
2705
+ * - 彻底删掉:连磁盘上的原文一起删,删了就真没了,所以要点一次确认。
2706
+ *
2707
+ * 文案只说人话:不写路径、不写文件后缀、不写接口名。
2708
+ */
2709
+ function WithdrawnSection({ items, open, onToggle, onRestore, onPurge }) {
2710
+ const rows = Array.isArray(items) ? items : []
2711
+ if (rows.length === 0) return null
2712
+ return h('div', { 'data-withdrawn-section': '' },
2076
2713
  h('button', {
2714
+ className: 'lc-btn ghost sm',
2077
2715
  type: 'button',
2078
- className: 'lc-row',
2079
- onClick: () => onOpen(card),
2716
+ 'data-withdrawn-toggle': '',
2717
+ 'aria-expanded': open === true,
2718
+ onClick: onToggle,
2719
+ style: { width: '100%', justifyContent: 'flex-start' },
2720
+ },
2721
+ h('span', { style: { display: 'inline-flex', transform: open === true ? 'rotate(90deg)' : 'none', transition: 'transform .12s' } }, h(Icon, { name: 'chevron', size: 12 })),
2722
+ h('span', null, `已经撤掉的 · ${rows.length}`),
2723
+ h('span', { className: 'lc-meta', style: { marginLeft: 4 } }, '(看不见,但原文还在)'),
2724
+ h('span', { style: { flex: '1 1 auto' } }),
2725
+ h('span', { className: 'lc-meta' }, open === true ? '收起' : '展开'),
2726
+ ),
2727
+ open !== true
2728
+ ? null
2729
+ : h('div', { className: 'lc-stack', style: { marginTop: 8 } },
2730
+ h('div', { className: 'lc-meta', style: { lineHeight: 1.7 } },
2731
+ '「放回来」会让它回到上面的列表;「彻底删掉」会把磁盘上的原文一起删掉,删了就真没了。'),
2732
+ rows.map((item) => {
2733
+ const name = String(item?.name ?? '').trim() === '' ? cardNameFromPath(item?.path) : String(item.name)
2734
+ return h('div', {
2735
+ key: item?.path ?? name,
2736
+ className: 'lc-card-item',
2737
+ 'data-withdrawn-row': item?.path ?? '',
2738
+ style: { cursor: 'default' },
2739
+ },
2740
+ h('div', { className: 'lc-grow lc-ellipsis', style: { fontWeight: 600, minWidth: 0 } }, name),
2741
+ h('button', {
2742
+ type: 'button',
2743
+ className: 'lc-btn sm',
2744
+ 'data-withdrawn-restore': item?.path ?? '',
2745
+ title: `把「${name}」放回来`,
2746
+ onClick: () => onRestore?.(item),
2747
+ }, h(Icon, { name: 'back', size: 13 }), h('span', null, '放回来')),
2748
+ h('button', {
2749
+ type: 'button',
2750
+ className: 'lc-btn sm',
2751
+ 'data-withdrawn-purge': item?.path ?? '',
2752
+ title: `把「${name}」彻底删掉`,
2753
+ onClick: () => onPurge?.(item),
2754
+ }, h(Icon, { name: 'trash', size: 13 }), h('span', null, '彻底删掉')),
2755
+ )
2756
+ }),
2757
+ ),
2758
+ )
2759
+ }
2760
+
2761
+ function CardRow({ card, onOpen, photo, onDelete, onEdit, pinned, onTogglePin }) {
2762
+ // 「一张卡」而不是「一行字」:正面只有头像和名字,名字下面一个「详细信息」;
2763
+ // 直接点卡片,卡片翻过来露出背面的简介,再点一下翻回来。
2764
+ // 翻面用 CSS 3D(transform + backface-visibility),没有 JS 动画成本。
2765
+ const [flipped, setFlipped] = useState(false)
2766
+ const name = String(card.name ?? '').trim() === '' ? '(还没起名字)' : card.name
2767
+ const intro = String(card.intro ?? '').trim()
2768
+ const face = {
2769
+ position: 'absolute', inset: 0, borderRadius: 14, border: '1px solid var(--lc-line)',
2770
+ background: 'var(--lc-panel)', overflow: 'hidden', display: 'flex', flexDirection: 'column',
2771
+ backfaceVisibility: 'hidden', WebkitBackfaceVisibility: 'hidden',
2772
+ boxShadow: '0 10px 22px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .55)',
2773
+ }
2774
+ const iconBtn = (opts) => h('button', {
2775
+ type: 'button',
2776
+ title: opts.title,
2777
+ 'data-card-action': opts.act,
2778
+ onClick: (e) => { e?.stopPropagation?.(); opts.onClick() },
2779
+ style: {
2780
+ width: 26, height: 26, borderRadius: 9, padding: 0, cursor: 'pointer', flex: '0 0 auto',
2781
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
2782
+ border: '1px solid var(--lc-line)', background: 'rgba(255,255,255,.82)', color: 'var(--lc-ink-2)',
2783
+ boxShadow: '0 1px 0 rgba(255,255,255,.7), 0 2px 4px rgba(0,0,0,.08)',
2784
+ },
2785
+ }, h(Icon, { name: opts.icon, size: 13 }))
2786
+
2787
+ return h('div', {
2788
+ className: 'lc-fcard',
2789
+ style: { flex: '1 1 150px', maxWidth: 210, minWidth: 132, perspective: 900 },
2790
+ },
2791
+ h('div', {
2792
+ style: {
2793
+ position: 'relative', width: '100%', aspectRatio: '3 / 4',
2794
+ transformStyle: 'preserve-3d', transition: 'transform .42s cubic-bezier(.2, .7, .3, 1)',
2795
+ transform: flipped ? 'rotateY(180deg)' : 'none',
2796
+ },
2797
+ },
2798
+ // ── 正面:头像 + 名字 + 「详细信息」 ───────────────────────────────────
2799
+ h('div', {
2800
+ style: face,
2801
+ 'data-face': 'front',
2802
+ onClick: () => setFlipped(true),
2803
+ },
2804
+ h('div', { className: 'lc-row', style: { padding: '8px 8px 0 8px', gap: 6, alignItems: 'flex-start' } },
2805
+ onTogglePin === undefined ? null : h('button', {
2806
+ type: 'button',
2807
+ title: pinned === true
2808
+ ? `这扇门现在用的是「${name}」,点一下取消`
2809
+ : `点一下让这扇门用「${name}」`,
2810
+ 'aria-pressed': pinned === true,
2811
+ 'data-pinned': pinned === true ? 'yes' : 'no',
2812
+ onClick: (e) => { e?.stopPropagation?.(); onTogglePin(card) },
2080
2813
  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,
2814
+ width: 24, height: 24, borderRadius: 12, padding: 0, cursor: 'pointer', flex: '0 0 auto',
2815
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
2816
+ border: pinned === true ? '1px solid var(--lc-doctor)' : '1px solid var(--lc-danger)',
2817
+ background: pinned === true ? 'var(--lc-doctor)' : 'var(--lc-danger-soft)',
2818
+ color: pinned === true ? '#ffffff' : 'var(--lc-danger)',
2084
2819
  },
2820
+ }, h(Icon, { name: pinned === true ? 'check' : 'x', size: 12 })),
2821
+ h('span', { style: { flex: '1 1 auto' } }),
2822
+ onEdit === undefined ? null : iconBtn({ act: 'edit', icon: 'pencil', title: `改「${name}」`, onClick: () => onEdit(card) }),
2823
+ onDelete === undefined ? null : iconBtn({ act: 'delete', icon: 'trash', title: `删掉「${name}」`, onClick: () => onDelete(card) }),
2824
+ ),
2825
+ h('div', {
2826
+ style: {
2827
+ flex: '1 1 auto', display: 'flex', flexDirection: 'column', alignItems: 'center',
2828
+ justifyContent: 'center', gap: 8, padding: '4px 10px 10px 10px', minHeight: 0,
2085
2829
  },
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
- ),
2830
+ },
2831
+ h(Avatar, { name, kind: card.kind, photo, big: true }),
2832
+ h('div', {
2833
+ style: {
2834
+ fontWeight: 700, fontSize: 15.5, textAlign: 'center', maxWidth: '100%',
2835
+ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
2836
+ },
2837
+ }, name),
2838
+ card.relation === undefined || card.relation === '' ? null : h('div', { className: 'lc-meta' }, card.relation),
2839
+ onOpen === undefined ? null : h('button', {
2840
+ type: 'button',
2841
+ className: 'lc-btn sm',
2842
+ 'data-card-open': card.id ?? '',
2843
+ title: `看「${name}」的详细信息`,
2844
+ onClick: (e) => { e?.stopPropagation?.(); onOpen(card) },
2845
+ style: { marginTop: 2, width: '100%' },
2846
+ }, '详细信息'),
2847
+ ),
2848
+ h('div', {
2849
+ className: 'lc-meta',
2850
+ style: { textAlign: 'center', padding: '0 8px 8px 8px', fontSize: 11.5 },
2851
+ }, '点卡片翻面'),
2852
+ ),
2853
+
2854
+ // ── 背面:简介 + 写全多少 + 标签 ───────────────────────────────────────
2855
+ h('div', {
2856
+ style: { ...face, transform: 'rotateY(180deg)' },
2857
+ 'data-face': 'back',
2858
+ onClick: () => setFlipped(false),
2859
+ },
2860
+ h('div', { className: 'lc-row', style: { padding: '8px 8px 0 8px', gap: 6, alignItems: 'flex-start' } },
2861
+ h('span', { style: { fontWeight: 700, fontSize: 13.5, flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, name),
2862
+ onDelete === undefined ? null : iconBtn({ act: 'delete-back', icon: 'trash', title: `删掉「${name}」`, onClick: () => onDelete(card) }),
2863
+ ),
2864
+ h('div', {
2865
+ style: {
2866
+ flex: '1 1 auto', minHeight: 0, overflow: 'hidden', padding: '6px 10px 0 10px',
2867
+ fontSize: 13, lineHeight: 1.65, color: 'var(--lc-ink-2)',
2868
+ },
2869
+ },
2870
+ intro === '' ? '这张卡还没写自述。' : intro,
2871
+ ),
2872
+ h('div', { style: { padding: '6px 10px 8px 10px' } },
2873
+ h('div', { className: 'lc-row', style: { gap: 6 } },
2874
+ h(Bar, { value: card.coverage }),
2875
+ h('span', { className: 'lc-meta', style: { flexShrink: 0 }, title: '这张卡写全了多少:性格、说话习惯、做过的事这些填了几样' }, `写全 ${card.coverage}%`),
2106
2876
  ),
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 })),
2877
+ (card.tags ?? []).length > 0
2878
+ ? h('div', { className: 'lc-wrap', style: { marginTop: 5 } }, card.tags.slice(0, 3).map((t) => h(Tag, { key: t }, t)))
2879
+ : null,
2880
+ h('div', { className: 'lc-meta', style: { marginTop: 5, textAlign: 'center' } }, '再点一下翻回正面'),
2881
+ ),
2882
+ ),
2883
+ ),
2125
2884
  )
2126
2885
  }
2127
2886
 
@@ -2349,6 +3108,28 @@ function GameView({ bookId, onBack, flash }) {
2349
3108
  } catch (e) { setErr(humanizeError(e)) }
2350
3109
  }
2351
3110
 
3111
+ /**
3112
+ * 删掉某一局存档。
3113
+ *
3114
+ * `game.delete` 后台一直都有,界面没接过——玩过几局之后,「之前玩到一半的」
3115
+ * 会一直往下堆,试一下就走的那几局也删不掉。
3116
+ */
3117
+ const removePlay = async (row) => {
3118
+ const said = String(row?.scene ?? '').trim() === '' ? '那一局' : String(row.scene)
3119
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3120
+ ? window.confirm(`把「${said}」这一局删掉?\n\n走了 ${Number(row?.turns ?? 0)} 步,删了就真没了,接不回来。\n已经写成某一章的内容不受影响,那些章还在。`)
3121
+ : true
3122
+ if (ok !== true) return
3123
+ setErr(null)
3124
+ try {
3125
+ const r = await call('game.delete', { book: bookId, id: String(row?.id ?? '') })
3126
+ if (r?.ok !== true) { setErr(r?.error ?? '这一局没删掉'); return }
3127
+ if (play !== null && play.id === row?.id) setPlay(null)
3128
+ await loadPlays()
3129
+ flash?.('删掉了那一局')
3130
+ } catch (e) { setErr(humanizeError(e)) }
3131
+ }
3132
+
2352
3133
  useEffect(() => {
2353
3134
  let gone = false
2354
3135
  loadPlays()
@@ -2399,10 +3180,11 @@ function GameView({ bookId, onBack, flash }) {
2399
3180
  ? null
2400
3181
  : h('div', { className: 'lc-stack', style: { gap: 6, marginTop: 10 } },
2401
3182
  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)} 步`)),
3183
+ plays.map((row) => h('div', { key: row.id, className: 'lc-row', style: { gap: 6 } },
3184
+ h(Btn, { block: true, size: 'sm', icon: 'history', onClick: () => open(row) },
3185
+ `${String(row.scene ?? '').trim() === '' ? '那一局' : String(row.scene)} · 走了 ${Number(row.turns ?? 0)} 步`),
3186
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', title: '删掉这一局', onClick: () => removePlay(row) }, '删掉这一局'),
3187
+ )),
2406
3188
  ),
2407
3189
  err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
2408
3190
  )
@@ -2491,16 +3273,31 @@ function CareerView({ onBack, flash }) {
2491
3273
  const [err, setErr] = useState(null)
2492
3274
  const [dirty, setDirty] = useState(false)
2493
3275
 
3276
+ /** 把读回来的东西摆到界面上。读不出来就照实说,别让它只停在转圈上。 */
3277
+ const applyRead = (r) => {
3278
+ if (r?.ok !== true) { setErr(r?.error ?? '你的简历这一份读不出来'); return }
3279
+ setProfile(buildCareerForm(r.profileSections ?? {}))
3280
+ setGoal(String(r.plan?.goal ?? ''))
3281
+ setHorizon(String(r.plan?.horizon ?? '1年'))
3282
+ }
3283
+
3284
+ /**
3285
+ * 读一次自己的简历。首次进来和「再试一次」走的是同一段。
3286
+ *
3287
+ * 以前「再试一次」只写了 `call('career.get', {})`,返回值被丢掉——点了以后
3288
+ * 界面还是空着转圈,跟没点一样,用户只能一直点下去。
3289
+ */
3290
+ const load = async () => {
3291
+ setErr(null)
3292
+ try {
3293
+ applyRead(await call('career.get', {}))
3294
+ } catch (e) { setErr(humanizeError(e)) }
3295
+ }
3296
+
2494
3297
  useEffect(() => {
2495
3298
  let gone = false
2496
3299
  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
- })
3300
+ .then((r) => { if (!gone) applyRead(r) })
2504
3301
  .catch((e) => { if (!gone) setErr(humanizeError(e)) })
2505
3302
  return () => { gone = true }
2506
3303
  }, [])
@@ -2539,7 +3336,7 @@ function CareerView({ onBack, flash }) {
2539
3336
  ? h(Spinner)
2540
3337
  : h('div', { className: 'lc-stack' },
2541
3338
  h(Note, { tone: 'err', icon: 'warning' }, err),
2542
- h(Btn, { block: true, onClick: () => { setErr(null); call('career.get', {}) } }, '再试一次'),
3339
+ h(Btn, { block: true, onClick: () => { load() } }, '再试一次'),
2543
3340
  ),
2544
3341
  )
2545
3342
  }
@@ -2641,7 +3438,7 @@ function copyText(text) {
2641
3438
  }
2642
3439
  }
2643
3440
 
2644
- function BookView({ bookId, onBack, flash }) {
3441
+ function BookView({ bookId, onBack, flash, flushRef }) {
2645
3442
  const [book, setBook] = useState(null)
2646
3443
  const [outline, setOutline] = useState(null)
2647
3444
  const [chapterIndex, setChapterIndex] = useState(0)
@@ -2655,8 +3452,24 @@ function BookView({ bookId, onBack, flash }) {
2655
3452
  const [outlineText, setOutlineText] = useState('')
2656
3453
  // 这一章的正文有没有还没存下的改动。切章之前必须先处理,否则写的东西会没。
2657
3454
  const [bodyDirty, setBodyDirty] = useState(false)
2658
-
2659
- const load = async (want) => {
3455
+ // 「改成剧本」。排在所有 hook 最后:上面那些槽位有测试按序号摆状态,
3456
+ // 插在中间会让它们集体错位。
3457
+ const [scriptText, setScriptText] = useState('')
3458
+ const [scriptReport, setScriptReport] = useState('')
3459
+ // 剧本有没有改了没存的。和正文的 bodyDirty 一个道理:切章之前得拦一下,
3460
+ // 否则人手改的那几场会静静消失,而且没有任何提示。
3461
+ const [scriptDirty, setScriptDirty] = useState(false)
3462
+ // 改剧本这一节的错误单独放:全页那个 err 在最底下,一节剧本三百多像素高,
3463
+ // 报错落在屏幕外,人只会觉得「点了没反应」。
3464
+ const [scriptErr, setScriptErr] = useState(null)
3465
+ // 这本书哪几章已经改出过剧本。后台一直有这个清单(`novel.script.list`),
3466
+ // 界面从来没调过——于是「哪一章改过」只存在于文件夹里。
3467
+ const [scripted, setScripted] = useState([])
3468
+ // 这一章的正文有没有真正读到。读失败(网络、后台报错、文件被占住)时不能让人
3469
+ // 接着在空框里写字再按「存好这一章」——那会把空白写进另一章的文件,一整章原稿就没了。
3470
+ const [chapterBroken, setChapterBroken] = useState(false)
3471
+
3472
+ const load = async (want, opts) => {
2660
3473
  setErr(null)
2661
3474
  try {
2662
3475
  const r = await call('novel.get', { id: bookId })
@@ -2664,19 +3477,145 @@ function BookView({ bookId, onBack, flash }) {
2664
3477
  setBook(r)
2665
3478
  const o = await call('novel.outline.get', { id: bookId })
2666
3479
  if (o?.ok === true) { setOutline(o); setOutlineText(String(o.text ?? '')) }
3480
+ // 哪几章已经改出过剧本(画章列表上的小标记用)。拿不到就算了,不是要紧事。
3481
+ const scripts = await call('novel.script.list', { id: bookId }).catch(() => null)
3482
+ setScripted(scripts?.ok === true && Array.isArray(scripts.scripts)
3483
+ ? scripts.scripts.map((x) => Number(x.index))
3484
+ : [])
2667
3485
  // 默认打开:有章节就打开最后一章,没有就从第一章开始
2668
3486
  const target = Number(want) > 0 ? Number(want) : (r.chapters.length === 0 ? 1 : r.chapters[r.chapters.length - 1].index)
3487
+ // 先翻章再改章号:翻章被拦下时,章号不能已经跑到新的一章去。
3488
+ const opened = await openChapter(target, opts)
3489
+ if (opened === 'error') {
3490
+ // 出错时章号也得跟标题对上:以前这里直接返回、章号停在旧值(初值是 0),
3491
+ // 屏幕上写着「写第 0 章」,点存就被后台当成「接在最后一章后面」,凭空多一章。
3492
+ // 正文没读到,存的动作已经按 chapterBroken 禁掉了。
3493
+ setChapterIndex(target)
3494
+ return
3495
+ }
3496
+ // 被拦下,或者这中间又有人点了别的章:什么都不改。
3497
+ if (opened !== true) return
2669
3498
  setChapterIndex(target)
2670
- await openChapter(target)
2671
3499
  } catch (e) { setErr(humanizeError(e)) }
3500
+ // 上一本书那份剧本没存上:现在才说,说了才算数。
3501
+ if (carryErr.current !== null) { setErr(String(carryErr.current)); carryErr.current = null }
2672
3502
  }
2673
3503
 
2674
- const openChapter = async (index) => {
2675
- setErr(null); setReview(null); setDraft(null)
3504
+ // 剧本改了没存,要走之前先替人存好。
3505
+ //
3506
+ // 这里以前弹的是「回去就没了」,可组件卸载那一刻又偷偷存了一份——弹窗说不要,
3507
+ // 实际存了,人点了「好」以为自己放弃成功,其实没有。现在只剩一种立场:真存。
3508
+ // 存成了说一句「先替你存好了」;存不上才问要不要放弃这一份。
3509
+ const settleScript = async (why) => {
3510
+ if (scriptDirty !== true || scriptText.trim() === '') return true
3511
+ const myBook = bookId
3512
+ const myIndex = chapterIndex
3513
+ const sent = scriptText
3514
+ setBusy('scriptSave'); setScriptErr(null)
3515
+ try {
3516
+ const r = await call('novel.script.save', { id: myBook, index: myIndex, text: sent })
3517
+ if (r?.ok === true) {
3518
+ setScriptDirty(false)
3519
+ setScripted((old) => (old.includes(myIndex) ? old : [...old, myIndex].sort((a, b) => a - b)))
3520
+ flash?.(`第 ${myIndex} 章的剧本先替你存好了`)
3521
+ return true
3522
+ }
3523
+ setScriptErr(r?.error ?? '这一份剧本没存上')
3524
+ } catch (e) { setScriptErr(humanizeError(e)) } finally { setBusy('') }
3525
+ // 存不上:只剩「放弃这一份」和「留下」两条路,问清了再走。
3526
+ const go = typeof window !== 'undefined' && typeof window.confirm === 'function'
3527
+ ? window.confirm(`第 ${myIndex} 章这份剧本没存上。\n\n${why}的话这一份就没了。还走吗?`)
3528
+ : true
3529
+ return go === true
3530
+ }
3531
+
3532
+ // 改剧本也要对号:点了「把这一章改成剧本」之后又翻章、又换书,
3533
+ // 草稿晚回来会落进现在这一章的框里,人一按「存好这份剧本」,
3534
+ // 第 5 章的内容就写成第 6 章的文件。换书之后更糟:A 书的稿子会存成 B 书的。
3535
+ // 所以草稿出发前记下「哪本书、哪一章」,回来对不上就整份丢掉。
3536
+ const scriptTicket = useRef(0)
3537
+
3538
+ // 每翻一次章就加一,回来的东西先对一下号。
3539
+ // 手快连点两章(或者网络慢)时,前一章的剧本会在后一章之后才回来,
3540
+ // 落在框里就成了「标题是第 3 章,剧本是第 2 章的」——这种错对不上账,人只会觉得插件疯了。
3541
+ const chapterTicket = useRef(0)
3542
+ // 框里此刻摆的是第几章、还有没有一章正在读。
3543
+ // 不能用 chapterIndex 判「点的就是我现在这一章」:章号要等读完才前进,
3544
+ // 人点第 2 章、它还在路上时,chapterIndex 还停在旧值(比如 3)。
3545
+ // 这时候再点第 3 章,会被当成「点的是自己这一章」而什么都不做,
3546
+ // 于是框里留着第 2 章的正文、章号写着第 3 章。
3547
+ const loadedRef = useRef(0)
3548
+ const pullingRef = useRef(0)
3549
+
3550
+ /**
3551
+ * 翻到某一章。
3552
+ *
3553
+ * `opts.sameChapter` 是给「刚把这一章存好、要重读一遍」用的:那时候没换章,
3554
+ * 不该弹「剧本还没存,换过去就没了」——人点了「好」,手改的剧本反倒没了。
3555
+ * 带上它就别去动剧本框,剧本跟正文是两份东西,各存各的。
3556
+ *
3557
+ * 返回 true 表示框里已经是这一章;返回 'stale' 表示这中间又有人点了别的章,
3558
+ * 这一次的结果该整份丢掉,调用方也不许再改章号。
3559
+ */
3560
+ const openChapter = async (index, opts) => {
3561
+ const sameChapter = opts !== undefined && opts !== null && opts.sameChapter === true
3562
+ // `settled`:调用方已经把要存的存过了(换书那一段),这里不许再拦一次。
3563
+ // 不然人会看到一个「第 2 章改出来的剧本还没存」的框,说的却是上一本书的章,
3564
+ // 点「取消」也照换不误——那框就是个摆设。
3565
+ const settled = opts !== undefined && opts !== null && opts.settled === true
3566
+ // 改过剧本还没存就切章,得先说一声。同一章重读不算切章。
3567
+ if (settled !== true && sameChapter !== true && (await settleScript('换过去')) !== true) return false
3568
+ const mine = ++chapterTicket.current
3569
+ pullingRef.current = Number(index)
3570
+ // 换章 / 换书了:还在路上的剧本草稿一律作废。
3571
+ scriptTicket.current += 1
3572
+ setErr(null); setReview(null); setDraft(null); setScriptErr(null)
3573
+ if (sameChapter !== true) { setScriptText(''); setScriptReport(''); setScriptDirty(false) }
2676
3574
  try {
2677
3575
  const r = await call('novel.chapter.get', { id: bookId, index })
2678
- setBody(r?.ok === true ? String(r.body ?? '') : '')
2679
- } catch (e) { setErr(humanizeError(e)) }
3576
+ if (mine !== chapterTicket.current) return 'stale'
3577
+ if (r?.ok !== true) {
3578
+ // 后台说这一章读不出来(文件被占住、内容坏了):不能当「这一章是空的」处理。
3579
+ // 当真当成空的话,人会在空框里写一段,再按「存好这一章」,
3580
+ // 存进去的是**这一章**的文件,原来那一份就被盖掉了。
3581
+ // 章号照旧前进——屏幕上的标题得跟点的那一章对上。
3582
+ setBody('')
3583
+ setChapterBroken(true)
3584
+ setErr(String(r?.error ?? '这一章没读出来。'))
3585
+ loadedRef.current = Number(index)
3586
+ pullingRef.current = 0
3587
+ return true
3588
+ }
3589
+ setBody(String(r.body ?? ''))
3590
+ setChapterBroken(false)
3591
+ if (sameChapter === true) return true
3592
+ // 这一章以前改过剧本没有——改过就直接摆出来,不用再问一次。
3593
+ const s = await call('novel.script.get', { id: bookId, index })
3594
+ if (mine !== chapterTicket.current) return 'stale'
3595
+ if (s?.ok === true) {
3596
+ if (String(s.text ?? '').trim() !== '') {
3597
+ setScriptText(String(s.text))
3598
+ setScriptReport(String(s.report ?? ''))
3599
+ }
3600
+ } else {
3601
+ // 剧本读坏了不能当没这回事:框不渲染、章列表还挂着「有剧本」,
3602
+ // 人只会以为自己改的东西没了,而且屏幕上没有一句话。
3603
+ setScriptErr(String(s?.error ?? '这一章的剧本读不出来。'))
3604
+ }
3605
+ setChapterBroken(false)
3606
+ loadedRef.current = Number(index)
3607
+ pullingRef.current = 0
3608
+ return true
3609
+ } catch (e) {
3610
+ if (mine === chapterTicket.current) {
3611
+ pullingRef.current = 0
3612
+ setErr(humanizeError(e))
3613
+ // 正文没读到:把这一章标成「别动」。以前这里直接返回,章号停在旧值,
3614
+ // 人点「存好这一章」就把眼下这个空框写进**另一章**的文件,原稿就没了。
3615
+ setChapterBroken(true)
3616
+ }
3617
+ return 'error'
3618
+ }
2680
3619
  }
2681
3620
 
2682
3621
  // 切章之前先把没存的正文收好。存不上就留在这一章,别让人以为写进去了。
@@ -2692,12 +3631,162 @@ function BookView({ bookId, onBack, flash }) {
2692
3631
  }
2693
3632
 
2694
3633
  const goChapter = async (index) => {
3634
+ // 点的是自己正待着的这一章:不用重读。以前会照样重读一遍,
3635
+ // 手改的剧本会因为一次「换过去」被磁盘上那一份换掉。
3636
+ // 但票号还是要往前走一步:刚才点过别的章、它那份还在路上,
3637
+ // 此刻也该作废——不然它回来照样落进这一章的框。
3638
+ if (Number(index) === Number(loadedRef.current) && pullingRef.current === 0) return
2695
3639
  if ((await keepBody()) !== true) return
3640
+ // 剧本那边没存就被拦下时,章号也不能跟着变——否则标题写着新章、框里还是旧章。
3641
+ if ((await openChapter(index)) !== true) return
2696
3642
  setChapterIndex(index)
2697
- await openChapter(index)
2698
3643
  }
2699
3644
 
2700
- useEffect(() => { load(0) }, [bookId])
3645
+ /**
3646
+ * 删掉某一章。
3647
+ *
3648
+ * `novel.chapter.delete` 后台一直都有,界面从来没调过——写歪了一章,
3649
+ * 用户只能去文件夹里找那个文件。删的是正文本身,不是「收起来」。
3650
+ */
3651
+ const removeChapter = async (c) => {
3652
+ const n = Number(c?.index ?? 0)
3653
+ // 有剧本的章,确认框里得说清剧本也一起没:那一份是人花了一次 AI 改出来的。
3654
+ const extra = scripted.includes(n)
3655
+ ? '这一章改出来的剧本也一起删。'
3656
+ : ''
3657
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3658
+ ? window.confirm(`把第 ${n} 章删掉?\n\n这一章的正文一起删,删了就真没了。${extra}别的章不受影响;大纲里那一行还在,你可以重写。`)
3659
+ : true
3660
+ if (ok !== true) return
3661
+ // 删的是**这一章**时,它上面那份没存的剧本才跟着作废。
3662
+ // 删别的章却去清当前章的状态,等于把人家正在写的正文和剧本一起抹了——
3663
+ // 以前就是这样:停在第 2 章写了一大段,顺手删掉第 1 章,第 2 章写的全没了,
3664
+ // 正文连问都没问一句。
3665
+ const deletingCurrent = n === chapterIndex
3666
+ if (deletingCurrent !== true) {
3667
+ // 删别的章:当前章该存的先存好,别让它被下面的重读顺手丢掉。
3668
+ if ((await keepBody()) !== true) return
3669
+ // 剧本也替它存回去。这里不问「走不走」——人没打算走,只是在删别的章;
3670
+ // 问了也只有一个正确答案,反倒把「删第 1 章」这件事拦下来。
3671
+ if (scriptDirty === true && scriptText.trim() !== '') {
3672
+ let saved = false
3673
+ try {
3674
+ const r = await call('novel.script.save', { id: bookId, index: chapterIndex, text: scriptText })
3675
+ if (r?.ok === true) { saved = true; setScriptDirty(false) }
3676
+ else setErr(r?.error ?? '这一章的剧本没存上,先别删')
3677
+ } catch (e) { setErr(humanizeError(e)) }
3678
+ // 存不上就别删:这一删,下面那次重读会把框里东西换掉,手改的就真没了。
3679
+ if (saved !== true) return
3680
+ }
3681
+ }
3682
+ setErr(null)
3683
+ try {
3684
+ const r = await call('novel.chapter.delete', { id: bookId, index: n })
3685
+ if (r?.ok !== true) { setErr(r?.error ?? '这一章没删掉'); return }
3686
+ // 删成功了才清当前章的状态。以前这两行写在删之前:后台一报错就 return,
3687
+ // 清空却已经生效,手写的正文和剧本在屏幕上没了、磁盘上也没存过。
3688
+ if (deletingCurrent === true) {
3689
+ setBodyDirty(false)
3690
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
3691
+ setScriptErr(null)
3692
+ }
3693
+ setScripted((old) => old.filter((x) => x !== n))
3694
+ flash?.(`删掉了第 ${n} 章`)
3695
+ // 重新读一遍这本书:章列表少一条。
3696
+ // 删的不是当前章时留在原地重读(人可能正写着),删的就是当前章才往前挪。
3697
+ // 挪的时候给 0:让 load 自己落到「现在还存在的最后一章」。
3698
+ // 以前传 n-1,而 n-1 可能刚在上一步被删掉,屏幕就停在一个没有的章号上。
3699
+ if (deletingCurrent === true) await load(0, { sameChapter: false })
3700
+ else await load(chapterIndex, { sameChapter: true })
3701
+ } catch (e) { setErr(humanizeError(e)) }
3702
+ }
3703
+
3704
+ // 上一本是哪本。换书时要在下面那个 effect 里认出「这是换了一本」。
3705
+ const lastBookId = useRef('')
3706
+ // 换书时替上一本存剧本,存失败了要报,可紧接着的 load() 会把 err 清掉。
3707
+ // 先存在这里,等 load 读完了再摆到屏幕上。
3708
+ const carryErr = useRef(null)
3709
+ // 换书(从书架再点一本进来)时组件不卸载、只是 bookId 变了:
3710
+ // 上一本改了没存的剧本会留在框里,跟着新书一起显示,看着像这本书的剧本;
3711
+ // 反过来,它也会被静悄悄丢掉。所以换书这一刻先替上一本存回去。
3712
+ // 注意此刻 scriptText / scriptDirty / chapterIndex 还是上一本的值(下面才清),
3713
+ // 正好用得上——晚了就没了。
3714
+ useEffect(() => {
3715
+ const before = lastBookId.current
3716
+ if (before !== '' && before !== bookId) {
3717
+ // 换书了:上一本还在路上的剧本草稿作废,不许它落进新书的框里。
3718
+ scriptTicket.current += 1
3719
+ // 上一本没存的剧本替它存回**原来那本**(不是新这本)。
3720
+ // 存的时候顺手报一下成没成:失败还得让新书那边看得见,
3721
+ // 不然人会以为「点了一下就都存好了」。
3722
+ if (scriptDirty === true && scriptText.trim() !== '') {
3723
+ const oldId = before
3724
+ const oldIndex = chapterIndex
3725
+ const oldText = scriptText
3726
+ // 先把这一刻的「哪本书、哪一章、什么内容」定下来,卸载兜底那份也一起作废:
3727
+ // 不然同一份稿会同时写进上一本和下一本。
3728
+ leaveRef.current = { id: oldId, index: oldIndex, text: oldText, dirty: true, taken: true }
3729
+ call('novel.script.save', { id: oldId, index: oldIndex, text: oldText })
3730
+ .then((r) => {
3731
+ // 提示要能活过紧接着的那次 load(load 开头会清 err):
3732
+ // 失败时先用一个不会被清掉的位置接着,等读完再摆出来。
3733
+ if (r?.ok === true) flash?.(`上一本书第 ${oldIndex} 章的剧本替你存好了`)
3734
+ else carryErr.current = String(r?.error ?? '上一本书的剧本没存上')
3735
+ })
3736
+ .catch(() => { carryErr.current = '上一本书的剧本没存上' })
3737
+ }
3738
+ }
3739
+ lastBookId.current = String(bookId ?? '')
3740
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
3741
+ setBody(''); setDraft(null); setReview(null); setBodyDirty(false)
3742
+ load(0, { settled: true })
3743
+ }, [bookId])
3744
+
3745
+ // 离开这一屏时(点顶上那个返回、换门、切到别的页)组件直接卸载,
3746
+ // 没有第二次机会弹窗问「剧本还没存,现在走吗」——上面那个 effect 只在换书时跑。
3747
+ // 所以卸载这一刻自己把没存的剧本收好:人没按「存好这份剧本」,
3748
+ // 不等于想把它丢掉。
3749
+ // `taken` 是给换书那一段用的:那一份已经有人存了,卸载兜底不许再存一遍,
3750
+ // 更不许把 A 书的内容写成 B 书的(id 与 text 配不上对时就是这么串过去的)。
3751
+ const leaveRef = useRef({ id: '', index: 0, text: '', dirty: false, taken: false })
3752
+ leaveRef.current = {
3753
+ id: bookId, index: chapterIndex, text: scriptText, dirty: scriptDirty,
3754
+ // 每帧重写的只是「当前值」,taken 只在换书那一刻被置上;
3755
+ // 置上之后要一直有效到这一帧结束,所以从上一帧继承。
3756
+ taken: leaveRef.current.taken === true && leaveRef.current.id === bookId ? true : false,
3757
+ }
3758
+ // 正文和剧本是两份东西,可离开这一屏时都得收好。以前只兜了剧本:
3759
+ // 写完一段正文点顶上的返回,字就没了,而且屏幕上不会有一句话。
3760
+ const bodyLeaveRef = useRef({ id: '', index: 0, body: '', dirty: false })
3761
+ bodyLeaveRef.current = { id: bookId, index: chapterIndex, body, dirty: bodyDirty }
3762
+ useEffect(() => () => {
3763
+ const now = leaveRef.current
3764
+ if (now.taken !== true && now.dirty === true && String(now.text).trim() !== '') {
3765
+ // 这一份已经没地方报错了(组件都卸载了),只能尽量存住。
3766
+ // 真正的「存不上怎么办」已经在 settleScript 里问过人了。
3767
+ call('novel.script.save', { id: now.id, index: now.index, text: now.text }).catch(() => null)
3768
+ }
3769
+ const nb = bodyLeaveRef.current
3770
+ if (nb.dirty === true && String(nb.body).trim() !== '') {
3771
+ call('novel.chapter.save', { id: nb.id, index: nb.index, body: nb.body }).catch(() => null)
3772
+ }
3773
+ }, [])
3774
+
3775
+ // 外面那一层(顶栏返回、换门)没法知道这一屏手头有没有没存的东西。
3776
+ // 把「先收好再走」放在它给的槽里:切屏前先调,收不上就留在这一屏。
3777
+ useEffect(() => {
3778
+ if (flushRef === undefined || flushRef === null) return
3779
+ flushRef.current = () => {
3780
+ // 什么都没改:同步放行,外面那一层就不用等一帧。
3781
+ if (bodyDirty !== true && scriptDirty !== true) return true
3782
+ return (async () => {
3783
+ const bodyOk = await keepBody()
3784
+ if (bodyOk !== true) return false
3785
+ return settleScript('换到别处')
3786
+ })()
3787
+ }
3788
+ return () => { flushRef.current = null }
3789
+ })
2701
3790
 
2702
3791
  const doPlan = async () => {
2703
3792
  setBusy('plan'); setErr(null)
@@ -2747,7 +3836,8 @@ function BookView({ bookId, onBack, flash }) {
2747
3836
  if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
2748
3837
  setBody(merged); setDraft(null); setBodyDirty(false)
2749
3838
  flash?.(`第 ${chapterIndex} 章存好了`)
2750
- await load(chapterIndex)
3839
+ // 同一章重读:别碰剧本框,也别弹「剧本还没存」。
3840
+ await load(chapterIndex, { sameChapter: true })
2751
3841
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
2752
3842
  }
2753
3843
 
@@ -2758,7 +3848,7 @@ function BookView({ bookId, onBack, flash }) {
2758
3848
  if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
2759
3849
  setBodyDirty(false)
2760
3850
  flash?.(`第 ${chapterIndex} 章存好了`)
2761
- await load(chapterIndex)
3851
+ await load(chapterIndex, { sameChapter: true })
2762
3852
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
2763
3853
  }
2764
3854
 
@@ -2774,6 +3864,119 @@ function BookView({ bookId, onBack, flash }) {
2774
3864
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
2775
3865
  }
2776
3866
 
3867
+ /**
3868
+ * 把这一章改成剧本。
3869
+ *
3870
+ * 改的是**存下来的那一版**:正文有没存的改动先存一次,不然后台改的是旧稿,
3871
+ * 用户盯着屏幕会以为它漏掉了刚写的那几句。
3872
+ */
3873
+ // 连点两下会真发两次(AI 那一侧是要花钱的)。按钮的 disabled 要等一次 await
3874
+ // 之后才置位,同一帧里的两次点击都赶在它前面。所以用一个同步的锁挡。
3875
+ const scriptLock = useRef(false)
3876
+
3877
+ const doScript = async () => {
3878
+ if (scriptLock.current === true) return
3879
+ if (body.trim() === '') { setScriptErr('这一章还空着,没什么可改的。'); return }
3880
+ // 框里已经有一份、而且改过没存:点「重改一份」会把它整份盖掉。
3881
+ // 不先问一句,人点错一次就是白改。
3882
+ if (scriptDirty === true && scriptText.trim() !== '') {
3883
+ const go = typeof window !== 'undefined' && typeof window.confirm === 'function'
3884
+ ? window.confirm(`第 ${chapterIndex} 章这份剧本改了还没存,重改一次会把它整份盖掉。\n\n继续吗?`)
3885
+ : true
3886
+ if (go !== true) return
3887
+ }
3888
+ scriptLock.current = true
3889
+ if ((await keepBody()) !== true) { scriptLock.current = false; return }
3890
+ // 出发前记下是哪本书的哪一章:回来要是对不上,说明人已经翻到别处了。
3891
+ const wantBook = bookId
3892
+ const wantIndex = chapterIndex
3893
+ const mine = ++scriptTicket.current
3894
+ setBusy('script'); setErr(null); setScriptErr(null)
3895
+ try {
3896
+ const r = await call('novel.script.draft', { id: wantBook, index: wantIndex })
3897
+ if (mine !== scriptTicket.current) return
3898
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '这次没改成。再点一次试试。'); return }
3899
+ setScriptText(String(r.text ?? ''))
3900
+ setScriptReport(String(r.report ?? ''))
3901
+ // 改出来但还没落盘,所以算「没存」:这时候切章要拦。
3902
+ setScriptDirty(true)
3903
+ } catch (e) { if (mine === scriptTicket.current) setScriptErr(humanizeError(e)) } finally {
3904
+ // 无条件复位。以前这里要票号还对得上才复位:人趁 AI 还在想的时候翻了章,
3905
+ // 票号一过就永远不复位,整页五个按钮从此全禁用,只有退出这本书才恢复。
3906
+ scriptLock.current = false
3907
+ setBusy('')
3908
+ }
3909
+ }
3910
+
3911
+ const saveScript = async () => {
3912
+ if (scriptLock.current === true) return
3913
+ if (scriptText.trim() === '') { setScriptErr('剧本还是空的,没什么可存的。'); return }
3914
+ // 记下这一次到底存的是哪一份:回来时框里的字已经不是这一份了,
3915
+ // 就不能把「还没存」这个标记清掉,否则那几个字会被当成已存、然后默默丢掉。
3916
+ const sent = scriptText
3917
+ // 还要记下是哪本书的哪一章:人可能趁这次保存还在路上就翻了章、换了书。
3918
+ // 那时候这个回包属于上一章,一个字都不能往现在这一章身上贴
3919
+ // (以前会清掉现在这一章的「还没存」、把上一章的报告摆到这一章里)。
3920
+ const myBook = bookId
3921
+ const myIndex = chapterIndex
3922
+ scriptLock.current = true
3923
+ setBusy('scriptSave'); setErr(null); setScriptErr(null)
3924
+ try {
3925
+ const r = await call('novel.script.save', { id: myBook, index: myIndex, text: sent })
3926
+ if (myBook !== bookId || myIndex !== chapterIndex) return
3927
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '没存上。这一份还在框里,再点一次就行。'); return }
3928
+ setScriptReport(String(r.report ?? ''))
3929
+ // 章列表上那个「有剧本」的小标记:存好之后立刻挂上,
3930
+ // 不然得退出这本书再进来才看得见,人会以为自己没存上。
3931
+ setScripted((old) => (old.includes(myIndex) ? old : [...old, myIndex].sort((a, b) => a - b)))
3932
+ if (scriptText === sent) {
3933
+ setScriptDirty(false)
3934
+ flash?.(`第 ${myIndex} 章的剧本存好了`)
3935
+ } else {
3936
+ // 存的过程中又改了:这一版还没存,标记留着,按钮上说出来。
3937
+ setScriptDirty(true)
3938
+ flash?.('存好了。存的时候你又改了,新改的这一版还没存')
3939
+ }
3940
+ } catch (e) { if (myBook === bookId && myIndex === chapterIndex) setScriptErr(humanizeError(e)) } finally {
3941
+ scriptLock.current = false
3942
+ setBusy('')
3943
+ }
3944
+ }
3945
+
3946
+ /**
3947
+ * 删掉这一章的剧本。
3948
+ *
3949
+ * 只删改编出来的那份,章节正文一点不动——所以这里说的「删」和删章不是一回事,
3950
+ * 提示语里要把这件事说清,否则有人会以为连这一章一起删了。
3951
+ */
3952
+ const removeScript = async () => {
3953
+ if (scriptLock.current === true) return
3954
+ const myIndex = chapterIndex
3955
+ // 手改过还没存的部分会跟着一起没,这句得说在确认框里。
3956
+ const unsaved = scriptDirty === true && scriptText.trim() !== ''
3957
+ ? '\n\n框里手改过、还没存的那部分也一起没。'
3958
+ : ''
3959
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3960
+ ? window.confirm(`把第 ${myIndex} 章改出来的剧本删掉?\n\n只删这份剧本,小说正文不动。想再要一份,可以重新改一次。${unsaved}`)
3961
+ : true
3962
+ if (ok !== true) return
3963
+ const myBook = bookId
3964
+ scriptLock.current = true
3965
+ setBusy('scriptDelete'); setErr(null); setScriptErr(null)
3966
+ try {
3967
+ const r = await call('novel.script.delete', { id: myBook, index: myIndex })
3968
+ // 这一回包只属于那一章:人要是在等的时候翻到别处,
3969
+ // 现在框里的东西是那一章的新内容,一个字都不能清。
3970
+ if (myBook !== bookId || myIndex !== chapterIndex) return
3971
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '这份剧本没删掉'); return }
3972
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
3973
+ setScripted((old) => old.filter((n) => n !== myIndex))
3974
+ flash?.(`删掉了第 ${myIndex} 章的剧本`)
3975
+ } catch (e) {
3976
+ if (myBook === bookId && myIndex === chapterIndex) setScriptErr(humanizeError(e))
3977
+ } finally { scriptLock.current = false; setBusy('') }
3978
+ }
3979
+
2777
3980
  if (book === null) {
2778
3981
  return h('div', { className: 'lc-pad lc-stack' },
2779
3982
  h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回书架'),
@@ -2788,7 +3991,13 @@ function BookView({ bookId, onBack, flash }) {
2788
3991
 
2789
3992
  return h('div', { className: 'lc-pad lc-stack', style: { gap: 12 } },
2790
3993
  h('div', { className: 'lc-row' },
2791
- h(Btn, { size: 'sm', icon: 'back', onClick: async () => { if ((await keepBody()) === true) onBack() } }, '回书架'),
3994
+ h(Btn, { size: 'sm', icon: 'back', onClick: async () => {
3995
+ // 先替人存,存不上才问「还走吗」。以前这里是「回去就没了」+ 卸载时偷偷存,
3996
+ // 说的话和做的事对不上。
3997
+ if ((await keepBody()) !== true) return
3998
+ if ((await settleScript('回去')) !== true) return
3999
+ onBack()
4000
+ } }, '回书架'),
2792
4001
  h('div', { className: 'lc-grow lc-ellipsis', style: { fontWeight: 700, fontSize: 16.5 } }, `《${title}》`),
2793
4002
  h('span', { className: 'lc-meta' }, `${chapters.length} 章`),
2794
4003
  ),
@@ -2836,6 +4045,32 @@ function BookView({ bookId, onBack, flash }) {
2836
4045
  : null,
2837
4046
  ),
2838
4047
 
4048
+ // ── 已经写过的章 ──
4049
+ // 以前这一块没有:写了几章之后想回头删掉某一章,界面上根本没有落脚的地方。
4050
+ chapters.length === 0
4051
+ ? null
4052
+ : h('div', { className: 'lc-sec' },
4053
+ h('div', { className: 'lc-row' },
4054
+ h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, `已经写过的章 · ${chapters.length}`)),
4055
+ h('span', { className: 'lc-meta' }, '点一章就能翻过去'),
4056
+ ),
4057
+ h('div', { className: 'lc-stack', style: { gap: 4, marginTop: 6 } },
4058
+ chapters.map((c) => h('div', { key: c.index, className: 'lc-row', style: { gap: 6 } },
4059
+ h(Btn, {
4060
+ size: 'sm', icon: 'book',
4061
+ tone: Number(c.index) === Number(chapterIndex) ? 'primary' : undefined,
4062
+ onClick: () => { goChapter(Number(c.index)) },
4063
+ }, `第 ${c.index} 章${String(c.title ?? '').trim() === '' ? '' : ` · ${String(c.title).slice(0, 16)}`}`),
4064
+ // 这一章改过剧本:给一个小标记。不然只有翻进去才知道自己改没改过。
4065
+ scripted.includes(Number(c.index))
4066
+ ? h('span', { className: 'lc-meta', title: '这一章已经有一份剧本' }, '有剧本')
4067
+ : null,
4068
+ h('div', { className: 'lc-grow' }),
4069
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', onClick: () => removeChapter(c) }, '删掉这一章'),
4070
+ )),
4071
+ ),
4072
+ ),
4073
+
2839
4074
  // ── 第二段:写这一章 ──
2840
4075
  h('div', { className: 'lc-sec' },
2841
4076
  h('div', { className: 'lc-row' },
@@ -2876,18 +4111,29 @@ function BookView({ bookId, onBack, flash }) {
2876
4111
  h('div', { className: 'lc-sec' },
2877
4112
  h('div', { className: 'lc-row' },
2878
4113
  h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, '正文')),
2879
- h('span', { className: 'lc-meta' }, `${body.length} 字`),
4114
+ // 正文改了没存也得说出来。剧本那边一直有这行标记,正文没有:
4115
+ // 人写完一段直接去点顶上的返回,屏幕上没有任何东西拦过他一眼。
4116
+ h('span', { className: 'lc-meta' },
4117
+ bodyDirty ? `${body.length} 字 · 还没存` : `${body.length} 字`),
2880
4118
  ),
4119
+ // 这一章的正文没读到(后台报错、文件被占住):框锁成只读,并当场说清。
4120
+ // 让它能改的话,人会在空框里写一段,再按「存好这一章」,
4121
+ // 存进去的是**另一章**的文件,那一章的原稿就没了。
4122
+ chapterBroken === true
4123
+ ? h(Note, { tone: 'err', icon: 'warning' },
4124
+ '这一章没读出来,所以先锁住了。退出这本书再进来一次;还是不行,就用访达看一眼那个文件夹还在不在。')
4125
+ : null,
2881
4126
  h('textarea', {
2882
4127
  className: 'lc-textarea',
2883
4128
  value: body,
2884
4129
  spellCheck: false,
4130
+ readOnly: chapterBroken === true,
2885
4131
  placeholder: '这一章还空着。让 AI 写一段,或者自己动手。',
2886
4132
  style: { minHeight: 260, marginTop: 6, lineHeight: 1.85 },
2887
4133
  onChange: (e) => { setBody(e.target.value); setBodyDirty(true) },
2888
4134
  }),
2889
4135
  h('div', { className: 'lc-row' },
2890
- h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '', onClick: saveBody }, busy === 'save' ? '正在存…' : '存好这一章'),
4136
+ h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '' || chapterBroken === true, onClick: saveBody }, busy === 'save' ? '正在存…' : '存好这一章'),
2891
4137
  h(Btn, { size: 'sm', icon: 'doctor', disabled: busy !== '' || body.trim() === '', onClick: doReview },
2892
4138
  busy === 'review' ? '正在挑毛病…' : '挑挑毛病'),
2893
4139
  h('div', { className: 'lc-grow' }),
@@ -2904,6 +4150,67 @@ function BookView({ bookId, onBack, flash }) {
2904
4150
  ),
2905
4151
  ),
2906
4152
 
4153
+ // ── 改成剧本 ──
4154
+ // 用户丢来一份《小说改剧本》,要的就是这一件事:章写完了,能不能变成能拍的东西。
4155
+ // 放在正文下面而不是单独一屏:改剧本看的永远是「这一章」,跟正文分开会让人
4156
+ // 在两屏之间来回确认自己改的是哪一章。
4157
+ h('div', { className: 'lc-sec' },
4158
+ h('div', { className: 'lc-row' },
4159
+ h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, '改成剧本')),
4160
+ h(Btn, { size: 'sm', tone: 'analyze', icon: 'spark', disabled: busy !== '' || body.trim() === '' || chapterBroken === true, onClick: doScript },
4161
+ busy === 'script' ? '正在改…' : (scriptText.trim() === '' ? '把这一章改成剧本' : '重改一份')),
4162
+ ),
4163
+ h('div', { className: 'lc-meta', style: { marginTop: 4, lineHeight: 1.7 } },
4164
+ // 先说「不会动正文」:人第一眼最怕的是自己的小说被改掉。
4165
+ '只读这一章的正文,小说一个字都不动;改出来的剧本单独存一份。',
4166
+ h('br'),
4167
+ '改出来的是能配音、能拍的剧本:切成一场一场,叙述变成 △ 动作,人物的话变成台词。',
4168
+ h('br'),
4169
+ '小说里那些拍不出来的东西(他心里一沉、命运的齿轮),改的时候会被丢下。'),
4170
+ scriptReport === ''
4171
+ ? null
4172
+ : h('div', {
4173
+ className: 'lc-meta',
4174
+ style: {
4175
+ marginTop: 6, whiteSpace: 'pre-wrap', lineHeight: 1.8,
4176
+ padding: '8px 10px', borderRadius: 8, background: 'var(--lc-analyze-soft)',
4177
+ },
4178
+ }, scriptReport),
4179
+ // 框里有字、或者改过还没存、或者有报告——都得把框和按钮摆出来。
4180
+ // 以前只判「有字」:人把框里的字全删掉,存/删两个按钮跟着一起消失,
4181
+ // 想清空清不掉、想删也删不了,还以为点了没反应。
4182
+ scriptText === '' && scriptDirty !== true && scriptReport === ''
4183
+ ? null
4184
+ : h('div', { className: 'lc-stack', style: { marginTop: 6 } },
4185
+ h('textarea', {
4186
+ className: 'lc-textarea',
4187
+ value: scriptText,
4188
+ spellCheck: false,
4189
+ // 正在存 / 正在重改 / 正在删的时候都不让改:
4190
+ // 改了的字会在回包那一刻被当成「已存」清掉标记,或者被 AI 那一版整份盖掉。
4191
+ readOnly: busy === 'scriptSave' || busy === 'script' || busy === 'scriptDelete',
4192
+ style: { minHeight: 300, lineHeight: 1.8 },
4193
+ onChange: (e) => { setScriptText(e.target.value); setScriptDirty(true) },
4194
+ }),
4195
+ h('div', { className: 'lc-row' },
4196
+ h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '' || scriptText.trim() === '', onClick: saveScript },
4197
+ busy === 'scriptSave' ? '正在存…' : '存好这份剧本'),
4198
+ // 「删掉这份」写全:不写清是剧本,人会以为删的是小说正文。
4199
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', disabled: busy !== '', onClick: removeScript }, '删掉这份剧本'),
4200
+ h('div', { className: 'lc-grow' }),
4201
+ // 字数去掉空白再数:报告里、存好之后的回执里都是这个口径,
4202
+ // 这里多算的空格和换行只会让人以为「存完少了几十个字」。
4203
+ h('span', { className: 'lc-meta' },
4204
+ scriptDirty
4205
+ ? `${scriptText.replace(/\s/g, '').length} 字 · 还没存`
4206
+ : `${scriptText.replace(/\s/g, '').length} 字`),
4207
+ ),
4208
+ ),
4209
+ // 这一节的报错就摆在这一节里。放全页最底下等于没报——
4210
+ // 剧本框本身就三百像素高,报错落到屏幕外,人只会觉得「点了没反应」。
4211
+ scriptErr === null ? null : h(Note, { tone: 'err', icon: 'warning' }, scriptErr),
4212
+ ),
4213
+
2907
4214
  err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
2908
4215
  )
2909
4216
  }
@@ -2926,6 +4233,10 @@ function TavernView({ chat, onChat, onBack, flash }) {
2926
4233
  // 「挑几句写进卡里」。同样排在最后。
2927
4234
  const [exBusy, setExBusy] = useState(false)
2928
4235
  const [exNote, setExNote] = useState('')
4236
+ // 这一张卡现在读不出来了(被删掉、被挪走、文件坏了)——后台照样回话,
4237
+ // 但它手上没有这张卡,演出来的就不是卡上那个人。以前这一句没人说,
4238
+ // 用户只会觉得「TA 今天怎么没性格了」。这一行排在最后,同上。
4239
+ const [cardWarn, setCardWarn] = useState('')
2929
4240
  const turns = Array.isArray(chat?.turns) ? chat.turns : []
2930
4241
  const rawName = String(chat?.card_name ?? '').trim()
2931
4242
  const name = rawName === '' ? 'TA' : rawName
@@ -2943,6 +4254,11 @@ function TavernView({ chat, onChat, onBack, flash }) {
2943
4254
  // 不然用户会以为自己那句话没发出去、再打一遍,最后文件里出现两份。
2944
4255
  if (Array.isArray(r?.turns)) onChat({ ...chat, turns: r.turns })
2945
4256
  if (r?.ok !== true) { setErr(r?.error ?? 'TA 没接上话,过一会儿再试一次'); return }
4257
+ // 后台在卡读不出来时会退化成空 persona 照样回话,并把原因放在 warning 里。
4258
+ // 不说的话,用户看到的只是「TA 变了个性格」,会以为是自己哪里点错了。
4259
+ setCardWarn(String(r?.warning ?? '').trim() === ''
4260
+ ? ''
4261
+ : '这张卡现在读不出来了,这一段没在照卡演。往上看一眼是不是刚删过或者挪过它。')
2946
4262
  setDraft('')
2947
4263
  } catch (e) {
2948
4264
  setErr(humanizeError(e))
@@ -3078,6 +4394,8 @@ function TavernView({ chat, onChat, onBack, flash }) {
3078
4394
  className: 'lc-stack',
3079
4395
  style: { gap: 7, maxHeight: '52vh', overflowY: 'auto', padding: '2px 1px' },
3080
4396
  }, turns.map(bubble)),
4397
+ // 紧贴在对话流末尾:这一段不是照卡演的,必须当场说,不能等用户自己发现。
4398
+ cardWarn === '' ? null : h(Note, { tone: 'warn', icon: 'warning' }, cardWarn),
3081
4399
  memoryText === '' ? null : h(Note, { icon: 'book' },
3082
4400
  h('div', { style: { fontWeight: 650, marginBottom: 3 } }, '前面这些已经收好了'),
3083
4401
  h('div', { style: { whiteSpace: 'pre-wrap' } }, memoryText),
@@ -3160,7 +4478,7 @@ function TavernView({ chat, onChat, onBack, flash }) {
3160
4478
  )
3161
4479
  }
3162
4480
 
3163
- function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onInterview, onAnalyze, worlds, onOpenWorld, onTavern, initialEditing }) {
4481
+ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, onStartInterview, onAnalyze, worlds, onOpenWorld, initialEditing, mode }) {
3164
4482
  const [editing, setEditing] = useState(initialEditing === true)
3165
4483
  const [busy, setBusy] = useState('')
3166
4484
  const [err, setErr] = useState(null)
@@ -3279,7 +4597,7 @@ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, on
3279
4597
 
3280
4598
  memFlag === null
3281
4599
  ? null
3282
- : h('div', { className: 'lc-meta' }, `这条是从你写过的记忆里认出来的,当时只记了半句。还差:${memFlag.missing.join('、')}。点「接着聊」就会专门问这几样。`),
4600
+ : h('div', { className: 'lc-meta' }, `这条是从你写过的记忆里认出来的,当时只记了半句。还差:${memFlag.missing.join('、')}。点「聊一聊」就会专门问这几样。`),
3283
4601
 
3284
4602
  cov === undefined ? null : h('div', null,
3285
4603
  h('div', { className: 'lc-row' },
@@ -3296,13 +4614,22 @@ function CardView({ card, onRefresh, proposal, setProposal, flash, onDeleted, on
3296
4614
  // 主操作:三个指向明确的按钮
3297
4615
  h('div', { className: 'lc-row', style: { marginTop: 2 } },
3298
4616
  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 演一段'),
4617
+ // 补这张卡也不在插件里问:开一个新对话,把「补哪一张」说给它听。
4618
+ // 带上名字,新对话里才不用再问一遍「你说的是谁」。
4619
+ h(Btn, {
4620
+ tone: 'interview',
4621
+ icon: 'chat',
4622
+ onClick: () => onStartInterview({
4623
+ about: String(data?.name ?? '').trim(),
4624
+ mode,
4625
+
4626
+ }),
4627
+ }, '聊一聊(新开一个对话)'),
3301
4628
  h(Btn, { tone: 'analyze', size: 'sm', icon: 'spark', onClick: onAnalyze }, '读材料'),
3302
4629
  ),
3303
4630
 
3304
4631
  cov !== undefined && cov.empty.length > 0
3305
- ? h('div', { className: 'lc-meta' }, '「接着聊」会专门问还空着的那几样。')
4632
+ ? h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里。')
3306
4633
  : null,
3307
4634
 
3308
4635
  issues.length > 0
@@ -4247,7 +5574,7 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4247
5574
  h('span', { className: 'lc-grow' }),
4248
5575
  h('span', { className: 'lc-meta' }, `选了 ${checked} 条`),
4249
5576
  ),
4250
- h('div', { className: 'lc-meta' }, '每一条下面都引用了材料里的原话。它编不出来的——材料里找不到原文的,已经被丢掉了。'),
5577
+ h('div', { className: 'lc-meta' }, '每一条下面都引用了材料里的原话。它编不出来的——材料里找不到原文的、和前面那条重复的,都已经丢掉了。'),
4251
5578
  adoptedBefore > 0
4252
5579
  ? h('div', { className: 'lc-meta' }, `其中 ${adoptedBefore} 条之前已经写进卡了,不再列在这里。`)
4253
5580
  : null,
@@ -4266,7 +5593,7 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4266
5593
  ),
4267
5594
  ))),
4268
5595
  (proposal.rejected ?? []).length > 0
4269
- ? h(Note, { tone: 'warn', icon: 'warning' }, `有 ${proposal.rejected.length} 条在材料里找不到原话,已经丢掉了。`)
5596
+ ? h(Note, { tone: 'warn', icon: 'warning' }, `没有采用的有 ${proposal.rejected.length} 条:${rejectedWords(proposal)}。`)
4270
5597
  : null,
4271
5598
  // 名下还没有卡时不给采纳按钮。硬给的话点下去只会得到「找不到这张卡」,
4272
5599
  // 而用户刚刚才看完一整页建议——说清楚比给个坏按钮好。
@@ -4293,6 +5620,36 @@ function ProposalPanel({ proposal, onClose, onApplied, applyBlocked, onBuildCard
4293
5620
  )
4294
5621
  }
4295
5622
 
5623
+ /**
5624
+ * 被丢掉的条目为什么被丢:引文对不上,还是和同一字段里另一条重复?
5625
+ * 提案里带的是完整 rejected(每条有 reason);分析结果和提案列表只带计数,
5626
+ * 后端会把计数拆成 rejectedDuplicate / rejectedQuote 两个数回传。
5627
+ * 拿不到原因的时候不许硬说成「找不到原话」——那是在冤枉用户。
5628
+ */
5629
+ function rejectedSplit(one) {
5630
+ const raw = one?.rejected
5631
+ if (Array.isArray(raw)) {
5632
+ const dup = raw.filter((r) => String(r?.reason ?? '').includes('重复')).length
5633
+ return { known: true, total: raw.length, dup, quote: raw.length - dup }
5634
+ }
5635
+ const total = Number(raw ?? 0) || 0
5636
+ if (one?.rejectedDuplicate !== undefined && one?.rejectedQuote !== undefined) {
5637
+ return { known: true, total, dup: Number(one.rejectedDuplicate) || 0, quote: Number(one.rejectedQuote) || 0 }
5638
+ }
5639
+ return { known: false, total, dup: 0, quote: total }
5640
+ }
5641
+
5642
+ /** 把「丢了几条、为什么丢」说成一句人话;一条都没丢时返回空串。 */
5643
+ function rejectedWords(one) {
5644
+ const split = rejectedSplit(one)
5645
+ if (!(split.total > 0)) return ''
5646
+ if (!split.known) return `${split.total} 条没能通过校验,已经丢掉(引文对不上,或者和前面那条重复)`
5647
+ const bits = []
5648
+ if (split.dup > 0) bits.push(`${split.dup} 条和前面那条重复,只留了一条`)
5649
+ if (split.quote > 0) bits.push(`${split.quote} 条在材料里找不到原话,已经丢掉`)
5650
+ return bits.join(';')
5651
+ }
5652
+
4296
5653
  /** 把字段名翻译成人话。 */
4297
5654
  function fieldLabel(field) {
4298
5655
  const table = {
@@ -4436,7 +5793,15 @@ function NewCardView({ state, onCreate, presetName }) {
4436
5793
  )
4437
5794
  }
4438
5795
 
4439
- // ── 访谈 ──────────────────────────────────────────────────────────
5796
+ // ── 访谈(已经不走了,留作参考)──────────────────────────────────
5797
+ //
5798
+ // 这一段是插件自己演的访谈:插件问、插件拆字段、插件写卡。现在所有入口
5799
+ // (首页的「聊一聊」、卡片页补信息、材料页)都改成开一个新对话,把
5800
+ // /lifecard-interview 那个 skill 带上——问法只有一份,两边不会走样。
5801
+ //
5802
+ // 所以:任何界面路径都进不到 InterviewView,VIEWS.interview 也没有入口了。
5803
+ // 代码和它的测试留着,是因为拆字段、写卡那些逻辑以后可能还要用;真要改
5804
+ // 访谈的问法,改的是 skill,不是这里。入口见 openInterviewSession。
4440
5805
 
4441
5806
  function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAnalyze, mode }) {
4442
5807
  // 这扇门建的是现实里的人,还是虚构的角色。两者的第一问本来就不该一样:
@@ -4482,6 +5847,10 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4482
5847
  // 不然分析页一条都不勾,而「一条都不勾」= 全读——别人的材料会被读进这张卡。
4483
5848
  const [materialPaths, setMaterialPaths] = useState([])
4484
5849
  const scrollRef = useRef(null)
5850
+ // 开局失败要收掉刚建的那张空卡。收不掉的时候(比如超过十分钟窗口)它不是
5851
+ // 一句道歉能了事的:列表里会留一张同名空卡,下次同名建卡就撞
5852
+ // 「已经有一张叫…」。所以得记下来,并给一个能点过去的地方。
5853
+ const [stuckCard, setStuckCard] = useState(null)
4485
5854
 
4486
5855
  // 宿主给什么就用什么;一个都没有(还没重启、旧版宿主)就用本地这份。
4487
5856
  const relations = (state?.relations?.length ?? 0) > 0 ? state.relations : RELATION_FALLBACK
@@ -4518,7 +5887,7 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4518
5887
  .split(/[、,,;;\s]+/)
4519
5888
  .map((s) => s.trim())
4520
5889
  .filter((s) => s !== '')
4521
- setBusy(true); setErr(null)
5890
+ setBusy(true); setErr(null); setStuckCard(null)
4522
5891
  try {
4523
5892
  const id = preset?.id ?? safeId(targetName)
4524
5893
  // 先按 id 精确匹配,再按名字兜底。顺序不能反:酒馆里「复制一份来演」
@@ -4582,10 +5951,21 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4582
5951
  // 问题没准备出来(多半是 AI 那边没响应)。这时候刚建的那张空卡要收回去:
4583
5952
  // 留着它就是列表里一张名字对、点开什么都没有的卡,用户下次还会再建一张。
4584
5953
  // 本来就有的卡不动——那张卡上有他自己写的东西。
5954
+ let leftover = false
4585
5955
  if (existing === undefined && typeof made?.path === 'string' && made.path !== '') {
4586
- try { await call('card.delete', { path: made.path, reason: '访谈没能开始,撤掉这次建的空卡' }) } catch (e) { /* 撤不掉也不该挡住这句话 */ }
5956
+ // 用 discard 而不是 delete:这张卡从没进过列表,写墓碑会占住名字,
5957
+ // 用户马上换个名字重来时就会撞上「这个名字被一张已经删掉的卡占着」。
5958
+ try {
5959
+ const dr = await call('card.discard', { path: made.path })
5960
+ // 收不掉就记一笔。以前这里连返回值都不看,界面只说「已经撤掉了」,
5961
+ // 用户回列表却看见一张空卡,还以为是新问题。
5962
+ if (dr?.ok !== true) leftover = true
5963
+ } catch (e) { leftover = true }
4587
5964
  }
4588
- setErr(`${p?.error ?? '没法准备问题'}。${existing === undefined ? '刚才建的那张空卡已经撤掉了,' : ''}过一会儿再点一次「开始」。`)
5965
+ setStuckCard(leftover ? { name: targetName } : null)
5966
+ setErr(leftover
5967
+ ? `${p?.error ?? '没法准备问题'}。刚才建的那张空卡没能收走,去列表里把它删掉再重试。`
5968
+ : `${p?.error ?? '没法准备问题'}。${existing === undefined ? '刚才建的那张空卡已经撤掉了,' : ''}过一会儿再点一次「开始」。`)
4589
5969
  setPhase('pick')
4590
5970
  return
4591
5971
  }
@@ -4601,6 +5981,10 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4601
5981
  }
4602
5982
 
4603
5983
  const advance = async (status, reason) => {
5984
+ // 正记着的时候再点一次,会把同一题记两遍、还多跳一题——
5985
+ // 用户看到的就是「答案和题目错位」。按键已经 disabled,
5986
+ // 但键盘回车和连点仍可能挤进来,所以这里再挡一道。
5987
+ if (busy === true) return
4604
5988
  if (current === null) return
4605
5989
  const q = current
4606
5990
  setBusy(true); setErr(null)
@@ -4613,6 +5997,7 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4613
5997
  status,
4614
5998
  reason,
4615
5999
  fills: q.fills,
6000
+ options: q.options,
4616
6001
  })
4617
6002
  // 记不下来就别往下走。以前这里不看结果:盘写不进去(文件夹被挪走、
4618
6003
  // 变成只读)时界面照样把这一问答进对话、照样跳下一题,用户答了半小时,
@@ -4633,14 +6018,14 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4633
6018
  setLog((prev) => [...prev, { role: 'bot', text: q.ask, options: q.options }, { role: 'me', text: status === 'skipped' ? (reason === 'sealed' ? '(这个不想说)' : '(跳过)') : '(以后再说)' }])
4634
6019
  }
4635
6020
  setAnswer('')
4636
- // 队列推进
4637
- const rest = queue.slice(1)
6021
+ // 队列推进:按「这一题不在队里了」来算,不靠 slice(1) 的位置假设
6022
+ const rest = queue.filter((item) => item.id !== q.id)
4638
6023
  if (rest.length === 0) {
4639
6024
  const p = await call('interview.plan', { about: aboutId, relation, limit: 3, kind: fiction ? 'fictional' : 'real' })
4640
6025
  // 没问着问题不等于问完了。以前这里不看结果:AI 没连上、模型抽风、
4641
6026
  // 文件夹读不出来,界面都会直接跳到结束页,还写「现在写满了 undefined%」。
4642
6027
  if (p?.ok !== true) {
4643
- setErr(`${p?.error ?? '想不出下一题'}。刚才那一句已经记下了,这里是没接上——过一会儿点「再问一题」接着来。`)
6028
+ setErr(`${p?.error ?? '想不出下一题'}。刚才那一句已经记下了,这里是没接上——过一会儿点下面「再问一题」接着来。`)
4644
6029
  return
4645
6030
  }
4646
6031
  setPlan(p)
@@ -4662,6 +6047,24 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4662
6047
  } finally { setBusy(false) }
4663
6048
  }
4664
6049
 
6050
+ // 队列走空了、但下一组问题没要到(模型没连上/抽风)时的退路。
6051
+ // 以前错误文案让人点「再问一题」,界面上根本没有这个按钮,
6052
+ // 用户只能重开一场或者干脆放弃。
6053
+ const askMore = async () => {
6054
+ if (busy === true) return
6055
+ setBusy(true); setErr(null)
6056
+ try {
6057
+ const p = await call('interview.plan', { about: aboutId, relation, limit: 3, kind: fiction ? 'fictional' : 'real' })
6058
+ if (p?.ok !== true) { setErr(p?.error ?? '这会儿想不出下一题,过一会儿再点一次。'); return }
6059
+ setPlan(p)
6060
+ setQueue(p.next ?? [])
6061
+ setCurrent((p.next ?? [])[0] ?? null)
6062
+ if ((p.next ?? []).length === 0) { setPhase('done'); await onRecorded() }
6063
+ } catch (e) {
6064
+ setErr(humanizeError(e))
6065
+ } finally { setBusy(false) }
6066
+ }
6067
+
4665
6068
  // 「结束这次访谈」是整场收工,不是「跳过」的另一个说法:输入框里已经写好的
4666
6069
  // 那句不会存进去。以前这个按钮挤在「跳过 / 不想说」旁边,手一滑整场就没了、
4667
6070
  // 写了一半的话跟着丢,结束页还说「你说的都记下来了」。现在它挪到顶上单独一格,
@@ -4778,6 +6181,16 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4778
6181
  : h('div', { className: 'lc-meta' },
4779
6182
  relations.find((r) => r.id === relation)?.hint ?? '随便点一个最贴的。这一句只决定先问什么,不决定他的身份。'),
4780
6183
  err === null ? null : h(Err, { text: err }),
6184
+ // 空卡没被收走:给一条能走的路,不是让人自己去列表里翻。
6185
+ stuckCard === null
6186
+ ? null
6187
+ : h('div', { className: 'lc-note' },
6188
+ h('div', { style: { lineHeight: 1.7 } },
6189
+ `「${String(stuckCard.name ?? '').trim() === '' ? '刚才建的那张卡' : String(stuckCard.name)}」那张空卡还在列表里。`),
6190
+ h('div', { className: 'lc-row', style: { marginTop: 8, gap: 6 } },
6191
+ h(Btn, { size: 'sm', icon: 'list', onClick: () => { setStuckCard(null); setErr(null); onDone() } }, '去列表里删掉它'),
6192
+ ),
6193
+ ),
4781
6194
  h(Btn, { tone: fiction ? fictionTone : 'interview', big: true, block: true, onClick: start, disabled: busy, icon: 'send' }, busy ? '准备中…' : '开始聊'),
4782
6195
  )
4783
6196
  }
@@ -4818,17 +6231,26 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4818
6231
  log.map((entry, n) => entry.role === 'bot'
4819
6232
  ? h('div', { key: n, className: 'lc-stack' },
4820
6233
  h('div', { className: 'lc-bubble bot' }, h('div', { style: { whiteSpace: 'pre-wrap' } }, entry.text)),
6234
+ // 已经答完的那几题,选项只留着让人回看,**不能再点**:
6235
+ // 它们属于上一题,点下去会把那句话填进「这一题」的答案框,
6236
+ // 于是记下来的答案和题对不上(用户说的「选项和上一题答案错位」)。
4821
6237
  (entry.options ?? []).length > 0
4822
6238
  ? 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),
6239
+ entry.options.map((opt, k) => h('div', {
6240
+ key: k, className: 'lc-opt lc-opt-past',
6241
+ 'data-past-option': 'yes',
4826
6242
  }, h('span', { className: 'lc-opt-num' }, String(k + 1)), h('span', null, opt))))
4827
6243
  : null,
4828
6244
  )
4829
6245
  : h('div', { key: n, className: 'lc-bubble me' }, h('div', { style: { whiteSpace: 'pre-wrap' } }, entry.text))),
4830
6246
 
4831
6247
  current === null ? null : h('div', { className: 'lc-stack', style: { marginTop: 10 } },
6248
+ // 这一题的问题必须**在答题时就看得见**。以前只把问题写进日志气泡,
6249
+ // 而气泡是答完才追加的,于是用户在答「第 N 题」时,屏幕上最后一条
6250
+ // 还是「第 N-1 题」——答的什么、写进哪一题,全靠猜。
6251
+ h('div', { className: 'lc-bubble bot', 'data-current-ask': current.id },
6252
+ h('div', { style: { whiteSpace: 'pre-wrap' } }, String(current.ask ?? '')),
6253
+ h('div', { className: 'lc-meta', style: { marginTop: 4 } }, '这一题')),
4832
6254
  (current.options ?? []).length > 0
4833
6255
  ? h('div', { className: 'lc-meta' }, '选一个,或者直接在下面写自己的:')
4834
6256
  : null,
@@ -4839,7 +6261,14 @@ function InterviewView({ state, listing, preset, onRecorded, flash, onDone, onAn
4839
6261
  ),
4840
6262
  ),
4841
6263
  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 })),
6264
+ err === null ? null : h('div', { style: { marginBottom: 6 } },
6265
+ h(Err, { text: err }),
6266
+ // 这一题已经记下了、下一组问题没要到:给一个真的能点的「再问一题」,
6267
+ // 而不是让人对着错误信息干等。
6268
+ queue.length <= 1
6269
+ ? h('div', { style: { marginTop: 6 } }, h(Btn, { size: 'sm', icon: 'chat', tone: 'primary', disabled: busy, onClick: askMore }, '再问一题'))
6270
+ : null,
6271
+ ),
4843
6272
  h('textarea', {
4844
6273
  className: 'lc-textarea', style: { minHeight: 62, marginBottom: 6 },
4845
6274
  value: answer, onChange: (e) => setAnswer(e.target.value),
@@ -4867,12 +6296,12 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
4867
6296
 
4868
6297
  const handleFiles = (fileList) => {
4869
6298
  const all = Array.from(fileList ?? [])
4870
- const files = all.filter((f) => /\.(png|json|charx|zip)$/i.test(f.name))
6299
+ const files = all.filter((f) => /\.(png|json|charx|zip|txt|md)$/i.test(f.name))
4871
6300
  // 以前过滤完直接就 return:拖进来的是一张 jpg 头像或一份 md 设定,
4872
6301
  // 界面上什么都不发生,用户只会以为这块坏了。
4873
6302
  setSkipNote(files.length > 0 || all.length === 0
4874
6303
  ? ''
4875
- : `这些认不出来:${all.map((f) => f.name).join('、')}。只认角色卡文件(.png / .json / .charx / .zip)。想贴一段文字,就切到上面「一段文字」。`)
6304
+ : `这些认不出来:${all.map((f) => f.name).join('、')}。只认角色卡文件(.png / .json / .charx / .zip / .txt)。想贴一段文字,就切到上面「一段文字」。`)
4876
6305
  if (files.length === 0) return
4877
6306
  onImport(files)
4878
6307
  }
@@ -4904,7 +6333,7 @@ function ImportView({ busy, onImport, onAnalyze, listing }) {
4904
6333
  h('h3', null, drag ? '松手就行' : '把文件拖到这里,或者点一下去选'),
4905
6334
  h('div', { className: 'lc-meta' }, '别人给你的角色卡都能读——图片也行,导出的文件也行。', h('br'), '可以一次选好几个。'),
4906
6335
  h('input', {
4907
- ref: inputRef, type: 'file', multiple: true, accept: '.png,.json,.charx,.zip',
6336
+ ref: inputRef, type: 'file', multiple: true, accept: '.png,.json,.charx,.zip,.txt,.md',
4908
6337
  style: { display: 'none' }, onChange: (e) => handleFiles(e.target.files),
4909
6338
  }),
4910
6339
  ),
@@ -4998,7 +6427,7 @@ function TextImport({ onAnalyze }) {
4998
6427
  * 直接建卡会造出一排空卡,看着像成功、其实什么也不能用。
4999
6428
  * 摆出来、标清楚每人缺什么,用户自己决定哪些值得现在做。
5000
6429
  */
5001
- function MemoryView({ onDone, onBack }) {
6430
+ function MemoryView({ onDone, onBack, mode, onStartInterview }) {
5002
6431
  const [scan, setScan] = useState(null)
5003
6432
  const [picked, setPicked] = useState(null) // null = 还没选过,等于全选
5004
6433
  const [busy, setBusy] = useState(false)
@@ -5063,7 +6492,12 @@ function MemoryView({ onDone, onBack }) {
5063
6492
  `${whereText}认出了 ${people.length} 个人。`),
5064
6493
 
5065
6494
  people.length === 0
5066
- ? h(Note, { tone: undefined, icon: 'person' }, '记忆里没有提到具体的人。可以先「陪我聊聊」,聊过的内容会变成材料。')
6495
+ ? h('div', { className: 'lc-stack' },
6496
+ h(Note, { tone: undefined, icon: 'person' }, '记忆里没有提到具体的人。可以先「聊一聊」,聊过的内容会变成材料。'),
6497
+ h('div', null,
6498
+ h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
6499
+ h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里'),
6500
+ ))
5067
6501
  : h('div', { className: 'lc-stack' },
5068
6502
  people.map((p) => {
5069
6503
  const key = peopleKey(p)
@@ -5150,7 +6584,8 @@ function peopleKey(p) {
5150
6584
  // ── 让 AI 读材料 ──────────────────────────────────────────────────
5151
6585
 
5152
6586
  function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMaterials, onBack, onNeedMaterial, onAppliedCard }) {
5153
- const materials = listing?.materials ?? []
6587
+ // 备份和临时文件不算材料(见 isRealMaterial):它们点开是空的,读也读不出东西。
6588
+ const materials = (listing?.materials ?? []).filter(isRealMaterial)
5154
6589
  const cards = listing?.cards ?? []
5155
6590
  // 从别的页带过来的人,可能只有一个名字:材料刚存下、卡还没建。
5156
6591
  // 这种也该直接开始读——读出来的东西先进「建议」,采纳时才建卡。
@@ -5161,9 +6596,17 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5161
6596
  // 带过来的材料可能是一份,也可能是好几份(访谈一路上记下来的)。
5162
6597
  // 不认数组的话会变成「[一份, 另一份]」被当成一个路径,一条都勾不上,
5163
6598
  // 而一条都不勾等于全读。
6599
+ // 「读哪些材料」分三种:null = 全读(默认),[] = 一份都不读,[路径…] = 只读这几份。
6600
+ // 以前用「长度 0 就是全读」来表示「还没选」,于是把最后一份也取消勾选以后,
6601
+ // 界面悄悄回到「全读」——用户以为自己刚取消了,下一次读的却是全部。
5164
6602
  const [chosen, setChosen] = useState(() => {
5165
- if (Array.isArray(presetMaterials)) return presetMaterials.filter((x) => typeof x === 'string' && x !== '')
5166
- return presetMaterials === undefined || presetMaterials === null ? [] : [presetMaterials]
6603
+ if (Array.isArray(presetMaterials)) {
6604
+ // 显式给了清单就照单办:空清单就是「一份不读」,还给它 []。
6605
+ // 折回 null 等于「全读」——一场什么都没记下的访谈会因此把
6606
+ // 别人的材料一起读进这张卡里。
6607
+ return presetMaterials.filter((x) => typeof x === 'string' && x !== '')
6608
+ }
6609
+ return presetMaterials === undefined || presetMaterials === null ? null : [presetMaterials]
5167
6610
  })
5168
6611
  const [busy, setBusy] = useState(false)
5169
6612
  const [err, setErr] = useState(null)
@@ -5251,16 +6694,20 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5251
6694
  // 那一份,还以为读的是全部。
5252
6695
  const toggleMaterial = (path) => {
5253
6696
  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
6697
+ // 收起态(全读)里点掉一份 = 从「全读」变成「只读剩下的那几份」。
6698
+ const now = prev === null ? materials.map((m) => m.path) : prev
6699
+ const next = now.includes(path) ? now.filter((p) => p !== path) : [...now, path]
6700
+ // 又全勾回来了:收回成「全读」,界面才如实显示
6701
+ return next.length === materials.length ? null : next
5259
6702
  })
5260
6703
  }
6704
+ // 一份都没选(不是「还没选」):这时候「开始读」得置灰,否则点下去要么读全部、
6705
+ // 要么后台报「选中的材料都不存在」,两种都不是用户想要的。
6706
+ const nothingChosen = chosen !== null && chosen.length === 0
5261
6707
 
5262
6708
  // 选了哪几份就按哪几份算字数:「一条都不勾 = 全读」。
5263
- const readChars = (chosen.length > 0 ? materials.filter((m) => chosen.includes(m.path)) : materials)
6709
+ const readChars = materials
6710
+ .filter((m) => chosen === null || chosen.includes(m.path))
5264
6711
  .reduce((sum, m) => sum + (Number(m.chars) || Number(m.size) || 0), 0)
5265
6712
  const longRead = readChars > 20000
5266
6713
 
@@ -5280,14 +6727,14 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5280
6727
  about,
5281
6728
  // about 可能是卡 id,也可能只是个名字(还没建卡)。两种都照实传。
5282
6729
  name: cards.find((c) => c.id === about)?.name ?? about,
5283
- materials: chosen.length > 0 ? chosen : undefined,
6730
+ materials: chosen === null ? undefined : chosen,
5284
6731
  concept: conceptForRun === null ? undefined : conceptForRun,
5285
6732
  // 这个人是真人还是虚构角色:采纳时如果卡还不存在,就按这个身份现建。
5286
6733
  kind: String(presetAbout?.kind ?? '').trim() === 'fictional' ? 'fictional' : 'real',
5287
6734
  })
5288
6735
  if (r.ok !== true) { setErr(r.error ?? '没跑成'); return }
5289
6736
  setResult(r)
5290
- flash(`读出了 ${r.accepted} 条${r.rejected > 0 ? `,${r.rejected} 条没能核实已丢掉` : ''}`)
6737
+ flash(`读出了 ${r.accepted} 条${r.rejected > 0 ? `,${rejectedWords(r)}` : ''}`)
5291
6738
  } catch (e) {
5292
6739
  // 「连不上后台」在等了几分钟之后出现,真实原因通常不是没启动,
5293
6740
  // 而是 AI 那边卡住了、连接被断开。说实话比说套话有用。
@@ -5383,9 +6830,14 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5383
6830
  ),
5384
6831
  ),
5385
6832
 
5386
- h(Field, { label: '读哪些材料', hint: chosen.length === 0 ? '一个都不选就是全读。' : `已选 ${chosen.length} 份。` },
6833
+ h(Field, {
6834
+ label: '读哪些材料',
6835
+ hint: nothingChosen
6836
+ ? '现在一份都没选。至少选一份,或者把要读的材料挑出来。'
6837
+ : chosen === null ? '不选 = 全读。' : `已选 ${chosen.length} 份。`,
6838
+ },
5387
6839
  h('div', { className: 'lc-stack' }, materials.map((m) => {
5388
- const on = chosen.includes(m.path) || chosen.length === 0
6840
+ const on = chosen === null || chosen.includes(m.path)
5389
6841
  return h('div', {
5390
6842
  key: m.path, className: 'lc-proposal-item' + (on ? ' on' : ''),
5391
6843
  onClick: () => toggleMaterial(m.path), role: 'button', tabIndex: 0,
@@ -5402,7 +6854,7 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5402
6854
  err === null ? null : h(Err, { text: err }),
5403
6855
 
5404
6856
  h('div', { className: 'lc-row' },
5405
- h(Btn, { tone: 'analyze', big: true, onClick: run, disabled: busy || about === '' || materials.length === 0, icon: 'spark' }, busy ? '正在读…' : '开始读'),
6857
+ h(Btn, { tone: 'analyze', big: true, onClick: run, disabled: busy || about === '' || materials.length === 0 || nothingChosen, icon: 'spark' }, busy ? '正在读…' : '开始读'),
5406
6858
  busy ? h(Spinner) : null,
5407
6859
  ),
5408
6860
  // 这一趟是真等:模型先在心里想一遍再写(实测小材料也要四十秒上下,
@@ -5417,7 +6869,7 @@ function AnalyzeView({ listing, state, flash, onProposal, presetAbout, presetMat
5417
6869
  result === null ? null : h('div', null,
5418
6870
  h(Note, { tone: 'ok', icon: 'check' },
5419
6871
  h('div', null, `读出了 ${result.accepted} 条。`),
5420
- result.rejected > 0 ? h('div', { className: 'lc-meta', style: { marginTop: 3 } }, `另有 ${result.rejected} 条在材料里找不到原句,已经丢掉——AI 编的东西进不来。`) : null,
6872
+ result.rejected > 0 ? h('div', { className: 'lc-meta', style: { marginTop: 3 } }, `另有 ${rejectedWords(result)}。`) : null,
5421
6873
  ),
5422
6874
  // 写小说和酒馆里,用户要的是「读完就有一张能用的角色卡」,
5423
6875
  // 不是再去访谈一遍——虚构角色本来就没有「他是我的什么人」这种问题,
@@ -6310,6 +7762,23 @@ const PANEL_ID = 'lifecard'
6310
7762
  const PANEL_ORDER = 35
6311
7763
 
6312
7764
  function apply(ctx) {
7765
+ // 留住宿主,供 openInterviewSession 开新会话用。
7766
+ // 必须在最前面:下面拿不到 betterSidebar 会提前 return,放后面就永远是 null。
7767
+ HOST = ctx
7768
+ // 开新会话的两样能力都是可选的:有就记下来,没有就一直是 null(走退路)。
7769
+ // 不写进 inject 导出数组——那会让缺服务的干净 profile 整个 apply 不执行。
7770
+ try {
7771
+ ctx.inject?.(['remote.session'], (scoped) => {
7772
+ const got = scoped.get?.('remote.session', false)
7773
+ if (got !== undefined && got !== null) REMOTE_SESSION = got
7774
+ })
7775
+ } catch (e) { /* 老宿主没有这个服务 */ }
7776
+ try {
7777
+ ctx.inject?.(['uiWorkspace'], (scoped) => {
7778
+ const got = scoped.get?.('uiWorkspace', false)
7779
+ if (got !== undefined && got !== null) UI_WORKSPACE = got
7780
+ })
7781
+ } catch (e) { /* 老宿主没有这个服务 */ }
6313
7782
  // 样式也算副作用:跟着插件一起上手、一起回收。
6314
7783
  ctx.effect(() => ensureStyle(document), 'lifecard: 样式')
6315
7784
 
@@ -6349,7 +7818,7 @@ function apply(ctx) {
6349
7818
  ctx.effect(() => sidebar.registerTab({
6350
7819
  id: 'lifecard',
6351
7820
  title: 'Life Cards',
6352
- description: '把你认识的人和虚构角色写成档案:聊着建、导入角色卡、或从材料里读出来',
7821
+ description: '把你认识的人和虚构角色写成档案:聊一聊、导入角色卡、或从材料里读出来',
6353
7822
  icon: () => h(TabIcon),
6354
7823
  order: 40,
6355
7824
  single: true,
@@ -6371,6 +7840,16 @@ const inject = ['slots']
6371
7840
  exports.apply = apply;
6372
7841
  exports.inject = inject;
6373
7842
  exports.LifeCardTab = LifeCardTab;
7843
+ // 测试专用口子:这两条路要等宿主服务就绪(ctx.inject)才分得清,
7844
+ // 假宿主里造不出 inject,所以允许测试直接把两个服务塞进来。
7845
+ exports.__openInterviewSession = openInterviewSession;
7846
+ // 测试专用口子:写小说那一页只有从根部点进去才会出现,而它的换书逻辑
7847
+ // (bookId 变了但组件不卸载)在假根部里绕太远,直接渲染这个组件最省事。
7848
+ exports.__BookView = BookView;
7849
+ exports.__setHostServices = (remote, ui) => {
7850
+ REMOTE_SESSION = remote === undefined ? null : remote;
7851
+ UI_WORKSPACE = ui === undefined ? null : ui;
7852
+ };
6374
7853
  return module.exports;
6375
7854
  }
6376
7855
  });