cortico-world-hands 0.19.0 → 0.20.1
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 +87 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -221,8 +221,9 @@ var HANDS_LOOK_CONFIG_GROUP = {
|
|
|
221
221
|
};
|
|
222
222
|
|
|
223
223
|
// src/world.ts
|
|
224
|
+
import { writeFileSync as writeFileSync2 } from "node:fs";
|
|
224
225
|
import { fileURLToPath } from "node:url";
|
|
225
|
-
import { join } from "node:path";
|
|
226
|
+
import { join as join2 } from "node:path";
|
|
226
227
|
|
|
227
228
|
// src/policy.ts
|
|
228
229
|
var PASS_RULES = [
|
|
@@ -500,9 +501,46 @@ var Honcho = class {
|
|
|
500
501
|
}
|
|
501
502
|
};
|
|
502
503
|
|
|
504
|
+
// src/stores.ts
|
|
505
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
506
|
+
import { join } from "node:path";
|
|
507
|
+
var JsonStore = class {
|
|
508
|
+
file;
|
|
509
|
+
fallback;
|
|
510
|
+
cached = null;
|
|
511
|
+
constructor(dir, name, fallback) {
|
|
512
|
+
this.fallback = fallback;
|
|
513
|
+
try {
|
|
514
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
515
|
+
} catch {
|
|
516
|
+
}
|
|
517
|
+
this.file = join(dir, name);
|
|
518
|
+
}
|
|
519
|
+
read() {
|
|
520
|
+
if (this.cached) return this.cached;
|
|
521
|
+
try {
|
|
522
|
+
if (existsSync(this.file)) {
|
|
523
|
+
const raw = JSON.parse(readFileSync(this.file, "utf8"));
|
|
524
|
+
this.cached = raw ?? this.fallback;
|
|
525
|
+
return this.cached;
|
|
526
|
+
}
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
this.cached = this.fallback;
|
|
530
|
+
return this.cached;
|
|
531
|
+
}
|
|
532
|
+
write(value) {
|
|
533
|
+
this.cached = value;
|
|
534
|
+
try {
|
|
535
|
+
writeFileSync(this.file, JSON.stringify(value, null, 2));
|
|
536
|
+
} catch {
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
|
|
503
541
|
// src/hands.ts
|
|
504
542
|
import { execFile } from "node:child_process";
|
|
505
|
-
import { readFileSync } from "node:fs";
|
|
543
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
506
544
|
import { get as httpGet, request as httpRequest } from "node:http";
|
|
507
545
|
var ACTION_TIMEOUT_MS = 6e3;
|
|
508
546
|
var PROBE_TTL_MS = 2e4;
|
|
@@ -903,7 +941,7 @@ var Hands = class {
|
|
|
903
941
|
if (Date.now() - this.tokenCache.at < 3e4) return this.tokenCache.value;
|
|
904
942
|
let value = "";
|
|
905
943
|
try {
|
|
906
|
-
const text =
|
|
944
|
+
const text = readFileSync2(file, "utf8").trim();
|
|
907
945
|
if (text && text.length <= 200) value = text;
|
|
908
946
|
} catch {
|
|
909
947
|
value = "";
|
|
@@ -1895,6 +1933,25 @@ var HANDS_TOOL_DECLS = [
|
|
|
1895
1933
|
tags: ["read"],
|
|
1896
1934
|
description: "\u770B\u4E0A\u4E00\u6B21\u540C\u6B65\u662F\u4EC0\u4E48\u65F6\u5019\u3001\u540C\u6B65\u4E86\u591A\u5C11\u6761\u3001\u4EBA\u683C\u539F\u6587\u591A\u5C11\u5B57\u3002",
|
|
1897
1935
|
parameters: { type: "object", properties: {} }
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
name: "persona_get",
|
|
1939
|
+
tags: ["read"],
|
|
1940
|
+
description: "\u8BFB\u5979\u81EA\u5DF1\u7684\u4EBA\u683C\u539F\u6587\uFF08CONSTITUTION\uFF09\u3002",
|
|
1941
|
+
parameters: { type: "object", properties: {} }
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
name: "persona_set",
|
|
1945
|
+
tags: ["act"],
|
|
1946
|
+
description: "\u6539\u5979\u81EA\u5DF1\u7684\u4EBA\u683C\u539F\u6587\u3002\u4F1A\u5148\u5907\u4EFD\u65E7\u7248\u5230\u5DE5\u4F5C\u533A CONSTITUTION.bak.<\u65F6\u95F4>\uFF0C\u518D\u5199\u5165\u3002\u6574\u6BB5\u66FF\u6362\uFF0C\u4E0D\u662F\u8FFD\u52A0\u3002",
|
|
1947
|
+
parameters: {
|
|
1948
|
+
type: "object",
|
|
1949
|
+
properties: {
|
|
1950
|
+
content: { type: "string", description: "\u65B0\u7684\u5B8C\u6574\u4EBA\u683C\u6587\u672C" },
|
|
1951
|
+
why: { type: "string", description: "\u4E3A\u4EC0\u4E48\u6539\uFF08\u8BB0\u4E00\u7B14\uFF09" }
|
|
1952
|
+
},
|
|
1953
|
+
required: ["content"]
|
|
1954
|
+
}
|
|
1898
1955
|
}
|
|
1899
1956
|
];
|
|
1900
1957
|
|
|
@@ -2002,6 +2059,27 @@ var HandsWorld = class {
|
|
|
2002
2059
|
this.mineTimer = null;
|
|
2003
2060
|
}
|
|
2004
2061
|
/** 每 30 秒看一次:日程到点投一条,早安/晚安/纪念日各一次。 */
|
|
2062
|
+
/** 读人格原文。 */
|
|
2063
|
+
async personaGet() {
|
|
2064
|
+
const dir = this.opts.botDir || this.opts.dataDir || ".";
|
|
2065
|
+
const text = readPersona(dir);
|
|
2066
|
+
return text ? text.slice(0, 6e3) : "\u5DE5\u4F5C\u533A\u91CC\u6CA1\u6709 CONSTITUTION.md";
|
|
2067
|
+
}
|
|
2068
|
+
/** 改人格原文:先备份,再整段替换。 */
|
|
2069
|
+
async personaSet(args) {
|
|
2070
|
+
const content = typeof args.content === "string" ? args.content.trim() : "";
|
|
2071
|
+
if (content.length < 200) return failed("\u4EBA\u683C\u592A\u77ED\u4E86\uFF08\u81F3\u5C11\u4E24\u767E\u5B57\uFF09\uFF0C\u628A\u6574\u6BB5\u5199\u5B8C\u6574\u518D\u7ED9\u6211\u3002");
|
|
2072
|
+
const dir = this.opts.botDir || this.opts.dataDir || ".";
|
|
2073
|
+
try {
|
|
2074
|
+
const old = readPersona(dir);
|
|
2075
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
2076
|
+
if (old) writeFileSync2(join2(dir, `CONSTITUTION.bak.${stamp}.md`), old);
|
|
2077
|
+
writeFileSync2(join2(dir, "CONSTITUTION.md"), content);
|
|
2078
|
+
return `\u4EBA\u683C\u6362\u597D\u4E86\uFF08\u65E7\u7248\u5907\u4EFD\u6210 CONSTITUTION.bak.${stamp}.md\uFF09`;
|
|
2079
|
+
} catch (err) {
|
|
2080
|
+
return failed("\u5199\u4E0D\u8FDB\u53BB\uFF1A" + String(err).slice(0, 120));
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2005
2083
|
/** 懿心 ↔ Coopanin:记忆推成 记忆库.md,人格原文存进懿心。 */
|
|
2006
2084
|
async runSync(manual) {
|
|
2007
2085
|
const dir = this.opts.botDir || this.opts.dataDir || ".";
|
|
@@ -2011,7 +2089,7 @@ var HandsWorld = class {
|
|
|
2011
2089
|
try {
|
|
2012
2090
|
const rows = await this.hands.memorySearch();
|
|
2013
2091
|
lines = rows.length;
|
|
2014
|
-
const target =
|
|
2092
|
+
const target = join2(dir, "\u8BB0\u5FC6\u5E93.md");
|
|
2015
2093
|
const r = mergeMemorySection(target, rows);
|
|
2016
2094
|
if (r.wrote) wrote.push("\u8BB0\u5FC6\u5E93.md");
|
|
2017
2095
|
const persona = readPersona(dir);
|
|
@@ -2182,7 +2260,7 @@ ${lines.join("\n")}
|
|
|
2182
2260
|
mediaDir() {
|
|
2183
2261
|
const base = this.opts.dataDir;
|
|
2184
2262
|
if (!base) return null;
|
|
2185
|
-
const dir = base.endsWith("/data") ?
|
|
2263
|
+
const dir = base.endsWith("/data") ? join2(base, "media") : join2(base, "data", "media");
|
|
2186
2264
|
return dir;
|
|
2187
2265
|
}
|
|
2188
2266
|
/** 钩子 5:QQ 在后台收到的消息,原样递给她;谁来的一眼能看清。 */
|
|
@@ -2274,6 +2352,10 @@ ${lines.join("\n")}
|
|
|
2274
2352
|
return await this.matchImage(args, false);
|
|
2275
2353
|
case "hand_tap_image":
|
|
2276
2354
|
return await this.matchImage(args, true);
|
|
2355
|
+
case "persona_get":
|
|
2356
|
+
return await this.personaGet();
|
|
2357
|
+
case "persona_set":
|
|
2358
|
+
return await this.personaSet(args);
|
|
2277
2359
|
case "sync_now":
|
|
2278
2360
|
return await this.runSync(true);
|
|
2279
2361
|
case "sync_status":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-hands",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
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",
|