cortico-world-hands 0.20.63 → 0.20.65

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.
Files changed (2) hide show
  1. package/dist/index.js +91 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -48,6 +48,10 @@ var HANDS_DEFAULTS = {
48
48
  discoveryHour: 21,
49
49
  /** 他离开多久回来,她会招呼一句(分钟)。0 关闭。 */
50
50
  returnGreetMinutes: 30,
51
+ /** 原位(屏幕宽度比例 0–1)。被拎走后她会自己走回去。 */
52
+ homeX: 0.06,
53
+ /** 隔多久回一次原位(分钟)。0 关闭。 */
54
+ homeReturnMinutes: 10,
51
55
  /** 这些应用在前台时她闭嘴(只推事件不说话),逗号分隔的包名。 */
52
56
  quietApps: "com.tencent.tmgp.dfm",
53
57
  quietStartHour: 2,
@@ -207,6 +211,18 @@ var HANDS_CONFIG_GROUP = {
207
211
  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",
208
212
  "x-hot": true
209
213
  },
214
+ [`${K}.homeX`]: {
215
+ type: "number",
216
+ title: "\u539F\u4F4D\uFF08\u5C4F\u5E55\u5BBD\u5EA6\u6BD4\u4F8B\uFF09",
217
+ description: "0 \u6700\u5DE6\u30011 \u6700\u53F3\uFF1B\u5979\u8D70\u56DE\u53BB\u7684\u4F4D\u7F6E\u3002\u9ED8\u8BA4 0.06\uFF08\u5DE6\u4E0B\u89D2\uFF09\u3002",
218
+ "x-hot": true
219
+ },
220
+ [`${K}.homeReturnMinutes`]: {
221
+ type: "number",
222
+ title: "\u9694\u591A\u4E45\u81EA\u5DF1\u8D70\u56DE\u539F\u4F4D\uFF08\u5206\u949F\uFF09",
223
+ description: "\u88AB\u62CE\u8D70\u6216\u8D70\u5F00\u540E\uFF0C\u8FC7\u8FD9\u4E48\u4E45\u5979\u4F1A\u6162\u6162\u8D70\u56DE\u53BB\u30020 \u5173\u95ED\u3002\u9ED8\u8BA4 10\u3002",
224
+ "x-hot": true
225
+ },
210
226
  [`${K}.returnGreetMinutes`]: {
211
227
  type: "number",
212
228
  title: "\u4ED6\u79BB\u5F00\u591A\u4E45\u56DE\u6765\u8981\u62DB\u547C",
@@ -2581,6 +2597,16 @@ var HANDS_TOOL_DECLS = [
2581
2597
  },
2582
2598
  required: ["text"]
2583
2599
  }
2600
+ },
2601
+ {
2602
+ name: "mood_set",
2603
+ tags: ["act"],
2604
+ description: "\u5199\u4E0B\u6211\u6B64\u523B\u7684\u5FC3\u60C5\uFF08\u4ECA\u5929\u4EE5\u5185\u90FD\u7B97\u8FD9\u53E5\uFF0C\u4E0D\u4F1A\u88AB\u968F\u673A\u5FC3\u60C5\u76D6\u6389\uFF09\u3002\u6BD4\u5982\u300C\u6709\u70B9\u95F7\u300D\u300C\u633A\u5F00\u5FC3\uFF0C\u56E0\u4E3A\u4ED6\u8BF4\u2026\u300D\u3002",
2605
+ parameters: {
2606
+ type: "object",
2607
+ properties: { text: { type: "string", description: "\u5FC3\u60C5\uFF0C\u4E00\u53E5\u8BDD" } },
2608
+ required: ["text"]
2609
+ }
2584
2610
  }
2585
2611
  ];
2586
2612
 
@@ -2629,6 +2655,9 @@ var HandsWorld = class {
2629
2655
  lastRequestDay = "";
2630
2656
  lastDiscoveryDay = "";
2631
2657
  lastSeenAt = Date.now();
2658
+ lastHomeAt = Date.now();
2659
+ lastProactiveAt = 0;
2660
+ proactiveGapMs = 10 * 6e4;
2632
2661
  mood = "";
2633
2662
  moodAt = 0;
2634
2663
  requestsToday = 0;
@@ -2713,6 +2742,9 @@ var HandsWorld = class {
2713
2742
  this.curiosityTimer = setInterval(() => {
2714
2743
  void this.maybeCuriosity();
2715
2744
  }, 5 * 6e4);
2745
+ setTimeout(() => {
2746
+ void this.announceChanges();
2747
+ }, 6e3);
2716
2748
  setTimeout(() => {
2717
2749
  void this.maybeCleanMedia();
2718
2750
  }, 2e4);
@@ -3024,6 +3056,7 @@ ${lines.join("\n")}
3024
3056
  }
3025
3057
  /** 今日小发现:留意他今天的一个小细节,晚上说给他听。 */
3026
3058
  async maybeDiscovery() {
3059
+ if (!this.canProactive()) return;
3027
3060
  const hourWanted = Number(this.opts.cfg.discoveryHour ?? 21);
3028
3061
  if (!Number.isFinite(hourWanted) || hourWanted <= 0) return;
3029
3062
  const now = /* @__PURE__ */ new Date();
@@ -3032,13 +3065,61 @@ ${lines.join("\n")}
3032
3065
  if (now.getHours() !== hourWanted) return;
3033
3066
  if (await this.isMutedApp()) return;
3034
3067
  this.lastDiscoveryDay = day;
3068
+ this.markProactive();
3035
3069
  await this.pushEvent(
3036
3070
  "[\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",
3037
3071
  "hands.discovery",
3038
3072
  "hands:discovery"
3039
3073
  );
3040
3074
  }
3075
+ /** 主动事件之间至少隔 10 分钟:别好奇、请求、小发现连着砸过来。 */
3076
+ canProactive() {
3077
+ return Date.now() - this.lastProactiveAt > this.proactiveGapMs;
3078
+ }
3079
+ markProactive() {
3080
+ this.lastProactiveAt = Date.now();
3081
+ }
3082
+ /** 启动时如果最近被改过,先告诉她改了哪块,不用她猜。 */
3083
+ async announceChanges() {
3084
+ try {
3085
+ const notes = await this.hands.noteList();
3086
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(5, 10);
3087
+ const hit = notes.filter((n) => !n.done && (n.text || "").startsWith("\u4ECA\u665A\u52A8\u4E86")).slice(-1)[0];
3088
+ if (!hit) return;
3089
+ await this.pushEvent(
3090
+ `[\u53D8\u66F4] ${hit.text}\u3002\u8FD9\u662F\u4E3B\u4EBA\uFF08\u548C\u4ED6\u7684\u5E2E\u624B\uFF09\u6539\u7684\uFF0C\u4E0D\u662F\u4F60\u6539\u7684\u2014\u2014\u4F60\u53EA\u9700\u8981\u77E5\u9053\u6539\u4E86\u54EA\u513F\uFF0C\u4E0D\u7528\u731C\u3002`,
3091
+ "hands.change",
3092
+ "hands:change"
3093
+ );
3094
+ } catch {
3095
+ }
3096
+ }
3097
+ /** 回家:被拎走了、或者走远了,隔一阵自己慢慢走回原位。 */
3098
+ async maybeWalkHome() {
3099
+ if (!this.canProactive()) return;
3100
+ const mins = Number(this.opts.cfg.homeReturnMinutes ?? 10);
3101
+ if (!Number.isFinite(mins) || mins <= 0) return;
3102
+ if (Date.now() - this.lastHomeAt < mins * 6e4) return;
3103
+ if (await this.isMutedApp()) return;
3104
+ const x = Math.max(0, Math.min(1, Number(this.opts.cfg.homeX ?? 0.06)));
3105
+ this.lastHomeAt = Date.now();
3106
+ this.markProactive();
3107
+ await this.pushEvent(
3108
+ `[\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`,
3109
+ "hands.home",
3110
+ "hands:home"
3111
+ );
3112
+ }
3041
3113
  /** 心情:每两小时换一次,带进“自己开口”的语气里。 */
3114
+ async moodNow() {
3115
+ try {
3116
+ const notes = await this.hands.noteList();
3117
+ const mine = notes.filter((n) => !n.done && (n.text || "").startsWith("\u5FC3\u60C5")).slice(-1)[0];
3118
+ if (mine) return mine.text.replace(/^心情[::]\s*/, "").slice(0, 30);
3119
+ } catch {
3120
+ }
3121
+ return this.currentMood();
3122
+ }
3042
3123
  currentMood() {
3043
3124
  const now = Date.now();
3044
3125
  if (!this.mood || now - this.moodAt > 2 * 36e5) {
@@ -3063,6 +3144,7 @@ ${lines.join("\n")}
3063
3144
  }
3064
3145
  /** 好奇心:隔一阵子,让她挑一件真的想知道的事来问。 */
3065
3146
  async maybeCuriosity() {
3147
+ if (!this.canProactive()) return;
3066
3148
  const mins = Number(this.opts.cfg.curiosityMinutes ?? 50);
3067
3149
  if (!Number.isFinite(mins) || mins <= 0) return;
3068
3150
  if (await this.isMutedApp()) return;
@@ -3079,6 +3161,7 @@ ${lines.join("\n")}
3079
3161
  pending = notes.filter((n) => !n.done && n.text.startsWith("\u597D\u5947")).length;
3080
3162
  } catch {
3081
3163
  }
3164
+ this.markProactive();
3082
3165
  await this.pushEvent(
3083
3166
  "[\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",
3084
3167
  "hands.curiosity",
@@ -3087,6 +3170,7 @@ ${lines.join("\n")}
3087
3170
  }
3088
3171
  /** 主动请求:一天最多几次,把「想请他做的小事」说出来。 */
3089
3172
  async maybeRequest() {
3173
+ if (!this.canProactive()) return;
3090
3174
  const perDay = Number(this.opts.cfg.requestPerDay ?? 2);
3091
3175
  if (!Number.isFinite(perDay) || perDay <= 0) return;
3092
3176
  if (await this.isMutedApp()) return;
@@ -3108,6 +3192,7 @@ ${lines.join("\n")}
3108
3192
  } catch {
3109
3193
  }
3110
3194
  this.requestsToday += 1;
3195
+ this.markProactive();
3111
3196
  await this.pushEvent(
3112
3197
  "[\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",
3113
3198
  "hands.request",
@@ -3148,6 +3233,7 @@ ${lines.join("\n")}
3148
3233
  await this.checkFollowups();
3149
3234
  await this.maybeRequest();
3150
3235
  await this.maybeDiscovery();
3236
+ await this.maybeWalkHome();
3151
3237
  }
3152
3238
  /** 她问过「你那个修好了吗」之后,要记得回头追一下。 */
3153
3239
  async checkFollowups() {
@@ -3295,6 +3381,7 @@ ${lines.join("\n")}
3295
3381
  }
3296
3382
  /** 隔一阵子允许她自己开口一次(尊重"没人找就别开口":只在白天、且真的隔了很久)。 */
3297
3383
  async maybeSelfTalk() {
3384
+ if (!this.canProactive()) return;
3298
3385
  const minutes = Number(this.opts.cfg.selfTalkMinutes ?? 0);
3299
3386
  if (!Number.isFinite(minutes) || minutes <= 0) return;
3300
3387
  const now = Date.now();
@@ -3306,8 +3393,9 @@ ${lines.join("\n")}
3306
3393
  if (await this.isMutedApp()) return;
3307
3394
  this.lastSelfTalkAt = now;
3308
3395
  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)];
3396
+ this.markProactive();
3309
3397
  await this.pushEvent(
3310
- `[\u81EA\u5DF1\u5F00\u53E3] \u4F60\u73B0\u5728\u5FC3\u60C5\uFF1A${this.currentMood()}\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`,
3398
+ `[\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`,
3311
3399
  "hands.selftalk",
3312
3400
  "hands:selftalk"
3313
3401
  );
@@ -3622,6 +3710,8 @@ ${text.slice(0, 2200)}`;
3622
3710
  return await this.screenUnlock();
3623
3711
  case "screen_sleep":
3624
3712
  return await this.screenSleep();
3713
+ case "mood_set":
3714
+ return await this.noteAdd({ text: "\u5FC3\u60C5\uFF1A" + String(args.text || ""), kind: "think" });
3625
3715
  case "pref_note":
3626
3716
  return await this.noteAdd({ text: (args.like === true ? "\u504F\u597D\uFF08\u559C\u6B22\uFF09\uFF1A" : "\u504F\u597D\uFF08\u4E0D\u559C\u6B22\uFF09\uFF1A") + String(args.text || ""), kind: "think" });
3627
3717
  case "curiosity_add":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.63",
3
+ "version": "0.20.65",
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",