dsh-whale-whispers 2.0.8 → 2.1.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/README.md +3 -2
- package/index.js +216 -44
- package/package.json +2 -2
- package/LICENSE +0 -21
- package/README.md.bak-200-20261107-190233 +0 -148
package/README.md
CHANGED
|
@@ -64,12 +64,13 @@
|
|
|
64
64
|
|
|
65
65
|
| 工具 | 作用 |
|
|
66
66
|
|---|---|
|
|
67
|
-
| `whale_whisper_append` |
|
|
68
|
-
| `whale_whisper_list` |
|
|
67
|
+
| `whale_whisper_append` | 收一句,写进**当前这段对话那一本**(按会话 id 认本,和面板同一条解析);重复的自动跳过 |
|
|
68
|
+
| `whale_whisper_list` | 读回最近的句子(查重、看自己收过什么;读所有本) |
|
|
69
69
|
| `whale_whisper_remove` | 删掉一句(整句匹配,不会误伤旁边那条) |
|
|
70
70
|
| `whale_whisper_merge` | 合并重复句,只留最早那条,返回删了几条 |
|
|
71
71
|
|
|
72
72
|
写进去是原子的(临时文件 + rename),格式跟文件里原有的一样:`- 「句子」(批注)`。
|
|
73
|
+
工具不会再写 `path` 那份旧单文件:拿不到会话 id 时也只写 `dir` 下的「未命名」。旧文件在第一次加载时会被一次性并进各本(并在配置里打 `migratedLegacy` 标记),之后只当历史存档。
|
|
73
74
|
|
|
74
75
|
想让它主动收,在 agent 的规矩里写一句:
|
|
75
76
|
|
package/index.js
CHANGED
|
@@ -406,7 +406,7 @@ function formatLine(text, note, context, conversation) {
|
|
|
406
406
|
* Insert one line under `## <today>`; append the section if it does not exist yet.
|
|
407
407
|
* Returns the new file content plus whether the line was actually added.
|
|
408
408
|
*/
|
|
409
|
-
export function insertQuote(source, text, note, context, conversation) {
|
|
409
|
+
export function insertQuote(source, text, note, context, conversation, dayKey) {
|
|
410
410
|
// 多行正文会把 md 的一行拆成几行、也会让查重认不出来,先压成一行
|
|
411
411
|
const oneLine = (v) => String(v == null ? '' : v).replace(/\s*\n+\s*/g, ' ').trim()
|
|
412
412
|
const cleanText = oneLine(text)
|
|
@@ -421,7 +421,7 @@ export function insertQuote(source, text, note, context, conversation) {
|
|
|
421
421
|
|
|
422
422
|
const eol = source.includes('\r\n') ? '\r\n' : '\n'
|
|
423
423
|
const lines = source.split(/\r?\n/)
|
|
424
|
-
const day = todayKey()
|
|
424
|
+
const day = String(dayKey || '').trim() || todayKey()
|
|
425
425
|
const header = `## ${day}`
|
|
426
426
|
const at = lines.findIndex((l) => l.trim() === header)
|
|
427
427
|
|
|
@@ -602,7 +602,101 @@ const textOutput = {
|
|
|
602
602
|
],
|
|
603
603
|
}
|
|
604
604
|
|
|
605
|
+
/**
|
|
606
|
+
* 一次性把 config.path 那份旧单文件并进 dir 下各自的本子。
|
|
607
|
+
* 旧文件只读不写:迁完在配置里打 migratedLegacy 标记,之后任何工具都不再碰它。
|
|
608
|
+
*/
|
|
609
|
+
export async function migrateLegacyOnce() {
|
|
610
|
+
const cfgFile = configCandidates()[0]
|
|
611
|
+
const cfg = (await readJson(cfgFile)) || {}
|
|
612
|
+
if (cfg && cfg.migratedLegacy === true) return { ok: true, skipped: true }
|
|
613
|
+
const base = await resolveTarget()
|
|
614
|
+
const legacyPath = base.path
|
|
615
|
+
let body = ''
|
|
616
|
+
try { body = await readFile(legacyPath, 'utf8') } catch { body = '' }
|
|
617
|
+
const dir = await quotesDir()
|
|
618
|
+
const items = body ? parseQuotes(body) : []
|
|
619
|
+
const perBook = new Map()
|
|
620
|
+
for (const it of items) {
|
|
621
|
+
const name = safeConvName(it.conversation) || safeConvName(base.title) || '未命名'
|
|
622
|
+
if (!perBook.has(name)) perBook.set(name, [])
|
|
623
|
+
perBook.get(name).push(it)
|
|
624
|
+
}
|
|
625
|
+
let added = 0
|
|
626
|
+
let skipped = 0
|
|
627
|
+
for (const [name, rows] of perBook) {
|
|
628
|
+
const file = await ensureConvFile(dir, name, true)
|
|
629
|
+
if (!file) continue
|
|
630
|
+
const result = await withQuoteLock(file, async () => {
|
|
631
|
+
let source = await readSource(file)
|
|
632
|
+
const have = new Set(parseQuotes(source).map((q) => normalise(q.text)))
|
|
633
|
+
let n = 0
|
|
634
|
+
let dup = 0
|
|
635
|
+
for (const it of rows) {
|
|
636
|
+
const key = normalise(it.text)
|
|
637
|
+
if (!key || key === normalise(PLACEHOLDER)) continue
|
|
638
|
+
// 本子里已经有同一句 → 留原位置那条(最早的那条),不动已有措辞
|
|
639
|
+
if (have.has(key)) { dup += 1; continue }
|
|
640
|
+
const r = insertQuote(source, it.text, it.note, it.context, '', it.date)
|
|
641
|
+
if (r.added) {
|
|
642
|
+
source = dropPlaceholder(r.content)
|
|
643
|
+
have.add(key)
|
|
644
|
+
n += 1
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
if (n) await writeAtomic(file, source)
|
|
648
|
+
return { n, dup }
|
|
649
|
+
})
|
|
650
|
+
added += result.n
|
|
651
|
+
skipped += result.dup
|
|
652
|
+
}
|
|
653
|
+
await saveConfig({
|
|
654
|
+
migratedLegacy: true,
|
|
655
|
+
legacyMigratedAt: new Date().toISOString(),
|
|
656
|
+
legacySource: legacyPath,
|
|
657
|
+
})
|
|
658
|
+
return { ok: true, added, skipped, dir, legacyPath }
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/** 把只有占位句 / 空壳的本子挪进 dir/.trash-empty(不删,留个后路)。 */
|
|
662
|
+
export async function pruneEmptyBooks(dir) {
|
|
663
|
+
const moved = []
|
|
664
|
+
let names = []
|
|
665
|
+
try { names = await readdir(dir) } catch { return moved }
|
|
666
|
+
const trashDir = join(dir, '.trash-empty')
|
|
667
|
+
for (const n of names) {
|
|
668
|
+
if (!n.toLowerCase().endsWith('.md')) continue
|
|
669
|
+
const file = join(dir, n)
|
|
670
|
+
let body = ''
|
|
671
|
+
try { body = await readFile(file, 'utf8') } catch { continue }
|
|
672
|
+
const real = parseQuotes(body).some((it) => {
|
|
673
|
+
const t = String(it.text || '').trim()
|
|
674
|
+
return t && t !== PLACEHOLDER
|
|
675
|
+
})
|
|
676
|
+
if (real) continue
|
|
677
|
+
try {
|
|
678
|
+
await mkdir(trashDir, { recursive: true })
|
|
679
|
+
await rename(file, join(trashDir, n))
|
|
680
|
+
moved.push(n)
|
|
681
|
+
} catch { /* 挪不动就算了 */ }
|
|
682
|
+
}
|
|
683
|
+
return moved
|
|
684
|
+
}
|
|
685
|
+
|
|
605
686
|
export function apply(ctx) {
|
|
687
|
+
/* ---------- 启动时收拾一次:搬旧单文件、清空壳本 ---------- */
|
|
688
|
+
|
|
689
|
+
// 都不阻塞加载,失败也不影响面板和工具。
|
|
690
|
+
ctx.effect(() => {
|
|
691
|
+
let alive = true
|
|
692
|
+
;(async () => {
|
|
693
|
+
try { await migrateLegacyOnce() } catch { /* 迁移失败不影响用 */ }
|
|
694
|
+
if (!alive) return
|
|
695
|
+
try { await pruneEmptyBooks(await quotesDir()) } catch { /* 同上 */ }
|
|
696
|
+
})()
|
|
697
|
+
return () => { alive = false }
|
|
698
|
+
})
|
|
699
|
+
|
|
606
700
|
/* ---------- the shared operation ---------- */
|
|
607
701
|
|
|
608
702
|
/** conv 为空 → 老的单文件(“全部对话”);否则用该对话自己的文件。 */
|
|
@@ -727,7 +821,19 @@ async function sessionTitleOf(sessionId) {
|
|
|
727
821
|
* 找不到才按会话标题(或给定名字)建一本并打上标记。
|
|
728
822
|
* 以后会话改名、书改名都不会再凭名字去认书。
|
|
729
823
|
*/
|
|
730
|
-
|
|
824
|
+
/** 只留一本的模式:所有会话都写配置里那一本,不再按会话分本(免得越用越多)。 */
|
|
825
|
+
const singleBookName = async () => {
|
|
826
|
+
const cfg = (await readJson(configCandidates()[0])) || {}
|
|
827
|
+
if (!cfg.singleBook) return ''
|
|
828
|
+
return safeConvName(cfg.title || '') || '鲸语'
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const sessionBook = async (dir, sidKey, fallbackName, create = true) => {
|
|
832
|
+
const single = await singleBookName()
|
|
833
|
+
if (single) {
|
|
834
|
+
const f = await ensureConvFile(dir, single, true)
|
|
835
|
+
return { path: f || '', conv: single, blocked: !f }
|
|
836
|
+
}
|
|
731
837
|
const key = String(sidKey || '').trim()
|
|
732
838
|
const found = key ? await findBySid(dir, key) : ''
|
|
733
839
|
if (found) return { path: found, conv: bookNameOf(dir, found), blocked: false }
|
|
@@ -739,6 +845,8 @@ async function sessionTitleOf(sessionId) {
|
|
|
739
845
|
if (!name) name = '未命名'
|
|
740
846
|
const removedNow = await removedConvList()
|
|
741
847
|
if (removedNow.includes(name)) return { path: '', conv: name, blocked: true }
|
|
848
|
+
// 只读访问(面板看一眼)不该造出新本:找不到就返回空,等真写了句子再建
|
|
849
|
+
if (!create) return { path: '', conv: name, blocked: false }
|
|
742
850
|
const exist = dir + '/' + name + '.md'
|
|
743
851
|
let has = false
|
|
744
852
|
try { await stat(exist); has = true } catch { has = false }
|
|
@@ -748,10 +856,42 @@ async function sessionTitleOf(sessionId) {
|
|
|
748
856
|
return { path: file, conv: name, blocked: false }
|
|
749
857
|
}
|
|
750
858
|
|
|
859
|
+
/** 这次工具调用属于哪个会话;子会话记到父会话那本里。 */
|
|
860
|
+
const sessionKeyOf = (exec) => {
|
|
861
|
+
const agent = exec && exec.agent
|
|
862
|
+
if (!agent) return ''
|
|
863
|
+
const header = agent.session && agent.session.header
|
|
864
|
+
if (header && header.origin === 'subagent' && header.parentSession) return String(header.parentSession).trim()
|
|
865
|
+
const id = agent.session && agent.session.id ? agent.session.id : agent.id
|
|
866
|
+
return String(id || '').trim()
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* 工具写句子时该落到哪一本:认 sid、和面板走同一条 sessionBook 解析。
|
|
871
|
+
* 拿不到 sid 才用 dir 下的「未命名」,**绝不**回落到 config.path 那份旧单文件。
|
|
872
|
+
*/
|
|
873
|
+
const bookForWrite = async (exec, conversation) => {
|
|
874
|
+
const dir = await quotesDir()
|
|
875
|
+
const single = await singleBookName()
|
|
876
|
+
if (single) {
|
|
877
|
+
const f = await ensureConvFile(dir, single, true)
|
|
878
|
+
return { path: f || '', conv: single, blocked: !f }
|
|
879
|
+
}
|
|
880
|
+
const sidKey = sessionKeyOf(exec)
|
|
881
|
+
const conv = safeConvName(conversation)
|
|
882
|
+
if (sidKey) return await sessionBook(dir, sidKey, conv)
|
|
883
|
+
const name = conv || '未命名'
|
|
884
|
+
if ((await removedConvList()).includes(name)) return { path: '', conv: name, blocked: true }
|
|
885
|
+
const file = await ensureConvFile(dir, name, true)
|
|
886
|
+
return { path: file || '', conv: name, blocked: !file }
|
|
887
|
+
}
|
|
888
|
+
|
|
751
889
|
const listQuotes = async (conv, sid, mode) => {
|
|
752
890
|
const cfgNow = (await readJson(configCandidates()[0])) || {}
|
|
753
891
|
const dir = await quotesDir()
|
|
754
|
-
const
|
|
892
|
+
const convsAll = await listConvFiles(dir)
|
|
893
|
+
const singleNow = await singleBookName()
|
|
894
|
+
const convs = singleNow ? convsAll.filter((n) => n === singleNow) : convsAll
|
|
755
895
|
const sidKey = String(sid || '').trim()
|
|
756
896
|
const wantAll = mode === 'all' || (!mode && !conv && !sidKey)
|
|
757
897
|
let active = ''
|
|
@@ -765,11 +905,7 @@ async function sessionTitleOf(sessionId) {
|
|
|
765
905
|
await writeAtomic(file, repaired)
|
|
766
906
|
source = repaired
|
|
767
907
|
}
|
|
768
|
-
|
|
769
|
-
if (!real.length) {
|
|
770
|
-
const migrated = await migrateLegacy(dir, label)
|
|
771
|
-
if (migrated) source = migrated
|
|
772
|
-
}
|
|
908
|
+
// 旧单文件已由 migrateLegacyOnce() 一次性并进各本,这里不再做「空本就去翻 legacy」的懒迁移
|
|
773
909
|
return source
|
|
774
910
|
}
|
|
775
911
|
|
|
@@ -799,7 +935,9 @@ async function sessionTitleOf(sessionId) {
|
|
|
799
935
|
path = dir
|
|
800
936
|
} else if (mode === 'name' && conv) {
|
|
801
937
|
active = await aliasOf(safeConvName(conv))
|
|
802
|
-
|
|
938
|
+
let exists = false
|
|
939
|
+
try { await stat(dir + '/' + active + '.md'); exists = true } catch { exists = false }
|
|
940
|
+
const file = exists ? dir + '/' + active + '.md' : ''
|
|
803
941
|
if (file) {
|
|
804
942
|
path = file
|
|
805
943
|
const source = await readBookSource(file, active)
|
|
@@ -812,7 +950,7 @@ async function sessionTitleOf(sessionId) {
|
|
|
812
950
|
}
|
|
813
951
|
} else {
|
|
814
952
|
// 会话视图:sid 才是身份,书名只是标签
|
|
815
|
-
const book = await sessionBook(dir, sidKey, conv)
|
|
953
|
+
const book = await sessionBook(dir, sidKey, conv, false)
|
|
816
954
|
active = book.conv
|
|
817
955
|
if (book.path) {
|
|
818
956
|
path = book.path
|
|
@@ -827,10 +965,9 @@ async function sessionTitleOf(sessionId) {
|
|
|
827
965
|
}
|
|
828
966
|
|
|
829
967
|
const title = typeof cfgNow.title === 'string' && cfgNow.title.trim() ? cfgNow.title.trim() : '鲸语'
|
|
830
|
-
//
|
|
968
|
+
// 下拉只列「真写过句子」的书;空壳(只有占位句)不占位置。
|
|
831
969
|
const listed = []
|
|
832
970
|
for (const n of convs) {
|
|
833
|
-
if (active && n === active) { listed.push(n); continue }
|
|
834
971
|
const f = join(dir, n + '.md')
|
|
835
972
|
const cached = await readParsedCached(f).catch(() => null)
|
|
836
973
|
const rows = (cached && Array.isArray(cached.parsed)) ? cached.parsed : []
|
|
@@ -863,19 +1000,16 @@ async function sessionTitleOf(sessionId) {
|
|
|
863
1000
|
}
|
|
864
1001
|
}
|
|
865
1002
|
|
|
866
|
-
const appendQuote = async (text, note, context, conversation) => {
|
|
1003
|
+
const appendQuote = async (text, note, context, conversation, exec) => {
|
|
867
1004
|
const body = String(text || '').replace(/\s*\n+\s*/g, ' ').trim()
|
|
868
1005
|
if (!body) return { ok: false, error: 'text 不能为空' }
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const target = await targetFor(convName, true)
|
|
877
|
-
const path = target.path
|
|
878
|
-
const title = target.title
|
|
1006
|
+
// 落到「当前会话那一本」:sid 是身份,书名只是标签。拿不到 sid 也不退回旧单文件。
|
|
1007
|
+
const book = await bookForWrite(exec, conversation)
|
|
1008
|
+
if (book.blocked) return { ok: false, error: '这本在回收站里,先从设置里收回来再记' }
|
|
1009
|
+
if (!book.path) return { ok: false, error: '找不到当前会话的语录本,没地方写(不会退回旧单文件)' }
|
|
1010
|
+
const path = book.path
|
|
1011
|
+
const title = book.conv
|
|
1012
|
+
const convName = conversation ? safeConvName(conversation) : ''
|
|
879
1013
|
const label = convName || title
|
|
880
1014
|
// 读-改-写整段上锁:两只鱼同时记,后写的不会把前一句吞掉
|
|
881
1015
|
const written = await withQuoteLock(path, async () => {
|
|
@@ -894,32 +1028,43 @@ async function sessionTitleOf(sessionId) {
|
|
|
894
1028
|
added,
|
|
895
1029
|
...(added ? {} : { reason: reason || 'skipped' }),
|
|
896
1030
|
title,
|
|
1031
|
+
conv: title,
|
|
897
1032
|
source: path,
|
|
898
1033
|
line: formatLine(body, note ? String(note).trim() : '', context ? String(context).trim() : '', conversation ? String(conversation).trim() : ''),
|
|
899
1034
|
total: parseQuotes(content).length,
|
|
900
1035
|
}
|
|
901
1036
|
}
|
|
902
1037
|
|
|
903
|
-
const removeQuote = async (text, conv) => {
|
|
1038
|
+
const removeQuote = async (text, conv, exec) => {
|
|
904
1039
|
const wanted = normalise(text)
|
|
905
1040
|
if (!wanted) return { ok: false, error: 'text 不能为空' }
|
|
906
1041
|
// 删除不能因为「这本还没建」就顺手建出一个空文件来(之前删未标注对话时就发生过)
|
|
907
1042
|
let path = ''
|
|
908
1043
|
let source = ''
|
|
909
|
-
if (conv) {
|
|
910
|
-
|
|
911
|
-
|
|
1044
|
+
if (conv || sessionKeyOf(exec)) {
|
|
1045
|
+
const dir = await quotesDir()
|
|
1046
|
+
const sidKey = sessionKeyOf(exec)
|
|
1047
|
+
let file = sidKey ? await findBySid(dir, sidKey) : ''
|
|
1048
|
+
if (!file) {
|
|
1049
|
+
const name = safeConvName(conv)
|
|
1050
|
+
if (name) file = dir + '/' + name + '.md'
|
|
1051
|
+
}
|
|
1052
|
+
if (file) {
|
|
1053
|
+
try {
|
|
1054
|
+
await stat(file)
|
|
1055
|
+
path = file
|
|
1056
|
+
source = await readFile(file, 'utf8')
|
|
1057
|
+
} catch { path = ''; source = '' }
|
|
1058
|
+
}
|
|
912
1059
|
}
|
|
913
1060
|
const eol = source.includes('\r\n') ? '\r\n' : '\n'
|
|
914
1061
|
const lines = source ? source.split(/\r?\n/) : []
|
|
915
1062
|
let at = path ? lines.findIndex((l) => l.trim().startsWith('- ') && normalise(splitLine(l)) === wanted) : -1
|
|
916
1063
|
if (at === -1) {
|
|
917
|
-
// 句子可能写在别的对话文件里(例如早期按 sid
|
|
918
|
-
//
|
|
1064
|
+
// 句子可能写在别的对话文件里(例如早期按 sid 落盘但没带对话名),再扫一遍 dir 下所有本。
|
|
1065
|
+
// 旧单文件 quotes.md 已不再参与读写,这里不认它。
|
|
919
1066
|
const quoteDir = await quotesDir()
|
|
920
|
-
const legacyPath = (await resolveTarget()).path
|
|
921
1067
|
const altPaths = []
|
|
922
|
-
if (legacyPath && legacyPath !== path) altPaths.push(legacyPath)
|
|
923
1068
|
let altNames = []
|
|
924
1069
|
try { altNames = (await readdir(quoteDir)).filter((n) => n.endsWith('.md')) } catch { altNames = [] }
|
|
925
1070
|
for (const name of altNames) {
|
|
@@ -952,9 +1097,10 @@ async function sessionTitleOf(sessionId) {
|
|
|
952
1097
|
return { ok: true, removed: splitLine(removed), line: removed, block, source: path, total: parseQuotes(joinLike(lines, source)).length }
|
|
953
1098
|
}
|
|
954
1099
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1100
|
+
/** 合并一本里的重复句:同样的句子只留最早那条。 */
|
|
1101
|
+
const mergeBook = async (path) => {
|
|
1102
|
+
let source = ''
|
|
1103
|
+
try { source = await readSource(path) } catch { return { ok: true, dropped: 0, total: 0, source: path } }
|
|
958
1104
|
const lines = source.split(/\r?\n/)
|
|
959
1105
|
const seen = new Set()
|
|
960
1106
|
const kept = []
|
|
@@ -974,6 +1120,27 @@ async function sessionTitleOf(sessionId) {
|
|
|
974
1120
|
return { ok: true, dropped, total: parseQuotes(joinLike(kept, source)).length, source: path }
|
|
975
1121
|
}
|
|
976
1122
|
|
|
1123
|
+
const mergeQuotes = async (conv, exec) => {
|
|
1124
|
+
// 指定了某一本(或带了 sid)就只合那一本;都没指定就把 dir 下每本各合一遍。
|
|
1125
|
+
if (conv || sessionKeyOf(exec)) {
|
|
1126
|
+
const book = await bookForWrite(exec, conv)
|
|
1127
|
+
if (book.blocked || !book.path) return { ok: false, error: '这本在回收站里或还没建' }
|
|
1128
|
+
return mergeBook(book.path)
|
|
1129
|
+
}
|
|
1130
|
+
const dir = await quotesDir()
|
|
1131
|
+
const names = await listConvFiles(dir)
|
|
1132
|
+
let dropped = 0
|
|
1133
|
+
let total = 0
|
|
1134
|
+
let files = 0
|
|
1135
|
+
for (const n of names) {
|
|
1136
|
+
const one = await mergeBook(dir + '/' + n + '.md')
|
|
1137
|
+
dropped += one.dropped
|
|
1138
|
+
total += one.total
|
|
1139
|
+
files += 1
|
|
1140
|
+
}
|
|
1141
|
+
return { ok: true, dropped, total, files, source: dir }
|
|
1142
|
+
}
|
|
1143
|
+
|
|
977
1144
|
/** Rewrite every `↳ 对话:<from>` line to <to>. Returns how many lines changed. */
|
|
978
1145
|
const renameConversation = async (from, to) => {
|
|
979
1146
|
const src = String(from || '').trim()
|
|
@@ -1352,7 +1519,7 @@ async function sessionTitleOf(sessionId) {
|
|
|
1352
1519
|
/* ignore */
|
|
1353
1520
|
}
|
|
1354
1521
|
return [
|
|
1355
|
-
'【鲸语】你有一个自己的句子本:whale_whisper_append({ text, note?, context
|
|
1522
|
+
'【鲸语】你有一个自己的句子本:whale_whisper_append({ text, note?, context? }) 记一句(自动写进当前这段对话那一本,不用填书名),whale_whisper_list 查重/回看,whale_whisper_remove 删一句。',
|
|
1356
1523
|
'只记站得住、想过之后还想再看的话(判断、比喻、认输、承认);寒暄、进度、汇报不记。',
|
|
1357
1524
|
'值得说的时候(不是每次)顺带一句「这句我收进鲸语了」。',
|
|
1358
1525
|
'频率:' + CAPTURE_RULES[level],
|
|
@@ -1508,9 +1675,12 @@ async function sessionTitleOf(sessionId) {
|
|
|
1508
1675
|
return jsonSend(res, 400, { ok: false, error: '这本在回收站里,先在设置里点「恢复」收回来再记' })
|
|
1509
1676
|
}
|
|
1510
1677
|
target = { path: book.path, conv: book.conv, title: conversation }
|
|
1511
|
-
} else {
|
|
1678
|
+
} else if (conversation) {
|
|
1512
1679
|
// 明确指定了某一本:按书名写,别被当前会话的 sid 抢走
|
|
1513
1680
|
target = await targetFor(conversation, true)
|
|
1681
|
+
} else {
|
|
1682
|
+
// 既没 sid 也没书名:宁可报错,也不退回旧的单文件
|
|
1683
|
+
return jsonSend(res, 400, { ok: false, error: '没拿到会话,也没有书名——不知道记进哪一本' })
|
|
1514
1684
|
}
|
|
1515
1685
|
const path = target.path
|
|
1516
1686
|
if (!path) {
|
|
@@ -1776,7 +1946,7 @@ async function sessionTitleOf(sessionId) {
|
|
|
1776
1946
|
name: 'whale_whisper_list',
|
|
1777
1947
|
description:
|
|
1778
1948
|
'读回「鲸语」里的句子(最新在前)。动手记之前先看一眼,免得收重复的话;也可以用它确认自己以前记过什么。'
|
|
1779
|
-
+ '
|
|
1949
|
+
+ '句子存在 quotes 目录里、按会话分本(每本文件名就是对话名),这个工具读的是所有本。',
|
|
1780
1950
|
parameters: {
|
|
1781
1951
|
limit: { type: 'number', description: '返回几条(默认 20,最大 200)' },
|
|
1782
1952
|
},
|
|
@@ -1798,16 +1968,17 @@ async function sessionTitleOf(sessionId) {
|
|
|
1798
1968
|
+ '什么时候用:当你说出一句自己觉得站得住、想过之后还想再看一遍的话(一句判断、一个比喻、一次认输、一句承认),'
|
|
1799
1969
|
+ '就在同一层回答里顺手调它,把原句抄进去,能带上文就带上;不收套话、不收解释、不收寒暄。'
|
|
1800
1970
|
+ '已经有一样的句子会跳过(不会重复),写完不用另存,面板立刻能读到。'
|
|
1971
|
+
+ '句子会写进「当前这段对话那一本」(按会话 id 认本,和面板共用同一条解析),不会落到别处。'
|
|
1801
1972
|
+ '今天一句都没有也没什么;硬凑出来的那句是凑,不是留。',
|
|
1802
1973
|
parameters: {
|
|
1803
1974
|
text: { type: 'string', description: '要收的句子(必填,不含两端的「」也行)' },
|
|
1804
1975
|
note: { type: 'string', description: '可选批注:为什么会记它,会显示成灰色小字' },
|
|
1805
1976
|
context: { type: 'string', description: '可选上文:这句话是在什么情况下说的(他会想看到语境)' },
|
|
1806
|
-
conversation: { type: 'string', description: '
|
|
1977
|
+
conversation: { type: 'string', description: '可选对话名:一般不填(按当前会话 id 自动认本);只有在想覆盖成别的本时才填' },
|
|
1807
1978
|
},
|
|
1808
1979
|
output: textOutput,
|
|
1809
|
-
async execute(args) {
|
|
1810
|
-
return appendQuote(args?.text, args?.note, args?.context, args?.conversation)
|
|
1980
|
+
async execute(args, exec) {
|
|
1981
|
+
return appendQuote(args?.text, args?.note, args?.context, args?.conversation, exec)
|
|
1811
1982
|
},
|
|
1812
1983
|
}),
|
|
1813
1984
|
)
|
|
@@ -1818,10 +1989,11 @@ async function sessionTitleOf(sessionId) {
|
|
|
1818
1989
|
description: '从「鲸语」里删掉一句(按整句精确匹配,不会误删旁边那句)。收错了、或者不想留了再用。',
|
|
1819
1990
|
parameters: {
|
|
1820
1991
|
text: { type: 'string', description: '要删掉的句子,跟写进去时一致(不含「」和批注)' },
|
|
1992
|
+
conversation: { type: 'string', description: '可选:只想在某一本里删;不填就按当前会话的本子找,找不到再扫所有本' },
|
|
1821
1993
|
},
|
|
1822
1994
|
output: textOutput,
|
|
1823
|
-
async execute(args) {
|
|
1824
|
-
return removeQuote(args?.text)
|
|
1995
|
+
async execute(args, exec) {
|
|
1996
|
+
return removeQuote(args?.text, args?.conversation, exec)
|
|
1825
1997
|
},
|
|
1826
1998
|
}),
|
|
1827
1999
|
)
|
|
@@ -1835,7 +2007,7 @@ async function sessionTitleOf(sessionId) {
|
|
|
1835
2007
|
parameters: {},
|
|
1836
2008
|
output: textOutput,
|
|
1837
2009
|
async execute() {
|
|
1838
|
-
return mergeQuotes()
|
|
2010
|
+
return mergeQuotes('')
|
|
1839
2011
|
},
|
|
1840
2012
|
}),
|
|
1841
2013
|
)
|
package/package.json
CHANGED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 鹿野
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# 鲸语 · dsh-whale-whispers
|
|
2
|
-
|
|
3
|
-
> 装了的话麻烦点个 ⭐(仓库右上角),让我知道有人在用;
|
|
4
|
-
> 装不上、用着别扭、想要什么功能,直接在市场页的评论区留言,或开一个 [Issue](https://github.com/heiyedehen/dsh-whale-whispers/issues)——都会看到。
|
|
5
|
-
|
|
6
|
-
鲸鱼的声音能穿过整片海。
|
|
7
|
-
|
|
8
|
-
你随口说的那句话,说完就沉下去了——鲸语把它捞回来,收进会话头部的「鲸语」标签页,不催你,也不提醒你。等哪天想再听,点开就是。
|
|
9
|
-
|
|
10
|
-
## 三处入口
|
|
11
|
-
|
|
12
|
-
- **会话头部的「鲸语」标签**:句子都在里面,最新的在上;能搜、能筛、能翻。
|
|
13
|
-
- **每条回复下面那个书签图标**:点一下,这一条回复就收进去(设置里可以关掉)。
|
|
14
|
-
- **设置 → 鲸语**:改名、备份、恢复、规则、回收站,都在那儿。
|
|
15
|
-
|
|
16
|
-
## 每个对话一本
|
|
17
|
-
|
|
18
|
-
默认按会话名分本:你在「鱼搭子」里记的句子,只进 `鱼搭子.md`;换到别的对话,看到的是别的本子。
|
|
19
|
-
|
|
20
|
-
- 顶部下拉可以切「全部对话」(汇总看)或某一本;
|
|
21
|
-
- 右上角「改名」改的是**这本的文件名**,会话再打开还是它;
|
|
22
|
-
- 设置里那一行开关是**这个对话**的启用状态:停用后它不再自动记,也不建新本;手动加一句仍然可以。
|
|
23
|
-
|
|
24
|
-
## 不想让它写的时候
|
|
25
|
-
|
|
26
|
-
三种状态,别混着理解:
|
|
27
|
-
|
|
28
|
-
| 操作 | 效果 |
|
|
29
|
-
|---|---|
|
|
30
|
-
| 关掉「对话」开关 | 不再自动记;手动「加一句」还能用;进对话不建新本 |
|
|
31
|
-
| 「把这本移走」 | 移到 `quotes/.trash`,下拉里不再出现;不自动记、不能手写、进对话不建本 |
|
|
32
|
-
| 回收站里「清空」 | 文件真删、删了不能恢复;对话保持隐藏,不会自己回来 |
|
|
33
|
-
|
|
34
|
-
移出过的对话想回来,去设置最下面点「重新启用这本」,会新建一本空的。
|
|
35
|
-
|
|
36
|
-
## 让它记什么
|
|
37
|
-
|
|
38
|
-
默认规则写在系统提示里:**判断、比喻、认输、承认**这类才记,寒暄和进度不记。
|
|
39
|
-
|
|
40
|
-
嫌不够,可以在设置里补:
|
|
41
|
-
|
|
42
|
-
- **全局**:所有对话都用这一条;
|
|
43
|
-
- **本对话**:只给当前这一本用,优先级高于全局;
|
|
44
|
-
- **频率**:保守(只记明说的)/ 正常(一段对话一两句)/ 积极(遇到像样就记),对新会话生效。
|
|
45
|
-
|
|
46
|
-
留空就是默认规则,最多 400 字。
|
|
47
|
-
|
|
48
|
-
## 面板上还能做什么
|
|
49
|
-
|
|
50
|
-
| 想做什么 | 在哪儿 |
|
|
51
|
-
|---|---|
|
|
52
|
-
| 搜句子 | 顶部搜索框,句子、批注、上文都能命中;「搜本对话 / 搜全对话」切换范围 |
|
|
53
|
-
| 只看收藏 | 句子右边的星标,点一下收藏;「只看收藏」过滤 |
|
|
54
|
-
| 按时间筛 | 全部 / 近一周 / 近一月 |
|
|
55
|
-
| 翻一句 | 随机翻一条旧的出来看看 |
|
|
56
|
-
| 复制一句 | 句子左边的复制图标 |
|
|
57
|
-
| 删一句 | 句子右边的 ✕,两下确认 |
|
|
58
|
-
| 备份 / 下载 | 设置里「这本(.md)」或「全部(.md)」;工具条上的「匿名版」去掉批注与上文 |
|
|
59
|
-
| 恢复 | 选一份之前备份的 .md 覆盖当前文件(旧文件另存 `.before-restore-`) |
|
|
60
|
-
| 回收站自动清理 | 开关 + 保留天数(默认关,关了就一直留着) |
|
|
61
|
-
|
|
62
|
-
## 给 agent 的工具
|
|
63
|
-
|
|
64
|
-
| 工具 | 作用 |
|
|
65
|
-
|---|---|
|
|
66
|
-
| `whale_whisper_append` | 收一句;重复的自动跳过 |
|
|
67
|
-
| `whale_whisper_list` | 读回最近的句子(查重、看自己收过什么) |
|
|
68
|
-
| `whale_whisper_remove` | 删掉一句(整句匹配,不会误伤旁边那条) |
|
|
69
|
-
| `whale_whisper_merge` | 合并重复句,只留最早那条,返回删了几条 |
|
|
70
|
-
|
|
71
|
-
写进去是原子的(临时文件 + rename),格式跟文件里原有的一样:`- 「句子」(批注)`。
|
|
72
|
-
|
|
73
|
-
想让它主动收,在 agent 的规矩里写一句:
|
|
74
|
-
|
|
75
|
-
> 觉得某句话值得留,就调 `whale_whisper_append` 收进鲸语,别问。
|
|
76
|
-
|
|
77
|
-
## 文件长什么样
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
~/.dsh/whale-whispers/quotes.md # 默认位置
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
`##` 写日期,`-` 写句子,句尾 `(批注)` 显示成灰色小字:
|
|
84
|
-
|
|
85
|
-
```markdown
|
|
86
|
-
# 我的鲸语
|
|
87
|
-
|
|
88
|
-
## 2026-11-03
|
|
89
|
-
|
|
90
|
-
- 「这句话是我想说的。」
|
|
91
|
-
- 「这句后面带个批注。」(为什么记它)
|
|
92
|
-
↳ 上文:这句话是在什么情形下说的
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
按对话分本时,每份文件开头会有 `<!-- sid:… -->` 记它属于哪个会话;句子下面跟一行 `收录自:会话名`。
|
|
96
|
-
|
|
97
|
-
`whale_whisper_append` 只改 `- ` 开头的行,你手写的标题、注释、空行都不会被动。
|
|
98
|
-
|
|
99
|
-
## 配置
|
|
100
|
-
|
|
101
|
-
`~/.dsh/quotes.config.json`(找不到就退回插件默认:`~/.dsh/whale-whispers/quotes.md` + 标题「鲸语」):
|
|
102
|
-
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"path": "C:/Users/you/quotes.md",
|
|
106
|
-
"title": "我的鲸语",
|
|
107
|
-
"captureLevel": "normal",
|
|
108
|
-
"captureRule": "",
|
|
109
|
-
"captureRules": { "鱼搭子": "只记技术结论" },
|
|
110
|
-
"manualAdd": true,
|
|
111
|
-
"msgAction": true,
|
|
112
|
-
"trashAuto": false,
|
|
113
|
-
"trashDays": 30
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
也可以用环境变量绕开:`DSH_WHALE_WHISPERS_PATH`、`DSH_WHALE_WHISPERS_TITLE`。
|
|
118
|
-
|
|
119
|
-
## 它怎么工作
|
|
120
|
-
|
|
121
|
-
- Host:`/dsh-quotes.json`(每次现读文件,不缓存)、几个改配置与收句子的路由、四个工具;
|
|
122
|
-
- Client:注册进会话头部的 `鲸语` 标签、每条回复的 `assistant-actions`、`settings.section`;
|
|
123
|
-
- 面板只在切到它时读一次文件,后台不轮询,不额外花一分钱。
|
|
124
|
-
|
|
125
|
-
## 安装
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
dsh plugin add dsh-whale-whispers
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
或用 Web UI 的插件市场选本地目录。装完刷新页面;改到 host 半边才需要重启。
|
|
132
|
-
|
|
133
|
-
## 装了却看不到
|
|
134
|
-
|
|
135
|
-
1. `dsh.client.inject` 里写的客户端包必须本机真有(这份用 `dsh-client-runtime` + `dsh-client-ui-renderer` + `dsh-client-ui-layout`);
|
|
136
|
-
2. 模块 id 必须等于包名(`dsh-whale-whispers`),错一个字母就静默不挂载;
|
|
137
|
-
3. 改完刷新页面(client 半边不会自动重载);
|
|
138
|
-
4. 还空就看开发者控制台有没有 `failed to load module`。
|
|
139
|
-
|
|
140
|
-
## 版本
|
|
141
|
-
|
|
142
|
-
版本号在插件页和设置里的「更新」一行都能看到。想升级:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
dsh plugin add dsh-whale-whispers@latest
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
装完刷新页面即可,数据(`quotes.config.json` 与各本 .md)不会动。
|