dsh-lifecard 0.2.2 → 0.4.0

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
@@ -841,7 +841,7 @@ const SECTIONS_REL = [
841
841
 
842
842
  // ── 主界面 ────────────────────────────────────────────────────────
843
843
 
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' }
844
+ const VIEWS = { doors: 'doors', novel: 'novel', book: 'book', game: 'game', career: 'career', tavern: 'tavern', tavernChat: 'tavernChat', home: 'home', card: 'card', diary: 'diary', interview: 'interview', import: 'import', analyze: 'analyze', doctor: 'doctor', setup: 'setup', newCard: 'newCard', world: 'world', memory: 'memory', jobs: 'jobs', net: 'net' }
845
845
 
846
846
  // ── 开一个新会话去问 ──────────────────────────────────────────────
847
847
  //
@@ -898,6 +898,18 @@ function openInterviewSession({ about, mode, ask } = {}) {
898
898
  return openInterviewSessionByServer(prompt, preset)
899
899
  }
900
900
 
901
+ /**
902
+ * 开今天这一篇日记。
903
+ *
904
+ * 第一句由后台拼(要带上前几天写的、带上「我」那张卡里已有的东西),
905
+ * 这边只管把这句话和预设一起塞进新会话。
906
+ */
907
+ function openDiarySession(started) {
908
+ const prompt = String(started?.text ?? '').trim()
909
+ if (prompt === '') return { ok: false, prompt: '', reason: '今天这一篇的那句话没拼出来' }
910
+ return openInterviewSessionByServer(prompt, String(started?.preset ?? 'lc-diary'))
911
+ }
912
+
901
913
  /**
902
914
  * 正路:让后台建会话、把第一句发出去,客户端再把那个会话切到眼前。
903
915
  *
@@ -1212,6 +1224,10 @@ function LifeCardTab(props) {
1212
1224
  // 首页那几个按钮是「从头开始」的意思:上一次打开的是谁,到这一页就作废。
1213
1225
  // 不这样清,刚看完某人的卡再回首页点「整理 N 份材料」,那一页会默默
1214
1226
  // 还选着刚才那个人。
1227
+ // 书那一屏(BookView)自己知道手头有没有没存的正文和剧本。顶栏的返回和换门
1228
+ // 都在外面这一层,直接切屏的话那一屏就卸载了,谁也来不及问一句——
1229
+ // 人写了一段正文点顶上那个返回,字就没了,屏幕上连个提示都没有。
1230
+ // 所以 BookView 挂载时把「先收好再走」这个函数放在这里,外面切屏前先调它。
1215
1231
  const go = useCallback((next) => {
1216
1232
  // 离开那一屏就把带过去的东西清掉:不留着上一次的「整理谁」「读哪一份材料」,
1217
1233
  // 也不留着「这张建议卡属于谁」。以前 pendingAbout 只写不清——点过一次
@@ -1394,6 +1410,27 @@ function LifeCardTab(props) {
1394
1410
  // 会把后面每一个槽都错开一格。
1395
1411
  const [handoff, setHandoff] = useState(null)
1396
1412
  const [chatsNote, setChatsNote] = useState(null)
1413
+ // 书那一屏(BookView)自己知道手头有没有没存的正文和剧本。顶栏的返回和换门
1414
+ // 都在外面这一层,直接切屏的话那一屏就卸载了,谁也来不及问一句。
1415
+ // 所以 BookView 挂载时把「先收好再走」这个函数放在这里,切屏前先调它。
1416
+ //
1417
+ // 这三个 hook 必须排在 App 所有 hook 的最后:测试(render-all、doors-test)
1418
+ // 是按序号把预置状态摆进 hookStore 的,插在中间会把后面每个槽位都顶歪。
1419
+ const bookFlush = useRef(null)
1420
+ // 手头干净时同步返回 true:切屏不该为了「没东西要存」多等一帧。
1421
+ // 真有没存的东西才返回一个 promise,那时候等一下是对的。
1422
+ const leaveBook = useCallback(() => {
1423
+ const f = bookFlush.current
1424
+ if (typeof f !== 'function') return true
1425
+ return f()
1426
+ }, [])
1427
+ // 顶栏返回、换门都走这里:先请那一屏把没存的收好,收好了再走。
1428
+ const leaveThen = useCallback((next) => {
1429
+ const r = leaveBook()
1430
+ if (r === true) { next(); return }
1431
+ Promise.resolve(r).then((ok) => { if (ok === true) next() }).catch(() => null)
1432
+ }, [leaveBook])
1433
+
1397
1434
  const startInterview = useCallback((opts) => {
1398
1435
  const started = openInterviewSession(opts === undefined || opts === null ? {} : opts)
1399
1436
  const settle = (result) => {
@@ -1417,6 +1454,49 @@ function LifeCardTab(props) {
1417
1454
  settle(started)
1418
1455
  }, [flash])
1419
1456
 
1457
+ /**
1458
+ * 点「写日记」:先进那一屏。
1459
+ *
1460
+ * 以前是「定过文件夹就直接开新对话」,结果是那一屏变成死代码——想换文件夹、
1461
+ * 想看看写过几天、想打开昨天那篇,全都没有入口(第一次选完位置,那个屏幕
1462
+ * 就再也回不去了)。现在这一颗按钮只负责把人送到那一屏,开新对话由那屏的
1463
+ * 主按钮发起。
1464
+ */
1465
+ const startDiary = useCallback(async () => {
1466
+ setError(null)
1467
+ setView(VIEWS.diary)
1468
+ }, [])
1469
+
1470
+ /** 日记那一屏的主按钮:真的把今天这一篇开起来。 */
1471
+ const runDiaryStart = useCallback(async () => {
1472
+ if (busy !== '') return
1473
+ setBusy('diary'); setError(null)
1474
+ try {
1475
+ const info = await call('diary.info', {})
1476
+ if (info?.ok !== true) { setError(info?.error ?? '日记那边没能打开'); return }
1477
+ if (info.ready !== true) { setError('还没有挑日记放在哪个文件夹'); return }
1478
+ const started = await call('diary.start', {})
1479
+ if (started?.ok !== true) { setError(started?.error ?? '今天这一篇没能开起来'); return }
1480
+ const done = await openDiarySession(started)
1481
+ if (done?.ok === true) {
1482
+ setHandoff(null)
1483
+ flash(done.note !== undefined ? String(done.note) : '已经在新对话里了,跟着它写就行', done.note === undefined ? 'ok' : 'warn')
1484
+ return
1485
+ }
1486
+ // 开不了新会话时那句话也可能没拼出来:空文本框没有任何用处,
1487
+ // 直接把原因说出来,别让用户对着一个空框发愣。
1488
+ if (String(done?.prompt ?? '').trim() === '') {
1489
+ setError(String(done?.reason ?? '今天这一篇开不起来,再点一次试试'))
1490
+ return
1491
+ }
1492
+ setHandoff(done)
1493
+ } catch (e) {
1494
+ setError(humanizeError(e))
1495
+ } finally {
1496
+ setBusy('')
1497
+ }
1498
+ }, [busy, flash])
1499
+
1420
1500
  /** 打开一本书,进到那一屏。 */
1421
1501
  const openBook = (book) => {
1422
1502
  setActiveBook({ id: book?.id ?? '', title: book?.title ?? '' })
@@ -1626,7 +1706,9 @@ function LifeCardTab(props) {
1626
1706
  [VIEWS.setup]: '选个文件夹',
1627
1707
  [VIEWS.newCard]: '新建一张卡',
1628
1708
  [VIEWS.world]: activeWorld?.data?.name ?? '这本世界书',
1629
- [VIEWS.jobs]: '下一步',
1709
+ [VIEWS.jobs]: '求职',
1710
+ [VIEWS.diary]: '写日记',
1711
+ [VIEWS.net]: '人物关系网',
1630
1712
  }
1631
1713
  // 「选个文件夹」页一般不该有返回按钮(还没地方可回),
1632
1714
  // 但已经选过文件夹、是从首页主动进来换的时候要能退回去。
@@ -1636,7 +1718,15 @@ function LifeCardTab(props) {
1636
1718
  // 顶部返回一律当成「回首页」:上次打开的是谁、刚才点的是哪份材料、
1637
1719
  // 看的是哪本世界书,到这里都作废。不这样清,从 A 的卡退回来再点别人的
1638
1720
  // 材料,分析页会默默还认着 A,读出来的东西全记到 A 名下。
1639
- 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,
1721
+ canBack ? h('button', {
1722
+ className: 'lc-btn ghost sm',
1723
+ onClick: () => {
1724
+ // 先问这一屏有没有没存的东西(书那一屏会自己存);存不上就留在原地。
1725
+ leaveThen(() => { go(VIEWS.home); setError(null); setProposal(null); setActiveWorld(null) })
1726
+ },
1727
+ title: '回到列表',
1728
+ type: 'button',
1729
+ }, h(Icon, { name: 'back', size: 14 })) : null,
1640
1730
  h('div', { className: 'lc-grow lc-ellipsis' },
1641
1731
  h('div', { className: 'lc-title lc-ellipsis' }, titles[view] ?? 'Life Cards'),
1642
1732
  mode === 'real' && view !== VIEWS.doors
@@ -1651,7 +1741,10 @@ function LifeCardTab(props) {
1651
1741
  ? null
1652
1742
  : h('button', {
1653
1743
  className: 'lc-btn ghost sm',
1654
- onClick: () => { setView(VIEWS.doors); setError(null); setProposal(null); setActiveWorld(null); setActiveCard(null) },
1744
+ onClick: () => {
1745
+ // 换门也是离开这一屏,一样先把没存的收好。
1746
+ leaveThen(() => { setView(VIEWS.doors); setError(null); setProposal(null); setActiveWorld(null); setActiveCard(null) })
1747
+ },
1655
1748
  title: '换成另一扇门',
1656
1749
  type: 'button',
1657
1750
  }, '换门'),
@@ -1768,7 +1861,7 @@ function LifeCardTab(props) {
1768
1861
  // 直接退回首页,用户点了没反应,还以为坏了。现在把清单单独摊开。
1769
1862
  return activeCard === null
1770
1863
  ? proposal === null
1771
- ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1864
+ ? h(HomeView, { state, listing, mode, onDiary: startDiary, 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 })
1772
1865
  : h('div', { className: 'lc-pad lc-stack' },
1773
1866
  proposal.about === undefined || String(proposal.about).trim() === ''
1774
1867
  ? null
@@ -1830,7 +1923,7 @@ function LifeCardTab(props) {
1830
1923
  })
1831
1924
  case VIEWS.world:
1832
1925
  return activeWorld === null
1833
- ? h(HomeView, { state, listing, mode, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1926
+ ? h(HomeView, { state, listing, mode, onDiary: startDiary, 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 })
1834
1927
  : h(WorldView, {
1835
1928
  world: activeWorld,
1836
1929
  listing,
@@ -1846,16 +1939,36 @@ function LifeCardTab(props) {
1846
1939
  return h(BookView, {
1847
1940
  bookId: String(activeBook?.id ?? ''),
1848
1941
  flash,
1942
+ flushRef: bookFlush,
1849
1943
  onBack: () => { setActiveBook(null); setView(VIEWS.novel) },
1850
1944
  })
1851
1945
  case VIEWS.doctor:
1852
1946
  return h(DoctorView, { report: doctor, onOpenCard: openCard, onRun: () => runDoctor(true) })
1947
+ case VIEWS.diary:
1948
+ return h(DiaryView, {
1949
+ flash,
1950
+ onBack: () => setView(VIEWS.home),
1951
+ onStart: runDiaryStart,
1952
+ busy,
1953
+ })
1954
+ case VIEWS.net:
1955
+ return h(NetView, {
1956
+ onBack: () => setView(VIEWS.home),
1957
+ // 走 openCard 而不是把列表里那一行直接摆上去:列表项只有摘要,
1958
+ // 卡那一页要的是正文字节,少了它摊开是空的。
1959
+ onOpen: (id) => {
1960
+ const hit = (listing?.cards ?? []).find((c) => String(c.id ?? '') === String(id ?? ''))
1961
+ if (hit === undefined) return
1962
+ openCard(hit)
1963
+ },
1964
+ onTalk: (name) => startInterview({ about: name, mode }),
1965
+ })
1853
1966
  case VIEWS.career:
1854
- return h(CareerView, { flash, onBack: () => setView(VIEWS.home) })
1967
+ return h(CareerView, { flash, cards: listing?.cards ?? [], onOpenCard: openCard, onBack: () => setView(VIEWS.home) })
1855
1968
  case VIEWS.jobs:
1856
1969
  return h(JobsView, { onBack: () => setView(VIEWS.home), flash })
1857
1970
  default:
1858
- return h(HomeView, { state, listing, mode, onStartInterview: startInterview, onOpen: openFromList, chats, onOpenChat: openChat, onOpenWorld: openWorld, onNavigate: go, onMore: () => setShowMore(!showMore), showMore, onProposal: openProposal, busy, intro: introSeen === false, onIntroDone: dismissIntro, onMaterial: (m) => { setMaterialFor(m.path); setView(VIEWS.analyze) }, onDeleteMaterial: deleteMaterial, onDoDoctor: () => runDoctor(), onForkCard: forkForTavern, onDeleteCard: deleteCard, onRestoreCard: restoreCard, onPurgeCard: purgeCard, onEditCard: (c) => openCard(c, true), pinId: (mode === 'real' ? pins.real : mode === 'tavern' ? pins.tavern : pins.novel), onPickPin: (id) => pinCard(mode, id), books, onOpenBook: openBook, onCreateBook: createBook, onDeleteBook: deleteBook, chatsNote })
1971
+ return h(HomeView, { state, listing, mode, onDiary: startDiary, 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 })
1859
1972
  }
1860
1973
  }
1861
1974
 
@@ -1874,7 +1987,11 @@ function LifeCardTab(props) {
1874
1987
  // 不静默失败——点了没反应,比说清「这一步要你手动搬一下」更让人困惑。
1875
1988
  handoff === null || handoff.ok === true ? null : h('div', { style: { padding: '10px 12px 0' }, 'data-interview-handoff': '1' },
1876
1989
  h(Note, { tone: 'warn', icon: 'warning' },
1877
- h('div', null, '这个版本不支持直接开会话,把下面这句复制到新对话里:'),
1990
+ // 有真原因就说真原因:以前这里写死一句「这个版本不支持」,
1991
+ // 而真正卡住的地方(预设没认出来、第一句没发出去)一句都没露出来。
1992
+ h('div', null, String(handoff.reason ?? '').trim() === ''
1993
+ ? '这一下没能直接开新对话,把下面这句复制到新对话里也一样能用:'
1994
+ : `${String(handoff.reason).trim()} 把下面这句复制到新对话里也一样能用:`),
1878
1995
  h('textarea', {
1879
1996
  readOnly: true,
1880
1997
  rows: 3,
@@ -1978,7 +2095,7 @@ const DOORS = [
1978
2095
  title: '真实人物记录',
1979
2096
  desc: '身边的人:他做过什么、怎么说话、你们之间发生过什么。',
1980
2097
  bullets: ['聊一聊,它会问你几个具体的问题', '贴材料,让 AI 读出能核实的内容', '找工作:贴招聘说明、练面试'],
1981
- modules: ['人物卡', '访谈记录', '材料与建议', '简历与规划'],
2098
+ modules: ['人物卡', '人物关系网', '访谈记录', '材料与建议', '简历与规划'],
1982
2099
  },
1983
2100
  {
1984
2101
  id: 'novel', icon: 'book', tone: 'import',
@@ -2178,7 +2295,7 @@ function DoorsView({ onPick, state, features, hidden, onHide, onShow }) {
2178
2295
  )
2179
2296
  }
2180
2297
 
2181
- function HomeView({ state, listing, mode, onStartInterview, onOpen, onOpenWorld, onNavigate, onProposal, busy, onDoDoctor, showMore, onMore, intro, onIntroDone, onMaterial, onDeleteMaterial, chats, onOpenChat, onForkCard, onDeleteCard, onRestoreCard, onPurgeCard, onEditCard, books, onOpenBook, onCreateBook, onDeleteBook, chatsNote, pinId, onPickPin }) {
2298
+ function HomeView({ state, listing, mode, onStartInterview, onDiary, 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 }) {
2182
2299
  // 这扇门是不是「真实人物记录」。写小说、酒馆那两扇门里不该出现
2183
2300
  // 「贴一份招聘说明」「从记忆里认人」这类动作——那是记录真人才用得上的。
2184
2301
  const isReal = mode !== 'novel' && mode !== 'tavern'
@@ -2333,6 +2450,15 @@ function HomeView({ state, listing, mode, onStartInterview, onOpen, onOpenWorld,
2333
2450
  desc: '一张空表,一个字段一个字段地写。',
2334
2451
  onClick: () => onNavigate(VIEWS.newCard),
2335
2452
  }),
2453
+ // 还没建卡的人也能写日记:日记不落在档案里,它自己有一个文件夹。
2454
+ isReal
2455
+ ? h(Action, {
2456
+ tone: 'doctor', icon: 'pencil',
2457
+ title: '今天写一篇日记',
2458
+ desc: '不用先建卡。它会问你今天哪件事最值得讲。',
2459
+ onClick: () => onDiary?.(),
2460
+ })
2461
+ : null,
2336
2462
  // 写小说最常用的其实不是填表:手里已经有一篇小说、一段人物小传,
2337
2463
  // 想让它读成人设。这条路以前只在「真实人物」那扇门里有。
2338
2464
  h(Action, {
@@ -2365,17 +2491,31 @@ function HomeView({ state, listing, mode, onStartInterview, onOpen, onOpenWorld,
2365
2491
  ),
2366
2492
 
2367
2493
  h('div', { className: 'lc-row', style: { marginTop: 2 } },
2368
- h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
2494
+ h(Btn, { tone: isReal ? 'interview' : fictionActionTone, size: 'sm', icon: 'chat', onClick: () => onStartInterview?.({ about: '', mode }) }, '聊一聊(新开一个对话)'),
2369
2495
  h(Btn, { tone: 'import', size: 'sm', icon: 'import', onClick: () => onNavigate(VIEWS.import) }, '导入'),
2370
2496
  isReal
2371
2497
  ? h(Btn, { tone: 'analyze', size: 'sm', icon: 'person', onClick: () => onNavigate(VIEWS.memory), title: '从你写过的记忆里认出身边的人' }, '从记忆里认人')
2372
2498
  : null,
2499
+ // 以前这个按钮叫「下一步」。用户的原话是「看不出是什么东西,点进去才知道」——
2500
+ // 一个名字要能自己说明它管什么。这一页干的就是求职那件事:贴一份招聘
2501
+ // 说明看差在哪、练一轮面试、记下投了哪些。叫「求职」两个字就够。
2373
2502
  isReal
2374
- ? h(Btn, { tone: 'primary', size: 'sm', icon: 'briefcase', onClick: () => onNavigate(VIEWS.jobs), title: '贴一份招聘说明,看看该不该投;或者练一轮面试' }, '下一步')
2503
+ ? h(Btn, { tone: 'primary', size: 'sm', icon: 'briefcase', onClick: () => onNavigate(VIEWS.jobs), title: '贴一份招聘说明,看看该不该投;或者练一轮面试' }, '求职')
2375
2504
  : null,
2376
2505
  isReal
2377
2506
  ? h(Btn, { size: 'sm', icon: 'book', onClick: () => onNavigate(VIEWS.career), title: '把自己的情况写清楚,让 AI 帮你看简历、算差距、规划怎么走' }, '简历与规划')
2378
2507
  : null,
2508
+ // 人物关系网:认识的人散在文件夹里看不出远近,这一屏以「我」为中心摆开。
2509
+ // 只在真实人物这扇门里给——写小说和酒馆要的是角色设定,不是社交圈。
2510
+ isReal
2511
+ ? h(Btn, { size: 'sm', icon: 'relation', onClick: () => onNavigate(VIEWS.net), title: '我认识的人,谁离我近、谁只是通过别人认识的' }, '人物关系网')
2512
+ : null,
2513
+ // 写日记:点一下就开新对话,进去直接开始写。
2514
+ // 不摆在这一排的最后面,是因为它是每天都会用一次的东西,
2515
+ // 而「求职」「简历与规划」是一阵子用一次。
2516
+ isReal
2517
+ ? h(Btn, { tone: 'doctor', size: 'sm', icon: 'pencil', onClick: () => onDiary?.(), title: '今天哪件事最值得讲——开一个新对话,它带你写' }, '写日记')
2518
+ : null,
2379
2519
  h('div', { className: 'lc-grow' }),
2380
2520
  // 「贴一段文章让 AI 读」不是只有记录真人才用得上:写小说、酒馆里
2381
2521
  // 手里有一段人物设定/小说片段,一样想让它读成人设。所以三扇门都给。
@@ -3219,6 +3359,414 @@ function GameView({ bookId, onBack, flash }) {
3219
3359
  )
3220
3360
  }
3221
3361
 
3362
+ /**
3363
+ * 写日记。
3364
+ *
3365
+ * 这一屏只干一件事:把「今天这一篇」开起来。
3366
+ *
3367
+ * 为什么日记不放在档案文件夹里:日记是每天写的东西,量比卡大得多,混在
3368
+ * people/ 里会把真正要看的那几张卡挤没。所以第一次进来问一次放哪儿,
3369
+ * 之后每天那一篇就落在那里——用户自己挑的位置,随时能在访达里翻。
3370
+ *
3371
+ * 一天一篇、摊平不分目录:好找,也方便丢进同步盘。
3372
+ */
3373
+ function DiaryView({ onBack, flash, onStart, busy }) {
3374
+ const [info, setInfo] = useState(null)
3375
+ const [dir, setDir] = useState('')
3376
+ const [editing, setEditing] = useState(false)
3377
+ const [saving, setSaving] = useState(false)
3378
+ const [err, setErr] = useState(null)
3379
+ const [opened, setOpened] = useState(null)
3380
+
3381
+ /** 读一次「现在什么状况」。读失败也把 info 填上,别让屏幕卡在半空。 */
3382
+ const load = async () => {
3383
+ setErr(null)
3384
+ try {
3385
+ const r = await call('diary.info', {})
3386
+ if (r?.ok !== true) { setErr(r?.error ?? '日记读不出来'); return false }
3387
+ setInfo(r)
3388
+ if (String(r.dir ?? '').trim() !== '') setDir(String(r.dir ?? ''))
3389
+ else if (String(r.suggest ?? '').trim() !== '') setDir(String(r.suggest))
3390
+ if (r.ready !== true) setEditing(true)
3391
+ if (r.broken === true) setEditing(true)
3392
+ return true
3393
+ } catch (e) { setErr(humanizeError(e)); return false }
3394
+ }
3395
+
3396
+ useEffect(() => {
3397
+ let gone = false
3398
+ call('diary.info', {})
3399
+ .then((r) => {
3400
+ if (gone) return
3401
+ if (r?.ok !== true) { setErr(r?.error ?? '日记读不出来'); return }
3402
+ setInfo(r)
3403
+ if (String(r.dir ?? '').trim() !== '') setDir(String(r.dir ?? ''))
3404
+ else if (String(r.suggest ?? '').trim() !== '') setDir(String(r.suggest))
3405
+ if (r.ready !== true || r.broken === true) setEditing(true)
3406
+ })
3407
+ .catch((e) => { if (!gone) setErr(humanizeError(e)) })
3408
+ return () => { gone = true }
3409
+ }, [])
3410
+
3411
+ const keep = async () => {
3412
+ setSaving(true); setErr(null)
3413
+ try {
3414
+ const r = await call('diary.dir.set', { dir })
3415
+ if (r?.ok !== true) { setErr(r?.error ?? '这个位置没能用起来'); return }
3416
+ // 位置真的记住了才说「好了」;接下来那次读失败就留在这一屏,
3417
+ // 不能一边弹绿色成功、一边把屏幕切成半空的样子。
3418
+ const ok = await load()
3419
+ if (ok !== true) return
3420
+ flash?.('好了,以后每天那一篇就存在这儿')
3421
+ setEditing(false)
3422
+ } catch (e) { setErr(humanizeError(e)) } finally { setSaving(false) }
3423
+ }
3424
+
3425
+ const openPast = async (date) => {
3426
+ try {
3427
+ const r = await call('diary.get', { date })
3428
+ if (r?.ok !== true) { setErr(r?.error ?? '那一天读不出来'); return }
3429
+ setOpened({ date, data: r.data })
3430
+ } catch (e) { setErr(humanizeError(e)) }
3431
+ }
3432
+
3433
+ if (info === null) {
3434
+ return h('div', { className: 'lc-pad lc-stack' },
3435
+ h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回首页'),
3436
+ err === null
3437
+ ? h(Spinner)
3438
+ : h('div', { className: 'lc-stack' },
3439
+ h(Note, { tone: 'err', icon: 'warning' }, err),
3440
+ h(Btn, { block: true, onClick: () => { load() } }, '再试一次'),
3441
+ h(Btn, { block: true, icon: 'folder', onClick: () => { setErr(null); setEditing(true) } }, '换个文件夹'),
3442
+ ),
3443
+ )
3444
+ }
3445
+
3446
+ if (opened !== null) {
3447
+ return h(DiaryEntryView, { entry: opened, onBack: () => setOpened(null) })
3448
+ }
3449
+
3450
+ if (editing === true) {
3451
+ return h('div', { className: 'lc-pad lc-stack' },
3452
+ h(Btn, { size: 'sm', icon: 'back', onClick: () => { if (info?.broken === true || info?.missing === true) onBack(); else { setEditing(false); setErr(null) } } },
3453
+ info?.broken === true || info?.missing === true ? '回首页' : '不换了'),
3454
+ h('div', { className: 'lc-empty', style: { paddingBottom: 12 } },
3455
+ h('div', { className: 'lc-empty-icon' }, h(Icon, { name: 'folder', size: 22 })),
3456
+ h('h3', null, '日记放在哪个文件夹'),
3457
+ h('div', { className: 'lc-meta' }, '日记不跟人物卡混在一起。', h('br'), '一天一篇纯文本,你随时能在访达(Finder)里找到。'),
3458
+ ),
3459
+ info?.broken === true || info?.missing === true
3460
+ ? h(Note, { tone: 'warn', icon: 'warning' }, info?.error ?? '原来那个文件夹不见了,日记还在里面,只是现在读不到。换一个位置,或者把它挪回来。')
3461
+ : null,
3462
+ h(Field, { label: '放在哪里', hint: '已经替你填好一个位置,看不顺眼可以改。' },
3463
+ h('input', {
3464
+ className: 'lc-input', value: dir, spellCheck: false,
3465
+ placeholder: '/Users/你/Documents/我的日记',
3466
+ onChange: (e) => setDir(e.target.value),
3467
+ }),
3468
+ ),
3469
+ err === null ? null : h(Err, { text: err }),
3470
+ keepButton(saving, dir, keep),
3471
+ )
3472
+ }
3473
+
3474
+ const recent = Array.isArray(info.recent) ? info.recent : []
3475
+ const started = busy === 'diary'
3476
+ return h('div', { className: 'lc-pad lc-stack' },
3477
+ h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回首页'),
3478
+ h('div', { className: 'lc-meta' }, `日记存在「${folderName(info.dir)}」这个文件夹里`),
3479
+ info?.missing === true || info?.broken === true
3480
+ ? h(Note, { tone: 'warn', icon: 'warning' },
3481
+ `${String(info?.error ?? '那个文件夹里现在一篇也读不到,可能被挪走了。').trim()}日记文件本身还在原来的地方,把它挪回原处、或者在这儿换一个位置都行。`)
3482
+ : null,
3483
+ h('div', { className: 'lc-empty', style: { padding: '14px 8px 10px' } },
3484
+ h('div', { className: 'lc-empty-icon' }, h(Icon, { name: 'pencil', size: 22 })),
3485
+ h('h3', null, info.todayDone === true ? '今天已经写过一篇' : '今天还没写'),
3486
+ h('div', { className: 'lc-meta' },
3487
+ info.todayDone === true
3488
+ ? '再点一次是接着那一篇往下写:已经写进去的它会先读一遍,不会重问,也不会把上午写的换掉。'
3489
+ : '不用先建卡。点一下就开始问今天哪件事最值得讲。'),
3490
+ ),
3491
+ h(Btn, {
3492
+ tone: 'primary', big: true, block: true, icon: 'pencil',
3493
+ disabled: started,
3494
+ onClick: () => { if (started) return; onStart?.() },
3495
+ }, started ? '正在开…' : (info.todayDone === true ? '接着写今天这一篇' : '今天就写这一篇')),
3496
+ h('div', { className: 'lc-meta' }, '会在新对话里问。不想讲就换一件,跳过也行。'),
3497
+ err === null ? null : h(Err, { text: err }),
3498
+ recent.length === 0
3499
+ ? null
3500
+ : h('div', { className: 'lc-sec' },
3501
+ h(GroupTitle, { icon: 'history' }, `写过 ${String(info.count ?? recent.length)} 天`),
3502
+ h('div', { className: 'lc-stack', style: { gap: 4 } },
3503
+ recent.map((one) => h('div', {
3504
+ key: one.date, className: 'lc-row', style: { cursor: 'pointer' },
3505
+ onClick: () => { if (String(one.date ?? '') !== '') openPast(String(one.date)) },
3506
+ },
3507
+ h('div', { className: 'lc-grow lc-ellipsis' }, String(one.date ?? '')),
3508
+ h('div', { className: 'lc-meta' }, one.chars === 0 || one.chars === undefined ? '还没写' : `${Math.round(Number(one.chars ?? 0) / 3)} 字`),
3509
+ )),
3510
+ ),
3511
+ ),
3512
+ h('div', { className: 'lc-row', style: { marginTop: 4 } },
3513
+ h(Btn, {
3514
+ size: 'sm', icon: 'folder',
3515
+ onClick: () => {
3516
+ const yes = typeof window === 'undefined' || typeof window.confirm !== 'function'
3517
+ ? true
3518
+ : window.confirm('换过去以后,现在这个文件夹里的日记不会跟过来(它们还在原处,只是这一屏看不到)。确定换吗?')
3519
+ if (yes === true) setEditing(true)
3520
+ },
3521
+ }, '换个文件夹'),
3522
+ ),
3523
+ )
3524
+ }
3525
+
3526
+ /** 日记文件夹那一屏跟用户说的名字:只给最后一段,别甩一整条绝对路径。 */
3527
+ function folderName(dir) {
3528
+ const raw = String(dir ?? '').trim().replace(/[\\/]+$/, '')
3529
+ if (raw === '') return '我的日记'
3530
+ const parts = raw.split(/[\\/]/)
3531
+ return parts[parts.length - 1] || raw
3532
+ }
3533
+
3534
+
3535
+ /** 某一天那一篇:只读,看完回去。 */
3536
+ function DiaryEntryView({ entry, onBack }) {
3537
+ const data = entry?.data ?? null
3538
+ const blocks = []
3539
+ for (const title of ['今天最值得讲的一件事', '当时在想什么', '情绪往下三层', '我做了什么决定', '下一步']) {
3540
+ const value = data?.[title]
3541
+ const text = Array.isArray(value) ? value.filter((x) => String(x ?? '').trim() !== '').join('\n') : String(value ?? '')
3542
+ if (text.trim() === '') continue
3543
+ blocks.push(h('div', { key: title, className: 'lc-sec' },
3544
+ h(GroupTitle, { icon: 'pencil' }, title),
3545
+ h('div', { style: { whiteSpace: 'pre-wrap' } }, text),
3546
+ ))
3547
+ }
3548
+ const scores = data?.scores !== null && typeof data?.scores === 'object' ? data.scores : {}
3549
+ const names = Object.keys(scores)
3550
+ return h('div', { className: 'lc-pad lc-stack' },
3551
+ h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回去'),
3552
+ h('h3', { style: { margin: '4px 0 0' } }, String(entry?.date ?? '')),
3553
+ blocks.length === 0 ? h('div', { className: 'lc-meta' }, '这一天没有写正文。') : blocks,
3554
+ names.length === 0
3555
+ ? null
3556
+ : h('div', { className: 'lc-sec' },
3557
+ h(GroupTitle, { icon: 'check' }, '今天这四样'),
3558
+ h('div', { className: 'lc-meta' }, names.map((name) => `${name} ${scores[name]}`).join(' · ')),
3559
+ ),
3560
+ )
3561
+ }
3562
+
3563
+ /** 日记那一屏底部那个「就用这个文件夹」按钮。写成一个函数是为了不让条件挤在一行里。 */
3564
+ function keepButton(busy, dir, keep) {
3565
+ return h('div', { style: { marginTop: 4 } },
3566
+ h(Btn, {
3567
+ tone: 'primary', big: true, block: true, icon: 'check',
3568
+ disabled: busy === true || String(dir ?? '').trim() === '',
3569
+ onClick: keep,
3570
+ }, busy === true ? '正在准备…' : '就用这个文件夹'),
3571
+ )
3572
+ }
3573
+
3574
+ /**
3575
+ * 人物关系网。
3576
+ *
3577
+ * 为什么单独做一屏:卡的列表按名字和更新时间排,谁离你近、谁只是通过
3578
+ * 别人认识的,在那里完全看不出来。这一屏只回答一件事——我在中间,
3579
+ * 认识的人是怎么散开的。
3580
+ *
3581
+ * 圈的口径后台算好(`relations.net`):0 圈是我自己,1 圈是直接写着和
3582
+ * 我有关系的人,2 圈是只和 1 圈里的人有关系的人。没有任何关系线索的
3583
+ * 人不进网,收在底下那一行——不收进来的话,他们会像凭空消失了一样。
3584
+ */
3585
+ function NetView({ onBack, onOpen, onTalk }) {
3586
+ const [net, setNet] = useState(null)
3587
+ const [err, setErr] = useState(null)
3588
+ const [showOutside, setShowOutside] = useState(false)
3589
+
3590
+ useEffect(() => {
3591
+ let alive = true
3592
+ call('relations.net', {}).then((r) => {
3593
+ if (alive !== true) return
3594
+ if (r?.ok !== true) { setErr(r?.error ?? '这张网没读出来'); return }
3595
+ setNet(r)
3596
+ }).catch((e) => { if (alive === true) setErr(humanizeError(e)) })
3597
+ return () => { alive = false }
3598
+ }, [])
3599
+
3600
+ if (net === null) {
3601
+ return h('div', { className: 'lc-pad lc-stack' },
3602
+ err === null
3603
+ ? h('div', { className: 'lc-empty' }, h(Spinner), h('div', { className: 'lc-meta', style: { marginTop: 8 } }, '正在把认识的人摆开…'))
3604
+ : h(Err, { text: err }),
3605
+ h(Btn, { onClick: onBack }, '回去'),
3606
+ )
3607
+ }
3608
+
3609
+ const self = net.self ?? null
3610
+ const inner = net.rings?.inner ?? []
3611
+ const outer = net.rings?.outer ?? []
3612
+ const outside = net.outside ?? []
3613
+
3614
+ // 画在圈上的位置:按人数均分一圈,从正上方开始。人太多就只画前 12 个,
3615
+ // 剩下的在下面的名单里——挤成一团比不画更难看懂。
3616
+ const onRing = (list, radius, ring) => {
3617
+ const shown = list.slice(0, 12)
3618
+ return shown.map((one, i) => {
3619
+ const angle = (Math.PI * 2 * i) / Math.max(1, shown.length) - Math.PI / 2
3620
+ return { one, ring, x: 170 + Math.cos(angle) * radius, y: 170 + Math.sin(angle) * radius }
3621
+ })
3622
+ }
3623
+ const innerSpots = onRing(inner, 86, 1)
3624
+ const outerSpots = onRing(outer, 138, 2)
3625
+
3626
+ // 二圈的人连到最近的那个一圈的人:谁把他带进来的,一眼看得出。
3627
+ const nearest = (spot) => {
3628
+ let best = null
3629
+ let gap = Infinity
3630
+ for (const one of innerSpots) {
3631
+ const d = (one.x - spot.x) ** 2 + (one.y - spot.y) ** 2
3632
+ if (d < gap) { gap = d; best = one }
3633
+ }
3634
+ return best
3635
+ }
3636
+
3637
+ const pic = h('svg', {
3638
+ viewBox: '0 0 340 340',
3639
+ width: '100%',
3640
+ height: 'auto',
3641
+ role: 'img',
3642
+ 'aria-label': '以我为中心的人物关系图',
3643
+ style: { display: 'block', maxHeight: 340 },
3644
+ },
3645
+ // 先画线,再画点。线在下面,名字才不会被穿过。
3646
+ innerSpots.map((spot) => h('line', {
3647
+ key: `l-${spot.one.id}`,
3648
+ x1: 170, y1: 170, x2: spot.x, y2: spot.y,
3649
+ stroke: 'currentColor', strokeOpacity: 0.22, strokeWidth: 1.2,
3650
+ })),
3651
+ outerSpots.map((spot) => {
3652
+ const from = nearest(spot)
3653
+ return h('line', {
3654
+ key: `lo-${spot.one.id}`,
3655
+ x1: from === null ? 170 : from.x, y1: from === null ? 170 : from.y,
3656
+ x2: spot.x, y2: spot.y,
3657
+ stroke: 'currentColor', strokeOpacity: 0.13, strokeWidth: 1,
3658
+ strokeDasharray: '3 3',
3659
+ })
3660
+ }),
3661
+ // 我自己
3662
+ h('g', {
3663
+ key: 'self',
3664
+ onClick: self === null ? undefined : () => onOpen?.(self.id),
3665
+ style: { cursor: self === null ? 'default' : 'pointer' },
3666
+ },
3667
+ h('circle', { cx: 170, cy: 170, r: 30, fill: 'var(--lc-accent)', fillOpacity: 0.16, stroke: 'var(--lc-accent)', strokeWidth: 1.4 }),
3668
+ h('text', {
3669
+ x: 170, y: 175, textAnchor: 'middle', fontSize: 13, fontWeight: 700, fill: 'currentColor',
3670
+ }, self === null ? '我' : cutName(self.name, 5)),
3671
+ ),
3672
+ [...innerSpots, ...outerSpots].map((spot) => h('g', {
3673
+ key: spot.one.id,
3674
+ onClick: () => onOpen?.(spot.one.id),
3675
+ style: { cursor: 'pointer' },
3676
+ },
3677
+ h('circle', {
3678
+ cx: spot.x, cy: spot.y, r: spot.ring === 1 ? 13 : 11,
3679
+ fill: 'var(--lc-panel, transparent)', stroke: 'currentColor',
3680
+ strokeOpacity: spot.ring === 1 ? 0.5 : 0.3, strokeWidth: 1.2,
3681
+ }),
3682
+ h('text', {
3683
+ x: spot.x, y: spot.y + (spot.ring === 1 ? 22 : 20),
3684
+ textAnchor: 'middle', fontSize: 9.5, fill: 'currentColor', fillOpacity: 0.8,
3685
+ }, cutName(spot.one.name, 5)),
3686
+ )),
3687
+ )
3688
+
3689
+ const rowOf = (one, tone) => h('button', {
3690
+ key: one.id,
3691
+ type: 'button',
3692
+ className: 'lc-listrow',
3693
+ style: { display: 'flex', alignItems: 'center', gap: 9, width: '100%', textAlign: 'left' },
3694
+ onClick: () => onOpen?.(one.id),
3695
+ },
3696
+ h(Avatar, { name: one.name, kind: one.kind }),
3697
+ h('span', { className: 'lc-grow' },
3698
+ h('div', null, one.name),
3699
+ h('div', { className: 'lc-meta' },
3700
+ one.relationLabel === '' ? KIND_LABEL[one.kind] ?? '' : one.relationLabel,
3701
+ ...(one.extras ?? []).map((x) => ` · ${x}`)),
3702
+ ),
3703
+ tone === undefined ? null : h(Tag, { tone }, tone === 'ok' ? '直接认识' : '通过别人'),
3704
+ )
3705
+
3706
+ return h('div', { className: 'lc-pad lc-stack' },
3707
+ h('div', { className: 'lc-meta' },
3708
+ self === null
3709
+ ? '还没有一张写着「我」的卡。把你自己也写成一张,这张网才有中心。'
3710
+ : `以「${self.name}」为中心,${inner.length} 个人是你直接认识的,${outer.length} 个是通过别人认识的。`),
3711
+
3712
+ self === null
3713
+ ? h(Action, {
3714
+ tone: 'interview', icon: 'person', title: '先把「我」写成一张卡',
3715
+ desc: '答完 AI 会写进 people/ 里,之后这张网就以你为中心了。',
3716
+ onClick: () => onTalk?.(''),
3717
+ })
3718
+ : pic,
3719
+
3720
+ inner.length === 0
3721
+ ? h(Note, { tone: undefined, icon: 'relation' }, '还没有人和你有直接关系。点一个人名进去,把他的关系写上是「父亲」「朋友」这样,他就会出现在这里。')
3722
+ : h('div', { className: 'lc-sec' },
3723
+ h(GroupTitle, { icon: 'people' }, `我直接认识的(${inner.length})`),
3724
+ h('div', { className: 'lc-stack' }, inner.map((one) => rowOf(one, 'ok'))),
3725
+ ),
3726
+
3727
+ outer.length === 0
3728
+ ? null
3729
+ : h('div', { className: 'lc-sec' },
3730
+ h(GroupTitle, { icon: 'relation' }, `通过别人认识的(${outer.length})`),
3731
+ h('div', { className: 'lc-stack' }, outer.map((one) => rowOf(one, undefined))),
3732
+ ),
3733
+
3734
+ outside.length === 0
3735
+ ? null
3736
+ : h('div', { className: 'lc-more' },
3737
+ h('button', {
3738
+ type: 'button', className: 'lc-more-open',
3739
+ onClick: () => setShowOutside(showOutside !== true),
3740
+ }, showOutside === true ? '收起来' : `还有 ${outside.length} 个人,卡片在,还没写出和你是什么关系`),
3741
+ showOutside !== true
3742
+ ? null
3743
+ : h('div', { className: 'lc-stack', style: { marginTop: 8 } },
3744
+ h('div', { className: 'lc-meta' }, '点进去把「他是我的什么人」写上,他们就会进到圈里。'),
3745
+ outside.map((one) => rowOf({ ...one, kind: one.kind ?? 'real', relationLabel: '', extras: [] }, undefined)),
3746
+ ),
3747
+ ),
3748
+
3749
+ err === null ? null : h(Err, { text: err }),
3750
+
3751
+ h('div', { className: 'lc-row' },
3752
+ self === null
3753
+ ? null
3754
+ : h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onTalk?.(self.name) }, '和「我」聊聊'),
3755
+ h('div', { className: 'lc-grow' }),
3756
+ h(Btn, { onClick: onBack }, '回去'),
3757
+ ),
3758
+ h('div', { className: 'lc-meta' },
3759
+ '这张网只按卡片上写的关系连。想连得更细(谁和谁也有关系),现在还没有地方能写——那要一段一段自己填。'),
3760
+ )
3761
+ }
3762
+
3763
+ /** 圈里只放得下几个字。名字太长就在这一屏截一下,点进去能看到全名。 */
3764
+ function cutName(name, n) {
3765
+ const text = String(name ?? '').trim()
3766
+ if (text === '') return ''
3767
+ return text.length <= n ? text : `${text.slice(0, n)}…`
3768
+ }
3769
+
3222
3770
  /**
3223
3771
  * 简历与规划。放在「真实人物记录」那扇门里(写小说和酒馆用不上)。
3224
3772
  *
@@ -3226,7 +3774,12 @@ function GameView({ bookId, onBack, flash }) {
3226
3774
  * 简历这东西最怕 AI 编。先把真实情况填进去,AI 只做整理和措辞,
3227
3775
  * 不编经历——不然投出去被问一句就露了。
3228
3776
  */
3229
- function CareerView({ onBack, flash }) {
3777
+ /** 一条摘抄的身份:格子加文字。勾选表拿它当键。 */
3778
+ function oneKey(one) {
3779
+ return `${String(one?.slot ?? '')}\u0000${String(one?.text ?? '')}`
3780
+ }
3781
+
3782
+ function CareerView({ onBack, flash, cards, onOpenCard }) {
3230
3783
  const [profile, setProfile] = useState(null)
3231
3784
  const [target, setTarget] = useState('')
3232
3785
  const [goal, setGoal] = useState('')
@@ -3235,6 +3788,11 @@ function CareerView({ onBack, flash }) {
3235
3788
  const [busy, setBusy] = useState('')
3236
3789
  const [err, setErr] = useState(null)
3237
3790
  const [dirty, setDirty] = useState(false)
3791
+ // 从卡里读这一段:pick 是挑中的那张卡的 id;mine 是摘出来的结果;
3792
+ // picked 是用户勾掉了哪几条(默认全勾)。
3793
+ const [pick, setPick] = useState('')
3794
+ const [mine, setMine] = useState(null)
3795
+ const [picked, setPicked] = useState({})
3238
3796
 
3239
3797
  /** 把读回来的东西摆到界面上。读不出来就照实说,别让它只停在转圈上。 */
3240
3798
  const applyRead = (r) => {
@@ -3290,6 +3848,43 @@ function CareerView({ onBack, flash }) {
3290
3848
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3291
3849
  }
3292
3850
 
3851
+ /**
3852
+ * 从一张卡里往出摘。
3853
+ *
3854
+ * 只摘、不写。摘完先摆出来,用户自己划掉不要的,再点一次才并进简历——
3855
+ * 卡是「这个人是谁」,简历是「他做过什么」,这两件事不能一步跨过去。
3856
+ */
3857
+ const mineFrom = async () => {
3858
+ const want = String(pick ?? '').trim()
3859
+ if (want === '') { setErr('先挑一张卡。'); return }
3860
+ setBusy('mine'); setErr(null); setMine(null)
3861
+ try {
3862
+ const r = await call('career.mine', { card: want })
3863
+ if (r?.ok !== true) { setErr(r?.error ?? '没摘出来'); return }
3864
+ // 默认全勾:摘出来的是从他自己的卡里抄的,错也错不到哪去;
3865
+ // 真不想要的那条,点一下就去掉了。
3866
+ const all = {}
3867
+ for (const one of r.items ?? []) all[oneKey(one)] = true
3868
+ setPicked(all)
3869
+ setMine(r)
3870
+ } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3871
+ }
3872
+
3873
+ /** 把勾着的几条并进简历,然后重读一遍——界面上的数和磁盘上的要是同一份。 */
3874
+ const mergePicked = async () => {
3875
+ const rows = (mine?.items ?? []).filter((one) => picked[oneKey(one)] === true)
3876
+ if (rows.length === 0) { setErr('一条都没勾,那就没东西可并。'); return }
3877
+ setBusy('merge'); setErr(null)
3878
+ try {
3879
+ const r = await call('career.merge', { items: rows.map((one) => ({ slot: one.slot, text: one.text })) })
3880
+ if (r?.ok !== true) { setErr(r?.error ?? '没并进去'); return }
3881
+ setProfile(buildCareerForm(r.profile ?? {}))
3882
+ setDirty(false)
3883
+ setMine(null)
3884
+ flash?.(r.added === 0 ? (r.note ?? '这几条本来就有') : `并进去 ${r.added} 条`)
3885
+ } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3886
+ }
3887
+
3293
3888
  // 先看有没有出错:出错的渲染在下面(要 profile 读出来才轮得到),
3294
3889
  // 所以这里必须自己先把错说出来,否则用户看到的是一辈子转圈。
3295
3890
  if (profile === null) {
@@ -3330,6 +3925,58 @@ function CareerView({ onBack, flash }) {
3330
3925
  field('还差什么', '你自己觉得还差什么(一行一条)', 3, '六级还没过\n没写过正式的报告'),
3331
3926
  ),
3332
3927
 
3928
+ // 「从卡里读」放在六格表单下面、「让 AI 帮忙」上面:
3929
+ // 它是「往这六格里添东西」,不是让 AI 代写。顺序反了人会以为
3930
+ // 必须先有卡才能写简历——其实照样能手填。
3931
+ h('div', { className: 'lc-sec lc-stack' },
3932
+ h('div', { className: 'lc-fhint' }, '从一张卡里读'),
3933
+ h('div', { className: 'lc-meta' }, '读过的人、写过的日记要是已经攒成一张卡,可以让它把里面写过的事摘出来。摘的就是原话,你自己划。'),
3934
+ (cards ?? []).length === 0
3935
+ ? h('div', { className: 'lc-meta' }, '现在还没有卡。可以先去建一张,也可以就在上面自己填。')
3936
+ : h('div', { className: 'lc-row' },
3937
+ h('select', {
3938
+ className: 'lc-select', value: pick, style: { flex: 1, minWidth: 0 },
3939
+ onChange: (e) => { setPick(e.target.value); setMine(null); setErr(null) },
3940
+ },
3941
+ h('option', { value: '' }, '挑一张卡'),
3942
+ (cards ?? []).map((c) => h('option', { key: String(c.path ?? c.id ?? c.name), value: String(c.path ?? c.id ?? '') },
3943
+ `${String(c.name ?? '(还没起名字)')}${c.relation ? ` · ${c.relation}` : ''}`)),
3944
+ ),
3945
+ h(Btn, { size: 'sm', icon: 'spark', disabled: busy !== '' || pick === '', onClick: mineFrom },
3946
+ busy === 'mine' ? '读着…' : '读读看'),
3947
+ ),
3948
+ mine === null ? null : h('div', { className: 'lc-stack' },
3949
+ h('div', { className: 'lc-fhint' }, `从「${mine.card?.name || '这张卡'}」里摘出来这些。不想要的点一下去掉。`),
3950
+ (mine.items ?? []).length === 0
3951
+ ? h(Note, { tone: 'warn', icon: 'warning' }, '这张卡里没有能直接写进简历的事。也许它记的是这个人是什么样,不是他做过什么——那就自己填。')
3952
+ : h('div', { className: 'lc-stack', style: { gap: 6 } },
3953
+ (mine.items ?? []).map((one) => {
3954
+ const key = oneKey(one)
3955
+ const on = picked[key] === true
3956
+ return h('div', {
3957
+ key, className: 'lc-opt', role: 'button',
3958
+ 'data-picked': on ? 'yes' : 'no',
3959
+ style: on ? undefined : { opacity: 0.45 },
3960
+ onClick: () => setPicked({ ...picked, [key]: !on }),
3961
+ },
3962
+ h('div', { className: 'lc-row', style: { alignItems: 'baseline', gap: 8 } },
3963
+ h('div', { className: 'lc-tag' }, (mine.labels ?? {})[one.slot] ?? one.slot),
3964
+ h('div', { className: 'lc-grow' }, one.text),
3965
+ ),
3966
+ h('div', { className: 'lc-quote' }, `原文:${one.quote}`),
3967
+ )
3968
+ }),
3969
+ ),
3970
+ (mine.dropped ?? []).length === 0 ? null : h('div', { className: 'lc-meta' },
3971
+ `还有 ${mine.dropped.length} 条没敢用,因为原文里找不到那一句,或者没说清该放哪儿。`),
3972
+ (mine.items ?? []).length === 0 ? null : h('div', { className: 'lc-row' },
3973
+ h(Btn, { tone: 'primary', disabled: busy !== '', onClick: mergePicked },
3974
+ busy === 'merge' ? '并着…' : '把勾着的并进简历'),
3975
+ h(Btn, { size: 'sm', disabled: busy !== '', onClick: () => { setMine(null); setErr(null) } }, '不要了'),
3976
+ ),
3977
+ ),
3978
+ ),
3979
+
3333
3980
  h('div', { className: 'lc-sec lc-stack' },
3334
3981
  h('div', { className: 'lc-fhint' }, '让 AI 帮忙'),
3335
3982
  h('input', {
@@ -3401,7 +4048,7 @@ function copyText(text) {
3401
4048
  }
3402
4049
  }
3403
4050
 
3404
- function BookView({ bookId, onBack, flash }) {
4051
+ function BookView({ bookId, onBack, flash, flushRef }) {
3405
4052
  const [book, setBook] = useState(null)
3406
4053
  const [outline, setOutline] = useState(null)
3407
4054
  const [chapterIndex, setChapterIndex] = useState(0)
@@ -3415,8 +4062,24 @@ function BookView({ bookId, onBack, flash }) {
3415
4062
  const [outlineText, setOutlineText] = useState('')
3416
4063
  // 这一章的正文有没有还没存下的改动。切章之前必须先处理,否则写的东西会没。
3417
4064
  const [bodyDirty, setBodyDirty] = useState(false)
3418
-
3419
- const load = async (want) => {
4065
+ // 「改成剧本」。排在所有 hook 最后:上面那些槽位有测试按序号摆状态,
4066
+ // 插在中间会让它们集体错位。
4067
+ const [scriptText, setScriptText] = useState('')
4068
+ const [scriptReport, setScriptReport] = useState('')
4069
+ // 剧本有没有改了没存的。和正文的 bodyDirty 一个道理:切章之前得拦一下,
4070
+ // 否则人手改的那几场会静静消失,而且没有任何提示。
4071
+ const [scriptDirty, setScriptDirty] = useState(false)
4072
+ // 改剧本这一节的错误单独放:全页那个 err 在最底下,一节剧本三百多像素高,
4073
+ // 报错落在屏幕外,人只会觉得「点了没反应」。
4074
+ const [scriptErr, setScriptErr] = useState(null)
4075
+ // 这本书哪几章已经改出过剧本。后台一直有这个清单(`novel.script.list`),
4076
+ // 界面从来没调过——于是「哪一章改过」只存在于文件夹里。
4077
+ const [scripted, setScripted] = useState([])
4078
+ // 这一章的正文有没有真正读到。读失败(网络、后台报错、文件被占住)时不能让人
4079
+ // 接着在空框里写字再按「存好这一章」——那会把空白写进另一章的文件,一整章原稿就没了。
4080
+ const [chapterBroken, setChapterBroken] = useState(false)
4081
+
4082
+ const load = async (want, opts) => {
3420
4083
  setErr(null)
3421
4084
  try {
3422
4085
  const r = await call('novel.get', { id: bookId })
@@ -3424,19 +4087,145 @@ function BookView({ bookId, onBack, flash }) {
3424
4087
  setBook(r)
3425
4088
  const o = await call('novel.outline.get', { id: bookId })
3426
4089
  if (o?.ok === true) { setOutline(o); setOutlineText(String(o.text ?? '')) }
4090
+ // 哪几章已经改出过剧本(画章列表上的小标记用)。拿不到就算了,不是要紧事。
4091
+ const scripts = await call('novel.script.list', { id: bookId }).catch(() => null)
4092
+ setScripted(scripts?.ok === true && Array.isArray(scripts.scripts)
4093
+ ? scripts.scripts.map((x) => Number(x.index))
4094
+ : [])
3427
4095
  // 默认打开:有章节就打开最后一章,没有就从第一章开始
3428
4096
  const target = Number(want) > 0 ? Number(want) : (r.chapters.length === 0 ? 1 : r.chapters[r.chapters.length - 1].index)
4097
+ // 先翻章再改章号:翻章被拦下时,章号不能已经跑到新的一章去。
4098
+ const opened = await openChapter(target, opts)
4099
+ if (opened === 'error') {
4100
+ // 出错时章号也得跟标题对上:以前这里直接返回、章号停在旧值(初值是 0),
4101
+ // 屏幕上写着「写第 0 章」,点存就被后台当成「接在最后一章后面」,凭空多一章。
4102
+ // 正文没读到,存的动作已经按 chapterBroken 禁掉了。
4103
+ setChapterIndex(target)
4104
+ return
4105
+ }
4106
+ // 被拦下,或者这中间又有人点了别的章:什么都不改。
4107
+ if (opened !== true) return
3429
4108
  setChapterIndex(target)
3430
- await openChapter(target)
3431
4109
  } catch (e) { setErr(humanizeError(e)) }
4110
+ // 上一本书那份剧本没存上:现在才说,说了才算数。
4111
+ if (carryErr.current !== null) { setErr(String(carryErr.current)); carryErr.current = null }
3432
4112
  }
3433
4113
 
3434
- const openChapter = async (index) => {
3435
- setErr(null); setReview(null); setDraft(null)
4114
+ // 剧本改了没存,要走之前先替人存好。
4115
+ //
4116
+ // 这里以前弹的是「回去就没了」,可组件卸载那一刻又偷偷存了一份——弹窗说不要,
4117
+ // 实际存了,人点了「好」以为自己放弃成功,其实没有。现在只剩一种立场:真存。
4118
+ // 存成了说一句「先替你存好了」;存不上才问要不要放弃这一份。
4119
+ const settleScript = async (why) => {
4120
+ if (scriptDirty !== true || scriptText.trim() === '') return true
4121
+ const myBook = bookId
4122
+ const myIndex = chapterIndex
4123
+ const sent = scriptText
4124
+ setBusy('scriptSave'); setScriptErr(null)
4125
+ try {
4126
+ const r = await call('novel.script.save', { id: myBook, index: myIndex, text: sent })
4127
+ if (r?.ok === true) {
4128
+ setScriptDirty(false)
4129
+ setScripted((old) => (old.includes(myIndex) ? old : [...old, myIndex].sort((a, b) => a - b)))
4130
+ flash?.(`第 ${myIndex} 章的剧本先替你存好了`)
4131
+ return true
4132
+ }
4133
+ setScriptErr(r?.error ?? '这一份剧本没存上')
4134
+ } catch (e) { setScriptErr(humanizeError(e)) } finally { setBusy('') }
4135
+ // 存不上:只剩「放弃这一份」和「留下」两条路,问清了再走。
4136
+ const go = typeof window !== 'undefined' && typeof window.confirm === 'function'
4137
+ ? window.confirm(`第 ${myIndex} 章这份剧本没存上。\n\n${why}的话这一份就没了。还走吗?`)
4138
+ : true
4139
+ return go === true
4140
+ }
4141
+
4142
+ // 改剧本也要对号:点了「把这一章改成剧本」之后又翻章、又换书,
4143
+ // 草稿晚回来会落进现在这一章的框里,人一按「存好这份剧本」,
4144
+ // 第 5 章的内容就写成第 6 章的文件。换书之后更糟:A 书的稿子会存成 B 书的。
4145
+ // 所以草稿出发前记下「哪本书、哪一章」,回来对不上就整份丢掉。
4146
+ const scriptTicket = useRef(0)
4147
+
4148
+ // 每翻一次章就加一,回来的东西先对一下号。
4149
+ // 手快连点两章(或者网络慢)时,前一章的剧本会在后一章之后才回来,
4150
+ // 落在框里就成了「标题是第 3 章,剧本是第 2 章的」——这种错对不上账,人只会觉得插件疯了。
4151
+ const chapterTicket = useRef(0)
4152
+ // 框里此刻摆的是第几章、还有没有一章正在读。
4153
+ // 不能用 chapterIndex 判「点的就是我现在这一章」:章号要等读完才前进,
4154
+ // 人点第 2 章、它还在路上时,chapterIndex 还停在旧值(比如 3)。
4155
+ // 这时候再点第 3 章,会被当成「点的是自己这一章」而什么都不做,
4156
+ // 于是框里留着第 2 章的正文、章号写着第 3 章。
4157
+ const loadedRef = useRef(0)
4158
+ const pullingRef = useRef(0)
4159
+
4160
+ /**
4161
+ * 翻到某一章。
4162
+ *
4163
+ * `opts.sameChapter` 是给「刚把这一章存好、要重读一遍」用的:那时候没换章,
4164
+ * 不该弹「剧本还没存,换过去就没了」——人点了「好」,手改的剧本反倒没了。
4165
+ * 带上它就别去动剧本框,剧本跟正文是两份东西,各存各的。
4166
+ *
4167
+ * 返回 true 表示框里已经是这一章;返回 'stale' 表示这中间又有人点了别的章,
4168
+ * 这一次的结果该整份丢掉,调用方也不许再改章号。
4169
+ */
4170
+ const openChapter = async (index, opts) => {
4171
+ const sameChapter = opts !== undefined && opts !== null && opts.sameChapter === true
4172
+ // `settled`:调用方已经把要存的存过了(换书那一段),这里不许再拦一次。
4173
+ // 不然人会看到一个「第 2 章改出来的剧本还没存」的框,说的却是上一本书的章,
4174
+ // 点「取消」也照换不误——那框就是个摆设。
4175
+ const settled = opts !== undefined && opts !== null && opts.settled === true
4176
+ // 改过剧本还没存就切章,得先说一声。同一章重读不算切章。
4177
+ if (settled !== true && sameChapter !== true && (await settleScript('换过去')) !== true) return false
4178
+ const mine = ++chapterTicket.current
4179
+ pullingRef.current = Number(index)
4180
+ // 换章 / 换书了:还在路上的剧本草稿一律作废。
4181
+ scriptTicket.current += 1
4182
+ setErr(null); setReview(null); setDraft(null); setScriptErr(null)
4183
+ if (sameChapter !== true) { setScriptText(''); setScriptReport(''); setScriptDirty(false) }
3436
4184
  try {
3437
4185
  const r = await call('novel.chapter.get', { id: bookId, index })
3438
- setBody(r?.ok === true ? String(r.body ?? '') : '')
3439
- } catch (e) { setErr(humanizeError(e)) }
4186
+ if (mine !== chapterTicket.current) return 'stale'
4187
+ if (r?.ok !== true) {
4188
+ // 后台说这一章读不出来(文件被占住、内容坏了):不能当「这一章是空的」处理。
4189
+ // 当真当成空的话,人会在空框里写一段,再按「存好这一章」,
4190
+ // 存进去的是**这一章**的文件,原来那一份就被盖掉了。
4191
+ // 章号照旧前进——屏幕上的标题得跟点的那一章对上。
4192
+ setBody('')
4193
+ setChapterBroken(true)
4194
+ setErr(String(r?.error ?? '这一章没读出来。'))
4195
+ loadedRef.current = Number(index)
4196
+ pullingRef.current = 0
4197
+ return true
4198
+ }
4199
+ setBody(String(r.body ?? ''))
4200
+ setChapterBroken(false)
4201
+ if (sameChapter === true) return true
4202
+ // 这一章以前改过剧本没有——改过就直接摆出来,不用再问一次。
4203
+ const s = await call('novel.script.get', { id: bookId, index })
4204
+ if (mine !== chapterTicket.current) return 'stale'
4205
+ if (s?.ok === true) {
4206
+ if (String(s.text ?? '').trim() !== '') {
4207
+ setScriptText(String(s.text))
4208
+ setScriptReport(String(s.report ?? ''))
4209
+ }
4210
+ } else {
4211
+ // 剧本读坏了不能当没这回事:框不渲染、章列表还挂着「有剧本」,
4212
+ // 人只会以为自己改的东西没了,而且屏幕上没有一句话。
4213
+ setScriptErr(String(s?.error ?? '这一章的剧本读不出来。'))
4214
+ }
4215
+ setChapterBroken(false)
4216
+ loadedRef.current = Number(index)
4217
+ pullingRef.current = 0
4218
+ return true
4219
+ } catch (e) {
4220
+ if (mine === chapterTicket.current) {
4221
+ pullingRef.current = 0
4222
+ setErr(humanizeError(e))
4223
+ // 正文没读到:把这一章标成「别动」。以前这里直接返回,章号停在旧值,
4224
+ // 人点「存好这一章」就把眼下这个空框写进**另一章**的文件,原稿就没了。
4225
+ setChapterBroken(true)
4226
+ }
4227
+ return 'error'
4228
+ }
3440
4229
  }
3441
4230
 
3442
4231
  // 切章之前先把没存的正文收好。存不上就留在这一章,别让人以为写进去了。
@@ -3452,9 +4241,15 @@ function BookView({ bookId, onBack, flash }) {
3452
4241
  }
3453
4242
 
3454
4243
  const goChapter = async (index) => {
4244
+ // 点的是自己正待着的这一章:不用重读。以前会照样重读一遍,
4245
+ // 手改的剧本会因为一次「换过去」被磁盘上那一份换掉。
4246
+ // 但票号还是要往前走一步:刚才点过别的章、它那份还在路上,
4247
+ // 此刻也该作废——不然它回来照样落进这一章的框。
4248
+ if (Number(index) === Number(loadedRef.current) && pullingRef.current === 0) return
3455
4249
  if ((await keepBody()) !== true) return
4250
+ // 剧本那边没存就被拦下时,章号也不能跟着变——否则标题写着新章、框里还是旧章。
4251
+ if ((await openChapter(index)) !== true) return
3456
4252
  setChapterIndex(index)
3457
- await openChapter(index)
3458
4253
  }
3459
4254
 
3460
4255
  /**
@@ -3465,22 +4260,143 @@ function BookView({ bookId, onBack, flash }) {
3465
4260
  */
3466
4261
  const removeChapter = async (c) => {
3467
4262
  const n = Number(c?.index ?? 0)
4263
+ // 有剧本的章,确认框里得说清剧本也一起没:那一份是人花了一次 AI 改出来的。
4264
+ const extra = scripted.includes(n)
4265
+ ? '这一章改出来的剧本也一起删。'
4266
+ : ''
3468
4267
  const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
3469
- ? window.confirm(`把第 ${n} 章删掉?\n\n这一章的正文一起删,删了就真没了。别的章不受影响;大纲里那一行还在,你可以重写。`)
4268
+ ? window.confirm(`把第 ${n} 章删掉?\n\n这一章的正文一起删,删了就真没了。${extra}别的章不受影响;大纲里那一行还在,你可以重写。`)
3470
4269
  : true
3471
4270
  if (ok !== true) return
4271
+ // 删的是**这一章**时,它上面那份没存的剧本才跟着作废。
4272
+ // 删别的章却去清当前章的状态,等于把人家正在写的正文和剧本一起抹了——
4273
+ // 以前就是这样:停在第 2 章写了一大段,顺手删掉第 1 章,第 2 章写的全没了,
4274
+ // 正文连问都没问一句。
4275
+ const deletingCurrent = n === chapterIndex
4276
+ if (deletingCurrent !== true) {
4277
+ // 删别的章:当前章该存的先存好,别让它被下面的重读顺手丢掉。
4278
+ if ((await keepBody()) !== true) return
4279
+ // 剧本也替它存回去。这里不问「走不走」——人没打算走,只是在删别的章;
4280
+ // 问了也只有一个正确答案,反倒把「删第 1 章」这件事拦下来。
4281
+ if (scriptDirty === true && scriptText.trim() !== '') {
4282
+ let saved = false
4283
+ try {
4284
+ const r = await call('novel.script.save', { id: bookId, index: chapterIndex, text: scriptText })
4285
+ if (r?.ok === true) { saved = true; setScriptDirty(false) }
4286
+ else setErr(r?.error ?? '这一章的剧本没存上,先别删')
4287
+ } catch (e) { setErr(humanizeError(e)) }
4288
+ // 存不上就别删:这一删,下面那次重读会把框里东西换掉,手改的就真没了。
4289
+ if (saved !== true) return
4290
+ }
4291
+ }
3472
4292
  setErr(null)
3473
- setBodyDirty(false)
3474
4293
  try {
3475
4294
  const r = await call('novel.chapter.delete', { id: bookId, index: n })
3476
4295
  if (r?.ok !== true) { setErr(r?.error ?? '这一章没删掉'); return }
4296
+ // 删成功了才清当前章的状态。以前这两行写在删之前:后台一报错就 return,
4297
+ // 清空却已经生效,手写的正文和剧本在屏幕上没了、磁盘上也没存过。
4298
+ if (deletingCurrent === true) {
4299
+ setBodyDirty(false)
4300
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
4301
+ setScriptErr(null)
4302
+ }
4303
+ setScripted((old) => old.filter((x) => x !== n))
3477
4304
  flash?.(`删掉了第 ${n} 章`)
3478
- // 重新读一遍这本书:章列表少一条,正文换成还在的那一章。
3479
- await load(n > 1 ? n - 1 : 0)
4305
+ // 重新读一遍这本书:章列表少一条。
4306
+ // 删的不是当前章时留在原地重读(人可能正写着),删的就是当前章才往前挪。
4307
+ // 挪的时候给 0:让 load 自己落到「现在还存在的最后一章」。
4308
+ // 以前传 n-1,而 n-1 可能刚在上一步被删掉,屏幕就停在一个没有的章号上。
4309
+ if (deletingCurrent === true) await load(0, { sameChapter: false })
4310
+ else await load(chapterIndex, { sameChapter: true })
3480
4311
  } catch (e) { setErr(humanizeError(e)) }
3481
4312
  }
3482
4313
 
3483
- useEffect(() => { load(0) }, [bookId])
4314
+ // 上一本是哪本。换书时要在下面那个 effect 里认出「这是换了一本」。
4315
+ const lastBookId = useRef('')
4316
+ // 换书时替上一本存剧本,存失败了要报,可紧接着的 load() 会把 err 清掉。
4317
+ // 先存在这里,等 load 读完了再摆到屏幕上。
4318
+ const carryErr = useRef(null)
4319
+ // 换书(从书架再点一本进来)时组件不卸载、只是 bookId 变了:
4320
+ // 上一本改了没存的剧本会留在框里,跟着新书一起显示,看着像这本书的剧本;
4321
+ // 反过来,它也会被静悄悄丢掉。所以换书这一刻先替上一本存回去。
4322
+ // 注意此刻 scriptText / scriptDirty / chapterIndex 还是上一本的值(下面才清),
4323
+ // 正好用得上——晚了就没了。
4324
+ useEffect(() => {
4325
+ const before = lastBookId.current
4326
+ if (before !== '' && before !== bookId) {
4327
+ // 换书了:上一本还在路上的剧本草稿作废,不许它落进新书的框里。
4328
+ scriptTicket.current += 1
4329
+ // 上一本没存的剧本替它存回**原来那本**(不是新这本)。
4330
+ // 存的时候顺手报一下成没成:失败还得让新书那边看得见,
4331
+ // 不然人会以为「点了一下就都存好了」。
4332
+ if (scriptDirty === true && scriptText.trim() !== '') {
4333
+ const oldId = before
4334
+ const oldIndex = chapterIndex
4335
+ const oldText = scriptText
4336
+ // 先把这一刻的「哪本书、哪一章、什么内容」定下来,卸载兜底那份也一起作废:
4337
+ // 不然同一份稿会同时写进上一本和下一本。
4338
+ leaveRef.current = { id: oldId, index: oldIndex, text: oldText, dirty: true, taken: true }
4339
+ call('novel.script.save', { id: oldId, index: oldIndex, text: oldText })
4340
+ .then((r) => {
4341
+ // 提示要能活过紧接着的那次 load(load 开头会清 err):
4342
+ // 失败时先用一个不会被清掉的位置接着,等读完再摆出来。
4343
+ if (r?.ok === true) flash?.(`上一本书第 ${oldIndex} 章的剧本替你存好了`)
4344
+ else carryErr.current = String(r?.error ?? '上一本书的剧本没存上')
4345
+ })
4346
+ .catch(() => { carryErr.current = '上一本书的剧本没存上' })
4347
+ }
4348
+ }
4349
+ lastBookId.current = String(bookId ?? '')
4350
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
4351
+ setBody(''); setDraft(null); setReview(null); setBodyDirty(false)
4352
+ load(0, { settled: true })
4353
+ }, [bookId])
4354
+
4355
+ // 离开这一屏时(点顶上那个返回、换门、切到别的页)组件直接卸载,
4356
+ // 没有第二次机会弹窗问「剧本还没存,现在走吗」——上面那个 effect 只在换书时跑。
4357
+ // 所以卸载这一刻自己把没存的剧本收好:人没按「存好这份剧本」,
4358
+ // 不等于想把它丢掉。
4359
+ // `taken` 是给换书那一段用的:那一份已经有人存了,卸载兜底不许再存一遍,
4360
+ // 更不许把 A 书的内容写成 B 书的(id 与 text 配不上对时就是这么串过去的)。
4361
+ const leaveRef = useRef({ id: '', index: 0, text: '', dirty: false, taken: false })
4362
+ leaveRef.current = {
4363
+ id: bookId, index: chapterIndex, text: scriptText, dirty: scriptDirty,
4364
+ // 每帧重写的只是「当前值」,taken 只在换书那一刻被置上;
4365
+ // 置上之后要一直有效到这一帧结束,所以从上一帧继承。
4366
+ taken: leaveRef.current.taken === true && leaveRef.current.id === bookId ? true : false,
4367
+ }
4368
+ // 正文和剧本是两份东西,可离开这一屏时都得收好。以前只兜了剧本:
4369
+ // 写完一段正文点顶上的返回,字就没了,而且屏幕上不会有一句话。
4370
+ const bodyLeaveRef = useRef({ id: '', index: 0, body: '', dirty: false })
4371
+ bodyLeaveRef.current = { id: bookId, index: chapterIndex, body, dirty: bodyDirty }
4372
+ useEffect(() => () => {
4373
+ const now = leaveRef.current
4374
+ if (now.taken !== true && now.dirty === true && String(now.text).trim() !== '') {
4375
+ // 这一份已经没地方报错了(组件都卸载了),只能尽量存住。
4376
+ // 真正的「存不上怎么办」已经在 settleScript 里问过人了。
4377
+ call('novel.script.save', { id: now.id, index: now.index, text: now.text }).catch(() => null)
4378
+ }
4379
+ const nb = bodyLeaveRef.current
4380
+ if (nb.dirty === true && String(nb.body).trim() !== '') {
4381
+ call('novel.chapter.save', { id: nb.id, index: nb.index, body: nb.body }).catch(() => null)
4382
+ }
4383
+ }, [])
4384
+
4385
+ // 外面那一层(顶栏返回、换门)没法知道这一屏手头有没有没存的东西。
4386
+ // 把「先收好再走」放在它给的槽里:切屏前先调,收不上就留在这一屏。
4387
+ useEffect(() => {
4388
+ if (flushRef === undefined || flushRef === null) return
4389
+ flushRef.current = () => {
4390
+ // 什么都没改:同步放行,外面那一层就不用等一帧。
4391
+ if (bodyDirty !== true && scriptDirty !== true) return true
4392
+ return (async () => {
4393
+ const bodyOk = await keepBody()
4394
+ if (bodyOk !== true) return false
4395
+ return settleScript('换到别处')
4396
+ })()
4397
+ }
4398
+ return () => { flushRef.current = null }
4399
+ })
3484
4400
 
3485
4401
  const doPlan = async () => {
3486
4402
  setBusy('plan'); setErr(null)
@@ -3530,7 +4446,8 @@ function BookView({ bookId, onBack, flash }) {
3530
4446
  if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
3531
4447
  setBody(merged); setDraft(null); setBodyDirty(false)
3532
4448
  flash?.(`第 ${chapterIndex} 章存好了`)
3533
- await load(chapterIndex)
4449
+ // 同一章重读:别碰剧本框,也别弹「剧本还没存」。
4450
+ await load(chapterIndex, { sameChapter: true })
3534
4451
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3535
4452
  }
3536
4453
 
@@ -3541,7 +4458,7 @@ function BookView({ bookId, onBack, flash }) {
3541
4458
  if (r?.ok !== true) { setErr(r?.error ?? '没存上'); return }
3542
4459
  setBodyDirty(false)
3543
4460
  flash?.(`第 ${chapterIndex} 章存好了`)
3544
- await load(chapterIndex)
4461
+ await load(chapterIndex, { sameChapter: true })
3545
4462
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3546
4463
  }
3547
4464
 
@@ -3557,6 +4474,119 @@ function BookView({ bookId, onBack, flash }) {
3557
4474
  } catch (e) { setErr(humanizeError(e)) } finally { setBusy('') }
3558
4475
  }
3559
4476
 
4477
+ /**
4478
+ * 把这一章改成剧本。
4479
+ *
4480
+ * 改的是**存下来的那一版**:正文有没存的改动先存一次,不然后台改的是旧稿,
4481
+ * 用户盯着屏幕会以为它漏掉了刚写的那几句。
4482
+ */
4483
+ // 连点两下会真发两次(AI 那一侧是要花钱的)。按钮的 disabled 要等一次 await
4484
+ // 之后才置位,同一帧里的两次点击都赶在它前面。所以用一个同步的锁挡。
4485
+ const scriptLock = useRef(false)
4486
+
4487
+ const doScript = async () => {
4488
+ if (scriptLock.current === true) return
4489
+ if (body.trim() === '') { setScriptErr('这一章还空着,没什么可改的。'); return }
4490
+ // 框里已经有一份、而且改过没存:点「重改一份」会把它整份盖掉。
4491
+ // 不先问一句,人点错一次就是白改。
4492
+ if (scriptDirty === true && scriptText.trim() !== '') {
4493
+ const go = typeof window !== 'undefined' && typeof window.confirm === 'function'
4494
+ ? window.confirm(`第 ${chapterIndex} 章这份剧本改了还没存,重改一次会把它整份盖掉。\n\n继续吗?`)
4495
+ : true
4496
+ if (go !== true) return
4497
+ }
4498
+ scriptLock.current = true
4499
+ if ((await keepBody()) !== true) { scriptLock.current = false; return }
4500
+ // 出发前记下是哪本书的哪一章:回来要是对不上,说明人已经翻到别处了。
4501
+ const wantBook = bookId
4502
+ const wantIndex = chapterIndex
4503
+ const mine = ++scriptTicket.current
4504
+ setBusy('script'); setErr(null); setScriptErr(null)
4505
+ try {
4506
+ const r = await call('novel.script.draft', { id: wantBook, index: wantIndex })
4507
+ if (mine !== scriptTicket.current) return
4508
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '这次没改成。再点一次试试。'); return }
4509
+ setScriptText(String(r.text ?? ''))
4510
+ setScriptReport(String(r.report ?? ''))
4511
+ // 改出来但还没落盘,所以算「没存」:这时候切章要拦。
4512
+ setScriptDirty(true)
4513
+ } catch (e) { if (mine === scriptTicket.current) setScriptErr(humanizeError(e)) } finally {
4514
+ // 无条件复位。以前这里要票号还对得上才复位:人趁 AI 还在想的时候翻了章,
4515
+ // 票号一过就永远不复位,整页五个按钮从此全禁用,只有退出这本书才恢复。
4516
+ scriptLock.current = false
4517
+ setBusy('')
4518
+ }
4519
+ }
4520
+
4521
+ const saveScript = async () => {
4522
+ if (scriptLock.current === true) return
4523
+ if (scriptText.trim() === '') { setScriptErr('剧本还是空的,没什么可存的。'); return }
4524
+ // 记下这一次到底存的是哪一份:回来时框里的字已经不是这一份了,
4525
+ // 就不能把「还没存」这个标记清掉,否则那几个字会被当成已存、然后默默丢掉。
4526
+ const sent = scriptText
4527
+ // 还要记下是哪本书的哪一章:人可能趁这次保存还在路上就翻了章、换了书。
4528
+ // 那时候这个回包属于上一章,一个字都不能往现在这一章身上贴
4529
+ // (以前会清掉现在这一章的「还没存」、把上一章的报告摆到这一章里)。
4530
+ const myBook = bookId
4531
+ const myIndex = chapterIndex
4532
+ scriptLock.current = true
4533
+ setBusy('scriptSave'); setErr(null); setScriptErr(null)
4534
+ try {
4535
+ const r = await call('novel.script.save', { id: myBook, index: myIndex, text: sent })
4536
+ if (myBook !== bookId || myIndex !== chapterIndex) return
4537
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '没存上。这一份还在框里,再点一次就行。'); return }
4538
+ setScriptReport(String(r.report ?? ''))
4539
+ // 章列表上那个「有剧本」的小标记:存好之后立刻挂上,
4540
+ // 不然得退出这本书再进来才看得见,人会以为自己没存上。
4541
+ setScripted((old) => (old.includes(myIndex) ? old : [...old, myIndex].sort((a, b) => a - b)))
4542
+ if (scriptText === sent) {
4543
+ setScriptDirty(false)
4544
+ flash?.(`第 ${myIndex} 章的剧本存好了`)
4545
+ } else {
4546
+ // 存的过程中又改了:这一版还没存,标记留着,按钮上说出来。
4547
+ setScriptDirty(true)
4548
+ flash?.('存好了。存的时候你又改了,新改的这一版还没存')
4549
+ }
4550
+ } catch (e) { if (myBook === bookId && myIndex === chapterIndex) setScriptErr(humanizeError(e)) } finally {
4551
+ scriptLock.current = false
4552
+ setBusy('')
4553
+ }
4554
+ }
4555
+
4556
+ /**
4557
+ * 删掉这一章的剧本。
4558
+ *
4559
+ * 只删改编出来的那份,章节正文一点不动——所以这里说的「删」和删章不是一回事,
4560
+ * 提示语里要把这件事说清,否则有人会以为连这一章一起删了。
4561
+ */
4562
+ const removeScript = async () => {
4563
+ if (scriptLock.current === true) return
4564
+ const myIndex = chapterIndex
4565
+ // 手改过还没存的部分会跟着一起没,这句得说在确认框里。
4566
+ const unsaved = scriptDirty === true && scriptText.trim() !== ''
4567
+ ? '\n\n框里手改过、还没存的那部分也一起没。'
4568
+ : ''
4569
+ const ok = typeof window !== 'undefined' && typeof window.confirm === 'function'
4570
+ ? window.confirm(`把第 ${myIndex} 章改出来的剧本删掉?\n\n只删这份剧本,小说正文不动。想再要一份,可以重新改一次。${unsaved}`)
4571
+ : true
4572
+ if (ok !== true) return
4573
+ const myBook = bookId
4574
+ scriptLock.current = true
4575
+ setBusy('scriptDelete'); setErr(null); setScriptErr(null)
4576
+ try {
4577
+ const r = await call('novel.script.delete', { id: myBook, index: myIndex })
4578
+ // 这一回包只属于那一章:人要是在等的时候翻到别处,
4579
+ // 现在框里的东西是那一章的新内容,一个字都不能清。
4580
+ if (myBook !== bookId || myIndex !== chapterIndex) return
4581
+ if (r?.ok !== true) { setScriptErr(r?.error ?? '这份剧本没删掉'); return }
4582
+ setScriptText(''); setScriptReport(''); setScriptDirty(false)
4583
+ setScripted((old) => old.filter((n) => n !== myIndex))
4584
+ flash?.(`删掉了第 ${myIndex} 章的剧本`)
4585
+ } catch (e) {
4586
+ if (myBook === bookId && myIndex === chapterIndex) setScriptErr(humanizeError(e))
4587
+ } finally { scriptLock.current = false; setBusy('') }
4588
+ }
4589
+
3560
4590
  if (book === null) {
3561
4591
  return h('div', { className: 'lc-pad lc-stack' },
3562
4592
  h(Btn, { size: 'sm', icon: 'back', onClick: onBack }, '回书架'),
@@ -3571,7 +4601,13 @@ function BookView({ bookId, onBack, flash }) {
3571
4601
 
3572
4602
  return h('div', { className: 'lc-pad lc-stack', style: { gap: 12 } },
3573
4603
  h('div', { className: 'lc-row' },
3574
- h(Btn, { size: 'sm', icon: 'back', onClick: async () => { if ((await keepBody()) === true) onBack() } }, '回书架'),
4604
+ h(Btn, { size: 'sm', icon: 'back', onClick: async () => {
4605
+ // 先替人存,存不上才问「还走吗」。以前这里是「回去就没了」+ 卸载时偷偷存,
4606
+ // 说的话和做的事对不上。
4607
+ if ((await keepBody()) !== true) return
4608
+ if ((await settleScript('回去')) !== true) return
4609
+ onBack()
4610
+ } }, '回书架'),
3575
4611
  h('div', { className: 'lc-grow lc-ellipsis', style: { fontWeight: 700, fontSize: 16.5 } }, `《${title}》`),
3576
4612
  h('span', { className: 'lc-meta' }, `${chapters.length} 章`),
3577
4613
  ),
@@ -3635,6 +4671,10 @@ function BookView({ bookId, onBack, flash }) {
3635
4671
  tone: Number(c.index) === Number(chapterIndex) ? 'primary' : undefined,
3636
4672
  onClick: () => { goChapter(Number(c.index)) },
3637
4673
  }, `第 ${c.index} 章${String(c.title ?? '').trim() === '' ? '' : ` · ${String(c.title).slice(0, 16)}`}`),
4674
+ // 这一章改过剧本:给一个小标记。不然只有翻进去才知道自己改没改过。
4675
+ scripted.includes(Number(c.index))
4676
+ ? h('span', { className: 'lc-meta', title: '这一章已经有一份剧本' }, '有剧本')
4677
+ : null,
3638
4678
  h('div', { className: 'lc-grow' }),
3639
4679
  h(Btn, { size: 'sm', ghost: true, icon: 'trash', onClick: () => removeChapter(c) }, '删掉这一章'),
3640
4680
  )),
@@ -3681,18 +4721,29 @@ function BookView({ bookId, onBack, flash }) {
3681
4721
  h('div', { className: 'lc-sec' },
3682
4722
  h('div', { className: 'lc-row' },
3683
4723
  h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, '正文')),
3684
- h('span', { className: 'lc-meta' }, `${body.length} 字`),
4724
+ // 正文改了没存也得说出来。剧本那边一直有这行标记,正文没有:
4725
+ // 人写完一段直接去点顶上的返回,屏幕上没有任何东西拦过他一眼。
4726
+ h('span', { className: 'lc-meta' },
4727
+ bodyDirty ? `${body.length} 字 · 还没存` : `${body.length} 字`),
3685
4728
  ),
4729
+ // 这一章的正文没读到(后台报错、文件被占住):框锁成只读,并当场说清。
4730
+ // 让它能改的话,人会在空框里写一段,再按「存好这一章」,
4731
+ // 存进去的是**另一章**的文件,那一章的原稿就没了。
4732
+ chapterBroken === true
4733
+ ? h(Note, { tone: 'err', icon: 'warning' },
4734
+ '这一章没读出来,所以先锁住了。退出这本书再进来一次;还是不行,就用访达看一眼那个文件夹还在不在。')
4735
+ : null,
3686
4736
  h('textarea', {
3687
4737
  className: 'lc-textarea',
3688
4738
  value: body,
3689
4739
  spellCheck: false,
4740
+ readOnly: chapterBroken === true,
3690
4741
  placeholder: '这一章还空着。让 AI 写一段,或者自己动手。',
3691
4742
  style: { minHeight: 260, marginTop: 6, lineHeight: 1.85 },
3692
4743
  onChange: (e) => { setBody(e.target.value); setBodyDirty(true) },
3693
4744
  }),
3694
4745
  h('div', { className: 'lc-row' },
3695
- h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '', onClick: saveBody }, busy === 'save' ? '正在存…' : '存好这一章'),
4746
+ h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '' || chapterBroken === true, onClick: saveBody }, busy === 'save' ? '正在存…' : '存好这一章'),
3696
4747
  h(Btn, { size: 'sm', icon: 'doctor', disabled: busy !== '' || body.trim() === '', onClick: doReview },
3697
4748
  busy === 'review' ? '正在挑毛病…' : '挑挑毛病'),
3698
4749
  h('div', { className: 'lc-grow' }),
@@ -3709,6 +4760,67 @@ function BookView({ bookId, onBack, flash }) {
3709
4760
  ),
3710
4761
  ),
3711
4762
 
4763
+ // ── 改成剧本 ──
4764
+ // 用户丢来一份《小说改剧本》,要的就是这一件事:章写完了,能不能变成能拍的东西。
4765
+ // 放在正文下面而不是单独一屏:改剧本看的永远是「这一章」,跟正文分开会让人
4766
+ // 在两屏之间来回确认自己改的是哪一章。
4767
+ h('div', { className: 'lc-sec' },
4768
+ h('div', { className: 'lc-row' },
4769
+ h('div', { className: 'lc-grow' }, h('span', { style: { fontWeight: 650 } }, '改成剧本')),
4770
+ h(Btn, { size: 'sm', tone: 'analyze', icon: 'spark', disabled: busy !== '' || body.trim() === '' || chapterBroken === true, onClick: doScript },
4771
+ busy === 'script' ? '正在改…' : (scriptText.trim() === '' ? '把这一章改成剧本' : '重改一份')),
4772
+ ),
4773
+ h('div', { className: 'lc-meta', style: { marginTop: 4, lineHeight: 1.7 } },
4774
+ // 先说「不会动正文」:人第一眼最怕的是自己的小说被改掉。
4775
+ '只读这一章的正文,小说一个字都不动;改出来的剧本单独存一份。',
4776
+ h('br'),
4777
+ '改出来的是能配音、能拍的剧本:切成一场一场,叙述变成 △ 动作,人物的话变成台词。',
4778
+ h('br'),
4779
+ '小说里那些拍不出来的东西(他心里一沉、命运的齿轮),改的时候会被丢下。'),
4780
+ scriptReport === ''
4781
+ ? null
4782
+ : h('div', {
4783
+ className: 'lc-meta',
4784
+ style: {
4785
+ marginTop: 6, whiteSpace: 'pre-wrap', lineHeight: 1.8,
4786
+ padding: '8px 10px', borderRadius: 8, background: 'var(--lc-analyze-soft)',
4787
+ },
4788
+ }, scriptReport),
4789
+ // 框里有字、或者改过还没存、或者有报告——都得把框和按钮摆出来。
4790
+ // 以前只判「有字」:人把框里的字全删掉,存/删两个按钮跟着一起消失,
4791
+ // 想清空清不掉、想删也删不了,还以为点了没反应。
4792
+ scriptText === '' && scriptDirty !== true && scriptReport === ''
4793
+ ? null
4794
+ : h('div', { className: 'lc-stack', style: { marginTop: 6 } },
4795
+ h('textarea', {
4796
+ className: 'lc-textarea',
4797
+ value: scriptText,
4798
+ spellCheck: false,
4799
+ // 正在存 / 正在重改 / 正在删的时候都不让改:
4800
+ // 改了的字会在回包那一刻被当成「已存」清掉标记,或者被 AI 那一版整份盖掉。
4801
+ readOnly: busy === 'scriptSave' || busy === 'script' || busy === 'scriptDelete',
4802
+ style: { minHeight: 300, lineHeight: 1.8 },
4803
+ onChange: (e) => { setScriptText(e.target.value); setScriptDirty(true) },
4804
+ }),
4805
+ h('div', { className: 'lc-row' },
4806
+ h(Btn, { size: 'sm', tone: 'primary', icon: 'check', disabled: busy !== '' || scriptText.trim() === '', onClick: saveScript },
4807
+ busy === 'scriptSave' ? '正在存…' : '存好这份剧本'),
4808
+ // 「删掉这份」写全:不写清是剧本,人会以为删的是小说正文。
4809
+ h(Btn, { size: 'sm', ghost: true, icon: 'trash', disabled: busy !== '', onClick: removeScript }, '删掉这份剧本'),
4810
+ h('div', { className: 'lc-grow' }),
4811
+ // 字数去掉空白再数:报告里、存好之后的回执里都是这个口径,
4812
+ // 这里多算的空格和换行只会让人以为「存完少了几十个字」。
4813
+ h('span', { className: 'lc-meta' },
4814
+ scriptDirty
4815
+ ? `${scriptText.replace(/\s/g, '').length} 字 · 还没存`
4816
+ : `${scriptText.replace(/\s/g, '').length} 字`),
4817
+ ),
4818
+ ),
4819
+ // 这一节的报错就摆在这一节里。放全页最底下等于没报——
4820
+ // 剧本框本身就三百像素高,报错落到屏幕外,人只会觉得「点了没反应」。
4821
+ scriptErr === null ? null : h(Note, { tone: 'err', icon: 'warning' }, scriptErr),
4822
+ ),
4823
+
3712
4824
  err === null ? null : h(Note, { tone: 'err', icon: 'warning' }, err),
3713
4825
  )
3714
4826
  }
@@ -5993,7 +7105,7 @@ function MemoryView({ onDone, onBack, mode, onStartInterview }) {
5993
7105
  ? h('div', { className: 'lc-stack' },
5994
7106
  h(Note, { tone: undefined, icon: 'person' }, '记忆里没有提到具体的人。可以先「聊一聊」,聊过的内容会变成材料。'),
5995
7107
  h('div', null,
5996
- h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onStartInterview({ about: '', mode }) }, '聊一聊(新开一个对话)'),
7108
+ h(Btn, { tone: 'interview', icon: 'chat', onClick: () => onStartInterview?.({ about: '', mode }) }, '聊一聊(新开一个对话)'),
5997
7109
  h('div', { className: 'lc-meta' }, '会在新对话里问,答完 AI 自己写进卡里'),
5998
7110
  ))
5999
7111
  : h('div', { className: 'lc-stack' },
@@ -6498,7 +7610,7 @@ function scoreSection(report, onOpenCard) {
6498
7610
  )
6499
7611
  }
6500
7612
 
6501
- // ── 下一步(求职 / 面试 / 简历) ────────────────────────────────────────────────────────
7613
+ // ── 求职(贴招聘说明 / 面试 / 投递表) ────────────────────────────────────────────────
6502
7614
 
6503
7615
  /** 投递状态的中文说法。和宿主侧 jobs-store.js 那份是同一套,改的时候两边一起改。 */
6504
7616
  const TRACK_LABEL = {
@@ -6513,11 +7625,15 @@ const TRACK_LABEL = {
6513
7625
  }
6514
7626
 
6515
7627
  /**
6516
- * 「下一步」这一页。
7628
+ * 「求职」这一页。
7629
+ *
7630
+ * 名字换过两次。最早叫「看工作」,用户觉得太窄;改成「下一步」,
7631
+ * 用户的反馈是「看不出是什么东西,点进去才知道」。可见名字要自己
7632
+ * 说明它管什么,而不是靠点进去才发现。
6517
7633
  *
6518
- * 为什么叫这个名字:它管的不只是「找工作」——改简历、练面试、
6519
- * 想清楚接下来半年怎么走,都是同一件事的不同阶段。叫「看工作」
6520
- * 会让人以为只有投简历那天才用得上。
7634
+ * 这一页真正干的事:贴一份招聘说明进来,换回一张「哪里会卡住你」的
7635
+ * 清单;练一轮面试;记下投了哪些。改简历和长期规划在另一页
7636
+ * (「简历与规划」),因为那是坐着写半个钟头的事,不是每天会点的。
6521
7637
  *
6522
7638
  * 只有一件事:把一份招聘说明贴进来,换回一张「哪里会卡住你」的清单。
6523
7639
  * 刻意没有的东西:批量投递、自动发信、岗位推荐流。这三样都会让人
@@ -7341,6 +8457,10 @@ const inject = ['slots']
7341
8457
  // 测试专用口子:这两条路要等宿主服务就绪(ctx.inject)才分得清,
7342
8458
  // 假宿主里造不出 inject,所以允许测试直接把两个服务塞进来。
7343
8459
  exports.__openInterviewSession = openInterviewSession;
8460
+ // 测试专用口子:写小说那一页只有从根部点进去才会出现,而它的换书逻辑
8461
+ // (bookId 变了但组件不卸载)在假根部里绕太远,直接渲染这个组件最省事。
8462
+ exports.__BookView = BookView;
8463
+ exports.__DiaryView = DiaryView;
7344
8464
  exports.__setHostServices = (remote, ui) => {
7345
8465
  REMOTE_SESSION = remote === undefined ? null : remote;
7346
8466
  UI_WORKSPACE = ui === undefined ? null : ui;