dsh-aiyayi 1.2.4 → 1.2.6
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/lib/presence.js +122 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
| 跟随会话模型 | 无需插件行(1.0.1 起移除 agent-default-model 行) | 本体模型直接跟随用户会话模型;旧版"preset 作用域挂 `@deepseek-ai/dsh-agent-default-model` + `isolate: {agentDefaultModel: true}`"的写法在新版 DSH 过不了 schema 校验(见坑 #13),已删除 |
|
|
12
12
|
| 干活的子智能体 | `@deepseek-ai/dsh-tool-subagent`(delegation 组,isolate workflowEngine) | `agentPreset: aiyayi-worker`(自建"小伙伴"预设,全量工具 + 原生自动压缩,见坑 #14);子代模型跟随用户会话模型,如需钉死可在 `agentOptions` 配置 provider/model |
|
|
13
13
|
| 工具白名单 | 自写插件 `aiyayi-restrict`(本包 `lib/restrict.js`,v3.1 pre-step 方案)+ `lib/own-tools.js` 单一真源 | 启动期零 restrict 调用;她每个会话第一步前,先用探针从校验器报错里解析出当刻继承面全集,再 `deny = 全集 − 她自己的工具`——宿主层漏进来的 acp_*/mnemon_*/compress/search_context/working_directory 等对她隐藏,且自动适应宿主工具增减。放行名单从 `own-tools.js` 读(注册处登记、放行处判定),新增工具只改一处,不再漂(见坑 #19)。**2026-11-02 实测生效**:新会话第 2 个请求起工具恰好 11 个,第 1 个请求仍带全套(见坑 #9) |
|
|
14
|
-
| 重逢感知 | 自写插件 `aiyayi-presence`(本包 `lib/presence.js`) | 每个回合第一步,往消息尾部追加一条 `[重逢]` 快照(time-context 同款 pre-step 注入范式):他多久没来(presence.json)、你上次活动、你上次留的状态(state.md)、没说出口的话(wishes.json
|
|
14
|
+
| 重逢感知 | 自写插件 `aiyayi-presence`(本包 `lib/presence.js`) | 每个回合第一步,往消息尾部追加一条 `[重逢]` 快照(time-context 同款 pre-step 注入范式):他多久没来(presence.json)、你上次活动、你上次留的状态(state.md)、没说出口的话(wishes.json)。快照还带**版本自述**:`你当前插件版本:dsh-aiyayi x.y.z`(package.json 现读不写死,让她对自己版本有概念、不与 DSH 桌面版混淆;有新版时 updates 插件照旧单独提醒)。跨会话生效,`[SCHEDULE REMINDER` 唤醒消息不算"他来了"。工具 `update_state`(收尾留状态)/ `wish`(add/list/done 心愿单) |
|
|
15
15
|
| 自我状态(体检单) | 同上 `aiyayi-presence`(v1.2.0 起) | `session/event` 总线折叠真实运行数据:模型与思考档、上下文用量(provider 实测 usage 优先,tokenMeter 估算兜底并标"估算")、缓存命中率、上轮输出 tok/s、本会话轮数、上轮异常。变化明显(≥2048 token / 模型切换 / 异常)才注入,不每轮白涨。用量过八成/九成(估算口径按中文偏差 ÷0.49 校准,见坑 #16)注入 `[上下文提醒]`:劝用户开新会话、并让用户走之前说一声好让她收尾(update_state/补记忆/把话说完);每档只提醒一次 |
|
|
16
16
|
| 主动开口 | `tool-schedule`(dsh 原生)+ persona 指引 | 到期提醒会把冷会话真唤醒、以 user 消息落进定闹钟的那个会话——她想主动说话就 `schedule_create` 定闹钟;DSH 没开着会存着、下次启动补投 |
|
|
17
|
-
| 新版本提醒 | 自写插件 `aiyayi-updates`(本包 `lib/updates.js`) | 每个会话第一个回合查一次 npm(registry.npmjs.org,失败落 npmmirror;成功结果缓存 6h、失败 30min 后重试):本地版本比 latest 旧时,往消息尾部追加 `[更新提示]` 快照,她会用自己的口吻顺口提一句。同一远端版本只提醒一次(updates.json
|
|
17
|
+
| 新版本提醒 | 自写插件 `aiyayi-updates`(本包 `lib/updates.js`) | 每个会话第一个回合查一次 npm(registry.npmjs.org,失败落 npmmirror;成功结果缓存 6h、失败 30min 后重试):本地版本比 latest 旧时,往消息尾部追加 `[更新提示]` 快照,她会用自己的口吻顺口提一句。同一远端版本只提醒一次(updates.json 落盘去重,跨重启不重复念叨);检查失败/离线一律静默。**判据:`~\\.dsh\\aiyayi\\updates.json` 不存在 = 从没发现过新版(本地已是最新);她答不上"自己是什么版本"是设计边界(升级判断靠被动推送),已由 presence 的版本自述补上** |
|
|
18
18
|
| 其他 | time-context、compaction 组(提前压缩,见坑 #14/#16)、tool-ask-user | 她没有 bash/文件/技能/搜索/网络工具,想动手只能派活 |
|
|
19
19
|
|
|
20
20
|
## 文件
|
|
@@ -77,3 +77,4 @@ GUI 新建会话 → agent preset 选「**阿依娅伊**」。聊天即可;她
|
|
|
77
77
|
21. **子智能体手写 memory.md 会产生双类别前缀污染(2026-11-05 实测;1.2.3 已修)**:小伙伴在派活收尾时有时会"帮她补记",直接把 `用户|用户|…`、`关系|关系|…` 这种带前缀的整句写进 core 行,导致条目类别前缀叠了两层(实测 7 条:关系×1、用户×3、事情×2)。修法:`parseLine` 新增 `stripRepeatedKindPrefix`——遇到连续 `类别|类别|…` 前缀循环剥到只剩一层(任何读取路径都免疫);`remember` 写入前也先剥 content 自带前缀(防再生);存量 7 条已一次性手工修复。教训:凡是"别人代写她记忆文件"的路径都要在解析层兜底,不能指望写手守规矩。
|
|
78
78
|
22. **子代(小伙伴)失败原因不透传到本体(2026-11-05 实测;1.2.3 已修)**:宿主对派出去的子智能体的结算消息只有一句 `failed before it finished` / `It left no closing message.`——真实原因(HTTP_402 积分余额不足、上游限流、403、Illegal API invocation)只躺在子会话自己的 `turn/end` error 事件里(宿主 `terminal.diagnostic` 只有在 provider 主动给时才透传,本地 spawn 的 provider 不给)。她不知道为啥失败 → 盲目重派 3 轮白耗 ~20 分钟。修法:`aiyayi-presence` 的 `session/event` 监听不再丢弃非本体的会话事件,改把 `header.origin==="subagent"`(或带 `header.parentSession`)的子会话 `turn/end` error 记进 `childFailures`(上限 20、只记 error、错误串截 120 字符),下一个 pre-step 注入 `⚠ [小伙伴] 你派出去干活的小智能体有 N 个报错了(宿主只回一句"failed before it finished",真原因在这):…`(每次最多列 3 条、已报过的去重不唠叨)。原理:session/event 总线对所有会话广播,插件端按 `agentsById` 过滤才是它之前只见本体的原因;子会话 header 带 `parentSession` 链接,可归属到正确的父会话。
|
|
79
79
|
23. **新会话首次对话时提醒"关闭思考"(2026-11-05 新增;1.2.4 已做)**:日常闲聊用不上深度思考,回复慢还费 token。`aiyayi-presence` 在每个**新会话的首次对话**(pre-step step===1、每会话只提醒一次)注入 `💡 小建议`:当本体模型的 `reasoningEffort` 已显式选了一个思考档位(有档位 = 必支持"关闭思考",见 pi-ai 校验规则"reasoningEfforts offers no level beyond off → refuse")或通过 `ctx.llm.resolveModelInfo()` 探到 `reasoning.efforts` 里有 `off` 档时,提醒她去模型选项里选「关闭思考」。已选 `off`/`none`、探不到模型信息(`ctx.llm` 不可用、resolveModelInfo 失败)或非推理模型(`reasoning: undefined`)都不打扰。教训:判断"模型支持某个能力"优先用运行时解析(resolveModelInfo),拿不到再退化为显式配置信号,且**只在首轮提醒一次**,别每轮唠叨。
|
|
80
|
+
24. **子代模型不跟随本体切换(2026-11-05 实测并修复;1.2.5 已做)**:派出去的子智能体在 spawn 时就冻结了当时的 provider/model/reasoningEffort(内核 `resolveChildAgentOptions` 从父会话当前 requestHeader 解析一次,之后 steer/followup/恢复都复用它——`agentOptions` 在续跑路径上被禁传,恢复走 descriptor 快照),所以本体因额度用完切模型继续时,**还在跑的小伙伴仍是旧模型,继续调旧渠道照样 402/限流**。修法:`aiyayi-presence` 的 `session/event` 监听把每个子会话登记进 `childSessions`(childId→parentSessionId,上限 64);本体自己的 `model/selection` 事件或 `request/header` 路由变化时,对名下每个子会话执行 `ctx.get("agents").get(childId).model.select({provider, model, reasoningEffort?})` ——内核 `AgentModel.select` 向子会话 append `model/selection` 投影事件,子会话下一步 prep 读 pending 覆盖冻结值,新模型即刻生效(同路由幂等,不会重复触发)。前提:插件与 tool-subagent 同在 preset-aiyayi 作用域,`ctx.get("agents")` 可解析;拿不到 agents 就静默跳过(尽力而为)。注意子代自己显式选的模型(modelSelectionSettings 让模型在派活时选)不会被覆盖成本体的——只有本体路由变化才同步。
|
package/lib/presence.js
CHANGED
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
* 6. 💡 关闭思考建议:新会话首次对话时,如果当前模型支持"关闭思考"
|
|
21
21
|
* (有 off 思考档位)且还没关掉,就提醒她劝用户去模型选项里选"关闭思考"
|
|
22
22
|
* (日常闲聊用不上深度思考,回复更快、更省 token);每个会话只提醒一次。
|
|
23
|
+
* 7. [小伙伴] 子代模型跟随:子智能体的模型在 spawn 时从本体当前模型冻结,
|
|
24
|
+
* 本体之后切换模型(额度用完换模型继续)不会自动传到子代,子代还在旧模型
|
|
25
|
+
* 上继续、照样报额度错。这里在 session/event 总线上登记所有子会话,检测到
|
|
26
|
+
* 本体自己的模型变了(model/selection 事件,或 request/header 路由变化),
|
|
27
|
+
* 就对名下每个子会话调 agent.model.select(新模型)——子会话的模型选择投影
|
|
28
|
+
* 记 pending,它下一步 prep 就会用新模型(尽力而为:agents 注册表拿不到或
|
|
29
|
+
* 单个子同步失败都不影响本体)。
|
|
23
30
|
*
|
|
24
31
|
* 只在 aiyayi 预设作用域挂载;她的子智能体(standard/worker 预设)不受影响。
|
|
25
32
|
* 新注册的工具是 scoped 的,不受 restrict 掩码影响(掩码只动全局继承面)。
|
|
@@ -27,7 +34,8 @@
|
|
|
27
34
|
import { randomUUID } from 'node:crypto'
|
|
28
35
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
29
36
|
import { homedir } from 'node:os'
|
|
30
|
-
import { join } from 'node:path'
|
|
37
|
+
import { dirname, join } from 'node:path'
|
|
38
|
+
import { fileURLToPath } from 'node:url'
|
|
31
39
|
import { registerOwnTool } from './own-tools.js'
|
|
32
40
|
|
|
33
41
|
/** Loader 身份。 */
|
|
@@ -41,6 +49,22 @@ const PRESENCE_FILE = join(DIR, 'presence.json')
|
|
|
41
49
|
const STATE_FILE = join(DIR, 'state.md')
|
|
42
50
|
const WISHES_FILE = join(DIR, 'wishes.json')
|
|
43
51
|
|
|
52
|
+
/** 本包根目录(presence.js 在 lib/ 下,上一级就是包根),读 package.json 拿版本。 */
|
|
53
|
+
const PKG_DIR = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
54
|
+
|
|
55
|
+
/** 自己的插件版本:package.json 现读、进程内缓存,不写死——升级改版本号就自动跟上。 */
|
|
56
|
+
let cachedVersion = null
|
|
57
|
+
function readLocalVersion() {
|
|
58
|
+
if (cachedVersion !== null) return cachedVersion
|
|
59
|
+
try {
|
|
60
|
+
const pkg = JSON.parse(readFileSync(join(PKG_DIR, 'package.json'), 'utf8'))
|
|
61
|
+
cachedVersion = typeof pkg?.version === 'string' ? pkg.version.trim() : ''
|
|
62
|
+
} catch {
|
|
63
|
+
cachedVersion = ''
|
|
64
|
+
}
|
|
65
|
+
return cachedVersion
|
|
66
|
+
}
|
|
67
|
+
|
|
44
68
|
const ACTIVE_THROTTLE_MS = 60_000
|
|
45
69
|
const MAX_STATE_CHARS = 300
|
|
46
70
|
const MAX_WISHES_IN_SNAPSHOT = 3
|
|
@@ -71,6 +95,66 @@ const childFailures = new Map()
|
|
|
71
95
|
/** 已经透传过的 childSessionId(同一断因不重复念叨)。 */
|
|
72
96
|
const childFailuresReported = new Set()
|
|
73
97
|
|
|
98
|
+
/* ------------------------------------------------------------------ *
|
|
99
|
+
* [小伙伴] 子代模型跟随:本体切模型 → 名下子会话 model.select 同步。
|
|
100
|
+
* ------------------------------------------------------------------ */
|
|
101
|
+
|
|
102
|
+
/** 见过的子会话上限(超出丢最旧登记,防无界增长)。 */
|
|
103
|
+
const MAX_CHILD_SESSIONS = 64
|
|
104
|
+
/** childSessionId -> parentSessionId(凡子会话都登记,不只报错的)。 */
|
|
105
|
+
const childSessions = new Map()
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 登记一个子会话:本体名下、还可能在跑的子智能体。
|
|
109
|
+
* @param {object} session 子会话对象(session/event 总线广播的任意会话)。
|
|
110
|
+
*/
|
|
111
|
+
function trackChildSession(session) {
|
|
112
|
+
const header = session?.header ?? {}
|
|
113
|
+
const isChild = header.origin === 'subagent' || typeof header.parentSession === 'string'
|
|
114
|
+
if (!isChild) return
|
|
115
|
+
const childId = session?.id ?? header.id
|
|
116
|
+
const parentId = typeof header.parentSession === 'string' ? header.parentSession : null
|
|
117
|
+
if (!childId || !parentId) return
|
|
118
|
+
childSessions.set(childId, parentId)
|
|
119
|
+
if (childSessions.size > MAX_CHILD_SESSIONS) {
|
|
120
|
+
// Map 保持插入序,删最旧的(第一个)。
|
|
121
|
+
const oldest = childSessions.keys().next().value
|
|
122
|
+
if (oldest !== undefined) childSessions.delete(oldest)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 本体模型变了 → 把新模型同步给名下每个还在跑的子会话。
|
|
128
|
+
* 内核:子代模型在 spawn 时从父会话 requestHeader 冻结(resolveChildAgentOptions),
|
|
129
|
+
* 之后父切模型不会自动传播;但子会话自己的模型选择投影(AgentModel.select 写
|
|
130
|
+
* pending)会在它下一步 prep 生效,覆盖 spawn 冻结值。所以这里对每个子 agent
|
|
131
|
+
* 调 model.select —— 全程尽力而为,拿不到 agents 注册表就静默跳过。
|
|
132
|
+
* @param {string} parentSessionId 本体会话 id
|
|
133
|
+
* @param {{provider:string, model:string, reasoningEffort?:string}} selection 新模型
|
|
134
|
+
* @param {object} ctx preset 作用域上下文(取 agents 注册表)
|
|
135
|
+
*/
|
|
136
|
+
function propagateModelToChildren(parentSessionId, selection, ctx) {
|
|
137
|
+
if (!parentSessionId || !selection?.provider || !selection?.model) return
|
|
138
|
+
let agents = null
|
|
139
|
+
try {
|
|
140
|
+
agents = ctx?.get?.('agents') ?? null
|
|
141
|
+
} catch {
|
|
142
|
+
agents = null
|
|
143
|
+
}
|
|
144
|
+
if (!agents) return
|
|
145
|
+
for (const [childId, parentId] of childSessions) {
|
|
146
|
+
if (parentId !== parentSessionId) continue
|
|
147
|
+
try {
|
|
148
|
+
const childAgent = agents.get?.(childId)
|
|
149
|
+
const select = childAgent?.model?.select
|
|
150
|
+
if (typeof select !== 'function') continue
|
|
151
|
+
select.call(childAgent.model, selection)
|
|
152
|
+
} catch {
|
|
153
|
+
/* 单个子会话同步失败不影响其它 */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
74
158
|
/* ------------------------------------------------------------------ *
|
|
75
159
|
* 💡 关闭思考建议(新会话首次对话只提醒一次)。
|
|
76
160
|
* ------------------------------------------------------------------ */
|
|
@@ -103,6 +187,9 @@ function onChildSessionEvent(session, event) {
|
|
|
103
187
|
const header = session?.header ?? {}
|
|
104
188
|
const isChild = header.origin === 'subagent' || typeof header.parentSession === 'string'
|
|
105
189
|
if (!isChild) return
|
|
190
|
+
// 子代模型跟随:先登记这个子会话(本体名下、还可能在跑),
|
|
191
|
+
// 本体之后切模型时把它也一起同步(见 propagateModelToChildren)。
|
|
192
|
+
trackChildSession(session)
|
|
106
193
|
if (event?.type !== 'turn/end') return
|
|
107
194
|
if (event?.data?.reason !== 'error') return
|
|
108
195
|
const childId = session?.id ?? session?.header?.id
|
|
@@ -179,7 +266,7 @@ function vitalsFor(agent) {
|
|
|
179
266
|
}
|
|
180
267
|
|
|
181
268
|
/** session/event 总线回放:折叠与已登记 agent 同会话的事件;子会话报错单独记账。 */
|
|
182
|
-
function onSessionEvent(session, event) {
|
|
269
|
+
function onSessionEvent(session, event, ctx) {
|
|
183
270
|
const id = session?.id ?? session?.header?.id
|
|
184
271
|
const agent = agentsById.get(id)
|
|
185
272
|
if (!agent) {
|
|
@@ -190,10 +277,34 @@ function onSessionEvent(session, event) {
|
|
|
190
277
|
const type = event?.type
|
|
191
278
|
const time = Number.isFinite(event?.time) ? event.time : Date.now()
|
|
192
279
|
const data = event?.data ?? {}
|
|
193
|
-
if (type === '
|
|
280
|
+
if (type === 'model/selection') {
|
|
281
|
+
// 本体自己切了模型(用户在模型选项里换了,或配额用完换模型继续):
|
|
282
|
+
// 把新模型同步给名下每个还在跑的子会话,它们下一步就用新模型。
|
|
283
|
+
const sel = data
|
|
284
|
+
if (sel?.provider && sel?.model) {
|
|
285
|
+
const selection = {
|
|
286
|
+
provider: String(sel.provider),
|
|
287
|
+
model: String(sel.model),
|
|
288
|
+
...(typeof sel.reasoningEffort === 'string' ? { reasoningEffort: sel.reasoningEffort } : {}),
|
|
289
|
+
}
|
|
290
|
+
propagateModelToChildren(id, selection, ctx)
|
|
291
|
+
v.config = selection
|
|
292
|
+
}
|
|
293
|
+
} else if (type === 'request/header') {
|
|
194
294
|
const cfg = data?.header?.config
|
|
195
295
|
if (cfg?.provider && cfg?.model) {
|
|
196
|
-
|
|
296
|
+
const prev = v.config
|
|
297
|
+
const next = {
|
|
298
|
+
provider: String(cfg.provider),
|
|
299
|
+
model: String(cfg.model),
|
|
300
|
+
reasoningEffort: cfg.reasoningEffort,
|
|
301
|
+
}
|
|
302
|
+
// 路由(provider/model)变了也算切模型(有时只有 request/header 没有
|
|
303
|
+
// model/selection 事件):同样同步给子会话。
|
|
304
|
+
if (prev && (prev.provider !== next.provider || prev.model !== next.model)) {
|
|
305
|
+
propagateModelToChildren(id, next, ctx)
|
|
306
|
+
}
|
|
307
|
+
v.config = next
|
|
197
308
|
}
|
|
198
309
|
} else if (type === 'request/context') {
|
|
199
310
|
const w = data?.contextWindow ?? data?.request?.contextWindow ?? data?.header?.contextWindow
|
|
@@ -475,7 +586,7 @@ export function apply(ctx) {
|
|
|
475
586
|
() =>
|
|
476
587
|
ctx.on('session/event', (session, event) => {
|
|
477
588
|
try {
|
|
478
|
-
onSessionEvent(session, event)
|
|
589
|
+
onSessionEvent(session, event, ctx)
|
|
479
590
|
} catch {
|
|
480
591
|
/* 单条事件折叠失败不影响别的 */
|
|
481
592
|
}
|
|
@@ -533,6 +644,11 @@ export function apply(ctx) {
|
|
|
533
644
|
const reunion = renderReunion(previous, now)
|
|
534
645
|
const childFails = renderChildFailures(sessionId)
|
|
535
646
|
|
|
647
|
+
// 版本自述:让"我是什么版本"有答案(区分插件版与 DSH 桌面版),
|
|
648
|
+
// 有新版时 updates 插件照旧单独提醒"本地 X → npm Y"。
|
|
649
|
+
const ownVersion = readLocalVersion()
|
|
650
|
+
const versionLine = ownVersion ? `你当前插件版本:dsh-aiyayi ${ownVersion}` : ''
|
|
651
|
+
|
|
536
652
|
// 💡 关闭思考建议:新会话首次对话、模型支持"关闭思考"且当前没关时,提醒一次。
|
|
537
653
|
let thinkingTip = ''
|
|
538
654
|
if (sessionId && !thinkingSuggestedSessions.has(sessionId)) {
|
|
@@ -564,7 +680,7 @@ export function apply(ctx) {
|
|
|
564
680
|
}
|
|
565
681
|
}
|
|
566
682
|
|
|
567
|
-
const sections = [reunion, vitals.changed ? vitals.text : '', reminder, thinkingTip, childFails].filter(Boolean)
|
|
683
|
+
const sections = [reunion, versionLine, vitals.changed ? vitals.text : '', reminder, thinkingTip, childFails].filter(Boolean)
|
|
568
684
|
if (sections.length > 0) {
|
|
569
685
|
return {
|
|
570
686
|
...decision,
|