@fabianactor/dsh-lil-whale-group 0.0.0-stage → 1.8.14
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/LICENSE +21 -0
- package/README.md +11 -2
- package/cordis.patch.yml +3 -0
- package/lib/config.js +128 -0
- package/lib/host-anchors.js +79 -0
- package/lib/index.js +3707 -0
- package/lib/instance-guard.js +129 -0
- package/lib/intent-core.js +343 -0
- package/lib/plan-core.js +109 -0
- package/lib/rename-core.js +69 -0
- package/lib/sleep-core.js +194 -0
- package/lib/sleep-status.js +74 -0
- package/lib/wake-config.js +52 -0
- package/lib/wake-preview-core.js +56 -0
- package/package.json +41 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FabianActor
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fabianactor/dsh-lil-whale-group(宿主侧)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
小小肥鱼(lil-whale)鱼塘的**宿主侧** bundle:群聊、巡守、叫醒、睡眠、自主触发、单实例防护。
|
|
4
|
+
|
|
5
|
+
它不是一个独立插件——完整的一套(鱼塘目录、安装脚本、鱼的模板、体检)在仓库里:
|
|
6
|
+
https://github.com/FabianActor/dsh-lil-whale
|
|
7
|
+
|
|
8
|
+
只把它 `dsh plugin add` 进 profile,会得到一个空壳面板(没有鱼、没有家、没有巡守)。正确做法见仓库 README 的「装起来」。
|
|
9
|
+
|
|
10
|
+
配套的界面包:`@fabianactor/dsh-lil-whale-group-ui`。
|
|
11
|
+
|
|
12
|
+
MIT License.
|
package/cordis.patch.yml
ADDED
package/lib/config.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 这台机器的假设,全从这里读。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要有这个文件:代码里写死 `<她的家>` 之类的东西,等于"这段程序只在这台机器上
|
|
5
|
+
* 成立"。打包给别人时最麻烦的不是改名,是这些路径 —— 装上以后跑不起来,报的还是一句
|
|
6
|
+
* `ENOENT: no such file or directory`,看不出是谁的问题。
|
|
7
|
+
*
|
|
8
|
+
* 读法(优先级从高到低):
|
|
9
|
+
* 1. 环境变量 `LIL_WHALE_CONFIG` 指向的 JSON 文件
|
|
10
|
+
* 2. 仓库根目录的 `lil-whale.config.json`
|
|
11
|
+
* 3. 一份"按标准布局"推出来的默认值(下面的 DEFAULTS)
|
|
12
|
+
*
|
|
13
|
+
* "标准布局"= 鱼塘根下 `app/` 是仓库、`homes/<键>/` 是鱼的家。所以别人克隆下来、
|
|
14
|
+
* 把鱼塘摆成这个形状,不写配置文件也能跑;只有布局不一样时才需要那份 JSON。
|
|
15
|
+
*
|
|
16
|
+
* 注意仓库根是从**本文件的位置**往上数出来的,不是从进程 cwd 数出来的 —— 宿主的 cwd 是
|
|
17
|
+
* "从哪儿启动的",我们的代码可能被 link 到别的 profile 目录里,cwd 靠不住。
|
|
18
|
+
*
|
|
19
|
+
* 字段命名(2026-11-14 改):每条鱼读的都是**自己**那份配置,所以 `self*` 指"这个进程
|
|
20
|
+
* 服务的那条鱼"。旧的 `her*` / `whale*` 是单鱼时代的名字(第二条鱼出现后 `whaleProfile`
|
|
21
|
+
* 在 fishball 的配置里只能填 `fishball`,读起来是错的),仍然接受,只作兼容别名。
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
24
|
+
import { dirname, join, resolve } from 'node:path'
|
|
25
|
+
import { fileURLToPath } from 'node:url'
|
|
26
|
+
|
|
27
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
28
|
+
// lib/ → dsh-lil-whale-group/ → plugin/ → 仓库根
|
|
29
|
+
const REPO_ROOT = resolve(HERE, '..', '..', '..')
|
|
30
|
+
|
|
31
|
+
const DEFAULTS = {
|
|
32
|
+
repoRoot: REPO_ROOT,
|
|
33
|
+
// 鱼塘布局(2026-11-13 起):<pond>\app 是仓库,鱼在 <pond>\homes\<键>。
|
|
34
|
+
// 配置丢了也不该指回旧布局(`<repo>\..\lil-whale` 那种),否则"默认值"会把新装的人带进老结构。
|
|
35
|
+
selfHome: resolve(REPO_ROOT, '..', 'homes', 'fish'),
|
|
36
|
+
selfWaker: join(REPO_ROOT, 'scripts', 'wake-fish.ps1'),
|
|
37
|
+
wakeMetrics: join(REPO_ROOT, 'logs', 'wake-metrics.log'),
|
|
38
|
+
pwshExe: process.platform === 'win32' ? 'pwsh.exe' : 'pwsh',
|
|
39
|
+
leeCwd: REPO_ROOT,
|
|
40
|
+
leeProfile: 'web',
|
|
41
|
+
selfProfile: 'fish',
|
|
42
|
+
// 这条鱼的进程开的端口。巡守要推门时敲的就是它;改端口必须同时改这里,否则巡守会去敲一扇没人的门。
|
|
43
|
+
selfPort: 3082,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 旧名字 → 新名字。旧配置仍然能读,只是会被换成 `self*`。 */
|
|
47
|
+
const LEGACY_KEYS = {
|
|
48
|
+
herHome: 'selfHome',
|
|
49
|
+
herDshHome: 'selfDshHome',
|
|
50
|
+
herWaker: 'selfWaker',
|
|
51
|
+
herPort: 'selfPort',
|
|
52
|
+
whaleProfile: 'selfProfile',
|
|
53
|
+
whaleCwd: 'selfCwd',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let cached = null
|
|
57
|
+
|
|
58
|
+
export function configPath() {
|
|
59
|
+
return process.env.LIL_WHALE_CONFIG || join(REPO_ROOT, 'lil-whale.config.json')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 派生字段(只由上面几个推出来,不许单独写死)。 */
|
|
63
|
+
function derive(c) {
|
|
64
|
+
// 先把旧名字抬成新名字(新名字优先)。
|
|
65
|
+
const lifted = { ...c }
|
|
66
|
+
for (const [oldKey, newKey] of Object.entries(LEGACY_KEYS)) {
|
|
67
|
+
if (lifted[newKey] === undefined && lifted[oldKey] !== undefined) lifted[newKey] = lifted[oldKey]
|
|
68
|
+
}
|
|
69
|
+
const selfHome = lifted.selfHome
|
|
70
|
+
// 共享区(pool)在她家之外:群、多成员账本都放这儿。
|
|
71
|
+
// 为什么不在她家里:群是共享空间,不是她的私人物品;第二条鱼出现后,
|
|
72
|
+
// 第二条的群文件写进第一条的家就是越界(Fabian 2026-11-12 拍板)。
|
|
73
|
+
// 她家里留 Junction 指回 pool,所以她的路径一个字都不用改。
|
|
74
|
+
// selfHome = <pond>\homes\<键> ⇒ 上两级才是 pond。
|
|
75
|
+
const poolDir = lifted.poolDir || resolve(selfHome, '..', '..', 'pool')
|
|
76
|
+
const out = {
|
|
77
|
+
...lifted,
|
|
78
|
+
poolDir,
|
|
79
|
+
poolStateDir: lifted.poolStateDir || join(poolDir, 'state'),
|
|
80
|
+
// 私聊是「两个人之间的窗口」,不放进群目录:群目录是共享区里公开的那一半(Fabian 2026-11-12 拍板)。
|
|
81
|
+
dmDir: lifted.dmDir || join(poolDir, 'dm'),
|
|
82
|
+
// 名册:谁是谁、叫什么、哪条鱼、端口、爹是谁。多鱼之后这些不许再写死在代码里。
|
|
83
|
+
membersFile: lifted.membersFile || join(poolDir, 'members.json'),
|
|
84
|
+
selfPort: Number(lifted.selfPort) || 3082,
|
|
85
|
+
groupDir: lifted.groupDir || join(poolDir, 'group'),
|
|
86
|
+
selfDshHome: lifted.selfDshHome || join(selfHome, 'dsh-home'),
|
|
87
|
+
selfCwd: lifted.selfCwd || selfHome,
|
|
88
|
+
chatCwd: lifted.chatCwd || dirname(lifted.repoRoot),
|
|
89
|
+
watchmanPidFile: lifted.watchmanPidFile || join(poolDir, 'state', 'watchman.pid'),
|
|
90
|
+
}
|
|
91
|
+
// 兼容别名:旧代码/旧脚本还在用 her* / whale*,给它们留一份只读映射。
|
|
92
|
+
out.herHome = out.selfHome
|
|
93
|
+
out.herDshHome = out.selfDshHome
|
|
94
|
+
out.herWaker = out.selfWaker
|
|
95
|
+
out.herPort = out.selfPort
|
|
96
|
+
out.whaleProfile = out.selfProfile
|
|
97
|
+
out.whaleCwd = out.selfCwd
|
|
98
|
+
return out
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 读一次,缓存起来(进程生命周期内不变 —— 改配置要重启,这是有意的:
|
|
103
|
+
* 热改路径会让"这个进程到底在读哪份文件"变成一个没人答得上来的问题)。
|
|
104
|
+
*/
|
|
105
|
+
export function config() {
|
|
106
|
+
if (cached) return cached
|
|
107
|
+
const path = configPath()
|
|
108
|
+
let raw = {}
|
|
109
|
+
let error = null
|
|
110
|
+
if (existsSync(path)) {
|
|
111
|
+
try {
|
|
112
|
+
raw = JSON.parse(readFileSync(path, 'utf8'))
|
|
113
|
+
} catch (e) {
|
|
114
|
+
// 配置写坏了要说出来,不能安静地用默认值跑 —— 那会让人以为自己改对了
|
|
115
|
+
error = `config 读取失败(${path}):${e.message}`
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let mtime = null
|
|
119
|
+
try { mtime = statSync(path).mtime.toISOString() } catch { /* 文件不在就没有 mtime */ }
|
|
120
|
+
cached = { ...derive({ ...DEFAULTS, ...raw }), _path: path, _exists: existsSync(path), _error: error, _mtime: mtime }
|
|
121
|
+
return cached
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** 给启动痕迹用的短摘要:哪份配置、这条鱼的家在哪儿。 */
|
|
125
|
+
export function configSummary() {
|
|
126
|
+
const c = config()
|
|
127
|
+
return { path: c._path, exists: c._exists, error: c._error, selfHome: c.selfHome, groupDir: c.groupDir }
|
|
128
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 宿主包在哪:2026-11-16 r195 起按"实际在跑的那个 dsh"一起找,不再只认 npm 全局安装。
|
|
2
|
+
//
|
|
3
|
+
// npx 跑 dsh 时包在 %LOCALAPPDATA%\npm-cache\_npx\<hash>\node_modules\@deepseek-ai\dsh,
|
|
4
|
+
// 老的两个锚点全落空 —— defineTool / createUserMessage 永远是 null(typeof null === "object"),
|
|
5
|
+
// 插件降级成裸对象注册,还每秒重试刷日志(第三方装机实测 P5/P6)。
|
|
6
|
+
|
|
7
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
8
|
+
import { dirname, join } from 'node:path'
|
|
9
|
+
|
|
10
|
+
export function isDshPackageJson(file) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(readFileSync(file, 'utf8'))?.name === '@deepseek-ai/dsh'
|
|
13
|
+
} catch {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 从某个入口文件往上找 @deepseek-ai/dsh/package.json(最多 8 层)。 */
|
|
19
|
+
export function dshPkgFromEntry(entry) {
|
|
20
|
+
if (!entry) return null
|
|
21
|
+
let dir = dirname(entry)
|
|
22
|
+
for (let i = 0; i < 8; i += 1) {
|
|
23
|
+
const candidate = join(dir, 'package.json')
|
|
24
|
+
if (existsSync(candidate) && isDshPackageJson(candidate)) return candidate
|
|
25
|
+
const parent = dirname(dir)
|
|
26
|
+
if (parent === dir) break
|
|
27
|
+
dir = parent
|
|
28
|
+
}
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** npx 缓存里所有 dsh 包,按 mtime 从新到旧;找不到就空数组。 */
|
|
33
|
+
export function npxDshPkgFiles() {
|
|
34
|
+
const base = process.env.npm_config_cache
|
|
35
|
+
|| (process.env.LOCALAPPDATA ? join(process.env.LOCALAPPDATA, 'npm-cache') : '')
|
|
36
|
+
if (!base) return []
|
|
37
|
+
const npxRoot = join(base, '_npx')
|
|
38
|
+
if (!existsSync(npxRoot)) return []
|
|
39
|
+
try {
|
|
40
|
+
return readdirSync(npxRoot)
|
|
41
|
+
.map((name) => join(npxRoot, name, 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
42
|
+
.filter((file) => existsSync(file) && isDshPackageJson(file))
|
|
43
|
+
.map((file) => ({ file, mtime: statSync(file).mtimeMs }))
|
|
44
|
+
.sort((a, b) => b.mtime - a.mtime)
|
|
45
|
+
.map((x) => x.file)
|
|
46
|
+
} catch {
|
|
47
|
+
return []
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 宿主包的入口候选(2026-11-16 r199,第三方 npx 装机实测 P5):
|
|
53
|
+
* - npm 全局:`<...>\node_modules\@deepseek-ai\dsh\node_modules\@deepseek-ai\<pkg>\lib\index.js`(嵌套)
|
|
54
|
+
* - npx / pnpm hoisted:`<...>\node_modules\@deepseek-ai\<pkg>\lib\index.js`(与 dsh 兄弟)
|
|
55
|
+
* 只拼前一种时,npx 机器上永远找不到 dsh-tools/dsh-llm,插件降级成裸对象注册。
|
|
56
|
+
*/
|
|
57
|
+
export function hostExportEntryCandidates(anchorFile, pkg) {
|
|
58
|
+
const dshDir = dirname(anchorFile) // ...\node_modules\@deepseek-ai\dsh
|
|
59
|
+
return [
|
|
60
|
+
{ layout: 'nested', file: join(dshDir, 'node_modules', '@deepseek-ai', pkg, 'lib', 'index.js') },
|
|
61
|
+
{ layout: 'hoisted', file: join(dirname(dshDir), pkg, 'lib', 'index.js') },
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 返回 [{ kind, file }];kind 进日志,file 只在进程里用(不把用户路径写进账本)。 */
|
|
66
|
+
export function hostAnchors() {
|
|
67
|
+
const out = []
|
|
68
|
+
const push = (kind, file) => {
|
|
69
|
+
if (typeof file !== 'string' || !file) return
|
|
70
|
+
if (out.some((a) => a.file === file)) return
|
|
71
|
+
out.push({ kind, file })
|
|
72
|
+
}
|
|
73
|
+
push('launcher-env', process.env.DSH_LAUNCHER_MODULE)
|
|
74
|
+
push('argv-entry', dshPkgFromEntry(process.argv[1]))
|
|
75
|
+
push('npm-global', join(process.env.APPDATA ?? '', 'npm', 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
76
|
+
push('npm-global-profile', join(process.env.USERPROFILE ?? '', 'AppData', 'Roaming', 'npm', 'node_modules', '@deepseek-ai', 'dsh', 'package.json'))
|
|
77
|
+
for (const file of npxDshPkgFiles()) push('npx-cache', file)
|
|
78
|
+
return out
|
|
79
|
+
}
|