dsh-galatea 0.4.1 → 0.4.3
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/index.js +34 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -74,7 +74,7 @@ export const Config = z.object({
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
/** 需要宿主注入的服务。 */
|
|
77
|
-
export const inject = ['systemPrompt', 'tools', 'agents'];
|
|
77
|
+
export const inject = ['systemPrompt', 'tools', 'agents', 'timer'];
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
80
|
* volatile 字段是**引用**,普通字段是**值**。
|
|
@@ -137,10 +137,29 @@ export function apply(ctx, config) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
// ── 能力自检 ────────────────────────────────────────────
|
|
141
|
+
// inject 里声明了、但 ctx 上其实没有的,一次报全。
|
|
142
|
+
// 为什么需要这一段:今天这一类的错已经犯到第六次,其中两次是 inject ——
|
|
143
|
+
// 声明漏了,代码走进 else 分支,只有一行 console.warn,
|
|
144
|
+
// 而真机上用户看不到 console.warn,于是表现为「配了完全不生效」。
|
|
145
|
+
// marker 先算出来:自检要用它记下「哪些服务没接上」。
|
|
146
|
+
// 用户已经知道去哪儿看 marker(README 写着),所以它是最便宜的可见出口。
|
|
147
|
+
const marker = cfg.markerPath || join(homedir(), '.dsh', 'galatea-loaded.txt');
|
|
148
|
+
|
|
149
|
+
const missing = inject.filter((name) => ctx == null || ctx[name] === undefined);
|
|
150
|
+
if (missing.length > 0) {
|
|
151
|
+
const line = `[galatea] 这些服务没接上:${missing.join(', ')} —— 对应的功能不会工作`;
|
|
152
|
+
console.warn(line);
|
|
153
|
+
try {
|
|
154
|
+
appendFileSync(marker, ` ${line}\n`);
|
|
155
|
+
} catch {
|
|
156
|
+
// 自检自己失败不该连累插件
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
140
160
|
// ── 正控:这一段真的跑过吗 ────────────────────────────────
|
|
141
161
|
// marker 不是日志。它只回答一个问题:apply() 到底有没有被执行。
|
|
142
162
|
// 「进程起来了」「配置里写了」都不算证据。
|
|
143
|
-
const marker = cfg.markerPath || join(homedir(), '.dsh', 'galatea-loaded.txt');
|
|
144
163
|
try {
|
|
145
164
|
mkdirSync(dirname(marker), { recursive: true });
|
|
146
165
|
appendFileSync(marker, `galatea loaded at ${new Date().toISOString()} pid=${process.pid}\n`);
|
|
@@ -221,9 +240,11 @@ export function apply(ctx, config) {
|
|
|
221
240
|
// 默认关(autoBeatMinutes = 0):一个会自己转的东西,不该在装上的那一刻就开始转。
|
|
222
241
|
const everyMin = Number(cfg.autoBeatMinutes ?? 0);
|
|
223
242
|
if (Number.isFinite(everyMin) && everyMin > 0) {
|
|
224
|
-
if (ctx && typeof ctx.
|
|
243
|
+
if (ctx && typeof ctx.interval === 'function') {
|
|
225
244
|
const ms = Math.max(60_000, everyMin * 60_000);
|
|
226
|
-
ctx.setInterval
|
|
245
|
+
// 用 ctx.interval,不用已 deprecated 的 ctx.setInterval —— 它返回 dispose,
|
|
246
|
+
// 由当前 fiber 管着,宿主热重载时不会叠出第二个定时器。
|
|
247
|
+
ctx.interval(() => {
|
|
227
248
|
try {
|
|
228
249
|
tick({});
|
|
229
250
|
} catch (err) {
|
|
@@ -233,7 +254,15 @@ export function apply(ctx, config) {
|
|
|
233
254
|
}, ms);
|
|
234
255
|
console.log(`[galatea] 自动心跳已开:每 ${everyMin} 分钟跑一次(只算不发)`);
|
|
235
256
|
} else {
|
|
236
|
-
console
|
|
257
|
+
// 用户明确要求了、却被静默拒绝 —— 这一次不能只在 console 里说。
|
|
258
|
+
// 真机上 console.warn 用户看不见,表现是「配了完全不生效,也没有任何提示」。
|
|
259
|
+
const line = '[galatea] 你配了 autoBeatMinutes,但宿主没有 ctx.interval —— 自动心跳不会跑。';
|
|
260
|
+
console.warn(line);
|
|
261
|
+
try {
|
|
262
|
+
appendFileSync(marker, ` ${line}\n`);
|
|
263
|
+
} catch {
|
|
264
|
+
// 记录失败不该连累插件
|
|
265
|
+
}
|
|
237
266
|
}
|
|
238
267
|
}
|
|
239
268
|
}
|