cortico-world-hands 0.20.23 → 0.20.24
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 +100 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ var HANDS_DEFAULTS = {
|
|
|
25
25
|
hookGrams: "three",
|
|
26
26
|
skinPackUrl: "",
|
|
27
27
|
qqOwner: "",
|
|
28
|
+
/** 自己开口的间隔分钟数;0 = 不主动开口。 */
|
|
29
|
+
selfTalkMinutes: 25,
|
|
28
30
|
qqSelf: "\u665A\u6C50",
|
|
29
31
|
ritualMorning: "08:00",
|
|
30
32
|
ritualNight: "23:00",
|
|
@@ -144,6 +146,12 @@ var HANDS_CONFIG_GROUP = {
|
|
|
144
146
|
description: "\u7559\u7A7A/0 \u8868\u793A\u6BCF 6 \u5C0F\u65F6\u68C0\u67E5\u4E00\u6B21\uFF0C\u8D85\u671F\u5C31\u6E05\u3002",
|
|
145
147
|
"x-hot": true
|
|
146
148
|
},
|
|
149
|
+
[`${K}.selfTalkMinutes`]: {
|
|
150
|
+
type: "number",
|
|
151
|
+
title: "\u6BCF\u9694\u51E0\u5206\u949F\u5141\u8BB8\u5979\u4E3B\u52A8\u8BF4\u4E00\u53E5",
|
|
152
|
+
description: "0 \u8868\u793A\u4E0D\u4E3B\u52A8\u5F00\u53E3\uFF1B\u5B89\u9759\u966A\u4F34\u4E5F\u662F\u966A\u4F34\u3002\u9ED8\u8BA4 25 \u5206\u949F\u3002",
|
|
153
|
+
"x-hot": true
|
|
154
|
+
},
|
|
147
155
|
[`${K}.qqSelf`]: {
|
|
148
156
|
type: "string",
|
|
149
157
|
title: "\u5979\u81EA\u5DF1\u7684 QQ \u540D\u5B57\uFF08\u7FA4\u91CC @ \u8FD9\u4E2A\u624D\u53EB\u5979\uFF09",
|
|
@@ -253,6 +261,7 @@ var HANDS_LOOK_CONFIG_GROUP = {
|
|
|
253
261
|
|
|
254
262
|
// src/world.ts
|
|
255
263
|
import { writeFileSync as writeFileSync4 } from "node:fs";
|
|
264
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
256
265
|
import { fileURLToPath } from "node:url";
|
|
257
266
|
import { join as join4 } from "node:path";
|
|
258
267
|
|
|
@@ -2248,6 +2257,19 @@ var HANDS_TOOL_DECLS = [
|
|
|
2248
2257
|
tags: ["read"],
|
|
2249
2258
|
description: "\u5217\u51FA\u300C\u6211\u4EEC\u7684\u65E5\u5B50\u300D\u9875\u9762\u4E0A\u7684\u5168\u90E8\u6761\u76EE\u3002",
|
|
2250
2259
|
parameters: { type: "object", properties: {} }
|
|
2260
|
+
},
|
|
2261
|
+
{
|
|
2262
|
+
name: "prompt_search",
|
|
2263
|
+
tags: ["read"],
|
|
2264
|
+
description: "\u5728\u6211\u7684\u63D0\u793A\u8BCD/\u5DE5\u4F5C\u533A\u6587\u6863\u91CC\u641C\u4E00\u6BB5\u8BDD\uFF08\u4EBA\u683C\u3001\u89C4\u77E9\u3001\u90E8\u7F72\u63D0\u793A\u8BCD\u90FD\u7B97\uFF09\uFF0C\u8FD4\u56DE\u547D\u4E2D\u7684\u884C\u548C\u51FA\u5904\u3002",
|
|
2265
|
+
parameters: {
|
|
2266
|
+
type: "object",
|
|
2267
|
+
properties: {
|
|
2268
|
+
q: { type: "string", description: "\u8981\u627E\u7684\u8BCD\u6216\u4E00\u53E5\u8BDD" },
|
|
2269
|
+
limit: { type: "integer", description: "\u6700\u591A\u8FD4\u56DE\u51E0\u6761\uFF0C\u9ED8\u8BA4 8" }
|
|
2270
|
+
},
|
|
2271
|
+
required: ["q"]
|
|
2272
|
+
}
|
|
2251
2273
|
}
|
|
2252
2274
|
];
|
|
2253
2275
|
|
|
@@ -2283,6 +2305,8 @@ var HandsWorld = class {
|
|
|
2283
2305
|
qqDueTimer = null;
|
|
2284
2306
|
mediaTimer = null;
|
|
2285
2307
|
watchTimer = null;
|
|
2308
|
+
selfTalkTimer = null;
|
|
2309
|
+
lastSelfTalkAt = 0;
|
|
2286
2310
|
handDown = null;
|
|
2287
2311
|
lastMediaDay = "";
|
|
2288
2312
|
cursor = 0;
|
|
@@ -2344,6 +2368,9 @@ var HandsWorld = class {
|
|
|
2344
2368
|
this.watchTimer = setInterval(() => {
|
|
2345
2369
|
void this.watchHands();
|
|
2346
2370
|
}, 6e4);
|
|
2371
|
+
this.selfTalkTimer = setInterval(() => {
|
|
2372
|
+
void this.maybeSelfTalk();
|
|
2373
|
+
}, 5 * 6e4);
|
|
2347
2374
|
setTimeout(() => {
|
|
2348
2375
|
void this.maybeCleanMedia();
|
|
2349
2376
|
}, 2e4);
|
|
@@ -2365,11 +2392,64 @@ var HandsWorld = class {
|
|
|
2365
2392
|
if (this.qqDueTimer) clearInterval(this.qqDueTimer);
|
|
2366
2393
|
if (this.mediaTimer) clearInterval(this.mediaTimer);
|
|
2367
2394
|
if (this.watchTimer) clearInterval(this.watchTimer);
|
|
2395
|
+
if (this.selfTalkTimer) clearInterval(this.selfTalkTimer);
|
|
2368
2396
|
this.pollTimer = null;
|
|
2369
2397
|
this.mineTimer = null;
|
|
2370
2398
|
}
|
|
2371
2399
|
/** 每 30 秒看一次:日程到点投一条,早安/晚安/纪念日各一次。 */
|
|
2372
2400
|
/** 读人格原文。 */
|
|
2401
|
+
/** 在人格/工作区文档里搜关键词。 */
|
|
2402
|
+
searchRoots() {
|
|
2403
|
+
const roots = [...this.opts.roots || []];
|
|
2404
|
+
if (this.opts.botDir) roots.unshift(this.opts.botDir);
|
|
2405
|
+
if (this.opts.dataDir) roots.push(this.opts.dataDir);
|
|
2406
|
+
try {
|
|
2407
|
+
roots.push(process.cwd());
|
|
2408
|
+
} catch {
|
|
2409
|
+
}
|
|
2410
|
+
return [...new Set(roots.filter(Boolean))];
|
|
2411
|
+
}
|
|
2412
|
+
async promptSearch(q, limit = 8) {
|
|
2413
|
+
const needle = q.trim().toLowerCase();
|
|
2414
|
+
if (!needle) return "\u8981\u641C\u4EC0\u4E48\uFF1F\u7ED9 q\u3002";
|
|
2415
|
+
const hits2 = [];
|
|
2416
|
+
const persona = await this.personaGet().catch(() => "");
|
|
2417
|
+
for (const line of persona.split(/\r?\n/)) {
|
|
2418
|
+
if (line.toLowerCase().includes(needle)) hits2.push(`[\u4EBA\u683C] ${line.trim().slice(0, 120)}`);
|
|
2419
|
+
if (hits2.length >= limit) break;
|
|
2420
|
+
}
|
|
2421
|
+
const roots = this.searchRoots();
|
|
2422
|
+
const exts = /\.(md|txt|yml|yaml|json)$/i;
|
|
2423
|
+
let scanned = 0;
|
|
2424
|
+
for (const root of roots) {
|
|
2425
|
+
if (hits2.length >= limit || scanned > 400) break;
|
|
2426
|
+
let entries = [];
|
|
2427
|
+
try {
|
|
2428
|
+
entries = await readdir(root);
|
|
2429
|
+
} catch {
|
|
2430
|
+
continue;
|
|
2431
|
+
}
|
|
2432
|
+
for (const name of entries) {
|
|
2433
|
+
if (hits2.length >= limit || scanned > 400) break;
|
|
2434
|
+
if (!exts.test(name)) continue;
|
|
2435
|
+
const path = `${root}/${name}`;
|
|
2436
|
+
scanned++;
|
|
2437
|
+
try {
|
|
2438
|
+
const buf = await readFile(path);
|
|
2439
|
+
const text = buf.toString("utf8");
|
|
2440
|
+
if (buf.length > 4e5) continue;
|
|
2441
|
+
for (const line of text.split(/\r?\n/)) {
|
|
2442
|
+
if (line.toLowerCase().includes(needle)) hits2.push(`[${name}] ${line.trim().slice(0, 120)}`);
|
|
2443
|
+
if (hits2.length >= limit) break;
|
|
2444
|
+
}
|
|
2445
|
+
} catch {
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
if (hits2.length === 0) return `\u63D0\u793A\u8BCD\u548C\u5DE5\u4F5C\u533A\u91CC\u6CA1\u627E\u5230\u300C${q}\u300D\u3002`;
|
|
2450
|
+
return `\u627E\u5230 ${hits2.length} \u5904\uFF1A
|
|
2451
|
+
` + hits2.join("\n");
|
|
2452
|
+
}
|
|
2373
2453
|
async personaGet() {
|
|
2374
2454
|
const dir = this.opts.botDir || this.opts.dataDir || ".";
|
|
2375
2455
|
const text = readPersona(dir);
|
|
@@ -2596,6 +2676,21 @@ ${lines.join("\n")}
|
|
|
2596
2676
|
);
|
|
2597
2677
|
}
|
|
2598
2678
|
}
|
|
2679
|
+
/** 隔一阵子允许她自己开口一次(尊重"没人找就别开口":只在白天、且真的隔了很久)。 */
|
|
2680
|
+
async maybeSelfTalk() {
|
|
2681
|
+
const minutes = Number(this.opts.cfg.selfTalkMinutes ?? 0);
|
|
2682
|
+
if (!Number.isFinite(minutes) || minutes <= 0) return;
|
|
2683
|
+
const now = Date.now();
|
|
2684
|
+
if (now - this.lastSelfTalkAt < minutes * 6e4) return;
|
|
2685
|
+
const hour = new Date(now).getHours();
|
|
2686
|
+
if (hour < 9 || hour >= 23) return;
|
|
2687
|
+
this.lastSelfTalkAt = now;
|
|
2688
|
+
await this.pushEvent(
|
|
2689
|
+
"[\u81EA\u5DF1\u5F00\u53E3] \u5B89\u9759\u4E86\u4E00\u9635\u4E86\u3002\u60F3\u8BF4\u5C31\u8BF4\u4E00\u53E5\uFF08\u4E00\u4E24\u53E5\u3001\u50CF\u5E73\u65F6\u804A\u5929\uFF09\uFF1B\u6CA1\u4EC0\u4E48\u60F3\u8BF4\u7684\u5C31\u5FFD\u7565\u8FD9\u6761\uFF0C\u522B\u786C\u51D1\u3002",
|
|
2690
|
+
"hands.selftalk",
|
|
2691
|
+
"hands:selftalk"
|
|
2692
|
+
);
|
|
2693
|
+
}
|
|
2599
2694
|
/** 手掉线时立刻告诉主人(每分钟看一次,掉了只报一次)。 */
|
|
2600
2695
|
async watchHands() {
|
|
2601
2696
|
const port = this.opts.cfg.handPort && this.opts.cfg.handPort > 1024 ? this.opts.cfg.handPort : 17897;
|
|
@@ -2766,6 +2861,11 @@ ${text.slice(0, 2200)}`;
|
|
|
2766
2861
|
}
|
|
2767
2862
|
return `\u300C${hit.text}\u300D@(${hit.center.x},${hit.center.y})`;
|
|
2768
2863
|
}
|
|
2864
|
+
case "prompt_search": {
|
|
2865
|
+
const q = typeof args.q === "string" ? args.q : "";
|
|
2866
|
+
const limit = args.limit === void 0 ? 8 : Math.max(1, Math.min(20, Math.round(Number(args.limit))));
|
|
2867
|
+
return await this.promptSearch(q, limit);
|
|
2868
|
+
}
|
|
2769
2869
|
case "day_add": {
|
|
2770
2870
|
const date = typeof args.date === "string" ? args.date.trim() : "";
|
|
2771
2871
|
const title = typeof args.title === "string" ? args.title.trim() : "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.24",
|
|
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",
|