@ssamurias/dsh-fish 1.0.3 → 1.0.5
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/AGENTS.md +5 -3
- package/CHANGELOG.md +55 -0
- package/README.md +92 -8
- package/RELEASE-NOTES-1.0.4.md +106 -0
- package/RELEASE-NOTES-1.0.5.md +79 -0
- package/docs/composite-pressure-v0.1.md +23 -0
- package/docs/composite-pressure-v0.2.md +18 -0
- package/docs/pressure-backtest-v0.1.md +19 -0
- package/docs/session-capacity-advice-v0.1.md +17 -0
- package/docs/session-pressure-design-v1.1.md +1173 -0
- package/docs/session-pressure-ui-v0.3.md +28 -0
- package/docs/tool-retention-diagnostics-v2.md +13 -0
- package/lib/appoint.js +154 -25
- package/lib/ask.js +70 -7
- package/lib/autobackup.js +2 -1
- package/lib/backup.js +58 -6
- package/lib/browse.js +191 -19
- package/lib/capture.js +48 -10
- package/lib/client.js +2203 -37
- package/lib/cloudbackup.js +24 -1
- package/lib/clouddrive.js +4 -1
- package/lib/compact.js +28 -11
- package/lib/configstamp.js +25 -0
- package/lib/cue.js +114 -0
- package/lib/derive.js +66 -5
- package/lib/doing.js +11 -2
- package/lib/dreamtable.js +5 -4
- package/lib/drive.js +66 -11
- package/lib/generator.js +1 -1
- package/lib/handoff.js +34 -16
- package/lib/home.js +3 -1
- package/lib/identity.js +23 -4
- package/lib/index.js +6 -1
- package/lib/interest.js +38 -0
- package/lib/look.js +16 -2
- package/lib/note.js +182 -41
- package/lib/observe.js +198 -4
- package/lib/persona.js +37 -15
- package/lib/proactive.js +6 -1
- package/lib/refuse.js +42 -0
- package/lib/restrict.js +8 -2
- package/lib/sametopic.js +94 -0
- package/lib/say.js +36 -7
- package/lib/scheduler.js +445 -24
- package/lib/selfcheck.js +9 -9
- package/lib/selfpronoun.js +7 -2
- package/lib/session-pressure-analysis.js +296 -0
- package/lib/session-pressure-data.js +239 -0
- package/lib/session-pressure-formulas.js +280 -0
- package/lib/session-pressure-load.js +110 -0
- package/lib/session-pressure.js +714 -0
- package/lib/settings.js +4 -1
- package/lib/sleepfact.js +110 -0
- package/lib/stance.js +212 -16
- package/lib/store.js +4 -0
- package/lib/sub.js +9 -7
- package/lib/turns.js +8 -1
- package/lib/use.js +2 -0
- package/lib/video.js +3 -0
- package/lib/watch.js +149 -3
- package/lib/whatseen.js +24 -2
- package/lib/wiki.js +1753 -0
- package/lib/wikiserve.js +148 -0
- package/media/feedback-qr.jpg +0 -0
- package/media/principle-drive.svg +28 -24
- package/media/principle-memory.svg +1 -1
- package/package.json +1 -1
- package/scripts/sync-pressure-formulas.mjs +17 -0
package/lib/wikiserve.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 内置说明的第三个出口:一个只在本机回环上的小 HTTP 服务(2026-11-16 用户 m03816)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有它。用户要的是「在设置页点一个蓝链,浏览器自动打开那份说明」。
|
|
5
|
+
* 前两次尝试都撞在宿主上:
|
|
6
|
+
* · 链到插件自己的路由(/dsh-fish/wiki)——桌面版 setWindowOpenHandler 对任何
|
|
7
|
+
* http(s) 都是 openExternal + deny,链接被甩进系统浏览器;而信任栅栏要的 cookie
|
|
8
|
+
* 是「按本次启动 secret 签名」的,只有 App 自己的 webContents 带着,浏览器里必然 401。
|
|
9
|
+
* · 链到 file:// ——同一个 handler 里 file: 既不 openExternal 也不放行,点了没反应。
|
|
10
|
+
*
|
|
11
|
+
* 这一次不一样:目标不是宿主的任何一条路由,而是**我们自己起的**一个服务。
|
|
12
|
+
* 它只监听 127.0.0.1,只认 GET,只吐一份静态 HTML,不经过宿主的信任栅栏,
|
|
13
|
+
* 也就没有那枚签名的 cookie 可谈——浏览器打开它,就像打开任何一个本地小站。
|
|
14
|
+
*
|
|
15
|
+
* 为什么默认端口写死 17321:用户会把这一页留在浏览器里反复看,地址稳定一点更方便;
|
|
16
|
+
* 被占了就退回系统分配的随机端口,UI 那一头永远是现取现显示,不缓存。
|
|
17
|
+
*
|
|
18
|
+
* 为什么校验 Host 头:服务绑在回环上,外部连不进来,但**浏览器里任何一个网页**都能
|
|
19
|
+
* 向 127.0.0.1 发请求(DNS rebinding 就是靠改 Host 把「外部域名」指过来)。
|
|
20
|
+
* Host 必须正好是本服务的地址,否则 403。
|
|
21
|
+
*/
|
|
22
|
+
import { createServer } from 'node:http'
|
|
23
|
+
|
|
24
|
+
const HOST = '127.0.0.1'
|
|
25
|
+
const DEFAULT_PORT = 17321
|
|
26
|
+
|
|
27
|
+
// 只有一份:插件重复 apply(cordis 会重新 apply)时不该叠出第二个监听
|
|
28
|
+
let STATE = null
|
|
29
|
+
|
|
30
|
+
function hostOk(raw, port) {
|
|
31
|
+
const h = String(raw || '').trim().toLowerCase()
|
|
32
|
+
return h === `${HOST}:${port}` || h === `localhost:${port}`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function send(res, code, headers, body) {
|
|
36
|
+
res.writeHead(code, headers)
|
|
37
|
+
res.end(body)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function plain(res, code, text) {
|
|
41
|
+
const body = Buffer.from(text, 'utf8')
|
|
42
|
+
send(res, code, {
|
|
43
|
+
'content-type': 'text/plain; charset=utf-8',
|
|
44
|
+
'content-length': body.length,
|
|
45
|
+
'cache-control': 'no-store',
|
|
46
|
+
}, body)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 起服务。可重复调用:已经在跑就只把新的 getHtml 换上(重启插件时根目录可能变了)。
|
|
51
|
+
* @param {{getHtml: () => string | Promise<string>, port?: number}} opts
|
|
52
|
+
*/
|
|
53
|
+
export function startWikiServer(opts = {}) {
|
|
54
|
+
const getHtml = typeof opts.getHtml === 'function' ? opts.getHtml : () => '<!doctype html><meta charset="utf-8"><p>说明还没准备好。</p>'
|
|
55
|
+
if (STATE) {
|
|
56
|
+
STATE.getHtml = getHtml
|
|
57
|
+
return api(STATE)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const st = { getHtml, port: 0, url: '', server: null, triedFallback: false }
|
|
61
|
+
|
|
62
|
+
const server = createServer(async (req, res) => {
|
|
63
|
+
// 只读:别的一律不接。省得以后有人顺手在这儿加个 POST 就成了写入面。
|
|
64
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
65
|
+
plain(res, 405, '只读。')
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
if (!hostOk(req.headers.host, st.port)) {
|
|
69
|
+
plain(res, 403, '不认这个地址。')
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
let path = '/'
|
|
73
|
+
try { path = new URL(req.url || '/', 'http://127.0.0.1').pathname } catch { path = '/' }
|
|
74
|
+
if (path !== '/' && path !== '/wiki' && path !== '/wiki.html') {
|
|
75
|
+
plain(res, 404, '没有这一页。')
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
let html = ''
|
|
79
|
+
try {
|
|
80
|
+
html = await st.getHtml()
|
|
81
|
+
} catch (err) {
|
|
82
|
+
plain(res, 500, `这份说明没读出来:${err?.message ?? err}`)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
const body = Buffer.from(String(html), 'utf8')
|
|
86
|
+
send(res, 200, {
|
|
87
|
+
'content-type': 'text/html; charset=utf-8',
|
|
88
|
+
'content-length': body.length,
|
|
89
|
+
'cache-control': 'no-store',
|
|
90
|
+
'x-content-type-options': 'nosniff',
|
|
91
|
+
'referrer-policy': 'no-referrer',
|
|
92
|
+
}, req.method === 'HEAD' ? undefined : body)
|
|
93
|
+
})
|
|
94
|
+
st.server = server
|
|
95
|
+
|
|
96
|
+
// 端口被占不算错:退回随机端口,地址照样能点。
|
|
97
|
+
server.on('error', (err) => {
|
|
98
|
+
if (err?.code === 'EADDRINUSE' && !st.triedFallback) {
|
|
99
|
+
st.triedFallback = true
|
|
100
|
+
try { server.listen(0, HOST) } catch { /* 下一层还有 error 事件 */ }
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
console.warn('[dsh-fish] 说明服务起不来', err?.message ?? err)
|
|
104
|
+
})
|
|
105
|
+
server.on('listening', () => {
|
|
106
|
+
const addr = server.address()
|
|
107
|
+
st.port = typeof addr === 'object' && addr ? addr.port : 0
|
|
108
|
+
st.url = `http://${HOST}:${st.port}/`
|
|
109
|
+
})
|
|
110
|
+
server.unref?.()
|
|
111
|
+
|
|
112
|
+
const wanted = Number.isInteger(opts.port) && opts.port >= 0 ? opts.port : DEFAULT_PORT
|
|
113
|
+
try { server.listen(wanted, HOST) } catch (err) {
|
|
114
|
+
console.warn('[dsh-fish] 说明服务起不来', err?.message ?? err)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
STATE = st
|
|
118
|
+
return api(st)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function api(st) {
|
|
122
|
+
return {
|
|
123
|
+
/** 起来之前是空串。UI 那一头拿到空串就显示「正在准备」。 */
|
|
124
|
+
get url() { return st.url },
|
|
125
|
+
get port() { return st.port },
|
|
126
|
+
close() {
|
|
127
|
+
if (STATE === st) STATE = null
|
|
128
|
+
try { st.server?.close() } catch { /* 已经关了 */ }
|
|
129
|
+
st.url = ''
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 给 /wiki.data 用:现取,不缓存。 */
|
|
135
|
+
export function wikiUrl() {
|
|
136
|
+
return STATE?.url || ''
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 停用/卸载时收干净。 */
|
|
140
|
+
export function closeWikiServer() {
|
|
141
|
+
const st = STATE
|
|
142
|
+
STATE = null
|
|
143
|
+
if (!st) return
|
|
144
|
+
try { st.server?.close() } catch { /* 已经关了 */ }
|
|
145
|
+
st.url = ''
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const WIKI_PORT = DEFAULT_PORT
|
package/media/feedback-qr.jpg
CHANGED
|
Binary file
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
<rect x="80" y="262" width="312" height="92" rx="10" fill="#f0fdfa" stroke="#99f6e4"/>
|
|
24
24
|
<text x="96" y="288" font-size="15" font-weight="700" fill="#0f766e">底噪</text>
|
|
25
|
-
<text x="96" y="312" font-size="14" fill="#44403c">每小时 +0.
|
|
25
|
+
<text x="96" y="312" font-size="14" fill="#44403c">每小时 +0.08,几周不动也会自己涨</text>
|
|
26
26
|
<text x="96" y="336" font-size="13" fill="#78716c">保证她不会因为「没素材」永远沉默</text>
|
|
27
27
|
|
|
28
28
|
<text x="80" y="384" font-size="15" font-weight="700" fill="#1c1917">桌上真有东西时,再加一笔</text>
|
|
@@ -37,34 +37,37 @@
|
|
|
37
37
|
<text x="94" y="546">够不着的事、撞过的墙</text>
|
|
38
38
|
</g>
|
|
39
39
|
|
|
40
|
-
<rect x="80" y="580" width="312" height="
|
|
41
|
-
<text x="96" y="606" font-size="15" font-weight="700" fill="#b45309"
|
|
40
|
+
<rect x="80" y="580" width="312" height="104" rx="10" fill="#fffbeb" stroke="#fde68a"/>
|
|
41
|
+
<text x="96" y="606" font-size="15" font-weight="700" fill="#b45309">上次没被接住</text>
|
|
42
42
|
<text x="96" y="630" font-size="13.5" fill="#44403c">下一次攒得慢(×0.7)</text>
|
|
43
|
-
<text x="96" y="650" font-size="13" fill="#78716c"
|
|
43
|
+
<text x="96" y="650" font-size="13" fill="#78716c">刚被驳回的 12 小时里更慢(×0.55)</text>
|
|
44
|
+
<text x="96" y="670" font-size="13" fill="#78716c">打扰是有成本的,不是想说话就该说</text>
|
|
44
45
|
|
|
45
|
-
<text x="80" y="
|
|
46
|
-
<text x="80" y="
|
|
46
|
+
<text x="80" y="706" font-size="13" fill="#78716c">门槛 0.8;连续两次没开口后 0.9。</text>
|
|
47
|
+
<text x="80" y="726" font-size="13" fill="#78716c">约 10 小时底噪攒满,攒满只说明「可以开」,</text>
|
|
48
|
+
<text x="80" y="746" font-size="13" fill="#78716c">不说明「必须说」。</text>
|
|
47
49
|
</g>
|
|
48
50
|
|
|
49
51
|
<!-- 中:这一轮开不开 -->
|
|
50
52
|
<g>
|
|
51
53
|
<rect x="452" y="176" width="440" height="600" rx="16" fill="#ffffff" stroke="#d6d3d1"/>
|
|
52
54
|
<text x="476" y="212" font-size="22" font-weight="700" fill="#0f766e">这一轮开不开</text>
|
|
53
|
-
<text x="476" y="238" font-size="14" fill="#78716c"
|
|
55
|
+
<text x="476" y="238" font-size="14" fill="#78716c">四个条件一起看,缺一件就不开;开不开 ≠ 说什么</text>
|
|
54
56
|
|
|
55
57
|
<g font-size="14" fill="#44403c">
|
|
56
58
|
<rect x="476" y="258" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
|
|
57
|
-
<text x="492" y="281">①
|
|
59
|
+
<text x="492" y="281">① 醒着时段里,今天还有额度(0–6 次)</text>
|
|
58
60
|
<rect x="476" y="302" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
|
|
59
|
-
<text x="492" y="325">②
|
|
61
|
+
<text x="492" y="325">② 确实有一阵没说话(默认 6 小时)</text>
|
|
60
62
|
<rect x="476" y="346" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
|
|
61
|
-
<text x="492" y="369">③
|
|
63
|
+
<text x="492" y="369">③ 桌上至少有一件真能说 / 能做的事</text>
|
|
62
64
|
<rect x="476" y="390" width="392" height="36" rx="8" fill="#f0fdfa" stroke="#99f6e4"/>
|
|
63
|
-
<text x="492" y="413">④
|
|
65
|
+
<text x="492" y="413" font-size="13">④ 24 小时内有新事(兴趣门 / 动手可例外)</text>
|
|
64
66
|
</g>
|
|
65
67
|
|
|
66
68
|
<rect x="476" y="448" width="392" height="52" rx="10" fill="#f5f5f4" stroke="#d6d3d1"/>
|
|
67
|
-
<text x="492" y="
|
|
69
|
+
<text x="492" y="468" font-size="13" fill="#57534e">空桌不醒;24 小时没新事也不醒。</text>
|
|
70
|
+
<text x="492" y="488" font-size="13" fill="#57534e">宁可这一轮不叫她,也不拿废话凑数。</text>
|
|
68
71
|
|
|
69
72
|
<line x1="672" y1="500" x2="672" y2="514" stroke="#0f766e" stroke-width="2"/>
|
|
70
73
|
<line x1="569" y1="514" x2="775" y2="514" stroke="#0f766e" stroke-width="2"/>
|
|
@@ -102,22 +105,23 @@
|
|
|
102
105
|
<rect x="944" y="382" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
|
|
103
106
|
<text x="958" y="404">她自己记下的便条(最多两张,不催)</text>
|
|
104
107
|
<rect x="944" y="424" width="376" height="34" rx="8" fill="#fafaf9" stroke="#e7e5e4"/>
|
|
105
|
-
<text x="958" y="446"
|
|
108
|
+
<text x="958" y="446">兴趣默认只排序;开门后 0.9 可单独起一轮</text>
|
|
106
109
|
</g>
|
|
110
|
+
<text x="958" y="476" font-size="12" fill="#78716c">(默认关;3 次以上、7 天没起过、一天一次)</text>
|
|
107
111
|
|
|
108
|
-
<text x="944" y="
|
|
112
|
+
<text x="944" y="522" font-size="22" font-weight="700" fill="#b45309">什么拦着</text>
|
|
109
113
|
<g font-size="13.5" fill="#44403c">
|
|
110
|
-
<rect x="944" y="
|
|
111
|
-
<text x="958" y="
|
|
112
|
-
<rect x="944" y="
|
|
113
|
-
<text x="958" y="
|
|
114
|
-
<rect x="944" y="
|
|
115
|
-
<text x="958" y="
|
|
116
|
-
<rect x="944" y="
|
|
117
|
-
<text x="958" y="
|
|
114
|
+
<rect x="944" y="538" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
|
|
115
|
+
<text x="958" y="560">一天 0–6 次;两次至少隔 45 分钟</text>
|
|
116
|
+
<rect x="944" y="580" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
|
|
117
|
+
<text x="958" y="602">消耗类一天 1 次;同一件 3 天内不重复</text>
|
|
118
|
+
<rect x="944" y="622" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
|
|
119
|
+
<text x="958" y="644">连着三次同类 → 停一周</text>
|
|
120
|
+
<rect x="944" y="664" width="376" height="34" rx="8" fill="#fffbeb" stroke="#fde68a"/>
|
|
121
|
+
<text x="958" y="686">一轮只做一件;第二次直接拦下</text>
|
|
118
122
|
</g>
|
|
119
|
-
<text x="944" y="
|
|
120
|
-
<text x="944" y="
|
|
123
|
+
<text x="944" y="726" font-size="13" fill="#78716c">额度是环境的边界,不写进人格;</text>
|
|
124
|
+
<text x="944" y="748" font-size="13" fill="#78716c">额度用完,只能来问你(1 天 1 次)。</text>
|
|
121
125
|
</g>
|
|
122
126
|
|
|
123
127
|
<!-- 底部 -->
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
<g>
|
|
97
97
|
<rect x="764" y="238" width="572" height="486" rx="16" fill="#ffffff" stroke="#e5e7eb" filter="url(#soft2)"/>
|
|
98
98
|
<text x="792" y="274" font-size="16" font-weight="700" fill="#111827">这一次真正摆在她眼前的</text>
|
|
99
|
-
<text x="792" y="298" font-size="12.5" fill="#6b7280">身份文档:默认
|
|
99
|
+
<text x="792" y="298" font-size="12.5" fill="#6b7280">身份文档:默认 2800 字预算,超了就按下面的顺序摆</text>
|
|
100
100
|
|
|
101
101
|
<!-- 核心段 -->
|
|
102
102
|
<rect x="792" y="314" width="516" height="112" rx="10" fill="#fef2f2" stroke="#fecaca"/>
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
const formulas = new URL('../lib/session-pressure-formulas.js', import.meta.url)
|
|
4
|
+
const client = new URL('../lib/client.js', import.meta.url)
|
|
5
|
+
const source = (await readFile(formulas, 'utf8')).replace(/\r\n/g, '\n').split('\nexport {')[0].trim()
|
|
6
|
+
const original = (await readFile(client, 'utf8')).replace(/\r\n/g, '\n')
|
|
7
|
+
const start = ' // BEGIN shared pressure formulas'
|
|
8
|
+
const end = ' // END shared pressure formulas'
|
|
9
|
+
const first = original.indexOf(start)
|
|
10
|
+
const last = original.indexOf(end, first)
|
|
11
|
+
if (first < 0 || last < 0) throw new Error('Missing client formula markers')
|
|
12
|
+
const body = source.split('\n').map(line => line ? ' ' + line : '').join('\n')
|
|
13
|
+
const generated = original.slice(0, first) + start + '\n' + body + '\n' + original.slice(last)
|
|
14
|
+
if (generated !== original) {
|
|
15
|
+
if (process.argv.includes('--check')) throw new Error('Client formulas are out of sync')
|
|
16
|
+
await writeFile(client, generated)
|
|
17
|
+
}
|