cortico-world-hands 0.20.65 → 0.20.67

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 +93 -0
  2. 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",
@@ -1189,6 +1205,24 @@ var EyesClient = class {
1189
1205
  ageMs: 0
1190
1206
  };
1191
1207
  }
1208
+ /** 四块放大:把整屏切成 2×2 再拼成一张大图,凑近看细节用。 */
1209
+ async quadFrame(maxWidth = 1440, quality = 76) {
1210
+ try {
1211
+ const w = Math.max(160, Math.min(2160, Math.round(maxWidth)));
1212
+ const q = Math.max(20, Math.min(95, Math.round(quality)));
1213
+ const res = await get(this.port(), `/screen.jpg?tiles=1&max=${w}&q=${q}`, 15e3);
1214
+ if (res.status !== 200 || res.body.length === 0) return null;
1215
+ return {
1216
+ bytes: new Uint8Array(res.body),
1217
+ width: Number.parseInt(res.header("x-width"), 10) || 0,
1218
+ height: Number.parseInt(res.header("x-height"), 10) || 0,
1219
+ pkg: flat(res.header("x-pkg"), 120),
1220
+ ageMs: Number.parseInt(res.header("x-age-ms"), 10) || 0
1221
+ };
1222
+ } catch {
1223
+ return null;
1224
+ }
1225
+ }
1192
1226
  async frame(maxWidth, quality) {
1193
1227
  try {
1194
1228
  const w = Math.max(160, Math.min(2160, Math.round(maxWidth)));
@@ -2607,6 +2641,15 @@ var HANDS_TOOL_DECLS = [
2607
2641
  properties: { text: { type: "string", description: "\u5FC3\u60C5\uFF0C\u4E00\u53E5\u8BDD" } },
2608
2642
  required: ["text"]
2609
2643
  }
2644
+ },
2645
+ {
2646
+ name: "hand_quad",
2647
+ tags: ["read"],
2648
+ description: "\u56DB\u5757\u653E\u5927\uFF1A\u628A\u6574\u5C4F\u5207\u6210 2\xD72 \u518D\u62FC\u6210\u4E00\u5F20\u5927\u56FE\uFF0C\u51D1\u8FD1\u770B\u5C0F\u5B57/\u56FE\u6807/\u56FE\u8868\u7EC6\u8282\u3002\u770B\u4E0D\u6E05\u56FE\u5F62\u65F6\u7528\u5B83\uFF0C\u522B\u731C\u3002",
2649
+ parameters: {
2650
+ type: "object",
2651
+ properties: { max: { type: "integer", description: "\u8F93\u51FA\u5BBD\u5EA6\uFF0C\u9ED8\u8BA4 1440" } }
2652
+ }
2610
2653
  }
2611
2654
  ];
2612
2655
 
@@ -2656,6 +2699,9 @@ var HandsWorld = class {
2656
2699
  lastDiscoveryDay = "";
2657
2700
  lastSeenAt = Date.now();
2658
2701
  lastHomeAt = Date.now();
2702
+ healthTimer = null;
2703
+ lastAlertAt = /* @__PURE__ */ new Map();
2704
+ lastHealthAt = 0;
2659
2705
  lastProactiveAt = 0;
2660
2706
  proactiveGapMs = 10 * 6e4;
2661
2707
  mood = "";
@@ -2742,6 +2788,9 @@ var HandsWorld = class {
2742
2788
  this.curiosityTimer = setInterval(() => {
2743
2789
  void this.maybeCuriosity();
2744
2790
  }, 5 * 6e4);
2791
+ this.healthTimer = setInterval(() => {
2792
+ void this.checkHealth();
2793
+ }, 6e4);
2745
2794
  setTimeout(() => {
2746
2795
  void this.announceChanges();
2747
2796
  }, 6e3);
@@ -2771,6 +2820,7 @@ var HandsWorld = class {
2771
2820
  if (this.keepNotesTimer) clearInterval(this.keepNotesTimer);
2772
2821
  if (this.routineTimer) clearInterval(this.routineTimer);
2773
2822
  if (this.curiosityTimer) clearInterval(this.curiosityTimer);
2823
+ if (this.healthTimer) clearInterval(this.healthTimer);
2774
2824
  this.pollTimer = null;
2775
2825
  this.mineTimer = null;
2776
2826
  }
@@ -3094,6 +3144,40 @@ ${lines.join("\n")}
3094
3144
  } catch {
3095
3145
  }
3096
3146
  }
3147
+ /** 异常看护:手掉线、磁盘快满、健康检查失败时主动报告,别自己扛。 */
3148
+ async checkHealth() {
3149
+ const mins = Number(this.opts.cfg.watchMinutes ?? 3);
3150
+ if (!Number.isFinite(mins) || mins <= 0) return;
3151
+ const now = Date.now();
3152
+ if (now - (this.lastHealthAt ?? 0) < mins * 6e4) return;
3153
+ this.lastHealthAt = now;
3154
+ const repeat = Number(this.opts.cfg.alertRepeatMinutes ?? 30) * 6e4;
3155
+ const report = async (key, text) => {
3156
+ const last = this.lastAlertAt.get(key) ?? 0;
3157
+ if (now - last < repeat) return;
3158
+ this.lastAlertAt.set(key, now);
3159
+ await this.pushEvent(`[\u5F02\u5E38] ${text}`, "hands.alert", "hands:alert");
3160
+ };
3161
+ try {
3162
+ const h = await this.hands.health();
3163
+ if (!h || h.ok !== true) {
3164
+ 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");
3165
+ }
3166
+ } catch (err) {
3167
+ await report("hand-err", "\u6211\u7684\u624B\u8FDE\u4E0D\u4E0A\uFF1A" + err.message.slice(0, 60) + "\u3002");
3168
+ }
3169
+ try {
3170
+ const fs = await import("node:fs/promises");
3171
+ const st = await fs.statfs?.("/");
3172
+ if (st && typeof st.bavail === "number") {
3173
+ const free = st.bavail * Number(st.bsize);
3174
+ if (free > 0 && free < 1024 * 1024 * 1024) {
3175
+ await report("disk-low", `\u78C1\u76D8\u53EA\u5269 ${(free / 1048576).toFixed(0)} MB \u4E86\uFF0C\u518D\u88C5/\u8BB0\u4E1C\u897F\u4F1A\u4E0D\u591F\u3002`);
3176
+ }
3177
+ }
3178
+ } catch {
3179
+ }
3180
+ }
3097
3181
  /** 回家:被拎走了、或者走远了,隔一阵自己慢慢走回原位。 */
3098
3182
  async maybeWalkHome() {
3099
3183
  if (!this.canProactive()) return;
@@ -3520,6 +3604,8 @@ ${lines.join("\n")}
3520
3604
  return await this.runSync(true);
3521
3605
  case "sync_status":
3522
3606
  return this.lastSync ? `\u4E0A\u6B21\u540C\u6B65 ${this.lastSync.at.slice(0, 19)}\uFF0C\u8BB0\u5FC6 ${this.lastSync.lines} \u6761\uFF0C\u4EBA\u683C ${this.lastSync.persona} \u5B57` : "\u8FD8\u6CA1\u540C\u6B65\u8FC7";
3607
+ case "hand_quad":
3608
+ return await this.handQuad(args);
3523
3609
  case "hand_read_page": {
3524
3610
  const pages = Math.max(1, Math.min(8, Math.round(Number(args.pages) || 3)));
3525
3611
  const seen = /* @__PURE__ */ new Set();
@@ -4005,6 +4091,13 @@ ${text.slice(0, 2200)}`;
4005
4091
  if (!["system", "secure", "global"].includes(ns) || !key) return failed("ns \u53D6 system/secure/global\uFF0Ckey \u5FC5\u586B\u3002");
4006
4092
  return await this.hands.sysSettingsGet(ns, key);
4007
4093
  }
4094
+ async handQuad(args) {
4095
+ const max = args.max === void 0 ? 1440 : Math.max(640, Math.min(2160, Math.round(Number(args.max))));
4096
+ const f = await this.hands.quadFrame(max, 76);
4097
+ if (!f) return failed("\u6CA1\u62FF\u5230\u753B\u9762\uFF08\u5C4F\u5E55\u9ED1\u7740\u3001\u6216\u8005\u773C\u775B\u6CA1\u5F00\uFF09\u3002");
4098
+ const blobs = this.looksLikeImage(f.bytes) ? [{ bytes: f.bytes, mime: "image/jpeg", name: "quad.jpg", fallbackText: "\uFF08\u8FD9\u662F\u5C4F\u5E55\u5207\u6210\u56DB\u5757\u653E\u5927\u540E\u7684\u56FE\uFF09" }] : [];
4099
+ return { text: `\u8FD9\u662F\u5C4F\u5E55\u7684\u56DB\u5757\u653E\u5927\u56FE${f.pkg ? `\uFF08${f.pkg}\uFF09` : ""}\uFF1A\u5DE6\u4E0A\u3001\u53F3\u4E0A\u3001\u5DE6\u4E0B\u3001\u53F3\u4E0B\uFF0C\u51D1\u8FD1\u770B\u7EC6\u8282\u3002`, blobs };
4100
+ }
4008
4101
  async handChain(args) {
4009
4102
  const raw = args.steps;
4010
4103
  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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.65",
3
+ "version": "0.20.67",
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",