@linxin666/dsh-pet 0.4.6 → 0.4.7

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/lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import { _ as RemarkPicker, a as AFFINITY_MAX, c as applyInteraction, d as emptyAffinity, f as rankOf, g as REMARK_LINE_MAX, h as REMARK_LINES_MAX, i as rowOf, l as applyTurnReward, m as REMARK_KINDS, n as animationForPhase, o as AFFINITY_RANKS, p as BUILTIN_REMARKS, r as defaultPetStateConfig, s as affinityViewOf, t as PetStateMachine, u as defaultAffinityConfig, v as builtinRemark, y as normalizePetRemarks } from "./state-NvDEoCln.js";
2
1
  import z from "@deepseek-ai/schemastery";
3
2
  import { Service } from "@deepseek-ai/cordis";
4
3
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
@@ -997,6 +996,362 @@ function projectAssistantStreamFrame(frame, runtime, nowMs = Date.now()) {
997
996
  }
998
997
  }
999
998
  //#endregion
999
+ //#region src/remarks.ts
1000
+ /** Every remark slot, in a stable order. */
1001
+ const REMARK_KINDS = [
1002
+ "pet",
1003
+ "petCooldown",
1004
+ "feed",
1005
+ "feedCooldown",
1006
+ "noTreats"
1007
+ ];
1008
+ /** Longest accepted reaction line (characters, trimmed before slicing). */
1009
+ const REMARK_LINE_MAX = 120;
1010
+ /** Longest accepted pool per slot. */
1011
+ const REMARK_LINES_MAX = 64;
1012
+ /**
1013
+ * Built-in default remark library. Every pool is plain zh copy in the
1014
+ * whale-girl voice; the first line of each pool is the legacy reaction the
1015
+ * plugin has always spoken, so existing installs and tests keep their
1016
+ * wording while the pool adds variety. No emoji characters anywhere (the
1017
+ * repo bans them); ~ is the whale-girl's signature.
1018
+ */
1019
+ const BUILTIN_REMARKS = {
1020
+ pet: [
1021
+ "咕噜咕噜~被摸摸好舒服!",
1022
+ "再摸摸这里,痒痒的~",
1023
+ "头顶温度刚刚好,安心~",
1024
+ "被摸到耳朵啦,扑通扑通!",
1025
+ "你的手掌好温暖,舍不得你走~",
1026
+ "呼噜呼噜~就靠在这里不走了!",
1027
+ "今天的摸头也收货成功!",
1028
+ "蹭蹭你的手心,这是回礼~",
1029
+ "多摸摸我,亲密度会涨哦!",
1030
+ "闭眼享受中,请勿打扰~",
1031
+ "头再低一点,够不着了~",
1032
+ "呼噜呼噜,声音都冒出来了",
1033
+ "这手感,比小鱼干还上瘾",
1034
+ "摸到第三下,满意",
1035
+ "耳朵后面,别漏了……啊,舒服",
1036
+ "被摸得尾巴都卷起来了"
1037
+ ],
1038
+ petCooldown: [
1039
+ "摸过头啦,让鲸鱼娘歇口气~",
1040
+ "羽毛都快被摸秃啦,缓一缓~",
1041
+ "呼……先让我喘口气嘛!",
1042
+ "再摸就要睡着了哦~",
1043
+ "稍微休息一下,待会儿再摸~",
1044
+ "头顶要冒烟啦,停一停!",
1045
+ "我知道你喜欢我,但也要节制呀~",
1046
+ "歇一歇,摸摸的手感会更好哦~",
1047
+ "咕……等我回个蓝~",
1048
+ "让我先消化一下刚才的爱!",
1049
+ "痒痒的,先让我缓一下……",
1050
+ "再摸就掉线了,真的",
1051
+ "库存的呼噜声用完了",
1052
+ "手歇会儿,我也要补个蓝",
1053
+ "舒服归舒服,得缓缓呀",
1054
+ "再摸下去,我就要融化了"
1055
+ ],
1056
+ feed: [
1057
+ "呜哇!小鱼干好好吃!",
1058
+ "咔嚓咔嚓,美味到尾巴打结~",
1059
+ "这条小鱼干是刚晒好的,好香!",
1060
+ "谢谢你,胃里暖暖的~",
1061
+ "囤粮 +1,今天也有好好被爱!",
1062
+ "好吃到想转圈圈~",
1063
+ "小鱼干最好吃了,再来亿条!",
1064
+ "饱餐一顿,马上满血复活~",
1065
+ "这个味道,是幸福的味道!",
1066
+ "吃完了还不忘舔舔爪子~",
1067
+ "这小鱼干,是今天的顶配",
1068
+ "一口下去,精神头全回来了",
1069
+ "脆!香!就是这个味儿",
1070
+ "边吃边摇尾巴,形象不要了",
1071
+ "好吃到眼睛都眯起来了",
1072
+ "这块鱼干我记住了,懂我的"
1073
+ ],
1074
+ feedCooldown: [
1075
+ "吃饱啦,晚点再喂~",
1076
+ "肚子圆滚滚的,装不下啦~",
1077
+ "再喂就要变成球啦!",
1078
+ "让我慢慢消化这份心意~",
1079
+ "小鱼干的香气还没散呢~",
1080
+ "呼……满足得动不了了~",
1081
+ "先散步一圈再吃下一顿!",
1082
+ "肚皮已经鼓鼓的啦~",
1083
+ "好吃是好吃,可也得节制呀~",
1084
+ "等我饿了会告诉你哦~",
1085
+ "胃说它满了,脑子说还能吃",
1086
+ "这条得留着慢慢品",
1087
+ "先消消食,待会儿再战",
1088
+ "塞不下了,真塞不下了",
1089
+ "闻着香,可惜没地方放了",
1090
+ "嗝……这顿值了"
1091
+ ],
1092
+ noTreats: [
1093
+ "没有小鱼干了,多陪我工作一会儿吧~",
1094
+ "粮仓空空,陪我完成几轮任务就会有小鱼干啦~",
1095
+ "小鱼干在路上啦,先一起加油工作!",
1096
+ "嘴巴寂寞了……快去完成一轮任务!",
1097
+ "陪我多工作一会儿,鱼干自动到账~",
1098
+ "现在喂我也只会饿着肚子说谢谢哦~",
1099
+ "粮仓见底啦,用几轮任务换一条鱼干吧~",
1100
+ "饿着肚子等你完成下一轮任务~",
1101
+ "小鱼干藏在你的工作里,去找找看!",
1102
+ "先工作后干饭,我们的约定哦~",
1103
+ "粮仓见底,全靠感情撑着了",
1104
+ "饿是真饿,活也是真得干",
1105
+ "画饼充饥……不对,画鱼干充饥",
1106
+ "没鱼干的日子,靠意志力过",
1107
+ "下一轮任务,我闻到了鱼干味",
1108
+ "先记账上,欠我两条,记住啦"
1109
+ ]
1110
+ };
1111
+ /** The legacy first line of one kind (direct callers' fallback copy). */
1112
+ function builtinRemark(kind) {
1113
+ return BUILTIN_REMARKS[kind][0];
1114
+ }
1115
+ /**
1116
+ * Normalize a manifest 'remarks' block into per-kind line pools. Unknown
1117
+ * slots and non-string entries are skipped with a warning; empty pools are
1118
+ * dropped so the built-in library takes the slot. Returns undefined when no
1119
+ * usable slot remains.
1120
+ */
1121
+ function normalizePetRemarks(raw, onWarning = () => {}) {
1122
+ if (raw === void 0) return void 0;
1123
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
1124
+ onWarning("remarks must be an object with pet/petCooldown/feed/feedCooldown/noTreats slots");
1125
+ return;
1126
+ }
1127
+ const remarks = {};
1128
+ for (const [key, value] of Object.entries(raw)) {
1129
+ if (!REMARK_KINDS.includes(key)) {
1130
+ onWarning("unknown remarks slot " + JSON.stringify(key));
1131
+ continue;
1132
+ }
1133
+ const lines = (Array.isArray(value) ? value : [value]).filter((line) => typeof line === "string").map((line) => line.trim()).filter((line) => line !== "").slice(0, 64).map((line) => line.slice(0, 120));
1134
+ if (lines.length === 0) {
1135
+ onWarning("remarks slot " + key + " carries no usable lines");
1136
+ continue;
1137
+ }
1138
+ remarks[key] = lines;
1139
+ }
1140
+ return Object.keys(remarks).length === 0 ? void 0 : remarks;
1141
+ }
1142
+ /**
1143
+ * Round-robin reaction picker over the effective pools (per-pet custom lines
1144
+ * override the built-in pool per slot). Counters are per slot, so each slot
1145
+ * cycles its own list independently and picks stay deterministic for tests.
1146
+ */
1147
+ var RemarkPicker = class {
1148
+ counters = /* @__PURE__ */ new Map();
1149
+ pools;
1150
+ constructor(overrides, voiceOverrides) {
1151
+ this.pools = {};
1152
+ for (const kind of REMARK_KINDS) {
1153
+ const custom = overrides?.[kind];
1154
+ const voice = voiceOverrides?.[kind];
1155
+ if (custom !== void 0 && custom.length > 0) this.pools[kind] = custom;
1156
+ else if (voice !== void 0 && voice.length > 0) this.pools[kind] = voice;
1157
+ else this.pools[kind] = BUILTIN_REMARKS[kind];
1158
+ }
1159
+ }
1160
+ /** The effective pool for one slot (custom override or built-in). */
1161
+ pool(kind) {
1162
+ return this.pools[kind];
1163
+ }
1164
+ /** The next line for one slot (round-robin within its pool). */
1165
+ pick(kind) {
1166
+ const pool = this.pools[kind];
1167
+ const index = (this.counters.get(kind) ?? 0) % pool.length;
1168
+ this.counters.set(kind, index + 1);
1169
+ return pool[index];
1170
+ }
1171
+ /** Select a line from a stable external counter without changing local picker state. */
1172
+ pickAt(kind, count) {
1173
+ const pool = this.pools[kind];
1174
+ return pool[Math.max(0, Math.floor(count)) % pool.length];
1175
+ }
1176
+ };
1177
+ //#endregion
1178
+ //#region src/affinity.ts
1179
+ /**
1180
+ * Affinity score — pure, clock-injected. The pet grows closer the more you
1181
+ * work together and care for it: every completed turn earns a small reward,
1182
+ * petting earns a tiny one (cooldown-gated), feeding earns the most.
1183
+ * Persistence lives in the service; this module only computes transitions.
1184
+ * Reaction copy resolves from the shared remark library (first line of each
1185
+ * built-in pool); the ledger layers per-pet custom remarks on top.
1186
+ * @module @linxin666/dsh-pet/affinity
1187
+ */
1188
+ /**
1189
+ * Affinity points cap. Historically 100; removed so long-term companions
1190
+ * keep growing — the default limit is now the full 999,999,999 range.
1191
+ */
1192
+ const AFFINITY_MAX = 999999999;
1193
+ /** Affinity ranks by points; the pet visibly grows with its rank.
1194
+ * The original four tiers (0/25/50/80) are unchanged; higher tiers reach
1195
+ * into the extended cap so the ladder stays meaningful for veteran
1196
+ * companions. Marker glyphs are plain ASCII (the repo bans all emoji
1197
+ * characters); they read as a growing star trail alongside the rank name. */
1198
+ const AFFINITY_RANKS = [
1199
+ {
1200
+ min: 0,
1201
+ name: "幼鲸",
1202
+ emoji: "*"
1203
+ },
1204
+ {
1205
+ min: 25,
1206
+ name: "伙伴",
1207
+ emoji: "**"
1208
+ },
1209
+ {
1210
+ min: 50,
1211
+ name: "挚友",
1212
+ emoji: "***"
1213
+ },
1214
+ {
1215
+ min: 80,
1216
+ name: "深海羁绊",
1217
+ emoji: "****"
1218
+ },
1219
+ {
1220
+ min: 200,
1221
+ name: "心有灵犀",
1222
+ emoji: "*****"
1223
+ },
1224
+ {
1225
+ min: 500,
1226
+ name: "传说羁绊",
1227
+ emoji: "******"
1228
+ },
1229
+ {
1230
+ min: 2e3,
1231
+ name: "神话羁绊",
1232
+ emoji: "*******"
1233
+ },
1234
+ {
1235
+ min: 1e4,
1236
+ name: "永恒之契",
1237
+ emoji: "********"
1238
+ },
1239
+ {
1240
+ min: 1e5,
1241
+ name: "鲸生共渡",
1242
+ emoji: "*********"
1243
+ }
1244
+ ];
1245
+ const defaultAffinityConfig = {
1246
+ turnReward: 1,
1247
+ petReward: 1,
1248
+ petCooldownMs: 1e4,
1249
+ feedReward: 5,
1250
+ feedCooldownMs: 3e4
1251
+ };
1252
+ function emptyAffinity() {
1253
+ return {
1254
+ points: 0,
1255
+ lastPetAt: 0,
1256
+ lastFeedAt: 0,
1257
+ pets: 0,
1258
+ feeds: 0,
1259
+ petRejects: 0,
1260
+ feedRejects: 0,
1261
+ turns: 0
1262
+ };
1263
+ }
1264
+ /** Rank for a point total. */
1265
+ function rankOf(points) {
1266
+ let rank = AFFINITY_RANKS[0];
1267
+ for (const candidate of AFFINITY_RANKS) if (points >= candidate.min) rank = candidate;
1268
+ return rank;
1269
+ }
1270
+ /** Derive the read-only view of one affinity state at a wall-clock instant. */
1271
+ function affinityViewOf(state, nowMs, config = defaultAffinityConfig) {
1272
+ const rank = rankOf(state.points);
1273
+ return {
1274
+ points: state.points,
1275
+ rank: rank.name,
1276
+ rankEmoji: rank.emoji,
1277
+ pets: state.pets,
1278
+ feeds: state.feeds,
1279
+ turns: state.turns,
1280
+ petCooldown: nowMs - state.lastPetAt < config.petCooldownMs,
1281
+ feedCooldown: nowMs - state.lastFeedAt < config.feedCooldownMs
1282
+ };
1283
+ }
1284
+ function clamp$1(points) {
1285
+ return Math.min(AFFINITY_MAX, Math.max(0, points));
1286
+ }
1287
+ /** Built-in reaction selected deterministically from a persisted counter. */
1288
+ function countedRemark(kind, count) {
1289
+ const pool = BUILTIN_REMARKS[kind];
1290
+ return pool[Math.max(0, Math.floor(count)) % pool.length] ?? builtinRemark(kind);
1291
+ }
1292
+ /**
1293
+ * Apply one interaction to a copy of the state (immutable style: returns a
1294
+ * new object; the caller replaces the persisted state). Cooldowns only
1295
+ * apply once the pet has been interacted with at least once (last*At === 0
1296
+ * means "never", so the first pet/feed always lands).
1297
+ */
1298
+ function applyInteraction(state, kind, nowMs, config = defaultAffinityConfig) {
1299
+ const next = { ...state };
1300
+ if (kind === "pet") {
1301
+ if (state.lastPetAt !== 0 && nowMs - state.lastPetAt < config.petCooldownMs) {
1302
+ next.petRejects += 1;
1303
+ return {
1304
+ affinity: next,
1305
+ delta: 0,
1306
+ reaction: countedRemark("petCooldown", state.petRejects),
1307
+ accepted: false
1308
+ };
1309
+ }
1310
+ next.lastPetAt = nowMs;
1311
+ next.pets += 1;
1312
+ next.points = clamp$1(state.points + config.petReward);
1313
+ return {
1314
+ affinity: next,
1315
+ delta: config.petReward,
1316
+ reaction: countedRemark("pet", state.pets),
1317
+ accepted: true
1318
+ };
1319
+ }
1320
+ if (kind === "feed") {
1321
+ if (state.lastFeedAt !== 0 && nowMs - state.lastFeedAt < config.feedCooldownMs) {
1322
+ next.feedRejects += 1;
1323
+ return {
1324
+ affinity: next,
1325
+ delta: 0,
1326
+ reaction: countedRemark("feedCooldown", state.feedRejects),
1327
+ accepted: false
1328
+ };
1329
+ }
1330
+ next.lastFeedAt = nowMs;
1331
+ next.feeds += 1;
1332
+ next.points = clamp$1(state.points + config.feedReward);
1333
+ return {
1334
+ affinity: next,
1335
+ delta: config.feedReward,
1336
+ reaction: countedRemark("feed", state.feeds),
1337
+ accepted: true
1338
+ };
1339
+ }
1340
+ return {
1341
+ affinity: state,
1342
+ delta: 0,
1343
+ reaction: "",
1344
+ accepted: false
1345
+ };
1346
+ }
1347
+ /** Reward one completed turn (called by the host on `done`). */
1348
+ function applyTurnReward(state, config = defaultAffinityConfig) {
1349
+ const next = { ...state };
1350
+ next.turns += 1;
1351
+ next.points = clamp$1(state.points + config.turnReward);
1352
+ return next;
1353
+ }
1354
+ //#endregion
1000
1355
  //#region src/treats.ts
1001
1356
  const defaultTreatConfig = {
1002
1357
  turnsPerTreat: 30,
@@ -4702,6 +5057,104 @@ function petEntryView(entry, globalVoice) {
4702
5057
  };
4703
5058
  }
4704
5059
  //#endregion
5060
+ //#region src/state.ts
5061
+ const defaultPetStateConfig = {
5062
+ celebrateMs: 2400,
5063
+ failureMs: 2400
5064
+ };
5065
+ /**
5066
+ * Map one activity phase onto the animation contract.
5067
+ * - thinking → `running` and tool → `running-right` (focused work).
5068
+ * - review → `review` while answer text is streaming.
5069
+ * - waiting → `waiting` (expectant pose, needs user input).
5070
+ * - done → `jumping` (celebration), then back to `idle` after the window.
5071
+ * - failed → `failed` briefly, then back to `idle`.
5072
+ * - idle → `idle` (calm breathing loop).
5073
+ */
5074
+ function animationForPhase(phase) {
5075
+ switch (phase) {
5076
+ case "thinking": return "running";
5077
+ case "tool": return "running-right";
5078
+ case "review": return "review";
5079
+ case "waiting": return "waiting";
5080
+ case "done": return "jumping";
5081
+ case "failed": return "failed";
5082
+ case "idle": return "idle";
5083
+ }
5084
+ }
5085
+ /** The spritesheet row index for one animation track. */
5086
+ function rowOf(animation) {
5087
+ return {
5088
+ "idle": 0,
5089
+ "running-right": 1,
5090
+ "running-left": 2,
5091
+ "waving": 3,
5092
+ "jumping": 4,
5093
+ "failed": 5,
5094
+ "waiting": 6,
5095
+ "running": 7,
5096
+ "review": 8
5097
+ }[animation];
5098
+ }
5099
+ /**
5100
+ * PetStateMachine — one instance per host process. Holds only the latest
5101
+ * input snapshot and terminal-state timing; no storage, no side effects.
5102
+ */
5103
+ var PetStateMachine = class {
5104
+ now;
5105
+ phase = "idle";
5106
+ line;
5107
+ phrase;
5108
+ sessionActive = false;
5109
+ doneAt;
5110
+ failedAt;
5111
+ config;
5112
+ constructor(config = defaultPetStateConfig, now = Date.now) {
5113
+ this.now = now;
5114
+ this.config = {
5115
+ ...defaultPetStateConfig,
5116
+ ...config
5117
+ };
5118
+ }
5119
+ /** Consume one projected activity update. */
5120
+ onActivityStatus(input) {
5121
+ this.phase = input.phase;
5122
+ this.line = input.line;
5123
+ this.phrase = input.phrase;
5124
+ this.doneAt = input.phase === "done" ? this.now() : void 0;
5125
+ this.failedAt = input.phase === "failed" ? this.now() : void 0;
5126
+ }
5127
+ /** A session became the active one (or a fresh session started). */
5128
+ onSessionActive() {
5129
+ this.sessionActive = true;
5130
+ }
5131
+ /** The active session was disposed (or none left). */
5132
+ onSessionDisposed() {
5133
+ this.sessionActive = false;
5134
+ this.phase = "idle";
5135
+ this.line = void 0;
5136
+ this.phrase = void 0;
5137
+ this.doneAt = void 0;
5138
+ this.failedAt = void 0;
5139
+ }
5140
+ /** Render the current animation decision. */
5141
+ render() {
5142
+ const nowMs = this.now();
5143
+ let animation = animationForPhase(this.phase);
5144
+ const doneSettled = this.phase === "done" && this.doneAt !== void 0 && nowMs - this.doneAt >= this.config.celebrateMs;
5145
+ const failedSettled = this.phase === "failed" && this.failedAt !== void 0 && nowMs - this.failedAt >= this.config.failureMs;
5146
+ if (doneSettled || failedSettled) animation = "idle";
5147
+ const bubble = this.phase === "idle" || doneSettled || failedSettled ? void 0 : this.phrase ?? this.line;
5148
+ return {
5149
+ animation,
5150
+ ...bubble === void 0 ? {} : { bubble },
5151
+ animationStartedAt: nowMs,
5152
+ phase: this.phase,
5153
+ sessionActive: this.sessionActive
5154
+ };
5155
+ }
5156
+ };
5157
+ //#endregion
4705
5158
  //#region src/service.ts
4706
5159
  /**
4707
5160
  * Pet host service — the `pet.*` RPC domain. A composition facade: it wires