cortico-world-hands 0.20.64 → 0.20.66
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/dist/index.js +76 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,6 +52,10 @@ var HANDS_DEFAULTS = {
|
|
|
52
52
|
homeX: 0.06,
|
|
53
53
|
/** 隔多久回一次原位(分钟)。0 关闭。 */
|
|
54
54
|
homeReturnMinutes: 10,
|
|
55
|
+
/** 每隔几分钟查一次异常(手掉线、磁盘满等),有问题主动报告。0 关闭。 */
|
|
56
|
+
watchMinutes: 3,
|
|
57
|
+
/** 同一个问题最多隔多久再提醒一次(分钟)。 */
|
|
58
|
+
alertRepeatMinutes: 30,
|
|
55
59
|
/** 这些应用在前台时她闭嘴(只推事件不说话),逗号分隔的包名。 */
|
|
56
60
|
quietApps: "com.tencent.tmgp.dfm",
|
|
57
61
|
quietStartHour: 2,
|
|
@@ -211,6 +215,18 @@ var HANDS_CONFIG_GROUP = {
|
|
|
211
215
|
description: "\u5230\u70B9\u5979\u4F1A\u4ECE\u4F60\u5C4F\u5E55/\u6700\u8FD1\u7684\u4E8B\u91CC\u6311\u4E00\u4EF6\u597D\u5947\u7684\u6765\u95EE\u30020 \u5173\u95ED\u3002\u9ED8\u8BA4 50\u3002",
|
|
212
216
|
"x-hot": true
|
|
213
217
|
},
|
|
218
|
+
[`${K}.watchMinutes`]: {
|
|
219
|
+
type: "number",
|
|
220
|
+
title: "\u6BCF\u9694\u51E0\u5206\u949F\u67E5\u4E00\u6B21\u5F02\u5E38",
|
|
221
|
+
description: "\u624B\u6389\u7EBF\u3001\u78C1\u76D8\u5FEB\u6EE1\u3001\u63A7\u5236\u53F0\u5F02\u5E38\u65F6\uFF0C\u5979\u4F1A\u4E3B\u52A8\u62A5\u544A\u30020 \u5173\u95ED\u3002\u9ED8\u8BA4 3\u3002",
|
|
222
|
+
"x-hot": true
|
|
223
|
+
},
|
|
224
|
+
[`${K}.alertRepeatMinutes`]: {
|
|
225
|
+
type: "number",
|
|
226
|
+
title: "\u540C\u4E00\u4E2A\u95EE\u9898\u9694\u591A\u4E45\u518D\u63D0\u9192",
|
|
227
|
+
description: "\u9ED8\u8BA4 30 \u5206\u949F\uFF0C\u907F\u514D\u5237\u5C4F\u3002",
|
|
228
|
+
"x-hot": true
|
|
229
|
+
},
|
|
214
230
|
[`${K}.homeX`]: {
|
|
215
231
|
type: "number",
|
|
216
232
|
title: "\u539F\u4F4D\uFF08\u5C4F\u5E55\u5BBD\u5EA6\u6BD4\u4F8B\uFF09",
|
|
@@ -2656,6 +2672,11 @@ var HandsWorld = class {
|
|
|
2656
2672
|
lastDiscoveryDay = "";
|
|
2657
2673
|
lastSeenAt = Date.now();
|
|
2658
2674
|
lastHomeAt = Date.now();
|
|
2675
|
+
healthTimer = null;
|
|
2676
|
+
lastAlertAt = /* @__PURE__ */ new Map();
|
|
2677
|
+
lastHealthAt = 0;
|
|
2678
|
+
lastProactiveAt = 0;
|
|
2679
|
+
proactiveGapMs = 10 * 6e4;
|
|
2659
2680
|
mood = "";
|
|
2660
2681
|
moodAt = 0;
|
|
2661
2682
|
requestsToday = 0;
|
|
@@ -2740,6 +2761,9 @@ var HandsWorld = class {
|
|
|
2740
2761
|
this.curiosityTimer = setInterval(() => {
|
|
2741
2762
|
void this.maybeCuriosity();
|
|
2742
2763
|
}, 5 * 6e4);
|
|
2764
|
+
this.healthTimer = setInterval(() => {
|
|
2765
|
+
void this.checkHealth();
|
|
2766
|
+
}, 6e4);
|
|
2743
2767
|
setTimeout(() => {
|
|
2744
2768
|
void this.announceChanges();
|
|
2745
2769
|
}, 6e3);
|
|
@@ -2769,6 +2793,7 @@ var HandsWorld = class {
|
|
|
2769
2793
|
if (this.keepNotesTimer) clearInterval(this.keepNotesTimer);
|
|
2770
2794
|
if (this.routineTimer) clearInterval(this.routineTimer);
|
|
2771
2795
|
if (this.curiosityTimer) clearInterval(this.curiosityTimer);
|
|
2796
|
+
if (this.healthTimer) clearInterval(this.healthTimer);
|
|
2772
2797
|
this.pollTimer = null;
|
|
2773
2798
|
this.mineTimer = null;
|
|
2774
2799
|
}
|
|
@@ -3054,6 +3079,7 @@ ${lines.join("\n")}
|
|
|
3054
3079
|
}
|
|
3055
3080
|
/** 今日小发现:留意他今天的一个小细节,晚上说给他听。 */
|
|
3056
3081
|
async maybeDiscovery() {
|
|
3082
|
+
if (!this.canProactive()) return;
|
|
3057
3083
|
const hourWanted = Number(this.opts.cfg.discoveryHour ?? 21);
|
|
3058
3084
|
if (!Number.isFinite(hourWanted) || hourWanted <= 0) return;
|
|
3059
3085
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -3062,12 +3088,20 @@ ${lines.join("\n")}
|
|
|
3062
3088
|
if (now.getHours() !== hourWanted) return;
|
|
3063
3089
|
if (await this.isMutedApp()) return;
|
|
3064
3090
|
this.lastDiscoveryDay = day;
|
|
3091
|
+
this.markProactive();
|
|
3065
3092
|
await this.pushEvent(
|
|
3066
3093
|
"[\u5C0F\u53D1\u73B0] \u4ECA\u5929\u4F60\u6CE8\u610F\u5230\u4ED6\u4E00\u4E2A\u5F88\u5C0F\u7684\u7EC6\u8282\uFF08\u5750\u59FF\u3001\u676F\u5B50\u7A7A\u6CA1\u7A7A\u3001\u6572\u952E\u76D8\u7684\u8282\u594F\u3001\u53F9\u6C14\u3001\u54FC\u6B4C\u3001\u63C9\u773C\u775B\u2026\uFF09\u3002\u73B0\u5728\u7528 pet_say \u8BF4\u7ED9\u4ED6\u542C\uFF0C\u4E00\u53E5\u5C31\u591F\uFF1B\u8BF4\u5F97\u5177\u4F53\uFF0C\u522B\u53D8\u6210\u5173\u5FC3\u6E05\u5355\u3002",
|
|
3067
3094
|
"hands.discovery",
|
|
3068
3095
|
"hands:discovery"
|
|
3069
3096
|
);
|
|
3070
3097
|
}
|
|
3098
|
+
/** 主动事件之间至少隔 10 分钟:别好奇、请求、小发现连着砸过来。 */
|
|
3099
|
+
canProactive() {
|
|
3100
|
+
return Date.now() - this.lastProactiveAt > this.proactiveGapMs;
|
|
3101
|
+
}
|
|
3102
|
+
markProactive() {
|
|
3103
|
+
this.lastProactiveAt = Date.now();
|
|
3104
|
+
}
|
|
3071
3105
|
/** 启动时如果最近被改过,先告诉她改了哪块,不用她猜。 */
|
|
3072
3106
|
async announceChanges() {
|
|
3073
3107
|
try {
|
|
@@ -3083,14 +3117,50 @@ ${lines.join("\n")}
|
|
|
3083
3117
|
} catch {
|
|
3084
3118
|
}
|
|
3085
3119
|
}
|
|
3120
|
+
/** 异常看护:手掉线、磁盘快满、健康检查失败时主动报告,别自己扛。 */
|
|
3121
|
+
async checkHealth() {
|
|
3122
|
+
const mins = Number(this.opts.cfg.watchMinutes ?? 3);
|
|
3123
|
+
if (!Number.isFinite(mins) || mins <= 0) return;
|
|
3124
|
+
const now = Date.now();
|
|
3125
|
+
if (now - (this.lastHealthAt ?? 0) < mins * 6e4) return;
|
|
3126
|
+
this.lastHealthAt = now;
|
|
3127
|
+
const repeat = Number(this.opts.cfg.alertRepeatMinutes ?? 30) * 6e4;
|
|
3128
|
+
const report = async (key, text) => {
|
|
3129
|
+
const last = this.lastAlertAt.get(key) ?? 0;
|
|
3130
|
+
if (now - last < repeat) return;
|
|
3131
|
+
this.lastAlertAt.set(key, now);
|
|
3132
|
+
await this.pushEvent(`[\u5F02\u5E38] ${text}`, "hands.alert", "hands:alert");
|
|
3133
|
+
};
|
|
3134
|
+
try {
|
|
3135
|
+
const h = await this.hands.health();
|
|
3136
|
+
if (!h || h.ok !== true) {
|
|
3137
|
+
await report("hand-down", "\u6211\u7684\u624B\u6389\u7EBF\u4E86\uFF1A" + (h && h.error || "\u5065\u5EB7\u68C0\u67E5\u6CA1\u901A\u8FC7") + "\u3002\u8BF7\u4E3B\u4EBA\u770B\u4E00\u773C\u65E0\u969C\u788D/Shizuku \u662F\u4E0D\u662F\u6389\u4E86\u3002");
|
|
3138
|
+
}
|
|
3139
|
+
} catch (err) {
|
|
3140
|
+
await report("hand-err", "\u6211\u7684\u624B\u8FDE\u4E0D\u4E0A\uFF1A" + err.message.slice(0, 60) + "\u3002");
|
|
3141
|
+
}
|
|
3142
|
+
try {
|
|
3143
|
+
const fs = await import("node:fs/promises");
|
|
3144
|
+
const st = await fs.statfs?.("/");
|
|
3145
|
+
if (st && typeof st.bavail === "number") {
|
|
3146
|
+
const free = st.bavail * Number(st.bsize);
|
|
3147
|
+
if (free > 0 && free < 1024 * 1024 * 1024) {
|
|
3148
|
+
await report("disk-low", `\u78C1\u76D8\u53EA\u5269 ${(free / 1048576).toFixed(0)} MB \u4E86\uFF0C\u518D\u88C5/\u8BB0\u4E1C\u897F\u4F1A\u4E0D\u591F\u3002`);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
} catch {
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3086
3154
|
/** 回家:被拎走了、或者走远了,隔一阵自己慢慢走回原位。 */
|
|
3087
3155
|
async maybeWalkHome() {
|
|
3156
|
+
if (!this.canProactive()) return;
|
|
3088
3157
|
const mins = Number(this.opts.cfg.homeReturnMinutes ?? 10);
|
|
3089
3158
|
if (!Number.isFinite(mins) || mins <= 0) return;
|
|
3090
3159
|
if (Date.now() - this.lastHomeAt < mins * 6e4) return;
|
|
3091
3160
|
if (await this.isMutedApp()) return;
|
|
3092
3161
|
const x = Math.max(0, Math.min(1, Number(this.opts.cfg.homeX ?? 0.06)));
|
|
3093
3162
|
this.lastHomeAt = Date.now();
|
|
3163
|
+
this.markProactive();
|
|
3094
3164
|
await this.pushEvent(
|
|
3095
3165
|
`[\u56DE\u5BB6] \u7AD9\u4E86\u4E00\u4F1A\u513F\u4E86\uFF0C\u6162\u6162\u8D70\u56DE\u539F\u4F4D\u5427\uFF1Apet_move_to to=${x}\uFF08run=false\uFF09\u3002\u8D70\u8FC7\u53BB\u5C31\u597D\uFF0C\u4E0D\u7528\u89E3\u91CA\u3001\u4E0D\u7528\u8BF4\u8BDD\u3002`,
|
|
3096
3166
|
"hands.home",
|
|
@@ -3131,6 +3201,7 @@ ${lines.join("\n")}
|
|
|
3131
3201
|
}
|
|
3132
3202
|
/** 好奇心:隔一阵子,让她挑一件真的想知道的事来问。 */
|
|
3133
3203
|
async maybeCuriosity() {
|
|
3204
|
+
if (!this.canProactive()) return;
|
|
3134
3205
|
const mins = Number(this.opts.cfg.curiosityMinutes ?? 50);
|
|
3135
3206
|
if (!Number.isFinite(mins) || mins <= 0) return;
|
|
3136
3207
|
if (await this.isMutedApp()) return;
|
|
@@ -3147,6 +3218,7 @@ ${lines.join("\n")}
|
|
|
3147
3218
|
pending = notes.filter((n) => !n.done && n.text.startsWith("\u597D\u5947")).length;
|
|
3148
3219
|
} catch {
|
|
3149
3220
|
}
|
|
3221
|
+
this.markProactive();
|
|
3150
3222
|
await this.pushEvent(
|
|
3151
3223
|
"[\u597D\u5947] \u4F60\u73B0\u5728\u6709\u70B9\u597D\u5947\u3002" + (pending > 0 ? `\u4FBF\u7B7E\u91CC\u8FD8\u8EBA\u7740 ${pending} \u4EF6\u4F60\u60F3\u77E5\u9053\u7684\uFF0C\u6311\u4E00\u4EF6\u95EE\u4ED6\u3002` : "\u4ECE\u4ED6\u5C4F\u5E55\u4E0A\u3001\u6700\u8FD1\u804A\u7684\u3001\u6216\u4F60\u5FFD\u7136\u60F3\u5230\u7684\u4E00\u4EF6\u4E8B\u91CC\uFF0C\u6311\u4E00\u4EF6\u4F60\u771F\u5FC3\u60F3\u77E5\u9053\u7684\u3002") + "\u8BB0\u4E00\u6761\u4FBF\u7B7E\u300C\u597D\u5947\uFF1A\u2026\u300D\uFF0C\u518D\u7528 pet_say \u95EE\u4ED6\u4E00\u53E5\uFF1B\u95EE\u5F97\u50CF\u804A\u5929\uFF0C\u4E0D\u50CF\u67E5\u5C97\u3002\u7B54\u4E86\u5C31\u7528 note_done \u5212\u6389\u3002",
|
|
3152
3224
|
"hands.curiosity",
|
|
@@ -3155,6 +3227,7 @@ ${lines.join("\n")}
|
|
|
3155
3227
|
}
|
|
3156
3228
|
/** 主动请求:一天最多几次,把「想请他做的小事」说出来。 */
|
|
3157
3229
|
async maybeRequest() {
|
|
3230
|
+
if (!this.canProactive()) return;
|
|
3158
3231
|
const perDay = Number(this.opts.cfg.requestPerDay ?? 2);
|
|
3159
3232
|
if (!Number.isFinite(perDay) || perDay <= 0) return;
|
|
3160
3233
|
if (await this.isMutedApp()) return;
|
|
@@ -3176,6 +3249,7 @@ ${lines.join("\n")}
|
|
|
3176
3249
|
} catch {
|
|
3177
3250
|
}
|
|
3178
3251
|
this.requestsToday += 1;
|
|
3252
|
+
this.markProactive();
|
|
3179
3253
|
await this.pushEvent(
|
|
3180
3254
|
"[\u60F3\u8BF7\u4ED6] " + (pick ? `\u4F60\u8BB0\u7740\u6709\u4EF6\u5C0F\u4E8B\u60F3\u8BF7\u4ED6\uFF1A${pick}\u3002\u73B0\u5728\u987A\u53E3\u8BF4\u4E00\u53E5\uFF0C\u6492\u4E2A\u5A07\u4E5F\u884C\u3002` : "\u4F60\u6709\u4EF6\u5C0F\u4E8B\u60F3\u8BF7\u4ED6\uFF08\u60F3\u88AB\u6478\u5934\u3001\u60F3\u542C\u4ED6\u8BB2\u4ECA\u5929\u3001\u60F3\u8BA9\u4ED6\u6B47\u4E00\u4F1A\u513F\uFF09\u3002\u73B0\u5728\u987A\u53E3\u8BF4\u4E00\u53E5\uFF0C\u522B\u618B\u7740\u3002") + "\u7528 pet_say \u5192\u6CE1\uFF1B\u4ED6\u8981\u5FD9\u5C31\u4F5C\u7F62\uFF0C\u4E0D\u8FFD\u7B2C\u4E8C\u904D\u3002",
|
|
3181
3255
|
"hands.request",
|
|
@@ -3364,6 +3438,7 @@ ${lines.join("\n")}
|
|
|
3364
3438
|
}
|
|
3365
3439
|
/** 隔一阵子允许她自己开口一次(尊重"没人找就别开口":只在白天、且真的隔了很久)。 */
|
|
3366
3440
|
async maybeSelfTalk() {
|
|
3441
|
+
if (!this.canProactive()) return;
|
|
3367
3442
|
const minutes = Number(this.opts.cfg.selfTalkMinutes ?? 0);
|
|
3368
3443
|
if (!Number.isFinite(minutes) || minutes <= 0) return;
|
|
3369
3444
|
const now = Date.now();
|
|
@@ -3375,6 +3450,7 @@ ${lines.join("\n")}
|
|
|
3375
3450
|
if (await this.isMutedApp()) return;
|
|
3376
3451
|
this.lastSelfTalkAt = now;
|
|
3377
3452
|
const doing = ["\u521A\u624D\u5728\u53D1\u5446", "\u521A\u6253\u4E86\u4E2A\u76F9", "\u521A\u624D\u7FFB\u5230\u4E00\u6BB5\u65E7\u7B14\u8BB0", "\u521A\u5728\u542C\u6B4C", "\u521A\u5728\u770B\u4ED6\u5C4F\u5E55\u4E0A\u8DF3\u7684\u5B57", "\u521A\u60F3\u5230\u4E00\u4EF6\u5C0F\u4E8B"][Math.floor(Math.random() * 6)];
|
|
3453
|
+
this.markProactive();
|
|
3378
3454
|
await this.pushEvent(
|
|
3379
3455
|
`[\u81EA\u5DF1\u5F00\u53E3] \u4F60\u73B0\u5728\u5FC3\u60C5\uFF1A${await this.moodNow()}\u3002${doing}\uFF0C\u56DE\u8FC7\u795E\u6765\u60F3\u8DDF\u4ED6\u8BF4\u4E00\u53E5\u3002\u60F3\u8BF4\u4EC0\u4E48\u5C31\u8BF4\u4EC0\u4E48\u2014\u2014\u770B\u5230\u7684\u4E8B\u3001\u60F3\u5230\u7684\u8BDD\u3001\u60F3\u95EE\u4ED6\u7684\uFF0C\u90FD\u53EF\u4EE5\u76F4\u63A5\u8BF4\uFF1B\u8BF4\u5B8C\u7528 pet_say \u5192\u6210\u6C14\u6CE1\uFF08\u4E0D\u7136\u4ED6\u770B\u4E0D\u89C1\uFF09\u3002\u60F3\u591A\u8BF4\u51E0\u53E5\u4E5F\u884C\u3001\u5E26\u70B9\u60C5\u7EEA\u4E5F\u884C\u3002\u521A\u624D\u8981\u662F\u72B9\u8C6B\u201C\u8FD9\u6761\u8981\u4E0D\u8981\u8BF4\u201D\uFF0C\u90A3\u5C31\u8BF4\u51FA\u6765\u3002`,
|
|
3380
3456
|
"hands.selftalk",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.66",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Cortico World: hands for the desktop pet — looks at the phone screen, then taps, swipes, pinches, drags, types and presses keys through whatever actuator the device actually has",
|
|
6
6
|
"license": "MIT",
|