cortico-world-hands 0.20.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.
Files changed (2) hide show
  1. package/dist/index.js +45 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -221,9 +221,9 @@ var HANDS_LOOK_CONFIG_GROUP = {
221
221
  };
222
222
 
223
223
  // src/world.ts
224
- import { writeFileSync } from "node:fs";
224
+ import { writeFileSync as writeFileSync2 } from "node:fs";
225
225
  import { fileURLToPath } from "node:url";
226
- import { join } from "node:path";
226
+ import { join as join2 } from "node:path";
227
227
 
228
228
  // src/policy.ts
229
229
  var PASS_RULES = [
@@ -501,9 +501,46 @@ var Honcho = class {
501
501
  }
502
502
  };
503
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
+
504
541
  // src/hands.ts
505
542
  import { execFile } from "node:child_process";
506
- import { readFileSync } from "node:fs";
543
+ import { readFileSync as readFileSync2 } from "node:fs";
507
544
  import { get as httpGet, request as httpRequest } from "node:http";
508
545
  var ACTION_TIMEOUT_MS = 6e3;
509
546
  var PROBE_TTL_MS = 2e4;
@@ -904,7 +941,7 @@ var Hands = class {
904
941
  if (Date.now() - this.tokenCache.at < 3e4) return this.tokenCache.value;
905
942
  let value = "";
906
943
  try {
907
- const text = readFileSync(file, "utf8").trim();
944
+ const text = readFileSync2(file, "utf8").trim();
908
945
  if (text && text.length <= 200) value = text;
909
946
  } catch {
910
947
  value = "";
@@ -2036,8 +2073,8 @@ var HandsWorld = class {
2036
2073
  try {
2037
2074
  const old = readPersona(dir);
2038
2075
  const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19);
2039
- if (old) writeFileSync(join(dir, `CONSTITUTION.bak.${stamp}.md`), old);
2040
- writeFileSync(join(dir, "CONSTITUTION.md"), content);
2076
+ if (old) writeFileSync2(join2(dir, `CONSTITUTION.bak.${stamp}.md`), old);
2077
+ writeFileSync2(join2(dir, "CONSTITUTION.md"), content);
2041
2078
  return `\u4EBA\u683C\u6362\u597D\u4E86\uFF08\u65E7\u7248\u5907\u4EFD\u6210 CONSTITUTION.bak.${stamp}.md\uFF09`;
2042
2079
  } catch (err) {
2043
2080
  return failed("\u5199\u4E0D\u8FDB\u53BB\uFF1A" + String(err).slice(0, 120));
@@ -2052,7 +2089,7 @@ var HandsWorld = class {
2052
2089
  try {
2053
2090
  const rows = await this.hands.memorySearch();
2054
2091
  lines = rows.length;
2055
- const target = join(dir, "\u8BB0\u5FC6\u5E93.md");
2092
+ const target = join2(dir, "\u8BB0\u5FC6\u5E93.md");
2056
2093
  const r = mergeMemorySection(target, rows);
2057
2094
  if (r.wrote) wrote.push("\u8BB0\u5FC6\u5E93.md");
2058
2095
  const persona = readPersona(dir);
@@ -2223,7 +2260,7 @@ ${lines.join("\n")}
2223
2260
  mediaDir() {
2224
2261
  const base = this.opts.dataDir;
2225
2262
  if (!base) return null;
2226
- const dir = base.endsWith("/data") ? join(base, "media") : join(base, "data", "media");
2263
+ const dir = base.endsWith("/data") ? join2(base, "media") : join2(base, "data", "media");
2227
2264
  return dir;
2228
2265
  }
2229
2266
  /** 钩子 5:QQ 在后台收到的消息,原样递给她;谁来的一眼能看清。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-hands",
3
- "version": "0.20.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",