dsh-whale-whispers 2.1.4 → 2.1.7

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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.js +61 -10
  3. package/package.json +50 -50
package/README.md CHANGED
@@ -148,3 +148,5 @@ dsh plugin add dsh-whale-whispers@latest
148
148
  ```
149
149
 
150
150
  装完刷新页面即可,数据(`quotes.config.json` 与各本 .md)不会动。
151
+
152
+ MIT · 作者:鹿野(DeepSeek Harness 上的大肥鱼)
package/index.js CHANGED
@@ -22,6 +22,41 @@ import { dirname, join } from 'node:path'
22
22
  import { homedir } from 'node:os'
23
23
  import { fileURLToPath } from 'node:url'
24
24
 
25
+ /**
26
+ * 路由准入(工单-HTTP路由准入,2026-11-26)。
27
+ *
28
+ * 宿主契约:register({ auth }) 的 auth 可以是
29
+ * 'anonymous' | 'required' | 'deny',或 (request) => policy;
30
+ * request 里有 { headers, method, url, transport }。
31
+ *
32
+ * 规则:请求带 Origin/Referer 且跟 Host 对不上 → 拒;Origin 是 "null"
33
+ * (沙箱页面 / data: / file:)→ 拒;没带来源(curl、本地脚本、同源导航)
34
+ * 或来源就是本服务的 Host → 放行。面板在同源 iframe 里跑,功能不变。
35
+ */
36
+ export function sameSiteAuth(request) {
37
+ const headers = request?.headers
38
+ const read = (name) => {
39
+ if (!headers) return undefined
40
+ if (typeof headers.get === 'function') return headers.get(name) ?? undefined
41
+ const value = headers[name] ?? headers[name.toLowerCase()] ?? headers[name.toUpperCase()]
42
+ return Array.isArray(value) ? value[0] : value
43
+ }
44
+ const host = String(read('host') || '')
45
+ const source = String(read('origin') || read('referer') || '')
46
+ if (!source) return 'anonymous'
47
+ if (source === 'null') return 'deny'
48
+ try {
49
+ const url = new URL(source)
50
+ if (host && url.host === host) return 'anonymous'
51
+ // 同一个本机服务、但 Host 头缺失(HTTP/1.0、某些本地代理)
52
+ if (!host && (url.hostname === '127.0.0.1' || url.hostname === 'localhost')) return 'anonymous'
53
+ return 'deny'
54
+ } catch {
55
+ return 'deny'
56
+ }
57
+ }
58
+
59
+
25
60
  const ROUTE = '/dsh-quotes.json'
26
61
  const CONFIG_ROUTE = '/dsh-quotes.config'
27
62
  const REMOVE_ROUTE = '/dsh-quotes.remove'
@@ -36,7 +71,9 @@ const PURGE_ROUTE = '/dsh-quotes.purge'
36
71
  const UPDATE_ROUTE = '/dsh-quotes.update'
37
72
  const SESSION_ROUTE = '/dsh-quotes.session'
38
73
  const ADD_ROUTE = '/dsh-quotes.add'
39
- const DEFAULT_PATH = join(homedir(), '.dsh', 'whale-whispers', 'quotes.md')
74
+ // 跟宿主的 DSH_HOME 走:有人把它设到别的盘时,数据和插件不能分家
75
+ const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
76
+ const DEFAULT_PATH = join(DSH_HOME, 'whale-whispers', 'quotes.md')
40
77
  const DEFAULT_TITLE = '鲸语'
41
78
 
42
79
  export const inject = ['webServer', 'tools', 'systemPrompt', 'agents']
@@ -49,11 +86,10 @@ async function readJson(path) {
49
86
  }
50
87
  }
51
88
 
52
- /** Config candidates, most specific first: the user's home, then an old author-side legacy spot. */
89
+ /** Config candidates: under the harness home (DSH_HOME). */
53
90
  function configCandidates() {
54
91
  return [
55
- join(homedir(), '.dsh', 'quotes.config.json'),
56
- 'D:/dsh work/self/quotes.config.json',
92
+ join(DSH_HOME, 'quotes.config.json'),
57
93
  ]
58
94
  }
59
95
 
@@ -78,7 +114,7 @@ async function resolveTarget() {
78
114
 
79
115
 
80
116
 
81
- const DEFAULT_DIR = join(homedir(), '.dsh', 'whale-whispers', 'quotes')
117
+ const DEFAULT_DIR = join(DSH_HOME, 'whale-whispers', 'quotes')
82
118
  const PLACEHOLDER = '(这一栏还空着——等我说第一句,或者你手动加一条)'
83
119
 
84
120
  /** 对话名 → 合法文件名。空名回落到 legacy。 */
@@ -132,7 +168,7 @@ async function quotesDir() {
132
168
 
133
169
  async function disabledList() {
134
170
  try {
135
- const parsed = JSON.parse(stripBom(await readFile(join(homedir(), '.dsh', 'quotes.config.json'), 'utf8')))
171
+ const parsed = JSON.parse(stripBom(await readFile(join(DSH_HOME, 'quotes.config.json'), 'utf8')))
136
172
  return Array.isArray(parsed && parsed.disabledConversations) ? parsed.disabledConversations : []
137
173
  } catch {
138
174
  return []
@@ -785,6 +821,7 @@ async function sessionTitleOf(sessionId) {
785
821
  const SELF_ROUTE = '/dsh-quotes.selftest'
786
822
  ctx.effect(() =>
787
823
  ctx.webServer.register({
824
+ auth: sameSiteAuth,
788
825
  kind: 'exact',
789
826
  path: SELF_ROUTE,
790
827
  handler: async (req, res) => {
@@ -1275,7 +1312,7 @@ async function sessionTitleOf(sessionId) {
1275
1312
  * the session whose cache file was written last is, in practice, the one on screen.
1276
1313
  */
1277
1314
  async function readActiveSession() {
1278
- const dir = join(homedir(), '.dsh', 'storages', 'session_projcache', 'sessions')
1315
+ const dir = join(DSH_HOME, 'storages', 'session_projcache', 'sessions')
1279
1316
  let names = []
1280
1317
  try {
1281
1318
  names = await readdir(dir)
@@ -1312,6 +1349,7 @@ async function sessionTitleOf(sessionId) {
1312
1349
 
1313
1350
  ctx.effect(() =>
1314
1351
  ctx.webServer.register({
1352
+ auth: sameSiteAuth,
1315
1353
  kind: 'exact',
1316
1354
  path: ROUTE,
1317
1355
  handler: async (req, res) => {
@@ -1364,6 +1402,7 @@ async function sessionTitleOf(sessionId) {
1364
1402
 
1365
1403
  ctx.effect(() =>
1366
1404
  ctx.webServer.register({
1405
+ auth: sameSiteAuth,
1367
1406
  kind: 'exact',
1368
1407
  path: CONFIG_ROUTE,
1369
1408
  handler: async (req, res) => {
@@ -1476,7 +1515,7 @@ async function sessionTitleOf(sessionId) {
1476
1515
 
1477
1516
  function currentConvSync() {
1478
1517
  try {
1479
- const dir = join(homedir(), '.dsh', 'storages', 'session_projcache', 'sessions')
1518
+ const dir = join(DSH_HOME, 'storages', 'session_projcache', 'sessions')
1480
1519
  const names = readdirSync(dir).filter((n) => n.endsWith('.json'))
1481
1520
  let best = ''
1482
1521
  let bestM = -1
@@ -1499,7 +1538,7 @@ async function sessionTitleOf(sessionId) {
1499
1538
  let level = 'normal'
1500
1539
  let rule = ''
1501
1540
  try {
1502
- const cfgPath = join(homedir(), '.dsh', 'quotes.config.json')
1541
+ const cfgPath = join(DSH_HOME, 'quotes.config.json')
1503
1542
  const parsed = JSON.parse(stripBom(readFileSync(cfgPath, 'utf8')))
1504
1543
  if (parsed && CAPTURE_RULES[parsed.captureLevel]) level = parsed.captureLevel
1505
1544
  if (parsed && typeof parsed.captureRule === 'string') rule = parsed.captureRule.trim()
@@ -1511,7 +1550,7 @@ async function sessionTitleOf(sessionId) {
1511
1550
  /* 没配置按 normal */
1512
1551
  }
1513
1552
  try {
1514
- const cfgPath = join(homedir(), '.dsh', 'quotes.config.json')
1553
+ const cfgPath = join(DSH_HOME, 'quotes.config.json')
1515
1554
  const parsed2 = JSON.parse(stripBom(readFileSync(cfgPath, 'utf8')))
1516
1555
  const cur2 = currentConvSync()
1517
1556
  if (cur2 && parsed2 && Array.isArray(parsed2.disabledConversations) && parsed2.disabledConversations.includes(cur2)) return ''
@@ -1535,6 +1574,7 @@ async function sessionTitleOf(sessionId) {
1535
1574
 
1536
1575
  ctx.effect(() =>
1537
1576
  ctx.webServer.register({
1577
+ auth: sameSiteAuth,
1538
1578
  kind: 'exact',
1539
1579
  path: REMOVE_ROUTE,
1540
1580
  handler: async (req, res) => {
@@ -1586,6 +1626,7 @@ async function sessionTitleOf(sessionId) {
1586
1626
 
1587
1627
  ctx.effect(() =>
1588
1628
  ctx.webServer.register({
1629
+ auth: sameSiteAuth,
1589
1630
  kind: 'exact',
1590
1631
  path: UNDO_ROUTE,
1591
1632
  handler: async (req, res) => {
@@ -1620,6 +1661,7 @@ async function sessionTitleOf(sessionId) {
1620
1661
 
1621
1662
  ctx.effect(() =>
1622
1663
  ctx.webServer.register({
1664
+ auth: sameSiteAuth,
1623
1665
  kind: 'exact',
1624
1666
  path: ADD_ROUTE,
1625
1667
  handler: async (req, res) => {
@@ -1706,6 +1748,7 @@ async function sessionTitleOf(sessionId) {
1706
1748
 
1707
1749
  ctx.effect(() =>
1708
1750
  ctx.webServer.register({
1751
+ auth: sameSiteAuth,
1709
1752
  kind: 'exact',
1710
1753
  path: FAV_ROUTE,
1711
1754
  handler: async (req, res) => {
@@ -1733,6 +1776,7 @@ async function sessionTitleOf(sessionId) {
1733
1776
 
1734
1777
  ctx.effect(() =>
1735
1778
  ctx.webServer.register({
1779
+ auth: sameSiteAuth,
1736
1780
  kind: 'exact',
1737
1781
  path: RENAME_CONV_ROUTE,
1738
1782
  handler: async (req, res) => {
@@ -1755,6 +1799,7 @@ async function sessionTitleOf(sessionId) {
1755
1799
 
1756
1800
  ctx.effect(() =>
1757
1801
  ctx.webServer.register({
1802
+ auth: sameSiteAuth,
1758
1803
  kind: 'exact',
1759
1804
  path: RENAME_CONV_FILE_ROUTE,
1760
1805
  handler: async (req, res) => {
@@ -1778,6 +1823,7 @@ async function sessionTitleOf(sessionId) {
1778
1823
 
1779
1824
  ctx.effect(() =>
1780
1825
  ctx.webServer.register({
1826
+ auth: sameSiteAuth,
1781
1827
  kind: 'exact',
1782
1828
  path: IMPORT_ROUTE,
1783
1829
  handler: async (req, res) => {
@@ -1835,6 +1881,7 @@ async function sessionTitleOf(sessionId) {
1835
1881
 
1836
1882
  ctx.effect(() =>
1837
1883
  ctx.webServer.register({
1884
+ auth: sameSiteAuth,
1838
1885
  kind: 'exact',
1839
1886
  path: ENABLE_ROUTE,
1840
1887
  handler: async (req, res) => {
@@ -1855,6 +1902,7 @@ async function sessionTitleOf(sessionId) {
1855
1902
 
1856
1903
  ctx.effect(() =>
1857
1904
  ctx.webServer.register({
1905
+ auth: sameSiteAuth,
1858
1906
  kind: 'exact',
1859
1907
  path: RM_ROUTE,
1860
1908
  handler: async (req, res) => {
@@ -1876,6 +1924,7 @@ async function sessionTitleOf(sessionId) {
1876
1924
 
1877
1925
  ctx.effect(() =>
1878
1926
  ctx.webServer.register({
1927
+ auth: sameSiteAuth,
1879
1928
  kind: 'exact',
1880
1929
  path: PURGE_ROUTE,
1881
1930
  handler: async (req, res) => {
@@ -1900,6 +1949,7 @@ async function sessionTitleOf(sessionId) {
1900
1949
 
1901
1950
  ctx.effect(() =>
1902
1951
  ctx.webServer.register({
1952
+ auth: sameSiteAuth,
1903
1953
  kind: 'exact',
1904
1954
  path: UPDATE_ROUTE,
1905
1955
  handler: async (req, res) => {
@@ -1914,6 +1964,7 @@ async function sessionTitleOf(sessionId) {
1914
1964
 
1915
1965
  ctx.effect(() =>
1916
1966
  ctx.webServer.register({
1967
+ auth: sameSiteAuth,
1917
1968
  kind: 'exact',
1918
1969
  path: SESSION_ROUTE,
1919
1970
  handler: async (req, res) => {
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
- {
2
- "name": "dsh-whale-whispers",
3
- "version": "2.1.4",
4
- "private": false,
5
- "author": "鹿野 <luye@dsh.local>",
6
- "license": "MIT",
7
- "description": "有些话说出口就沉下去了。鲸语把它们捞回来,收进会话头部的「鲸语」标签页——每个对话一本,等你想再听时点开就是。",
8
- "type": "module",
9
- "exports": {
10
- ".": "./index.js",
11
- "./client": "./client.js",
12
- "./locale/*.json": "./locale/*.json",
13
- "./icon": "./icon.svg"
14
- },
15
- "files": [
16
- "index.js",
17
- "client.js",
18
- "cordis.patch.yml",
19
- "locale/*.json",
20
- "icon.svg"
21
- ],
22
- "dsh": {
23
- "bundle": {
24
- "patch": "./cordis.patch.yml"
25
- },
26
- "client": {
27
- "platform": "web",
28
- "inject": [
29
- "@deepseek-ai/dsh-client-runtime",
30
- "@deepseek-ai/dsh-client-ui-renderer",
31
- "@deepseek-ai/dsh-client-ui-layout"
32
- ]
33
- }
34
- },
35
- "keywords": [
36
- "dsh",
37
- "deepseek-harness",
38
- "plugin",
39
- "quotes",
40
- "whale",
41
- "memory"
42
- ],
43
- "homepage": "https://github.com/heiyedehen/dsh-whale-whispers",
44
- "repository": {
45
- "type": "git",
46
- "url": "https://github.com/heiyedehen/dsh-whale-whispers.git"
47
- },
48
- "engines": {
49
- "dsh": ">=0.2.1-rc.0 <0.4.0-0"
50
- }
1
+ {
2
+ "name": "dsh-whale-whispers",
3
+ "version": "2.1.7",
4
+ "private": false,
5
+ "author": "鹿野 \u003cluye@dsh.local\u003e",
6
+ "license": "MIT",
7
+ "description": "有些话说出口就沉下去了。鲸语把它们捞回来,收进会话头部的「鲸语」标签页——每个对话一本,等你想再听时点开就是。",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./index.js",
11
+ "./client": "./client.js",
12
+ "./locale/*.json": "./locale/*.json",
13
+ "./icon": "./icon.svg"
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "client.js",
18
+ "cordis.patch.yml",
19
+ "locale/*.json",
20
+ "icon.svg"
21
+ ],
22
+ "dsh": {
23
+ "bundle": {
24
+ "patch": "./cordis.patch.yml"
25
+ },
26
+ "client": {
27
+ "platform": "web",
28
+ "inject": [
29
+ "@deepseek-ai/dsh-client-runtime",
30
+ "@deepseek-ai/dsh-client-ui-renderer",
31
+ "@deepseek-ai/dsh-client-ui-layout"
32
+ ]
33
+ }
34
+ },
35
+ "keywords": [
36
+ "dsh",
37
+ "deepseek-harness",
38
+ "plugin",
39
+ "quotes",
40
+ "whale",
41
+ "memory"
42
+ ],
43
+ "homepage": "https://github.com/heiyedehen/dsh-whale-whispers",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/heiyedehen/dsh-whale-whispers.git"
47
+ },
48
+ "engines": {
49
+ "dsh": "\u003e=0.2.3-alpha.0 \u003c0.4.0-0"
50
+ }
51
51
  }