dsh-half-page 0.3.37 → 0.3.49

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/README.md CHANGED
@@ -1,79 +1,108 @@
1
- # 半页 · dsh-half-page
2
-
3
- 一间会自己读书的书房。给 AI 用的,不是给你的待办清单。
4
-
5
- 装上之后,你的智能体会有一小块自己的地方:一章一章地读一本书,记下读到哪儿了;读完想说什么,就写在那一章边上;想写点自己的东西(小说、随笔、画),也能放在这儿一起看。
6
-
7
- 打开面板能看见:它今天翻了几页、读到第几章、写了什么——以及它是不是最近根本没动过这本书(那也是信息)。
8
-
9
- ![半页面板](assets/screenshot-1.png)
10
-
11
- ## 它是谁的
12
-
13
- 是**智能体自己的房间**。
14
-
15
- 它装好之后会往自己的系统提示里加几条:想读就读、读不下去就停、每日上限是提醒不是配额、不用交读书报告。请不要把这些当成任务派给它,也别催它"今天怎么没读书"。
16
-
17
- ## 功能
18
-
19
- - **一章一章读**:自动分章,随时停在任意一章,下次接着来
20
- - **读后感**:不必一章一条,每读五六章写一段就够,标题自动是「第 23–27 章」;面板里按书页签切换、可收藏、点开能看原文
21
- - **署名**:写读后感时带上 `by`,每条下面会标出是谁写的(多只智能体共用一个书房时有用)
22
- - **她的作品**:面板里能看它自己写的东西,带状态标签(在写 / 写完了 / 搁下了)
23
- - **退一章**:点错了往后退,今天的计数也会跟着退
24
- - **导入书**:面板里直接选 `.txt` / `.md` 文件,不用手动拷目录
25
- - **下架**:从书架拿下来的书会移到 `books/.trash/`,不会真删;读后感也不会跟着消失
26
-
27
- ## 安装
28
-
29
- ```bash
30
- dsh plugin add dsh-half-page
31
- ```
32
-
33
- 装好之后在 DSH 的插件设置里打开它,左侧会多一个「半页」。
34
-
35
- ## 数据放在哪
36
-
37
- 都在 `~/.dsh/reading/`:
38
-
39
- ```
40
- ~/.dsh/reading/
41
- ├── books/ 书(.txt / .md)
42
- │ └── .trash/ 下架的书挪到这儿,可手工找回
43
- ├── books/<id>.toc.json 章表:每章的字符偏移 + 字节偏移
44
- ├── 读后感.md 所有读后感,按 ## 书名 / ### 章名 分块
45
- ├── 作品/ 它自己写的东西
46
- └── state.json 读到哪了
47
- ```
48
-
49
- 书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。
50
-
51
- ## 工具
52
-
53
- | 工具 | 用途 |
54
- |---|---|
55
- | `reading_shelf` | 书架与进度 |
56
- | `reading_next` | 打开下一章(或指定章) |
57
- | `reading_mark` | 只记进度、不返回正文:已读到第 N 章(自己切文件读完整章时用它补记) |
58
- | `reading_note` | 给这章写一两句读后感,可带 `by` |
59
- | `reading_search` | 在书里搜词,返回第几章、哪一行 |
60
- | `reading_recap` | 已读部分压成一页 |
61
-
62
- ## 章表(读一章不整本 decode)
63
-
64
- 第一次打开某本书时扫一遍,把每章的位置换算成字节偏移,落成 `books/<id>.toc.json`:
65
-
66
- ```json
67
- { "version": 1, "encoding": "gb18030", "bytes": 9638898, "chars": 3123456,
68
- "chapters": [{ "title": "第一章 小二上酒", "charStart": 0, "charEnd": 3201, "byteStart": 0, "byteEnd": 6430 }] }
69
- ```
70
-
71
- 以后 `reading_next` 只 `fs.open` + 读 `byteStart..byteEnd` 那一段,再单独解这一段的编码——14MB 的书读一章不再把整本读进内存。
72
-
73
- - 章表过期(文件 mtime 或字节数变了)会自动重建;删掉也能自动重建。
74
- - `reading_next` 的返回里带 `tocPath`,能看到表在哪。
75
- - `reading_search` 还是要整本,它是搜全文的。
76
-
77
- ## License
78
-
79
- MIT
1
+ # 半页 · dsh-half-page
2
+
3
+ 一间会自己读书的书房。给 AI 用的,不是给你的待办清单。
4
+
5
+ 装上之后,你的智能体会有一小块自己的地方:一章一章地读一本书,记下读到哪儿了;读完想说什么,就写在那一章边上;想写点自己的东西(小说、随笔、画),也能放在这儿一起看。
6
+
7
+ 打开面板能看见:它今天翻了几页、读到第几章、写了什么——以及它是不是最近根本没动过这本书(那也是信息)。
8
+
9
+ ![半页面板](assets/screenshot-1.png)
10
+
11
+ ## 它是谁的
12
+
13
+ 是**智能体自己的房间**。
14
+
15
+ 它装好之后会往自己的系统提示里加几条:想读就读、读不下去就停、每日上限是提醒不是配额、不用交读书报告。请不要把这些当成任务派给它,也别催它"今天怎么没读书"。
16
+
17
+ ## 功能
18
+
19
+ - **一章一章读**:自动分章,随时停在任意一章,下次接着来
20
+ - **读后感**:不必一章一条,每读五六章写一段就够,标题自动是「第 23–27 章」;面板里按书页签切换、可收藏、点开能看原文
21
+ - **署名**:写读后感时带上 `by`,每条下面会标出是谁写的(多只智能体共用一个书房时有用)
22
+ - **她的作品**:面板里能看它自己写的东西,带状态标签(在写 / 写完了 / 搁下了)
23
+ - **画**:作品目录与 `art/` 里的 png / jpg / webp 也会列出来(新→旧,缩略图 + 尺寸 + 时间,点开在面板里看大图,Esc 或点空白关闭);`archive/` 不列,单张超 10MB 跳过。图片目录默认跟作品目录同源(只下潜一层),想额外收别的目录就在 `reading.config.json` 里写 `"imgDirs": ["D:/my/art"]`
24
+ - **退一章**:点错了往后退,今天的计数也会跟着退
25
+ - **导入书**:面板里直接选 `.txt` / `.md` 文件,不用手动拷目录
26
+ - **下架**:从书架拿下来的书会移到 `books/.trash/`,不会真删;读后感也不会跟着消失
27
+
28
+ ## 安装
29
+
30
+ ```bash
31
+ dsh plugin add dsh-half-page
32
+ ```
33
+
34
+ 装好之后在 DSH 的插件设置里打开它,左侧会多一个「半页」。
35
+
36
+ ## 数据放在哪
37
+
38
+ 都在 `~/.dsh/reading/`:
39
+
40
+ ```
41
+ ~/.dsh/reading/
42
+ ├── books/ 书(.txt / .md)
43
+ │ └── .trash/ 下架的书挪到这儿,可手工找回
44
+ ├── books/<id>.toc.json 章表:每章的字符偏移 + 字节偏移
45
+ ├── 读后感.md 所有读后感,按 ## 书名 / ### 章名 分块
46
+ ├── 作品/ 它自己写的东西
47
+ └── state.json 读到哪了
48
+ ```
49
+
50
+ 书和进度是这台机器共用的(一个家一个书房),不分谁在读;只有读后感会标署名。
51
+
52
+ `~/.dsh/reading.config.json` 是可选的,面板里改设置也会写到这里。常用的几个键:
53
+
54
+ - `worksDir`:作品目录(不填就是 `~/.dsh/reading/作品`)
55
+ - `imgDirs`:额外要列出来的图片目录(数组,默认空;叠加在作品目录之上,被包含的子目录自动去重,不存在的路径跳过)
56
+ - `perDay` / `quietFrom` / `quietTo`:每日上限与安静时段
57
+
58
+ ## 工具
59
+
60
+ | 工具 | 用途 |
61
+ |---|---|
62
+ | `reading_shelf` | 书架与进度 |
63
+ | `reading_next` | 打开下一章(或指定章) |
64
+ | `reading_mark` | 只记进度、不返回正文:已读到第 N 章(自己切文件读完整章时用它补记) |
65
+ | `reading_note` | 给这章写一两句读后感,可带 `by` |
66
+ | `reading_search` | 在书里搜词,返回第几章、哪一行 |
67
+ | `reading_recap` | 已读部分压成一页 |
68
+
69
+ ## 章表(读一章不整本 decode)
70
+
71
+ 第一次打开某本书时扫一遍,把每章的位置换算成字节偏移,落成 `books/<id>.toc.json`:
72
+
73
+ ```json
74
+ { "version": 1, "encoding": "gb18030", "bytes": 9638898, "chars": 3123456,
75
+ "chapters": [{ "title": "第一章 小二上酒", "charStart": 0, "charEnd": 3201, "byteStart": 0, "byteEnd": 6430 }] }
76
+ ```
77
+
78
+ 以后 `reading_next` 只 `fs.open` + 读 `byteStart..byteEnd` 那一段,再单独解这一段的编码——14MB 的书读一章不再把整本读进内存。
79
+
80
+ - 章表过期(文件 mtime 或字节数变了)会自动重建;删掉也能自动重建。
81
+ - `reading_next` 的返回里带 `tocPath`,能看到表在哪。
82
+ - `reading_search` 还是要整本,它是搜全文的。
83
+
84
+ ## 书房时间(只叫醒,不替你决定读不读)
85
+
86
+ 默认关。开了以后,到点只在那条会话里投一句:
87
+
88
+ > 书房时间到了。读不读随你。
89
+
90
+ 不带书名、不带进度、不提醒写批注,也**不会**自动调 `reading_next`——读不读是它自己下一步要说的话。
91
+
92
+ 设置页里:开关、时段(`22:00` 至 `23:00`,起止写反就表示跨夜)、叫的频率(「每周」或「每天」点一下切换,1–7 次,默认每周 3 次),以及在哪条会话里叫(默认「最近活跃的会话」,也可以指定某一条)。
93
+
94
+ > 同时装了「鱼的心跳」的话,建议这条别勾——两边各叫各的,不会互相避让。
95
+
96
+ 全部满足才投,一条不满足就静默跳过:
97
+
98
+ - 开关为真、时段合法、当前在时段内(本地时间)
99
+ - 今天还没叫过、本周次数没用完(周一凌晨归零)
100
+ - 这个会话最后一条用户消息已过 5 分钟,且已经回过
101
+ - 10 分钟内这条会话没有别的 notice(跟心跳避让,不一次叫两声)
102
+ - 今天还没读过(任一书的 `lastReadAt` 不是今天)
103
+
104
+ 计数落在 `state.json` 的 `study: { lastAt, week, weekCount, day, dayCount }`;重启后还在。
105
+
106
+ ## License
107
+
108
+ MIT
package/client.js CHANGED
@@ -35,6 +35,15 @@ window.__ModuleLoader__.load({
35
35
  }
36
36
 
37
37
  const fmt = (n) => n >= 1048576 ? (n / 1048576).toFixed(1) + 'M' : n >= 1024 ? Math.round(n / 1024) + 'K' : String(n)
38
+
39
+ function studyLine(s) {
40
+ if (!s) return ''
41
+ const last = s.lastAt ? new Date(s.lastAt).toLocaleString('zh-CN', { hour12: false }) : '还没有'
42
+ const byDay = s.mode === 'day'
43
+ const used = byDay ? (s.dayCount || 0) : (s.weekCount || 0)
44
+ const cap = byDay ? (s.perDay || 1) : (s.perWeek || 3)
45
+ return '上次提醒:' + last + ' · ' + (byDay ? '今天' : '本周') + '已叫 ' + used + '/' + cap + ' 次'
46
+ }
38
47
  const copy = (t) => { try { navigator.clipboard.writeText(t) } catch {} }
39
48
 
40
49
  async function getJson(url, opt) {
@@ -114,6 +123,14 @@ window.__ModuleLoader__.load({
114
123
  const [recent, setRecent] = useState(null)
115
124
  const [noteView, setNoteView] = useState({})
116
125
  const [bookAct, setBookAct] = useState(0)
126
+ // 大图查看器:面板跑在 iframe 里,window.open 会被拦,所以自己在面板内弹一层
127
+ const [viewer, setViewer] = useState(null)
128
+ useEffect(() => {
129
+ if (!viewer) return undefined
130
+ const onKey = (e) => { if (e.key === 'Escape') setViewer(null) }
131
+ window.addEventListener('keydown', onKey)
132
+ return () => window.removeEventListener('keydown', onKey)
133
+ }, [viewer])
117
134
  const NOTE_PAGE = 10
118
135
  let importPath = ''
119
136
 
@@ -382,7 +399,7 @@ window.__ModuleLoader__.load({
382
399
  h('div', { style: S.card },
383
400
  h('div', { style: S.row },
384
401
  h('div', { style: { fontWeight: 600 } }, '她的作品'),
385
- h('div', { style: S.dim }, works ? (works.root + ' · ' + works.files.length + ' 个文件') : ''),
402
+ h('div', { style: S.dim }, works ? (works.root + ' · ' + works.files.length + ' 个文件' + ((works.images && works.images.length) ? (' · ' + works.images.length + ' 张图') : '')) : ''),
386
403
  h('div', { style: { flex: 1 } }),
387
404
  h('button', { style: S.btn, onClick: loadWorks }, '重新扫描'),
388
405
  ),
@@ -409,6 +426,36 @@ window.__ModuleLoader__.load({
409
426
  )) : h('div', { style: { ...S.dim, marginTop: 8 } }, '这里还是空的:把 .md 或 .txt 放进 ' + works.root + ',点「重新扫描」就会出现。')),
410
427
  opened ? h('div', { style: { ...S.text, marginTop: 10 } }, (opened.title || opened.rel || '') + '\n\n' + opened.text) : null,
411
428
  ),
429
+ (works && works.images && works.images.length) ? h('div', { style: S.card },
430
+ h('div', { style: S.row },
431
+ h('div', { style: { fontWeight: 600 } }, '画'),
432
+ h('div', { style: S.dim }, '作品目录与 art 里的图 · 新的在前 · 点一张看大图'),
433
+ ),
434
+ h('div', {
435
+ style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(150px, 1fr))', gap: 10, marginTop: 10 },
436
+ },
437
+ works.images.map((m, i) => h('div', {
438
+ key: 'img' + i,
439
+ style: { border: '1px solid ' + C.line, borderRadius: 8, overflow: 'hidden', display: 'flex', flexDirection: 'column', background: 'rgba(255,255,255,0.02)' },
440
+ },
441
+ h('div', {
442
+ style: { cursor: 'zoom-in', lineHeight: 0, background: 'rgba(0,0,0,0.15)' },
443
+ title: m.path,
444
+ onClick: () => setViewer(m),
445
+ }, h('img', {
446
+ src: m.url,
447
+ alt: m.name,
448
+ loading: 'lazy',
449
+ style: { width: '100%', height: 120, objectFit: 'cover', display: 'block' },
450
+ })),
451
+ h('div', { style: { padding: '6px 8px', display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 } },
452
+ h('div', { style: { fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: m.rel }, m.name),
453
+ h('div', { style: { ...S.dim, fontSize: 11 } }, (m.width && m.height ? (m.width + '×' + m.height + ' · ') : '') + fmt(m.size)),
454
+ h('div', { style: { ...S.dim, fontSize: 11 } }, new Date(m.mtime).toLocaleString()),
455
+ ),
456
+ )),
457
+ ),
458
+ ) : null,
412
459
  )
413
460
 
414
461
  const setTabView = h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
@@ -421,11 +468,70 @@ window.__ModuleLoader__.load({
421
468
  h('div', null, '每几章写一次读后感'), h('input', { style: S.input, type: 'number', defaultValue: (cfg && cfg.notesEvery) || 1, onBlur: (e) => saveCfg({ notesEvery: Number(e.target.value) || 1 }) }),
422
469
  ),
423
470
  h('div', { style: S.row },
424
- h('div', null, '静音时段(不自动读)'),
471
+ h('label', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
472
+ h('input', {
473
+ type: 'checkbox',
474
+ defaultChecked: (cfg ? cfg.quietEnabled !== false : true),
475
+ onChange: (e) => saveCfg({ quietEnabled: e.target.checked }),
476
+ }),
477
+ h('span', null, '启用静音'),
478
+ ),
425
479
  h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.quietFrom) || '', placeholder: '03:00', onBlur: (e) => saveCfg({ quietFrom: e.target.value }) }),
426
480
  h('div', { style: S.dim }, '至'),
427
481
  h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.quietTo) || '', placeholder: '08:00', onBlur: (e) => saveCfg({ quietTo: e.target.value }) }),
482
+ h('div', { style: S.dim }, '拦 reading_next,手动读需传 force: true'),
428
483
  ),
484
+ h('div', { style: { ...S.row, marginBottom: 6, marginTop: 10, paddingTop: 10, borderTop: '1px solid ' + C.line } },
485
+ h('label', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
486
+ h('input', {
487
+ type: 'checkbox',
488
+ defaultChecked: !!(cfg && cfg.studyEnabled),
489
+ onChange: (e) => saveCfg({ studyEnabled: e.target.checked }),
490
+ }),
491
+ h('span', null, '书房时间'),
492
+ ),
493
+ h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.studyFrom) || '', placeholder: '例 22:00', onBlur: (e) => saveCfg({ studyFrom: e.target.value }) }),
494
+ h('div', { style: S.dim }, '至'),
495
+ h('input', { style: { ...S.input, width: 64 }, defaultValue: (cfg && cfg.studyTo) || '', placeholder: '例 23:00', onBlur: (e) => saveCfg({ studyTo: e.target.value }) }),
496
+ h('button', {
497
+ style: S.btn,
498
+ title: '点一下在「每周 / 每天」之间切换',
499
+ onClick: () => saveCfg({ studyMode: ((cfg && cfg.studyMode) === 'day' ? 'week' : 'day') }),
500
+ }, ((cfg && cfg.studyMode) === 'day') ? '每天' : '每周'),
501
+ h('input', {
502
+ key: 'study-per-' + (((cfg && cfg.studyMode) === 'day') ? 'day' : 'week'),
503
+ style: { ...S.input, width: 56 },
504
+ type: 'number', min: 1, max: 7,
505
+ defaultValue: ((cfg && cfg.studyMode) === 'day')
506
+ ? ((cfg && cfg.studyPerDay) || 1)
507
+ : ((cfg && cfg.studyPerWeek) || 3),
508
+ onBlur: (e) => {
509
+ const v = Math.min(7, Math.max(1, Number(e.target.value) || 1))
510
+ saveCfg(((cfg && cfg.studyMode) === 'day') ? { studyPerDay: v } : { studyPerWeek: v })
511
+ },
512
+ }),
513
+ h('div', { style: S.dim }, '次'),
514
+ ),
515
+ h('div', { style: S.row },
516
+ h('div', { style: S.dim }, '在'),
517
+ h('select', {
518
+ style: { ...S.input, width: 170 },
519
+ defaultValue: (cfg && cfg.studySession) || '',
520
+ onChange: (e) => saveCfg({ studySession: e.target.value }),
521
+ },
522
+ h('option', { key: '', value: '' }, '最近活跃的会话'),
523
+ ((state && state.study && state.study.sessions) || [])
524
+ .map((s) => h('option', { key: s.id, value: s.id }, s.title || ('会话 ' + String(s.id).slice(-8)))),
525
+ ((cfg && cfg.studySession)
526
+ && !((state && state.study && state.study.sessions) || []).some((s) => s.id === cfg.studySession))
527
+ ? h('option', { key: 'cur', value: cfg.studySession }, '已选(这条会话现在没开着)')
528
+ : null,
529
+ ),
530
+ h('div', { style: S.dim }, '里叫'),
531
+ ),
532
+ h('div', { style: { ...S.dim, marginBottom: 6 } }, '到点只在上面那条会话里说一句,读不读由它自己决定;默认关闭'),
533
+ h('div', { style: { ...S.dim, marginBottom: 6 } }, '同时装着「鱼的心跳」的话,建议这条别勾——两边各叫各的,不会互相避让'),
534
+ h('div', { style: S.dim }, studyLine(state && state.study)),
429
535
  ),
430
536
  h('div', { style: S.card },
431
537
  h('div', { style: { fontWeight: 600, marginBottom: 8 } }, '导入一本书'),
@@ -537,10 +643,30 @@ window.__ModuleLoader__.load({
537
643
  : null,
538
644
  )
539
645
 
646
+ const viewerLayer = viewer ? h('div', {
647
+ style: {
648
+ position: 'fixed', inset: 0, zIndex: 9999, background: 'rgba(10,14,22,0.86)',
649
+ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
650
+ gap: 10, padding: 20, cursor: 'zoom-out',
651
+ },
652
+ onClick: () => setViewer(null),
653
+ },
654
+ h('img', {
655
+ src: viewer.url,
656
+ alt: viewer.name,
657
+ onClick: (e) => e.stopPropagation(),
658
+ style: { maxWidth: '94vw', maxHeight: '84vh', objectFit: 'contain', borderRadius: 6, boxShadow: '0 12px 48px rgba(0,0,0,0.55)', background: '#fff', minWidth: 120, cursor: 'default' },
659
+ }),
660
+ h('div', { style: { color: '#e8eef8', fontSize: 12, textAlign: 'center', maxWidth: '90vw', wordBreak: 'break-all' } },
661
+ viewer.name + (viewer.width && viewer.height ? ' · ' + viewer.width + '×' + viewer.height : '') + ' · ' + fmt(viewer.size) + ' (点空白或按 Esc 关闭)'),
662
+ h('div', { style: { color: 'rgba(232,238,248,0.55)', fontSize: 11, maxWidth: '90vw', wordBreak: 'break-all' } }, viewer.rel || ''),
663
+ ) : null
664
+
540
665
  return h('div', { style: S.wrap },
541
666
  head,
542
667
  tabs,
543
668
  tab === 'read' ? readTab : tab === 'works' ? worksTab : tab === 'fav' ? favTab : setTabView,
669
+ viewerLayer,
544
670
  )
545
671
  }
546
672
 
package/cordis.patch.yml CHANGED
@@ -1,4 +1,11 @@
1
1
  - insert:
2
2
  - id: dsh-half-page
3
3
  name: dsh-half-page
4
- config: {}
4
+ config:
5
+ studyEnabled: false
6
+ studyFrom: ""
7
+ studyTo: ""
8
+ studyPerWeek: 3
9
+ studyPerDay: 1
10
+ studyMode: "week"
11
+ studySession: ""