@clawtopia/werewolf-evolution 0.1.12 → 0.1.14
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 +25 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,10 +7,6 @@ import {
|
|
|
7
7
|
// src/context-store.ts
|
|
8
8
|
import { createHash as createHash2 } from "crypto";
|
|
9
9
|
|
|
10
|
-
// src/envelope.ts
|
|
11
|
-
import { createHash } from "crypto";
|
|
12
|
-
import { z } from "zod";
|
|
13
|
-
|
|
14
10
|
// src/types.ts
|
|
15
11
|
var DEBRIEF_HEADER = "[WEREWOLF_DEBRIEF v2]";
|
|
16
12
|
var DEBRIEF_POLICY_VERSION = "werewolf-debrief-v3";
|
|
@@ -18,6 +14,8 @@ var ENVELOPE_START = "== DEBRIEF_ENVELOPE_JSON ==";
|
|
|
18
14
|
var ENVELOPE_END = "== END_DEBRIEF_ENVELOPE_JSON ==";
|
|
19
15
|
|
|
20
16
|
// src/envelope.ts
|
|
17
|
+
import { createHash } from "crypto";
|
|
18
|
+
import { z } from "zod";
|
|
21
19
|
var MAX_DEBRIEF_BODY_BYTES = 64 * 1024;
|
|
22
20
|
var SAFE_ID = /^[A-Za-z0-9:_-]{1,200}$/;
|
|
23
21
|
var SAFE_PROFILE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
@@ -333,6 +331,12 @@ var CAPTURE_TTL_MS = 10 * 60 * 1e3;
|
|
|
333
331
|
var MAX_CAPTURES = 256;
|
|
334
332
|
var SUGGESTION_COMMAND = /^\s*(采纳|忽略|拒绝)\s+(S-\d{3,6})\s*[。.!!]?\s*$/i;
|
|
335
333
|
var LEGACY_DIRECT_CONVERSATION = /^private:(?:HUMAN|human):([0-9]+)$/;
|
|
334
|
+
function promptContainsInbound(prompt, inbound) {
|
|
335
|
+
if (prompt.includes(inbound.content)) return true;
|
|
336
|
+
if (inbound.kind !== "debrief") return false;
|
|
337
|
+
const lines = prompt.split(/\r?\n/);
|
|
338
|
+
return lines.includes(DEBRIEF_HEADER) && lines.some((line) => /^debriefId:\s*(\S+)\s*$/.exec(line)?.[1] === inbound.envelope.debriefId);
|
|
339
|
+
}
|
|
336
340
|
function isExplicitConfiguredOwner(config, channelId, senderId) {
|
|
337
341
|
if (channelId !== "clawtopia" && channelId !== "coolclaw" || !senderId) return false;
|
|
338
342
|
const owners = record(record(config)?.commands)?.ownerAllowFrom;
|
|
@@ -450,7 +454,8 @@ var EvolutionContextStore = class {
|
|
|
450
454
|
if (!prompt) return void 0;
|
|
451
455
|
const pending = this.inboundBySession.get(sessionKey);
|
|
452
456
|
if (!pending) return void 0;
|
|
453
|
-
|
|
457
|
+
const matches = pending.filter((candidate) => promptContainsInbound(prompt, candidate));
|
|
458
|
+
return matches.length === 1 ? matches[0] : void 0;
|
|
454
459
|
}
|
|
455
460
|
stableInboundKey(ctx, sessionKey, event) {
|
|
456
461
|
const messageId = event.messageId?.trim();
|
|
@@ -762,20 +767,20 @@ var NO_TARGET_ALTERNATIVE_LANGUAGE = /(?:保留投票权|等待更多信息|暂
|
|
|
762
767
|
var EXPLICIT_TARGET_LANGUAGE = /(?:(?:改投|改票(?:到|给)?|归票|票投|投票(?:给|到)?|投(?:给|到)?|查验|验|刀|毒|救|开枪带走|目标(?:改为|是)?)\s*|target(?:\s+seat)?[^0-9]{0,6})([1-9][0-9]*)\s*(?:号|座|\b)/gi;
|
|
763
768
|
var FINAL_RESULT_LANGUAGE = /(?:最终|终局|全场|对局结果|比赛结果)[^。;,,!!]{0,16}(?:获胜|胜利|胜出|取胜|赢了|输了|落败|失败)|(?:好人(?:阵营)?|村民|平民|狼人(?:阵营)?|狼队)[^。;,,!!]{0,10}(?:获胜|胜利|胜出|取胜|赢了|输了|落败)|(?:险胜|惨胜|翻盘获胜|为(?:最终)?胜利铺路)|赢下(?:本局|这局|对局|比赛)|(?:GOOD|WOLF)(?:_TEAM)?_WIN|(?:the\s+)?(?:(?:good|village|wolf)\s+team|villagers?|village|wolves|wolf|werewolves?)\s+(?:wins?|won|loses?|lost)|(?:won|lost) the game|final (?:victory|defeat)/i;
|
|
764
769
|
var SEAT_REFERENCE_LANGUAGE = /([1-9][0-9]*)\s*号(?:玩家)?/g;
|
|
765
|
-
var BEHAVIOR_TERMS = "\u53D1\u8A00|\u8868\u73B0|\u884C\u4E3A|\u8BF4\u6CD5|\u5185\u5BB9|\u7AD9\u8FB9|\u7968\u578B|\u6295\u7968|\u5F52\u7968|\u7529\u9505|\u8D28\u7591|\u5BF9\u8DF3|\u8D77\u8DF3|\u608D\u8DF3|\u5012\u94A9|\u67E5\u6740|\u4FDD\u4EBA|\u8E29\u4EBA|\u653B\u51FB|\u8FA9\u89E3|\u8DDF\u7968|\u51B2\u7968|\u8868\u6C34";
|
|
770
|
+
var BEHAVIOR_TERMS = "\u53D1\u8A00|\u8868\u73B0|\u884C\u4E3A|\u8BF4\u6CD5|\u5185\u5BB9|\u7AD9\u8FB9|\u7968\u578B|\u6295\u7968|\u5F52\u7968|\u7529\u9505|\u8D28\u7591|\u5BF9\u8DF3|\u8D77\u8DF3|\u608D\u8DF3|\u5012\u94A9|\u67E5\u6740|\u4FDD\u4EBA|\u8E29\u4EBA|\u653B\u51FB|\u8FA9\u89E3|\u8DDF\u7968|\u51B2\u7968|\u8868\u6C34|\u81EA\u79F0|\u58F0\u79F0|\u516C\u5F00\u8EAB\u4EFD|\u516C\u5F00\u9884\u8A00\u5BB6|\u516C\u5F00\u5973\u5DEB|\u516C\u5F00\u730E\u4EBA|\u8DF3\u9884\u8A00\u5BB6|\u8DF3\u5973\u5DEB|\u8DF3\u730E\u4EBA";
|
|
766
771
|
var FIRST_NIGHT_DAYTIME_INFORMATION = new RegExp(
|
|
767
|
-
`(?:\u73A9\u5BB6)?\u53D1\u8A00\u98CE\u683C|(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u968F\u540E|\u540E\u7EED)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:${BEHAVIOR_TERMS})|(?:${BEHAVIOR_TERMS})[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u968F\u540E|\u540E\u7EED)`,
|
|
772
|
+
`(?:\u73A9\u5BB6)?\u53D1\u8A00\u98CE\u683C|(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u7B2C\u4E8C\u591C|\u660E\u5929|\u660E\u65E5|\u4E0B\u4E2A(?:\u56DE\u5408|\u8F6E|\u767D\u5929|\u591C\u665A)|\u4E0B\u4E00(?:\u5929|\u56DE\u5408|\u8F6E|\u591C|\u591C\u665A)|\u968F\u540E|\u540E\u7EED)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:${BEHAVIOR_TERMS})|(?:${BEHAVIOR_TERMS})[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u7B2C\u4E8C\u591C|\u660E\u5929|\u660E\u65E5|\u4E0B\u4E2A(?:\u56DE\u5408|\u8F6E|\u767D\u5929|\u591C\u665A)|\u4E0B\u4E00(?:\u5929|\u56DE\u5408|\u8F6E|\u591C|\u591C\u665A)|\u968F\u540E|\u540E\u7EED)`,
|
|
768
773
|
"i"
|
|
769
774
|
);
|
|
770
775
|
var DIRECTLY_NEGATED_DAYTIME_INFORMATION = /(?:尚无|暂无|没有|尚未(?:出现|发生)?)(?:任何)?(?:白天|白昼|日间|首日|第一天)?(?:发言|站边|票型|归票|信息)|不(?:得|可|能|应)?(?:参考|使用|依赖)(?:(?:任何)?(?:白天|白昼|日间|首日|第一天)(?:发言|站边|票型|归票|信息)|(?:玩家)?发言风格)|(?:白天|白昼|日间|首日|第一天)(?:发言|站边|票型|归票|信息)(?:尚无|暂无|尚未(?:出现|发生)|不可用|不能使用)/gi;
|
|
771
776
|
var RELATIVE_FUTURE_BEHAVIOR_LANGUAGE = new RegExp(
|
|
772
|
-
`(?:(?:\u540E\u7F6E\u4F4D|\u5176\u4ED6\u73A9\u5BB6)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,10}(?:\u968F\u540E|\u4E4B\u540E|\u5C06\u4F1A?|\u7A0D\u540E)|\u5929\u4EAE(?:\u540E|\u4E4B\u540E)|\u6B21\u65E5|\u4E0B\u4E00(?:\u5929|\u8F6E|\u4E2A\u767D\u5929))[^\u3002\uFF1B\uFF0C,!\uFF01]{0,20}(?:${BEHAVIOR_TERMS})`,
|
|
777
|
+
`(?:(?:\u540E\u7F6E\u4F4D|\u5176\u4ED6\u73A9\u5BB6)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,10}(?:\u968F\u540E|\u4E4B\u540E|\u5C06\u4F1A?|\u7A0D\u540E)|\u5929\u4EAE(?:\u540E|\u4E4B\u540E)|\u6B21\u65E5|\u660E\u5929|\u660E\u65E5|\u4E0B\u4E2A(?:\u5929|\u56DE\u5408|\u8F6E|\u767D\u5929|\u591C\u665A)|\u4E0B\u4E00(?:\u5929|\u56DE\u5408|\u8F6E|\u4E2A\u767D\u5929|\u591C|\u591C\u665A))[^\u3002\uFF1B\uFF0C,!\uFF01]{0,20}(?:${BEHAVIOR_TERMS})`,
|
|
773
778
|
"i"
|
|
774
779
|
);
|
|
775
|
-
var ABSOLUTE_DAY_BEHAVIOR_LANGUAGE = new RegExp(
|
|
780
|
+
var ABSOLUTE_DAY_BEHAVIOR_LANGUAGE = new RegExp(`(?:\u7B2C([0-9\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D\u5341]+)|([\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D\u5341]+))\\s*(?:\u5929|\u8F6E|\u56DE\u5408|\u591C|\u591C\u665A)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,24}(?:${BEHAVIOR_TERMS})`, "gi");
|
|
776
781
|
var BEHAVIOR_OCCURRENCE_LANGUAGE = new RegExp(`(?:${BEHAVIOR_TERMS})`, "i");
|
|
777
782
|
var PAST_BEHAVIOR_LANGUAGE = new RegExp(`(?:\u6B64\u524D|\u4E4B\u524D|\u66FE\u7ECF|\u8FC7\u53BB|\u4E0A\u4E00\u8F6E|\u4E0A\u4E00\u591C|\u6628\u591C)|\u5DF2\u7ECF(?!\u51B3\u5B9A)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,4}(?:${BEHAVIOR_TERMS})`, "i");
|
|
778
|
-
var CURRENT_ACTOR_ACTION_LANGUAGE = /(
|
|
783
|
+
var CURRENT_ACTOR_ACTION_LANGUAGE = /(?:当前|本次|此时|轮到|发言(?:时|中)|投票时|行动时|查验时|已经决定|正在|正要|准备|计划|将要)/i;
|
|
779
784
|
var NEGATED_BEHAVIOR_LANGUAGE = new RegExp(`(?:\u6CA1\u6709|\u5E76\u672A|\u672A\u66FE|\u4E0D\u66FE|\u4ECE\u672A|\u5C1A\u672A|\u4E0D)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,6}(?:${BEHAVIOR_TERMS})|(?:did not|never|no)\\b`, "i");
|
|
780
785
|
var BEHAVIOR_TARGET_LANGUAGE = /(?:归票|投票(?:给|到)?|票投(?:给|到)?|投(?:给|到)|跟票(?:给|到)?|冲票(?:给|到)?|查杀|保人|踩|攻击|质疑)(?:给|到|向)?\s*([1-9][0-9]*)\s*号/i;
|
|
781
786
|
var TARGET_REFERENCE_PREFIX = /(?:归票|投票|票投|投给|投到|跟票|冲票|查杀|保人|踩|攻击|质疑)(?:给|到|向)?\s*$/i;
|
|
@@ -786,7 +791,7 @@ var BEHAVIOR_GROUPS = [
|
|
|
786
791
|
/(?:甩锅|推责|责任推|把责任)/i,
|
|
787
792
|
/(?:站边|支持|认好|认狼|side with|support)/i,
|
|
788
793
|
/(?:质疑|怀疑|攻击|踩人|question|suspect|attack)/i,
|
|
789
|
-
/(
|
|
794
|
+
/(?:对跳|起跳|悍跳|拍身份|公开身份|自称|声称|(?:公开|跳)(?:预言家|女巫|猎人)|role claim|claim(?:ed)? (?:seer|witch|hunter))/i,
|
|
790
795
|
/(?:倒钩)/i,
|
|
791
796
|
/(?:查杀)/i,
|
|
792
797
|
/(?:保人|金水)/i,
|
|
@@ -903,9 +908,13 @@ function factSupportsBehaviorClaim(fact, claim) {
|
|
|
903
908
|
return false;
|
|
904
909
|
}
|
|
905
910
|
const groups = BEHAVIOR_GROUPS.filter((pattern) => pattern.test(claim));
|
|
911
|
+
const isCompletedVoteClaim = /(?:投票|投给|投到|票投|出票)/i.test(claim) && claimedTarget !== void 0;
|
|
912
|
+
if (isCompletedVoteClaim) {
|
|
913
|
+
return VOTE_FACT_TYPES.has(fact.type) && (fact.targetSeat ?? behaviorTarget(summary)) === claimedTarget;
|
|
914
|
+
}
|
|
906
915
|
if (groups.length > 0) {
|
|
907
|
-
if (
|
|
908
|
-
return groups.some((pattern) => pattern
|
|
916
|
+
if (!SPEECH_FACT_TYPES.has(fact.type)) return false;
|
|
917
|
+
return groups.some((pattern) => pattern.test(summary));
|
|
909
918
|
}
|
|
910
919
|
if (/(?:发言|说法|内容)/i.test(claim) && SPEECH_FACT_TYPES.has(fact.type)) {
|
|
911
920
|
const shortGenericClaim = semanticText(claim).length <= 6;
|
|
@@ -956,7 +965,7 @@ function dependsOnFutureBehavior(value, currentRound) {
|
|
|
956
965
|
if (RELATIVE_FUTURE_BEHAVIOR_LANGUAGE.test(value)) return true;
|
|
957
966
|
if (currentRound === void 0) return false;
|
|
958
967
|
for (const match of value.matchAll(ABSOLUTE_DAY_BEHAVIOR_LANGUAGE)) {
|
|
959
|
-
const referencedRound = chineseNumber(match[1]);
|
|
968
|
+
const referencedRound = chineseNumber(match[1] ?? match[2] ?? "");
|
|
960
969
|
if (referencedRound !== void 0 && referencedRound > currentRound) return true;
|
|
961
970
|
}
|
|
962
971
|
return false;
|
|
@@ -3115,6 +3124,8 @@ var WerewolfEvolutionService = class {
|
|
|
3115
3124
|
"- If alternativeActionType=DAY_VOTE, copy a legal seat from that window.availableTargetSeats, or send alternativeTargetSeat=null for explicit abstention. Do not omit the target for DAY_VOTE.",
|
|
3116
3125
|
"- SELF must use a decisionWindow whose actorSeat equals eligibility.recipientSeat. OBSERVED and EXEMPLAR must use another actor's decisionWindow.",
|
|
3117
3126
|
"- knownFactRefs must be earlier than the anchor and visible to the window actor; POSTGAME_ONLY is never known, SEAT_n_ONLY is visible only to that seat, and WOLF_TEAM is visible only to a wolf actor.",
|
|
3127
|
+
"- trigger, rule, boundary, and alternativeAction must depend only on information that already existed at the anchor and is supported by knownFactRefs; reject relative future wording such as tomorrow, next round, next day/night, or day/round N after the current anchor round.",
|
|
3128
|
+
"- A seat behavior claim must match actor, behavior category, explicit target, negation polarity, and event type. Completed votes require DAY_VOTE_SUBMIT/DAY_REVOTE_SUBMIT facts; role claims, stance, questions, and other speech behaviors require DAY_SPEAK/LAST_WORD/WOLF_SPEECH facts. When uncertain, reject rather than fail open.",
|
|
3118
3129
|
"- outcomeFactRefs must be later than the anchor and include at least one local outcome fact whose type appears in localOutcomeFactTypes.",
|
|
3119
3130
|
"- GAME_FINISHED, FINAL_IDENTITY, and GAME_RESULT are never local outcome facts and cannot be the only outcome evidence.",
|
|
3120
3131
|
"- behavior must describe only what actually happened at the anchor; never copy rule or alternativeAction into behavior as if it occurred.",
|
package/package.json
CHANGED