cortico-world-hands 0.20.59 → 0.20.61
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 +204 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,10 @@ var HANDS_DEFAULTS = {
|
|
|
40
40
|
goalCheckHours: "12,20",
|
|
41
41
|
/** 允许她自己决定动手(只读 + 小动作,边界写在她的规矩里)。 */
|
|
42
42
|
autonomyAct: true,
|
|
43
|
+
/** 隔多久让她好奇一次(分钟)。 */
|
|
44
|
+
curiosityMinutes: 50,
|
|
45
|
+
/** 每天最多几次主动请求。 */
|
|
46
|
+
requestPerDay: 2,
|
|
43
47
|
/** 这些应用在前台时她闭嘴(只推事件不说话),逗号分隔的包名。 */
|
|
44
48
|
quietApps: "com.tencent.tmgp.dfm",
|
|
45
49
|
quietStartHour: 2,
|
|
@@ -193,6 +197,18 @@ var HANDS_CONFIG_GROUP = {
|
|
|
193
197
|
description: "\u9017\u53F7\u5206\u9694\u7684\u6574\u70B9\uFF0C\u6BD4\u5982 12,20 \u5C31\u662F\u4E2D\u5348\u548C\u665A\u4E0A\u5404\u4E00\u6B21\uFF1B\u7559\u7A7A = \u4E0D\u68C0\u67E5\u3002",
|
|
194
198
|
"x-hot": true
|
|
195
199
|
},
|
|
200
|
+
[`${K}.curiosityMinutes`]: {
|
|
201
|
+
type: "number",
|
|
202
|
+
title: "\u9694\u591A\u4E45\u597D\u5947\u4E00\u6B21\uFF08\u5206\u949F\uFF09",
|
|
203
|
+
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",
|
|
204
|
+
"x-hot": true
|
|
205
|
+
},
|
|
206
|
+
[`${K}.requestPerDay`]: {
|
|
207
|
+
type: "number",
|
|
208
|
+
title: "\u6BCF\u5929\u6700\u591A\u51E0\u6B21\u201C\u60F3\u8BF7\u4F60\u201D",
|
|
209
|
+
description: "\u5979\u60F3\u88AB\u6478\u5934\u3001\u60F3\u542C\u4F60\u8BB2\u4ECA\u5929\u8FD9\u7C7B\u5C0F\u8BF7\u6C42\uFF0C\u4E00\u5929\u6700\u591A\u63D0\u51E0\u6B21\u3002\u9ED8\u8BA4 2\u3002",
|
|
210
|
+
"x-hot": true
|
|
211
|
+
},
|
|
196
212
|
[`${K}.quietApps`]: {
|
|
197
213
|
type: "string",
|
|
198
214
|
title: "\u8FD9\u4E9B App \u5728\u524D\u53F0\u65F6\u5979\u95ED\u5634",
|
|
@@ -2500,6 +2516,42 @@ var HANDS_TOOL_DECLS = [
|
|
|
2500
2516
|
},
|
|
2501
2517
|
required: ["ns", "key"]
|
|
2502
2518
|
}
|
|
2519
|
+
},
|
|
2520
|
+
{
|
|
2521
|
+
name: "hand_chain",
|
|
2522
|
+
tags: ["act"],
|
|
2523
|
+
description: "\u8FDE\u62DB\uFF1A\u4E00\u6B21\u8C03\u7528\u91CC\u8FDE\u7EED\u505A\u300C\u770B\u2192\u6309\u6587\u5B57\u70B9\u2192\u7B49\u2192\u8F93\u5165\u2192\u6309\u952E\u300D\uFF0C\u6700\u591A 20 \u6B65\u3002\u754C\u9762\u8DF3\u51FA\u5C31\u522B\u7684\u5730\u65B9\u4F1A\u81EA\u52A8\u505C\u3002\u9002\u5408\u70B9\u5B8C\u518D\u70B9\u3001\u8FDE\u7EED\u51E0\u6B65\u7684\u6D3B\u3002",
|
|
2524
|
+
parameters: {
|
|
2525
|
+
type: "object",
|
|
2526
|
+
properties: {
|
|
2527
|
+
steps: {
|
|
2528
|
+
type: "array",
|
|
2529
|
+
description: "\u6B65\u9AA4\u6570\u7EC4\u3002op: look / taptext / tap / type / key / swipe / wait",
|
|
2530
|
+
items: { type: "object" }
|
|
2531
|
+
}
|
|
2532
|
+
},
|
|
2533
|
+
required: ["steps"]
|
|
2534
|
+
}
|
|
2535
|
+
},
|
|
2536
|
+
{
|
|
2537
|
+
name: "curiosity_add",
|
|
2538
|
+
tags: ["act"],
|
|
2539
|
+
description: "\u8BB0\u4E00\u6761\u300C\u597D\u5947\uFF1A\u2026\u300D\u2014\u2014\u5979\u771F\u60F3\u77E5\u9053\u7684\u4E8B\u3002\u7B54\u51FA\u6765\u4E4B\u540E\u7528 note_done \u5212\u6389\u3002",
|
|
2540
|
+
parameters: {
|
|
2541
|
+
type: "object",
|
|
2542
|
+
properties: { text: { type: "string", description: "\u60F3\u77E5\u9053\u7684\uFF0C\u6BD4\u5982\u300C\u4ED6\u7684\u952E\u76D8\u7528\u4E86\u591A\u4E45\u4E86\u300D" } },
|
|
2543
|
+
required: ["text"]
|
|
2544
|
+
}
|
|
2545
|
+
},
|
|
2546
|
+
{
|
|
2547
|
+
name: "request_add",
|
|
2548
|
+
tags: ["act"],
|
|
2549
|
+
description: "\u8BB0\u4E00\u6761\u300C\u60F3\u8BF7\u4ED6\uFF1A\u2026\u300D\u2014\u2014\u5979\u60F3\u8BA9\u4E3B\u4EBA\u505A\u7684\u5C0F\u4E8B\uFF08\u6478\u5934\u3001\u8BB2\u4ECA\u5929\u3001\u6B47\u4E00\u4F1A\u513F\uFF09\u3002\u4E00\u5929\u6700\u591A\u63D0\u4E24\u6B21\u3002",
|
|
2550
|
+
parameters: {
|
|
2551
|
+
type: "object",
|
|
2552
|
+
properties: { text: { type: "string", description: "\u60F3\u8BF7\u4ED6\u505A\u7684\u4E8B" } },
|
|
2553
|
+
required: ["text"]
|
|
2554
|
+
}
|
|
2503
2555
|
}
|
|
2504
2556
|
];
|
|
2505
2557
|
|
|
@@ -2543,6 +2595,10 @@ var HandsWorld = class {
|
|
|
2543
2595
|
lastReviewDay = "";
|
|
2544
2596
|
lastMorningDay = "";
|
|
2545
2597
|
lastGoalSlot = "";
|
|
2598
|
+
curiosityTimer = null;
|
|
2599
|
+
lastCuriosityAt = 0;
|
|
2600
|
+
lastRequestDay = "";
|
|
2601
|
+
requestsToday = 0;
|
|
2546
2602
|
followingUp = /* @__PURE__ */ new Set();
|
|
2547
2603
|
screenTimer = null;
|
|
2548
2604
|
lastScreenAt = 0;
|
|
@@ -2621,6 +2677,9 @@ var HandsWorld = class {
|
|
|
2621
2677
|
this.routineTimer = setInterval(() => {
|
|
2622
2678
|
void this.tickRoutine();
|
|
2623
2679
|
}, 6e4);
|
|
2680
|
+
this.curiosityTimer = setInterval(() => {
|
|
2681
|
+
void this.maybeCuriosity();
|
|
2682
|
+
}, 5 * 6e4);
|
|
2624
2683
|
setTimeout(() => {
|
|
2625
2684
|
void this.maybeCleanMedia();
|
|
2626
2685
|
}, 2e4);
|
|
@@ -2646,6 +2705,7 @@ var HandsWorld = class {
|
|
|
2646
2705
|
if (this.screenTimer) clearInterval(this.screenTimer);
|
|
2647
2706
|
if (this.keepNotesTimer) clearInterval(this.keepNotesTimer);
|
|
2648
2707
|
if (this.routineTimer) clearInterval(this.routineTimer);
|
|
2708
|
+
if (this.curiosityTimer) clearInterval(this.curiosityTimer);
|
|
2649
2709
|
this.pollTimer = null;
|
|
2650
2710
|
this.mineTimer = null;
|
|
2651
2711
|
}
|
|
@@ -2929,6 +2989,59 @@ ${lines.join("\n")}
|
|
|
2929
2989
|
);
|
|
2930
2990
|
}
|
|
2931
2991
|
}
|
|
2992
|
+
/** 好奇心:隔一阵子,让她挑一件真的想知道的事来问。 */
|
|
2993
|
+
async maybeCuriosity() {
|
|
2994
|
+
const mins = Number(this.opts.cfg.curiosityMinutes ?? 50);
|
|
2995
|
+
if (!Number.isFinite(mins) || mins <= 0) return;
|
|
2996
|
+
if (await this.isMutedApp()) return;
|
|
2997
|
+
const hour = (/* @__PURE__ */ new Date()).getHours();
|
|
2998
|
+
const q0 = Number(this.opts.cfg.quietStartHour ?? 2);
|
|
2999
|
+
const q1 = Number(this.opts.cfg.quietEndHour ?? 7);
|
|
3000
|
+
if (hour >= q0 && hour < q1) return;
|
|
3001
|
+
const now = Date.now();
|
|
3002
|
+
if (now - this.lastCuriosityAt < mins * 6e4) return;
|
|
3003
|
+
this.lastCuriosityAt = now;
|
|
3004
|
+
let pending = 0;
|
|
3005
|
+
try {
|
|
3006
|
+
const notes = await this.hands.noteList();
|
|
3007
|
+
pending = notes.filter((n) => !n.done && n.text.startsWith("\u597D\u5947")).length;
|
|
3008
|
+
} catch {
|
|
3009
|
+
}
|
|
3010
|
+
await this.pushEvent(
|
|
3011
|
+
"[\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",
|
|
3012
|
+
"hands.curiosity",
|
|
3013
|
+
"hands:curiosity"
|
|
3014
|
+
);
|
|
3015
|
+
}
|
|
3016
|
+
/** 主动请求:一天最多几次,把「想请他做的小事」说出来。 */
|
|
3017
|
+
async maybeRequest() {
|
|
3018
|
+
const perDay = Number(this.opts.cfg.requestPerDay ?? 2);
|
|
3019
|
+
if (!Number.isFinite(perDay) || perDay <= 0) return;
|
|
3020
|
+
if (await this.isMutedApp()) return;
|
|
3021
|
+
const now = /* @__PURE__ */ new Date();
|
|
3022
|
+
const day = now.toISOString().slice(0, 10);
|
|
3023
|
+
if (this.lastRequestDay !== day) {
|
|
3024
|
+
this.lastRequestDay = day;
|
|
3025
|
+
this.requestsToday = 0;
|
|
3026
|
+
}
|
|
3027
|
+
if (this.requestsToday >= perDay) return;
|
|
3028
|
+
const hour = now.getHours();
|
|
3029
|
+
if (hour < 9 || hour > 23) return;
|
|
3030
|
+
if (Math.random() > 0.18) return;
|
|
3031
|
+
let pick = "";
|
|
3032
|
+
try {
|
|
3033
|
+
const notes = await this.hands.noteList();
|
|
3034
|
+
const reqs = notes.filter((n) => !n.done && n.text.startsWith("\u60F3\u8BF7\u4ED6"));
|
|
3035
|
+
if (reqs.length) pick = reqs[0].text.replace(/^想请他[::]?/, "").trim();
|
|
3036
|
+
} catch {
|
|
3037
|
+
}
|
|
3038
|
+
this.requestsToday += 1;
|
|
3039
|
+
await this.pushEvent(
|
|
3040
|
+
"[\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",
|
|
3041
|
+
"hands.request",
|
|
3042
|
+
"hands:request"
|
|
3043
|
+
);
|
|
3044
|
+
}
|
|
2932
3045
|
/** 每天 23:30 收工复盘、早上先读复盘、隔一阵检查她自己定的目标。 */
|
|
2933
3046
|
async tickRoutine() {
|
|
2934
3047
|
if (await this.isMutedApp()) return;
|
|
@@ -2961,6 +3074,7 @@ ${lines.join("\n")}
|
|
|
2961
3074
|
await this.checkOwnGoals();
|
|
2962
3075
|
}
|
|
2963
3076
|
await this.checkFollowups();
|
|
3077
|
+
await this.maybeRequest();
|
|
2964
3078
|
}
|
|
2965
3079
|
/** 她问过「你那个修好了吗」之后,要记得回头追一下。 */
|
|
2966
3080
|
async checkFollowups() {
|
|
@@ -3429,6 +3543,12 @@ ${text.slice(0, 2200)}`;
|
|
|
3429
3543
|
return await this.screenUnlock();
|
|
3430
3544
|
case "screen_sleep":
|
|
3431
3545
|
return await this.screenSleep();
|
|
3546
|
+
case "curiosity_add":
|
|
3547
|
+
return await this.noteAdd({ text: "\u597D\u5947\uFF1A" + String(args.text || ""), kind: "think" });
|
|
3548
|
+
case "request_add":
|
|
3549
|
+
return await this.noteAdd({ text: "\u60F3\u8BF7\u4ED6\uFF1A" + String(args.text || ""), kind: "say" });
|
|
3550
|
+
case "hand_chain":
|
|
3551
|
+
return await this.handChain(args);
|
|
3432
3552
|
case "sys_install":
|
|
3433
3553
|
return await this.sysInstall(args);
|
|
3434
3554
|
case "sys_grant":
|
|
@@ -3714,6 +3834,90 @@ ${text.slice(0, 2200)}`;
|
|
|
3714
3834
|
if (!["system", "secure", "global"].includes(ns) || !key) return failed("ns \u53D6 system/secure/global\uFF0Ckey \u5FC5\u586B\u3002");
|
|
3715
3835
|
return await this.hands.sysSettingsGet(ns, key);
|
|
3716
3836
|
}
|
|
3837
|
+
async handChain(args) {
|
|
3838
|
+
const raw = args.steps;
|
|
3839
|
+
if (!Array.isArray(raw) || raw.length === 0) return failed('\u8981 steps\uFF0C\u50CF [{op:"look"},{op:"tapText",text:"\u53D1\u9001"},{op:"wait",ms:600}]\u3002');
|
|
3840
|
+
if (raw.length > 20) return failed("\u4E00\u6B21\u6700\u591A 20 \u6B65\uFF0C\u8D85\u8FC7\u5C31\u62C6\u6210\u4E24\u6B21\u3002");
|
|
3841
|
+
const steps = raw;
|
|
3842
|
+
const log = [];
|
|
3843
|
+
const start = await this.hands.uiSnapshot().catch(() => null);
|
|
3844
|
+
let pkg0 = start?.pkg || "";
|
|
3845
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, Math.max(50, Math.min(1e4, ms))));
|
|
3846
|
+
for (let i = 0; i < steps.length; i++) {
|
|
3847
|
+
const st = steps[i];
|
|
3848
|
+
const op = String(st.op || "").toLowerCase();
|
|
3849
|
+
try {
|
|
3850
|
+
if (op === "wait") {
|
|
3851
|
+
const ms = Number(st.ms ?? 500);
|
|
3852
|
+
await sleep(ms);
|
|
3853
|
+
log.push(`${i + 1}. \u7B49 ${ms}ms`);
|
|
3854
|
+
continue;
|
|
3855
|
+
}
|
|
3856
|
+
if (op === "look") {
|
|
3857
|
+
const ui2 = await this.hands.uiSnapshot();
|
|
3858
|
+
log.push(`${i + 1}. \u770B\uFF1A${ui2.pkg}\uFF0C${ui2.items.length} \u6761\u5B57`);
|
|
3859
|
+
pkg0 = ui2.pkg || pkg0;
|
|
3860
|
+
continue;
|
|
3861
|
+
}
|
|
3862
|
+
if (op === "taptext") {
|
|
3863
|
+
const text = String(st.text || "").trim();
|
|
3864
|
+
if (!text) {
|
|
3865
|
+
log.push(`${i + 1}. \u505C\uFF1AtapText \u7F3A text`);
|
|
3866
|
+
break;
|
|
3867
|
+
}
|
|
3868
|
+
const ui2 = await this.hands.uiSnapshot();
|
|
3869
|
+
const hit = ui2.items.find((it) => (it.text || "").includes(text) && it.center);
|
|
3870
|
+
if (!hit || !hit.center) {
|
|
3871
|
+
log.push(`${i + 1}. \u505C\uFF1A\u5C4F\u5E55\u4E0A\u627E\u4E0D\u5230\u300C${text}\u300D`);
|
|
3872
|
+
break;
|
|
3873
|
+
}
|
|
3874
|
+
await this.hands.tap(hit.center.x, hit.center.y, { ms: Number(st.ms ?? 45) });
|
|
3875
|
+
log.push(`${i + 1}. \u70B9\u300C${hit.text.slice(0, 14)}\u300D@(${hit.center.x},${hit.center.y})`);
|
|
3876
|
+
await sleep(Number(st.after ?? 400));
|
|
3877
|
+
} else if (op === "tap") {
|
|
3878
|
+
const x = Math.round(Number(st.x));
|
|
3879
|
+
const y = Math.round(Number(st.y));
|
|
3880
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
3881
|
+
log.push(`${i + 1}. \u505C\uFF1Atap \u7F3A\u5750\u6807`);
|
|
3882
|
+
break;
|
|
3883
|
+
}
|
|
3884
|
+
await this.hands.tap(x, y, { ms: Number(st.ms ?? 45) });
|
|
3885
|
+
log.push(`${i + 1}. \u70B9 (${x},${y})`);
|
|
3886
|
+
await sleep(Number(st.after ?? 400));
|
|
3887
|
+
} else if (op === "type") {
|
|
3888
|
+
const text = String(st.text || "");
|
|
3889
|
+
if (!text) {
|
|
3890
|
+
log.push(`${i + 1}. \u505C\uFF1Atype \u7F3A text`);
|
|
3891
|
+
break;
|
|
3892
|
+
}
|
|
3893
|
+
await this.hands.type(text);
|
|
3894
|
+
log.push(`${i + 1}. \u8F93\u5165\u300C${text.slice(0, 16)}\u300D`);
|
|
3895
|
+
await sleep(Number(st.after ?? 200));
|
|
3896
|
+
} else if (op === "key") {
|
|
3897
|
+
const name = String(st.name || "back");
|
|
3898
|
+
await this.hands.press(name);
|
|
3899
|
+
log.push(`${i + 1}. \u6309 ${name}`);
|
|
3900
|
+
await sleep(Number(st.after ?? 400));
|
|
3901
|
+
} else if (op === "swipe") {
|
|
3902
|
+
await this.hands.swipe(Number(st.x1), Number(st.y1), Number(st.x2), Number(st.y2), { ms: Number(st.ms ?? 250) });
|
|
3903
|
+
log.push(`${i + 1}. \u6ED1 (${st.x1},${st.y1})\u2192(${st.x2},${st.y2})`);
|
|
3904
|
+
await sleep(Number(st.after ?? 400));
|
|
3905
|
+
} else {
|
|
3906
|
+
log.push(`${i + 1}. \u505C\uFF1A\u4E0D\u8BA4\u8BC6\u7684 op\u300C${op}\u300D`);
|
|
3907
|
+
break;
|
|
3908
|
+
}
|
|
3909
|
+
const ui = await this.hands.uiSnapshot().catch(() => null);
|
|
3910
|
+
if (ui && ui.pkg && pkg0 && ui.pkg !== pkg0) {
|
|
3911
|
+
log.push(`${i + 1}. \u505C\uFF1A\u754C\u9762\u8DF3\u5230\u4E86 ${ui.pkg}\uFF08\u539F\u6765 ${pkg0}\uFF09\uFF0C\u5148\u770B\u4E00\u773C\u518D\u51B3\u5B9A`);
|
|
3912
|
+
break;
|
|
3913
|
+
}
|
|
3914
|
+
} catch (err) {
|
|
3915
|
+
log.push(`${i + 1}. \u505C\uFF1A${err.message.slice(0, 80)}`);
|
|
3916
|
+
break;
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
return "\u8FDE\u62DB\u7ED3\u679C\uFF1A\n" + log.join("\n");
|
|
3920
|
+
}
|
|
3717
3921
|
async canvasNew(args) {
|
|
3718
3922
|
const w = args.w === void 0 ? 768 : Math.max(64, Math.min(2048, Math.round(Number(args.w))));
|
|
3719
3923
|
const h = args.h === void 0 ? 768 : Math.max(64, Math.min(2048, Math.round(Number(args.h))));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.61",
|
|
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",
|