@clawtopia/werewolf-evolution 0.1.16 → 0.1.18
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 +451 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -763,11 +763,14 @@ var EXECUTION_PROPOSAL_TEMPLATES = {
|
|
|
763
763
|
var STRATEGY_LANGUAGE = /(?:改变|改投|改票|转票|投给|投票目标|查验目标|验谁|刀谁|刀口|毒谁|救谁|用药|开枪|起跳|跳预言家|自刀|悍跳|倒钩|站边|目标座位|targetSeat|actionType|vote target|check target|kill target)/i;
|
|
764
764
|
var FIXED_RULE_LANGUAGE = /(?:JSON\s*schema|JSON格式|非法动作|角色动作合法|私有信息保护|不虚构时间线|工具失败|输出超时|现实人格|人身攻击)/i;
|
|
765
765
|
var COUNTER_EFFECT_LANGUAGE = /(?:未能|没有|无法|无效|反而|恶化|失败|矛盾|误导|暴露|did not|failed|ineffective|worse|contradict)/i;
|
|
766
|
+
var ADVERSE_LOCAL_EFFECT_LANGUAGE = /(?:未能|无法|无效|反而|恶化|失败|错误|矛盾|误导|暴露|质疑|追问|要求补充|分歧|混乱|降低|减少|缩小|被[^。;,,!!]{0,8}(?:放逐|投出|淘汰)|(?:狼面|好人面)[^。;,,!!]{0,6}(?:拉满|下降)|did not|failed|ineffective|worse|questioned|challenged)/i;
|
|
767
|
+
var BENEFICIAL_LOCAL_EFFECT_LANGUAGE = /(?:成功|改善|提升|增加|跟进|认可|支持|聚焦|集中|形成[^。;,,!!]{0,8}(?:讨论|站边|共识)|达成[^。;,,!!]{0,8}(?:一致|共识)|(?:提交|改投)[^。;,,!!]{0,8}投票|(?:放逐|投出|淘汰)[^。;,,!!]{0,6}(?:目标|狼人|狼)|没有再次(?:质疑|追问|要求补充)|不再(?:质疑|追问|要求补充)|succeeded|improved|followed up|supported|reached consensus)/i;
|
|
766
768
|
var NO_TARGET_ALTERNATIVE_LANGUAGE = /(?:保留投票权|等待更多信息|暂不(?:投票|选择|行动)|弃票|不选(?:择)?(?:任何)?(?:目标|座位)|不指定目标|不设目标|继续观望|\b(?:wait for more information|abstain|hold (?:the )?vote|choose no target)\b)/i;
|
|
767
769
|
var AMBIGUOUS_ALTERNATIVE_LANGUAGE = /(?:或者|或是|要么|二选一|[号座]\s*或\s*[1-9]|[1-9][0-9]*\s*[、/]\s*[1-9][0-9]*|[1-9][0-9]*\s*号?\s*(?:和|与)\s*[1-9][0-9]*\s*号?\s*(?:(?:中|之间)\s*)?(?:选择|选一个|任选|择一|中的一个)|\bor\b)/i;
|
|
768
770
|
var TARGET_UNCHANGED_LANGUAGE = /(?:不|不得|不会)(?:改变|更改|调整|切换)(?:当前|原有|既定)?(?:的)?(?:行动|投票|查验|刀人|用药|开枪)?目标|(?:保持|维持)(?:原有|原定|既定|当前|相同)(?:的)?(?:行动|投票|查验|刀人|用药|开枪)?目标/i;
|
|
769
771
|
var RETAINED_TARGET_SEAT_LANGUAGE = /(?:行动|投票|查验|刀人|用药|开枪)?目标\s*(?:仍(?:然)?|依然|依旧|继续|保持|维持|不变)\s*(?:是|为)?\s*([1-9][0-9]*)\s*号/i;
|
|
770
772
|
var LOCAL_OUTCOME_INFERENCE_LANGUAGE = /(?:,|;|。|,|;)\s*(?:(?:由此|因此|从而|所以)(?:可见|可知|可判断|说明|证明|表明|意味着)?|(?:这)?(?:说明|证明|表明|意味着|可见|足以(?:说明|证明|表明))|\b(?:therefore|thus|this (?:proves?|shows?|means?))\b)/i;
|
|
773
|
+
var SOCIAL_OUTCOME_LANGUAGE = /(?:将|把)[^。;,,!!]{0,12}(?:怀疑|焦点|注意力)[^。;,,!!]{0,8}(?:导向|转向|锁定)|(?:被|已被|因此被)?[^。;,,!!]{0,8}(?:排除|移出)[^。;,,!!]{0,8}(?:怀疑|狼坑|焦点)|(?:形成|达成|建立)[^。;,,!!]{0,8}(?:统一站边|一致判断|共识)|(?:狼面|好人面)[^。;,,!!]{0,6}(?:拉满|上升|下降)|(?:纠错|怀疑)(?:空间|范围)[^。;,,!!]{0,6}(?:缩小|扩大)|\b(?:cleared from suspicion|consensus formed|attention shifted to)\b/i;
|
|
771
774
|
var ABSOLUTE_STRATEGY_LANGUAGE = /(?:必须|必然|绝对|肯定|一定|毫无疑问|等于直接|唯一(?:正确|合理)?(?:的)?(?:选择|做法)|只能|只能够|无论如何(?:都)?|非[^。;,,!!]{0,8}不可|别无选择|\bmust\b|\balways\b|\bnever\b|\bdefinitely\b|\bcertain(?:ly)?\b|\bguaranteed?\b|the only (?:correct |valid )?(?:choice|option))/i;
|
|
772
775
|
var EXPLICIT_TARGET_LANGUAGE = /(?:(?:改投|改票(?:到|给)?|归票|票投|投票(?:给|到)?|投(?:给|到)?|查验|验|刀|毒|救|开枪带走|目标(?:改为|是)?)\s*|target(?:\s+seat)?[^0-9]{0,6})([1-9][0-9]*)\s*(?:号|座|\b)/gi;
|
|
773
776
|
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;
|
|
@@ -807,6 +810,10 @@ var BEHAVIOR_GROUPS = [
|
|
|
807
810
|
/(?:保人|金水)/i,
|
|
808
811
|
/(?:辩解|表水)/i
|
|
809
812
|
];
|
|
813
|
+
var ROLE_NAME = "\u9884\u8A00\u5BB6|\u5973\u5DEB|\u730E\u4EBA|\u72FC\u4EBA|\u597D\u4EBA|\u5E73\u6C11|\u6751\u6C11";
|
|
814
|
+
var ENGLISH_ROLE_NAME = "seer|witch|hunter|werewolf|wolf|good(?: player)?|villager";
|
|
815
|
+
var CONDITIONAL_IDENTITY_LANGUAGE = /(?:如果|若|假如|假设|可能|或许|怀疑|认为|倾向|猜测|未必|不确定)[^。;,,!!]{0,8}$/i;
|
|
816
|
+
var SPEECH_OUTCOME_FACT_TYPES = /* @__PURE__ */ new Set(["DAY_SPEAK", "LAST_WORD", "WOLF_SPEECH"]);
|
|
810
817
|
var LOCAL_OUTCOME_FACT_TYPES = /* @__PURE__ */ new Set([
|
|
811
818
|
"WOLF_CHOOSE",
|
|
812
819
|
"WOLF_SPEECH",
|
|
@@ -942,6 +949,13 @@ function factSupportsBehaviorClaim(fact, claim) {
|
|
|
942
949
|
}
|
|
943
950
|
return similarity(claim, summary) >= 0.35;
|
|
944
951
|
}
|
|
952
|
+
function behaviorActorSeats(value) {
|
|
953
|
+
const actors = new Set(seatBehaviorClaims(value).map(({ seat }) => seat));
|
|
954
|
+
for (const match of value.matchAll(/(?:^|[。;,,;]\s*)seat\s*=?\s*([1-9][0-9]*)\s*(?:;|,)?\s*(?:content\s*=)?/gi)) {
|
|
955
|
+
actors.add(Number(match[1]));
|
|
956
|
+
}
|
|
957
|
+
return actors;
|
|
958
|
+
}
|
|
945
959
|
function seatBehaviorClaims(value) {
|
|
946
960
|
const claims = [];
|
|
947
961
|
for (const clause of value.split(/[。;,,!!]/)) {
|
|
@@ -1011,16 +1025,30 @@ function dependsOnFutureBehavior(value, currentRound) {
|
|
|
1011
1025
|
}
|
|
1012
1026
|
function assertBehaviorIsObserved(proposal) {
|
|
1013
1027
|
const behavior = proposal.behavior ?? "";
|
|
1014
|
-
const overlap = Math.max(
|
|
1028
|
+
const overlap = proposal.source === "EXEMPLAR" || proposal.action === "COUNTER" ? similarity(behavior, proposal.alternativeAction ?? "") : Math.max(
|
|
1015
1029
|
similarity(behavior, proposal.alternativeAction ?? ""),
|
|
1016
1030
|
similarity(behavior, proposal.rule ?? "")
|
|
1017
1031
|
);
|
|
1018
1032
|
if (overlap >= 0.68) {
|
|
1019
1033
|
throw new ProposalError(
|
|
1020
1034
|
"BEHAVIOR_COUNTERFACTUAL",
|
|
1021
|
-
"behavior must describe the observed action, not the
|
|
1035
|
+
"behavior must describe the observed action, not the counterfactual action"
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function assertBehaviorMatchesAnchor(proposal, behavior, anchor) {
|
|
1040
|
+
const explicitActors = behaviorActorSeats(behavior);
|
|
1041
|
+
if ([...explicitActors].some((seat) => anchor.actorSeat !== seat)) {
|
|
1042
|
+
throw new ProposalError(
|
|
1043
|
+
"BEHAVIOR_FACT_MISMATCH",
|
|
1044
|
+
"behavior actor seat does not match the trusted anchor fact"
|
|
1022
1045
|
);
|
|
1023
1046
|
}
|
|
1047
|
+
if (factSupportsBehaviorClaim(anchor, behavior)) return;
|
|
1048
|
+
throw new ProposalError(
|
|
1049
|
+
"BEHAVIOR_FACT_MISMATCH",
|
|
1050
|
+
"behavior is not supported by the trusted anchor fact"
|
|
1051
|
+
);
|
|
1024
1052
|
}
|
|
1025
1053
|
function assertAlternativeTargetConsistent(proposal) {
|
|
1026
1054
|
const target = proposal.alternativeTargetSeat;
|
|
@@ -1067,17 +1095,181 @@ function assertNoAbsoluteStrategyClaim(proposal) {
|
|
|
1067
1095
|
);
|
|
1068
1096
|
}
|
|
1069
1097
|
}
|
|
1098
|
+
function omitsRepeatedContent(value) {
|
|
1099
|
+
return /(?:省略|删去|跳过|避免|减少|不(?:再|要)?)[^。;,,!!]{0,20}(?:复述|重复)|\b(?:omit|skip|remove|avoid|reduce|do not)\b[^.;]{0,20}\b(?:repeat|duplicate)/i.test(value);
|
|
1100
|
+
}
|
|
1101
|
+
function addsNewInformation(value) {
|
|
1102
|
+
const withoutNegatedAdd = value.replace(/(?:不|没有|未)(?:再)?(?:补充|新增|提供|增加)[^。;,,!!]{0,8}(?:信息|观点|判断|依据|逻辑|内容)/gi, "");
|
|
1103
|
+
return /(?:(?:补充|新增)[^。;,,!!]{0,8}(?:信息|观点|判断|依据|逻辑|内容)|新(?:的)?(?:信息|观点|判断|依据|逻辑|内容)|相对于前置(?:发言|内容))|\b(?:add|provide|state|include)\b[^.;]{0,20}\bnew (?:information|reasoning|judgment|evidence)/i.test(withoutNegatedAdd);
|
|
1104
|
+
}
|
|
1105
|
+
function repeatsPriorContent(value) {
|
|
1106
|
+
return !omitsRepeatedContent(value) && /(?:完整|再次|继续|直接)?[^。;,,!!]{0,4}(?:复述|重复)[^。;,,!!]{0,12}(?:前置|已有|相同|观点|内容|立场)|\b(?:repeat|duplicate)\b[^.;]{0,20}\b(?:prior|same|existing)/i.test(value);
|
|
1107
|
+
}
|
|
1108
|
+
function retractsPriorJudgment(value) {
|
|
1109
|
+
const withoutNegatedRetraction = value.replace(/(?:不|没有|并未|未曾|尚未)(?:再)?[^。;,,!!]{0,4}(?:撤回|收回|更正|纠正|修正|改口|更新)[^。;,,!!]{0,12}(?:判断|观点|结论|说法|发言)/gi, "");
|
|
1110
|
+
return /(?:撤回|收回|更正|纠正|修正|改口|更新)[^。;,,!!]{0,12}(?:旧|此前|之前|先前|原有|原先)?[^。;,,!!]{0,4}(?:判断|观点|结论|说法|发言)|(?:旧|此前|之前|先前|原有|原先)[^。;,,!!]{0,8}(?:判断|观点|结论|说法|发言)[^。;,,!!]{0,8}(?:撤回|收回|更正|纠正|修正|改口|更新)|\b(?:retract|withdraw|correct|revise|update)\b[^.;]{0,20}\b(?:prior|previous|old)\b/i.test(withoutNegatedRetraction);
|
|
1111
|
+
}
|
|
1112
|
+
function discussesOwnRoleClaimTiming(value) {
|
|
1113
|
+
const roleClaimPattern = /(?:起跳|悍跳|跳(?:预言家|女巫|猎人)|公开(?:自己|自身|本人的)?(?:身份|神职)|公开(?:预言家|女巫|猎人)身份|拍(?:明)?身份|亮明身份|隐藏身份|身份宣称|role claim|claim (?:seer|witch|hunter))/i;
|
|
1114
|
+
const timingPattern = /(?:决定|选择|是否|何时|时机|首日|第一天|立即|直接|暂缓|延后|推迟|隐藏|不跳|起跳|公开|when|whether|timing|immediately|delay)/i;
|
|
1115
|
+
return topicHasAffirmedMatch(value, roleClaimPattern, true) && topicHasAffirmedMatch(value, timingPattern, false);
|
|
1116
|
+
}
|
|
1117
|
+
function assertDecisionTopic(decisionType, topic, required, allowDirectNegation = false) {
|
|
1118
|
+
if (required.every((pattern) => topicHasAffirmedMatch(topic, pattern, allowDirectNegation))) return;
|
|
1119
|
+
throw new ProposalError(
|
|
1120
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1121
|
+
`${decisionType} does not match the rule and alternative action topic`
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
function topicHasAffirmedMatch(value, pattern, allowDirectNegation) {
|
|
1125
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
1126
|
+
for (const match of value.matchAll(new RegExp(pattern.source, flags))) {
|
|
1127
|
+
if (!topicMatchIsDisclaimed(value, match.index, match[0].length, allowDirectNegation)) return true;
|
|
1128
|
+
}
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
function topicMatchIsDisclaimed(value, start, length, allowDirectNegation) {
|
|
1132
|
+
const clauseStart = Math.max(
|
|
1133
|
+
value.lastIndexOf("\u3002", start - 1),
|
|
1134
|
+
value.lastIndexOf("\uFF1B", start - 1),
|
|
1135
|
+
value.lastIndexOf("\uFF0C", start - 1),
|
|
1136
|
+
value.lastIndexOf(".", start - 1),
|
|
1137
|
+
value.lastIndexOf(";", start - 1),
|
|
1138
|
+
value.lastIndexOf(",", start - 1),
|
|
1139
|
+
value.lastIndexOf("?", start - 1),
|
|
1140
|
+
value.lastIndexOf("\uFF1F", start - 1),
|
|
1141
|
+
value.lastIndexOf("!", start - 1),
|
|
1142
|
+
value.lastIndexOf("\uFF01", start - 1)
|
|
1143
|
+
) + 1;
|
|
1144
|
+
const remaining = value.slice(start + length);
|
|
1145
|
+
const relativeClauseEnd = remaining.search(/[。;,.!!,;??]/);
|
|
1146
|
+
const clauseEnd = relativeClauseEnd === -1 ? value.length : start + length + relativeClauseEnd;
|
|
1147
|
+
const before = value.slice(clauseStart, start);
|
|
1148
|
+
const after = value.slice(start + length, clauseEnd);
|
|
1149
|
+
const clause = value.slice(clauseStart, clauseEnd);
|
|
1150
|
+
const disclaimedBefore = /(?:不|未|没有|并未|无需|无须|拒绝)(?:再)?(?:涉及|讨论|处理|针对|关于|考虑|选择|决定|说明|解释|报告|执行|进行|使用|改变)\s*[^。;,,!!]{0,4}$/i.test(before);
|
|
1151
|
+
const directlyNegated = /(?:不|未|没有|并未)\s*$/i.test(before);
|
|
1152
|
+
const disclaimedAfter = /^[^。;,,!!]{0,10}(?:无关|予以排除|不予(?:考虑|纳入)|不(?:再|被)?(?:涉及|讨论|处理|考虑|选择|决定|说明|解释|报告|执行|进行|使用|改变|包含|覆盖|纳入))/i.test(after);
|
|
1153
|
+
const englishDisclaimedBefore = /\b(?:(?:is|are|was|were|be|being|been)\s+)?not\s+(?:about|related\s+to|concerned\s+with|focused\s+on|intended\s+to|meant\s+to|dealing\s+with)\s+[^.;,!?]{0,18}$/i.test(before) || /\b(?:do|does|did|will|would|should|must|can|cannot|could)\s+not\s+(?:address|discuss|handle|choose|decide|consider|explain|report|perform|use|change|involve)\s+[^.;,!?]{0,18}$/i.test(before);
|
|
1154
|
+
const englishDirectlyNegated = /\b(?:(?:do|does|did|will|would|should|must|can|cannot|could)\s+not|never)\s*$/i.test(before);
|
|
1155
|
+
const englishDisclaimedAfter = /^[^.;,!?]{0,18}\b(?:is|are)?\s*(?:excluded|omitted|rejected|unrelated|outside\s+(?:the\s+)?scope|out\s+of\s+scope|not\s+(?:addressed|discussed|handled|chosen|decided|considered|explained|reported|performed|used|changed|covered|included))/i.test(after);
|
|
1156
|
+
const metaTopicLanguage = /(?:本|该|这条|当前)?(?:规则|主题|议题|建议|提案|内容|范围)|\b(?:rule|topic|subject|proposal|scope)\b/i;
|
|
1157
|
+
const metaExclusionLanguage = /(?:排除|避开|回避|无关|不(?:在|属于)[^。;,,!!]{0,10}(?:范围|议题|主题)|不(?:涉及|讨论|处理|针对|关于|考虑|包含|覆盖)|不予(?:考虑|纳入))|\b(?:excludes?|avoids?|omits?|rejects?|irrelevant|unrelated|nothing\s+to\s+do\s+with|outside\s+(?:the\s+)?scope|out\s+of\s+scope|does?\s+not\s+(?:cover|include|address|discuss|handle|concern)|not\s+(?:about|related\s+to|concerned\s+with|focused\s+on|dealing\s+with|covered|included))\b/i;
|
|
1158
|
+
const metaTopicDisclaimed = metaTopicLanguage.test(clause) && metaExclusionLanguage.test(clause);
|
|
1159
|
+
return disclaimedBefore || englishDisclaimedBefore || !allowDirectNegation && (directlyNegated || englishDirectlyNegated) || disclaimedAfter || englishDisclaimedAfter || metaTopicDisclaimed;
|
|
1160
|
+
}
|
|
1070
1161
|
function assertDecisionTypeSemantics(proposal) {
|
|
1071
|
-
|
|
1072
|
-
const
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1162
|
+
const rule = proposal.rule ?? "";
|
|
1163
|
+
const alternative = proposal.alternativeAction ?? "";
|
|
1164
|
+
const behavior = proposal.behavior ?? "";
|
|
1165
|
+
if (proposal.decisionType === "AVOID_REPEATING_PRIOR_SPEAKERS") {
|
|
1166
|
+
const topic2 = `${rule}\u3002 ${alternative}`;
|
|
1167
|
+
const followsRule = omitsRepeatedContent(behavior) && addsNewInformation(behavior);
|
|
1168
|
+
if (proposal.source !== "EXEMPLAR" && proposal.action !== "COUNTER" && followsRule) {
|
|
1169
|
+
throw new ProposalError(
|
|
1170
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1171
|
+
"SELF and OBSERVED must describe a failed action, not an action that already follows the rule"
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
if (!omitsRepeatedContent(topic2) || !addsNewInformation(topic2)) {
|
|
1175
|
+
throw new ProposalError(
|
|
1176
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1177
|
+
"AVOID_REPEATING_PRIOR_SPEAKERS must describe omitting repeated content and adding new information"
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
if (proposal.source === "EXEMPLAR" || proposal.action === "COUNTER") {
|
|
1181
|
+
if (!followsRule || proposal.action !== "COUNTER" && !repeatsPriorContent(alternative)) {
|
|
1182
|
+
throw new ProposalError(
|
|
1183
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1184
|
+
"EXEMPLAR behavior must follow the rule and contrast with a worse counterfactual"
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
if (proposal.decisionType === "RETRACT_PUBLIC_JUDGMENT") {
|
|
1191
|
+
if (!retractsPriorJudgment(rule) || !retractsPriorJudgment(alternative)) {
|
|
1192
|
+
throw new ProposalError(
|
|
1193
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1194
|
+
"RETRACT_PUBLIC_JUDGMENT must retract or correct a prior public judgment"
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
const followsRule = retractsPriorJudgment(behavior);
|
|
1198
|
+
if ((proposal.source === "EXEMPLAR" || proposal.action === "COUNTER") !== followsRule) {
|
|
1199
|
+
throw new ProposalError(
|
|
1200
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1201
|
+
"The observed retraction direction does not match the selected evidence source"
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
if (proposal.decisionType === "CHOOSE_ROLE_CLAIM_TIMING" && (!discussesOwnRoleClaimTiming(rule) || !discussesOwnRoleClaimTiming(alternative))) {
|
|
1076
1207
|
throw new ProposalError(
|
|
1077
1208
|
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1078
|
-
"
|
|
1209
|
+
"CHOOSE_ROLE_CLAIM_TIMING must decide when the actor makes or withholds their own role claim"
|
|
1079
1210
|
);
|
|
1080
1211
|
}
|
|
1212
|
+
if (proposal.decisionType === "CHOOSE_ROLE_CLAIM_TIMING") return;
|
|
1213
|
+
const topic = `${rule}\u3002 ${alternative}`;
|
|
1214
|
+
switch (proposal.decisionType) {
|
|
1215
|
+
case "REPORT_DECIDED_ROLE_CLAIM":
|
|
1216
|
+
const reportTopic = proposal.source === "EXEMPLAR" || proposal.action === "COUNTER" ? behavior : topic;
|
|
1217
|
+
if (/(?:不|没有|并未|拒绝)(?:再)?[^。;,,!!]{0,8}(?:报告|公开|说明|交代)[^。;,,!!]{0,8}(?:身份|神职|查验|验人|role|claim|inspection)|(?:do not|did not|not going to|refuse to)[^.;]{0,12}(?:report|reveal|claim)/i.test(reportTopic)) {
|
|
1218
|
+
throw new ProposalError(
|
|
1219
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1220
|
+
"REPORT_DECIDED_ROLE_CLAIM must positively report the already-decided claim"
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
assertDecisionTopic(proposal.decisionType, reportTopic, [
|
|
1224
|
+
/(?:查验|验人|身份|神职|预言家|女巫|猎人|role claim|claim|inspection)/i,
|
|
1225
|
+
/(?:说明|报告|交代|补充|完整|公开|report|state|explain|include)/i
|
|
1226
|
+
]);
|
|
1227
|
+
return;
|
|
1228
|
+
case "EXPLAIN_DECIDED_VOTE":
|
|
1229
|
+
assertDecisionTopic(proposal.decisionType, topic, [
|
|
1230
|
+
/(?:投票|票投|投给|票型|vote)/i,
|
|
1231
|
+
/(?:理由|依据|解释|说明|reason|because|explain)/i
|
|
1232
|
+
]);
|
|
1233
|
+
return;
|
|
1234
|
+
case "EXPLAIN_DECIDED_WOLF_TARGET":
|
|
1235
|
+
assertDecisionTopic(proposal.decisionType, topic, [
|
|
1236
|
+
/(?:狼队|刀人|行动目标|击杀目标|wolf|kill target)/i,
|
|
1237
|
+
/(?:理由|依据|解释|说明|计划|reason|because|explain|plan)/i
|
|
1238
|
+
]);
|
|
1239
|
+
return;
|
|
1240
|
+
case "CHOOSE_WOLF_KILL_TARGET":
|
|
1241
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:刀|击杀|狼队[^。;]{0,8}目标|wolf[^.;]{0,8}target|kill)/i]);
|
|
1242
|
+
return;
|
|
1243
|
+
case "CHOOSE_SEER_TARGET":
|
|
1244
|
+
case "CHOOSE_SEER_CHECK_TARGET":
|
|
1245
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:查验|验人|预言家[^。;]{0,8}目标|seer|inspect|check)/i]);
|
|
1246
|
+
return;
|
|
1247
|
+
case "CHOOSE_WITCH_SAVE":
|
|
1248
|
+
assertDecisionTopic(
|
|
1249
|
+
proposal.decisionType,
|
|
1250
|
+
topic,
|
|
1251
|
+
[/(?:救人|救药|解药|使用救|不救|女巫[^。;]{0,8}救|save|antidote)/i],
|
|
1252
|
+
true
|
|
1253
|
+
);
|
|
1254
|
+
return;
|
|
1255
|
+
case "CHOOSE_WITCH_POISON_TARGET":
|
|
1256
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:毒药|用毒|毒杀|毒[^。;]{0,8}号|女巫[^。;]{0,8}毒|poison)/i]);
|
|
1257
|
+
return;
|
|
1258
|
+
case "CHOOSE_VOTE_TARGET":
|
|
1259
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:投票|改投|票投|投给|vote)/i]);
|
|
1260
|
+
return;
|
|
1261
|
+
case "CHOOSE_HUNTER_SHOT_TARGET":
|
|
1262
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:开枪|带走|猎人[^。;]{0,8}目标|shoot)/i]);
|
|
1263
|
+
return;
|
|
1264
|
+
case "IMPROVE_LAST_WORD_CONTENT":
|
|
1265
|
+
assertDecisionTopic(proposal.decisionType, topic, [/(?:遗言|最后发言|last words?)/i]);
|
|
1266
|
+
return;
|
|
1267
|
+
default:
|
|
1268
|
+
throw new ProposalError(
|
|
1269
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1270
|
+
`Unsupported decisionType semantics: ${proposal.decisionType}`
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1081
1273
|
}
|
|
1082
1274
|
function parseVoteCounts(summary) {
|
|
1083
1275
|
const match = /DAY_(?:RE)?VOTE_COUNT:\s*\{?([^}\r\n]*)\}?/i.exec(summary);
|
|
@@ -1126,6 +1318,51 @@ function assertedEliminatedSeats(observed) {
|
|
|
1126
1318
|
}
|
|
1127
1319
|
return seats;
|
|
1128
1320
|
}
|
|
1321
|
+
var SOCIAL_OUTCOME_FAMILIES = [
|
|
1322
|
+
{
|
|
1323
|
+
claim: /(?:怀疑|焦点|注意力|排除|狼面|好人面|纠错|suspicion|focus|attention|cleared)/i,
|
|
1324
|
+
evidence: /(?:怀疑|质疑|焦点|注意力|排除|认好|认狼|狼面|好人面|纠错|suspicion|suspect|question|focus|attention|clear)/i
|
|
1325
|
+
},
|
|
1326
|
+
{
|
|
1327
|
+
claim: /(?:共识|一致判断|统一站边|consensus)/i,
|
|
1328
|
+
evidence: /(?:共识|一致|站边|认可|支持|同意|consensus|agree|support)/i
|
|
1329
|
+
}
|
|
1330
|
+
];
|
|
1331
|
+
function referencedSeats(value) {
|
|
1332
|
+
const seats = new Set([...value.matchAll(SEAT_REFERENCE_LANGUAGE)].map((match) => Number(match[1])));
|
|
1333
|
+
for (const match of value.matchAll(/(?:seat\s*=?\s*)([1-9][0-9]*)\b/gi)) seats.add(Number(match[1]));
|
|
1334
|
+
return seats;
|
|
1335
|
+
}
|
|
1336
|
+
function speechFactSupportsSocialOutcome(fact, observed) {
|
|
1337
|
+
const claimedSeats = referencedSeats(observed);
|
|
1338
|
+
const factSeats = referencedSeats(fact.summary);
|
|
1339
|
+
if (fact.actorSeat != null) factSeats.add(fact.actorSeat);
|
|
1340
|
+
if (fact.targetSeat != null) factSeats.add(fact.targetSeat);
|
|
1341
|
+
if ([...claimedSeats].some((seat) => !factSeats.has(seat))) return false;
|
|
1342
|
+
const claimedRelations = socialActorTargetRelations(observed);
|
|
1343
|
+
const factRelations = socialActorTargetRelations(fact.summary);
|
|
1344
|
+
if ([...claimedRelations].some((relation) => !factRelations.has(relation))) return false;
|
|
1345
|
+
const claimsClearance = /(?:排除[^。;,,!!]{0,12}(?:怀疑|狼坑|焦点)|移出[^。;,,!!]{0,12}(?:怀疑|狼坑|焦点)|不再怀疑|cleared from suspicion)/i.test(observed);
|
|
1346
|
+
if (claimsClearance && !/(?:排除[^。;,,!!]{0,12}(?:怀疑|狼坑|焦点)|移出[^。;,,!!]{0,12}(?:怀疑|狼坑|焦点)|不再怀疑|cleared from suspicion)/i.test(fact.summary)) {
|
|
1347
|
+
return false;
|
|
1348
|
+
}
|
|
1349
|
+
const matchedFamilies = SOCIAL_OUTCOME_FAMILIES.filter(({ claim }) => claim.test(observed));
|
|
1350
|
+
return matchedFamilies.length > 0 && matchedFamilies.every(({ evidence }) => evidence.test(fact.summary));
|
|
1351
|
+
}
|
|
1352
|
+
function socialActorTargetRelations(value) {
|
|
1353
|
+
const relations = /* @__PURE__ */ new Set();
|
|
1354
|
+
const patterns = [
|
|
1355
|
+
/(?:seat\s*=?\s*)?([1-9][0-9]*)\s*号?[^。;,,!!]{0,16}(?:质疑|怀疑|锁定|攻击|suspect|question|focus(?:ed)? on)[^。;,,!!]{0,12}(?:seat\s*)?([1-9][0-9]*)\s*号?/gi,
|
|
1356
|
+
/(?:seat\s*=?\s*)?([1-9][0-9]*)\s*号?[^。;,,!!]{0,20}(?:焦点|注意力)[^。;,,!!]{0,8}(?:锁定到|导向|转向|shifted to)[^。;,,!!]{0,8}(?:seat\s*)?([1-9][0-9]*)\s*号?/gi,
|
|
1357
|
+
/(?:seat\s*=?\s*)?([1-9][0-9]*)\s*号?[^。;,,!!]{0,12}(?:排除|移出)[^。;,,!!]{0,6}(?:对|针对)\s*(?:seat\s*)?([1-9][0-9]*)\s*号?[^。;,,!!]{0,8}(?:怀疑|狼坑|焦点)/gi
|
|
1358
|
+
];
|
|
1359
|
+
for (const pattern of patterns) {
|
|
1360
|
+
for (const match of value.matchAll(pattern)) {
|
|
1361
|
+
relations.add(`${Number(match[1])}->${Number(match[2])}`);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
return relations;
|
|
1365
|
+
}
|
|
1129
1366
|
function assertObservedOutcomeSemantics(observed, outcomeFacts) {
|
|
1130
1367
|
if (LOCAL_OUTCOME_INFERENCE_LANGUAGE.test(observed)) {
|
|
1131
1368
|
throw new ProposalError(
|
|
@@ -1133,6 +1370,21 @@ function assertObservedOutcomeSemantics(observed, outcomeFacts) {
|
|
|
1133
1370
|
"observedLocalEffect must state later facts directly instead of claiming they prove an interpretation"
|
|
1134
1371
|
);
|
|
1135
1372
|
}
|
|
1373
|
+
if (SOCIAL_OUTCOME_LANGUAGE.test(observed)) {
|
|
1374
|
+
const speechFacts = outcomeFacts.filter((fact) => SPEECH_OUTCOME_FACT_TYPES.has(fact.type));
|
|
1375
|
+
if (speechFacts.length === 0) {
|
|
1376
|
+
throw new ProposalError(
|
|
1377
|
+
"SOCIAL_OUTCOME_FACT_REQUIRED",
|
|
1378
|
+
"A social-state interpretation requires a referenced later speech fact"
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
if (!speechFacts.some((fact) => speechFactSupportsSocialOutcome(fact, observed))) {
|
|
1382
|
+
throw new ProposalError(
|
|
1383
|
+
"SOCIAL_OUTCOME_FACT_MISMATCH",
|
|
1384
|
+
"The referenced speech facts do not state the claimed social-state change"
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1136
1388
|
const countFacts = outcomeFacts.filter((fact) => fact.type === "DAY_VOTE_COUNT" || fact.type === "DAY_REVOTE_COUNT").map((fact) => parseVoteCounts(fact.summary)).filter((counts) => counts !== void 0);
|
|
1137
1389
|
for (const claim of assertedVoteCounts(observed)) {
|
|
1138
1390
|
if (!countFacts.some((counts) => counts.get(claim.seat) === claim.count)) {
|
|
@@ -1161,6 +1413,35 @@ function assertObservedOutcomeSemantics(observed, outcomeFacts) {
|
|
|
1161
1413
|
}
|
|
1162
1414
|
}
|
|
1163
1415
|
}
|
|
1416
|
+
function assertSourceOutcomeDirection(proposal, observed) {
|
|
1417
|
+
const withoutBeneficialNegation = observed.replace(/(?:没有再次|不再)(?:质疑|追问|要求补充)/gi, "");
|
|
1418
|
+
const adverse = ADVERSE_LOCAL_EFFECT_LANGUAGE.test(withoutBeneficialNegation);
|
|
1419
|
+
const beneficial = BENEFICIAL_LOCAL_EFFECT_LANGUAGE.test(observed);
|
|
1420
|
+
if (proposal.action === "COUNTER") {
|
|
1421
|
+
if (!adverse) {
|
|
1422
|
+
throw new ProposalError(
|
|
1423
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1424
|
+
"COUNTER must describe an adverse local effect that falsifies the existing rule"
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
if (proposal.source === "EXEMPLAR") {
|
|
1430
|
+
if (!beneficial || adverse) {
|
|
1431
|
+
throw new ProposalError(
|
|
1432
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1433
|
+
"EXEMPLAR must describe a beneficial local effect without an adverse result"
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
if (!adverse) {
|
|
1439
|
+
throw new ProposalError(
|
|
1440
|
+
"SOURCE_DIRECTION_MISMATCH",
|
|
1441
|
+
"SELF and OBSERVED require an adverse local effect as evidence of failed behavior"
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1164
1445
|
function assertLocalOutcomeEvidence(outcomeCount, localOutcomeCount, observed) {
|
|
1165
1446
|
if (outcomeCount === 0 || localOutcomeCount === 0) {
|
|
1166
1447
|
throw new ProposalError(
|
|
@@ -1172,6 +1453,89 @@ function assertLocalOutcomeEvidence(outcomeCount, localOutcomeCount, observed) {
|
|
|
1172
1453
|
throw new ProposalError("FINAL_RESULT_NOT_LOCAL", "Final victory or defeat is not a local effect");
|
|
1173
1454
|
}
|
|
1174
1455
|
}
|
|
1456
|
+
function actionTimeIdentityAssertions(value) {
|
|
1457
|
+
const assertions = [];
|
|
1458
|
+
const negativePatterns = [
|
|
1459
|
+
new RegExp(`([1-9][0-9]*)\\s*\u53F7(?:\u73A9\u5BB6)?[^\u3002\uFF1B\uFF0C,!\uFF01]{0,8}(?:\u4E0D\u662F|\u5E76\u975E|\u4E0D\u4E3A)\\s*(?:\u771F\u6B63|\u771F\u5B9E)?(?:\u7684)?(${ROLE_NAME})`, "g"),
|
|
1460
|
+
new RegExp(`(?:seat\\s*)?([1-9][0-9]*)[^.;,!]{0,12}(?:is|was)\\s+not\\s+(?:the\\s+)?(?:real\\s+)?(${ENGLISH_ROLE_NAME})\\b`, "gi")
|
|
1461
|
+
];
|
|
1462
|
+
for (const pattern of negativePatterns) {
|
|
1463
|
+
for (const match of value.matchAll(pattern)) {
|
|
1464
|
+
assertions.push({ seat: Number(match[1]), role: normalizeIdentity(match[2]), negated: true });
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
const patterns = [
|
|
1468
|
+
new RegExp(`([1-9][0-9]*)\\s*\u53F7(?:\u73A9\u5BB6)?[^\u3002\uFF1B\uFF0C,!\uFF01]{0,8}(?:\u771F\u6B63|\u771F\u5B9E)?(?:\u7684)?(?:\u8EAB\u4EFD)?(?:\u662F|\u4E3A)\\s*(?:\u771F\u6B63|\u771F\u5B9E)?(?:\u7684)?(${ROLE_NAME})`, "g"),
|
|
1469
|
+
new RegExp(`(?:\u771F\u6B63|\u771F\u5B9E)(?:\u7684)?(${ROLE_NAME})\\s*(?:\u662F|\u4E3A)?\\s*([1-9][0-9]*)\\s*\u53F7`, "g")
|
|
1470
|
+
];
|
|
1471
|
+
for (const [index, pattern] of patterns.entries()) {
|
|
1472
|
+
for (const match of value.matchAll(pattern)) {
|
|
1473
|
+
const prefix = value.slice(Math.max(0, match.index - 12), match.index);
|
|
1474
|
+
if (CONDITIONAL_IDENTITY_LANGUAGE.test(prefix) || /(?:自称|声称|号称|可能|或许|怀疑|认为|倾向|猜测|未必|不确定)/i.test(match[0])) continue;
|
|
1475
|
+
assertions.push(index === 0 ? { seat: Number(match[1]), role: match[2] } : { seat: Number(match[2]), role: match[1] });
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const englishPatterns = [
|
|
1479
|
+
new RegExp(`(?:seat\\s*)?([1-9][0-9]*)[^.;,!]{0,12}(?:is|was|=)\\s*(?:the\\s+)?(?:real\\s+)?(${ENGLISH_ROLE_NAME})\\b`, "gi"),
|
|
1480
|
+
new RegExp(`(?:the\\s+)?(?:real\\s+)?(${ENGLISH_ROLE_NAME})\\s+(?:is|was|=)?\\s*(?:seat\\s*)?([1-9][0-9]*)\\b`, "gi")
|
|
1481
|
+
];
|
|
1482
|
+
for (const [index, pattern] of englishPatterns.entries()) {
|
|
1483
|
+
for (const match of value.matchAll(pattern)) {
|
|
1484
|
+
const prefix = value.slice(Math.max(0, match.index - 24), match.index);
|
|
1485
|
+
if (/\b(?:if|maybe|perhaps|suspect|think|likely|uncertain)\s*$/i.test(prefix)) continue;
|
|
1486
|
+
assertions.push(index === 0 ? { seat: Number(match[1]), role: normalizeIdentity(match[2]) } : { seat: Number(match[2]), role: normalizeIdentity(match[1]) });
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return assertions;
|
|
1490
|
+
}
|
|
1491
|
+
function normalizeIdentity(value) {
|
|
1492
|
+
switch (value.trim().toLowerCase()) {
|
|
1493
|
+
case "seer":
|
|
1494
|
+
return "\u9884\u8A00\u5BB6";
|
|
1495
|
+
case "witch":
|
|
1496
|
+
return "\u5973\u5DEB";
|
|
1497
|
+
case "hunter":
|
|
1498
|
+
return "\u730E\u4EBA";
|
|
1499
|
+
case "werewolf":
|
|
1500
|
+
case "wolf":
|
|
1501
|
+
return "\u72FC\u4EBA";
|
|
1502
|
+
case "good":
|
|
1503
|
+
case "good player":
|
|
1504
|
+
return "\u597D\u4EBA";
|
|
1505
|
+
case "villager":
|
|
1506
|
+
return "\u5E73\u6C11";
|
|
1507
|
+
case "\u6751\u6C11":
|
|
1508
|
+
return "\u5E73\u6C11";
|
|
1509
|
+
default:
|
|
1510
|
+
return value;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function seerResultIdentity(fact) {
|
|
1514
|
+
const match = /(?:=|是|为)\s*(狼人|好人|WOLF|GOOD|true|false)(?=$|[\s;,.,。])/i.exec(fact.summary);
|
|
1515
|
+
if (!match) return void 0;
|
|
1516
|
+
const value = match[1].toLowerCase();
|
|
1517
|
+
if (value === "\u72FC\u4EBA" || value === "wolf" || value === "true") return "\u72FC\u4EBA";
|
|
1518
|
+
return "\u597D\u4EBA";
|
|
1519
|
+
}
|
|
1520
|
+
function factEstablishesIdentity(fact, seat, role) {
|
|
1521
|
+
const identity = normalizeIdentity(role);
|
|
1522
|
+
if (fact.type === "SEER_RESULT" && fact.targetSeat === seat) {
|
|
1523
|
+
return seerResultIdentity(fact) === identity;
|
|
1524
|
+
}
|
|
1525
|
+
if (fact.actorSeat !== seat) return false;
|
|
1526
|
+
if (identity === "\u5973\u5DEB") return fact.type.startsWith("WITCH_");
|
|
1527
|
+
if (identity === "\u9884\u8A00\u5BB6") return fact.type === "SEER_RESULT" || fact.type === "SEER_CHECK" || fact.type === "SEER_SKIP_CHECK";
|
|
1528
|
+
if (identity === "\u730E\u4EBA") return fact.type.includes("HUNTER_SHOOT") || fact.type.includes("HUNTER_PASS");
|
|
1529
|
+
if (identity === "\u72FC\u4EBA") return fact.type.startsWith("WOLF_");
|
|
1530
|
+
if (identity === "\u597D\u4EBA") return fact.type.startsWith("WITCH_") || fact.type.startsWith("SEER_") || fact.type.includes("HUNTER_");
|
|
1531
|
+
return false;
|
|
1532
|
+
}
|
|
1533
|
+
function factEstablishesNegativeIdentity(fact, seat, role) {
|
|
1534
|
+
const identity = normalizeIdentity(role);
|
|
1535
|
+
if (fact.type !== "SEER_RESULT" || fact.targetSeat !== seat || identity !== "\u72FC\u4EBA" && identity !== "\u597D\u4EBA") return false;
|
|
1536
|
+
const actual = seerResultIdentity(fact);
|
|
1537
|
+
return actual !== void 0 && actual !== identity;
|
|
1538
|
+
}
|
|
1175
1539
|
function assertActionTimeSemantics(proposal, window, anchor, knownFacts) {
|
|
1176
1540
|
const actionTimeFields = [
|
|
1177
1541
|
proposal.trigger,
|
|
@@ -1195,6 +1559,15 @@ function assertActionTimeSemantics(proposal, window, anchor, knownFacts) {
|
|
|
1195
1559
|
);
|
|
1196
1560
|
}
|
|
1197
1561
|
const actionTimeText = actionTimeFields.join("\u3002 ");
|
|
1562
|
+
for (const identity of actionTimeIdentityAssertions(actionTimeText)) {
|
|
1563
|
+
const established = identity.negated ? knownFacts.some((fact) => factEstablishesNegativeIdentity(fact, identity.seat, identity.role)) : knownFacts.some((fact) => factEstablishesIdentity(fact, identity.seat, identity.role));
|
|
1564
|
+
if (!established) {
|
|
1565
|
+
throw new ProposalError(
|
|
1566
|
+
"ACTION_TIME_IDENTITY_UNSUPPORTED",
|
|
1567
|
+
"A concrete seat identity was not established by visible facts before the action"
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1198
1571
|
for (const { seat, claim } of seatBehaviorClaims(actionTimeText)) {
|
|
1199
1572
|
if (seat === window.actorSeat && isCurrentDecisionActorClaim(claim)) continue;
|
|
1200
1573
|
const supported = [anchor, ...knownFacts].some((fact) => fact.actorSeat === seat && factSupportsBehaviorClaim(fact, claim));
|
|
@@ -1272,7 +1645,7 @@ function classifyRisk(proposal, decisionType = proposal.decisionType ?? "") {
|
|
|
1272
1645
|
true
|
|
1273
1646
|
) ? "execution" : "strategy";
|
|
1274
1647
|
}
|
|
1275
|
-
function assertExistingSemantics(proposal, existing, window, action, players) {
|
|
1648
|
+
function assertExistingSemantics(proposal, existing, window, action, players, describedBehavior) {
|
|
1276
1649
|
if (existing.status === "archived") {
|
|
1277
1650
|
throw new ProposalError("TOPIC_ARCHIVED", `Archived topic cannot receive ${action}`);
|
|
1278
1651
|
}
|
|
@@ -1287,6 +1660,48 @@ function assertExistingSemantics(proposal, existing, window, action, players) {
|
|
|
1287
1660
|
if (action === "COUNTER" && !COUNTER_EFFECT_LANGUAGE.test(proposal.observedLocalEffect ?? "")) {
|
|
1288
1661
|
throw new ProposalError("COUNTER_NOT_FALSIFYING", "COUNTER must describe a concrete failed or adverse local outcome");
|
|
1289
1662
|
}
|
|
1663
|
+
if (action === "COUNTER" && !counterBehaviorFollowsRule(proposal, existing, describedBehavior)) {
|
|
1664
|
+
throw new ProposalError(
|
|
1665
|
+
"COUNTER_BEHAVIOR_MISMATCH",
|
|
1666
|
+
"COUNTER behavior must show that the trusted anchor actually executed the existing rule"
|
|
1667
|
+
);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
function counterBehaviorFollowsRule(proposal, existing, behavior) {
|
|
1671
|
+
if (proposal.decisionType === "AVOID_REPEATING_PRIOR_SPEAKERS") {
|
|
1672
|
+
return omitsRepeatedContent(behavior) && addsNewInformation(behavior);
|
|
1673
|
+
}
|
|
1674
|
+
if (proposal.decisionType === "RETRACT_PUBLIC_JUDGMENT") {
|
|
1675
|
+
return retractsPriorJudgment(behavior);
|
|
1676
|
+
}
|
|
1677
|
+
if (proposal.decisionType === "REPORT_DECIDED_ROLE_CLAIM") {
|
|
1678
|
+
return /(?:完整|全部|明确)[^。;,,!!]{0,16}(?:查验|验人|信息链|验人计划)|(?:查验|验人)[^。;,,!!]{0,24}(?:结果|金水|查杀)[^。;,,!!]{0,24}(?:计划|信息链)/i.test(behavior);
|
|
1679
|
+
}
|
|
1680
|
+
const targetDecisionTypes = /* @__PURE__ */ new Set([
|
|
1681
|
+
"CHOOSE_WOLF_KILL_TARGET",
|
|
1682
|
+
"CHOOSE_SEER_TARGET",
|
|
1683
|
+
"CHOOSE_SEER_CHECK_TARGET",
|
|
1684
|
+
"CHOOSE_WITCH_POISON_TARGET",
|
|
1685
|
+
"CHOOSE_VOTE_TARGET",
|
|
1686
|
+
"CHOOSE_HUNTER_SHOT_TARGET"
|
|
1687
|
+
]);
|
|
1688
|
+
if (targetDecisionTypes.has(proposal.decisionType ?? "")) {
|
|
1689
|
+
const expectedTargets = [...existing.rule.matchAll(EXPLICIT_TARGET_LANGUAGE)].map((match) => Number(match[1]));
|
|
1690
|
+
const rawTarget = /->\s*([1-9][0-9]*)\b/.exec(behavior) ?? /(?:WOLF_CHOOSE|SEER_CHECK|WITCH_POISON|HUNTER_SHOOT)\s*:\s*(?:[1-9][0-9]*\s*->\s*)?([1-9][0-9]*)\b/i.exec(behavior);
|
|
1691
|
+
const actualTarget = behaviorTarget(behavior) ?? (rawTarget ? Number(rawTarget[1]) : void 0);
|
|
1692
|
+
const negatedAction = /(?:没有|并未|未曾|不曾|从未|尚未|不)[^。;,,!!]{0,20}(?:改投|投票|查验|验人|刀|毒|救|开枪|起跳|公开身份)|(?:did not|never|not)[^.;]{0,20}(?:vote|check|inspect|kill|poison|save|shoot|claim)/i.test(behavior);
|
|
1693
|
+
return expectedTargets.length === 1 && actualTarget === expectedTargets[0] && !negatedAction;
|
|
1694
|
+
}
|
|
1695
|
+
if (proposal.decisionType === "CHOOSE_ROLE_CLAIM_TIMING") {
|
|
1696
|
+
const withheld = (value) => /(?:不(?:公开|起跳|跳)|隐藏身份|暂缓|延后|推迟)[^。;,,!!]{0,12}(?:身份|神职|起跳|公开)?|(?:withhold|hide|delay|do not claim)/i.test(value);
|
|
1697
|
+
const claimed = (value) => /(?:直接|立即|选择|决定)?(?:公开(?:自己|自身)?(?:身份|神职)|起跳|跳(?:预言家|女巫|猎人)|claim(?:ed)? (?:seer|witch|hunter))/i.test(value);
|
|
1698
|
+
return withheld(existing.rule) && withheld(behavior) || !withheld(existing.rule) && claimed(existing.rule) && claimed(behavior) && !withheld(behavior);
|
|
1699
|
+
}
|
|
1700
|
+
if (proposal.decisionType === "CHOOSE_WITCH_SAVE") {
|
|
1701
|
+
const skipsSave = (value) => /(?:不救|不用|不使用|跳过|放弃)[^。;,,!!]{0,8}(?:救|解药)?|(?:skip|do not use|withhold)[^.;]{0,12}(?:save|antidote)/i.test(value);
|
|
1702
|
+
return skipsSave(existing.rule) === skipsSave(behavior) && /(?:救|解药|save|antidote)/i.test(behavior);
|
|
1703
|
+
}
|
|
1704
|
+
return false;
|
|
1290
1705
|
}
|
|
1291
1706
|
function assertRefinement(proposal, existing, risk) {
|
|
1292
1707
|
if (!sameSemanticText(proposal.rule, existing.rule)) {
|
|
@@ -1363,6 +1778,12 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1363
1778
|
if (proposal.source !== "SELF" && window.actorSeat === envelope.game.recipientSeat) {
|
|
1364
1779
|
throw new ProposalError("OTHER_ACTOR_MISMATCH", "OBSERVED and EXEMPLAR evidence must anchor another player's action");
|
|
1365
1780
|
}
|
|
1781
|
+
if (action === "COUNTER" && proposal.source === "EXEMPLAR") {
|
|
1782
|
+
throw new ProposalError(
|
|
1783
|
+
"COUNTER_SOURCE_INVALID",
|
|
1784
|
+
"COUNTER is limited to SELF or OBSERVED evidence that followed an existing rule and produced an adverse result"
|
|
1785
|
+
);
|
|
1786
|
+
}
|
|
1366
1787
|
const anchorFactId = requireText(proposal, "anchorFactId");
|
|
1367
1788
|
if (anchorFactId !== window.anchorFactId) {
|
|
1368
1789
|
throw new ProposalError("ANCHOR_WINDOW_MISMATCH", "anchorFactId does not match the trusted decision window");
|
|
@@ -1370,7 +1791,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1370
1791
|
requireText(proposal, "trigger", 4);
|
|
1371
1792
|
const rule = requireText(proposal, "rule", 4);
|
|
1372
1793
|
requireText(proposal, "boundary", 4);
|
|
1373
|
-
requireText(proposal, "behavior", 4);
|
|
1794
|
+
const describedBehavior = requireText(proposal, "behavior", 4);
|
|
1374
1795
|
requireText(proposal, "alternativeAction", 4);
|
|
1375
1796
|
requireText(proposal, "expectedLocalEffect", 4);
|
|
1376
1797
|
const observed = requireText(proposal, "observedLocalEffect", 4);
|
|
@@ -1388,7 +1809,6 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1388
1809
|
throw new ProposalError("ANCHOR_NOT_OBSERVABLE", "The action anchor is missing or postgame-only");
|
|
1389
1810
|
}
|
|
1390
1811
|
assertBehaviorIsObserved(proposal);
|
|
1391
|
-
proposal.behavior = anchor.summary;
|
|
1392
1812
|
assertCounterfactualCoherence(proposal, anchor);
|
|
1393
1813
|
const known = proposal.knownFactRefs ?? [];
|
|
1394
1814
|
const outcomes = proposal.outcomeFactRefs ?? [];
|
|
@@ -1427,6 +1847,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1427
1847
|
}
|
|
1428
1848
|
assertActionTimeSemantics(proposal, window, anchor, knownFacts);
|
|
1429
1849
|
assertDecisionTypeSemantics(proposal);
|
|
1850
|
+
assertBehaviorMatchesAnchor(proposal, describedBehavior, anchor);
|
|
1430
1851
|
assertLocalOutcomeEvidence(outcomes.length, localOutcomeCount, observed);
|
|
1431
1852
|
assertObservedOutcomeSemantics(observed, outcomeFacts);
|
|
1432
1853
|
const allRefs = /* @__PURE__ */ new Set([...known, ...outcomes]);
|
|
@@ -1438,9 +1859,10 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1438
1859
|
assertAlternativeTarget(proposal, window, risk);
|
|
1439
1860
|
assertAlternativeTargetConsistent(proposal);
|
|
1440
1861
|
if (existing) {
|
|
1441
|
-
assertExistingSemantics(proposal, existing, window, action, envelope.game.players);
|
|
1862
|
+
assertExistingSemantics(proposal, existing, window, action, envelope.game.players, describedBehavior);
|
|
1442
1863
|
if (action === "REFINE") assertRefinement(proposal, existing, risk);
|
|
1443
1864
|
}
|
|
1865
|
+
assertSourceOutcomeDirection(proposal, observed);
|
|
1444
1866
|
if (action === "NEW") {
|
|
1445
1867
|
const proposedText = `${proposal.trigger} ${proposal.rule} ${proposal.boundary}`;
|
|
1446
1868
|
const duplicate = evidence.lessons.find((lesson) => lesson.status !== "archived" && lesson.profile === profile && similarity(proposedText, `${lesson.trigger} ${lesson.rule} ${lesson.boundary}`) >= 0.72);
|
|
@@ -1448,6 +1870,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1448
1870
|
throw new ProposalError("SIMILAR_TOPIC_EXISTS", `Use SUPPORT, COUNTER or REFINE for ${duplicate.id}`);
|
|
1449
1871
|
}
|
|
1450
1872
|
}
|
|
1873
|
+
proposal.behavior = anchor.summary;
|
|
1451
1874
|
return { proposal, risk, existing, decisionWindow: window };
|
|
1452
1875
|
}
|
|
1453
1876
|
|
|
@@ -2650,7 +3073,7 @@ function reconcileSuggestions(state, lesson, now) {
|
|
|
2650
3073
|
}
|
|
2651
3074
|
}
|
|
2652
3075
|
}
|
|
2653
|
-
function enforceProfileLimits(state, profile) {
|
|
3076
|
+
function enforceProfileLimits(state, profile, now) {
|
|
2654
3077
|
const candidates = state.evidence.lessons.filter((lesson) => lesson.profile === profile && lesson.status === "candidate");
|
|
2655
3078
|
if (candidates.length > MAX_CANDIDATE) {
|
|
2656
3079
|
candidates.sort((left, right) => left.lastReviewed.localeCompare(right.lastReviewed) || left.createdAt.localeCompare(right.createdAt));
|
|
@@ -2666,6 +3089,9 @@ function enforceProfileLimits(state, profile) {
|
|
|
2666
3089
|
probation.sort((left, right) => right.lastReviewed.localeCompare(left.lastReviewed));
|
|
2667
3090
|
for (const lesson of probation.slice(1)) lesson.status = "archived";
|
|
2668
3091
|
}
|
|
3092
|
+
for (const lesson of state.evidence.lessons.filter((item) => item.profile === profile)) {
|
|
3093
|
+
reconcileSuggestions(state, lesson, now);
|
|
3094
|
+
}
|
|
2669
3095
|
}
|
|
2670
3096
|
function ensureSuggestion(state, lesson, now) {
|
|
2671
3097
|
if (lesson.status !== "candidate") return;
|
|
@@ -2745,10 +3171,7 @@ function applyProposal(state, envelope, bodyHash, proposal, risk, window, now =
|
|
|
2745
3171
|
ensureSuggestion(state, lesson, now);
|
|
2746
3172
|
}
|
|
2747
3173
|
reconcileSuggestions(state, lesson, now);
|
|
2748
|
-
enforceProfileLimits(state, lesson.profile);
|
|
2749
|
-
for (const affected of state.evidence.lessons.filter((item) => item.profile === lesson.profile)) {
|
|
2750
|
-
reconcileSuggestions(state, affected, now);
|
|
2751
|
-
}
|
|
3174
|
+
enforceProfileLimits(state, lesson.profile, now);
|
|
2752
3175
|
result = { ...result, outcome: lesson.status, lessonId: lesson.id, risk: lesson.risk };
|
|
2753
3176
|
}
|
|
2754
3177
|
state.ledger.entries.push({
|
|
@@ -3289,26 +3712,33 @@ var WerewolfEvolutionService = class {
|
|
|
3289
3712
|
"- Copy decisionType exactly from the selected decisionWindow.allowedDecisionTypes. Copy alternativeActionType exactly from that same window.availableActionTypes; these are different fields and must not be mixed.",
|
|
3290
3713
|
"- 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.",
|
|
3291
3714
|
"- SELF must use a decisionWindow whose actorSeat equals eligibility.recipientSeat. OBSERVED and EXEMPLAR must use another actor's decisionWindow.",
|
|
3715
|
+
"- For NEW, SUPPORT, and REFINE, SELF and OBSERVED must describe a failed action with an adverse local effect: behavior is the failed action, while rule and alternativeAction describe the improvement.",
|
|
3716
|
+
"- EXEMPLAR must describe another actor's successful action: behavior follows rule, observedLocalEffect is beneficial, and alternativeAction is a worse counterfactual that did not happen.",
|
|
3717
|
+
"- COUNTER is limited to SELF or OBSERVED: behavior is the actual action that followed the existing rule, observedLocalEffect is the adverse result that falsifies it, and alternativeAction is a different concrete counterfactual. EXEMPLAR cannot be COUNTER.",
|
|
3292
3718
|
"- 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.",
|
|
3293
3719
|
"- 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.",
|
|
3720
|
+
"- A concrete final identity for another seat requires visible pre-anchor facts that established that identity. A postgame identity, model inference, or unverified role claim is insufficient.",
|
|
3294
3721
|
"- 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.",
|
|
3295
3722
|
"- outcomeFactRefs must be later than the anchor and include at least one local outcome fact whose type appears in localOutcomeFactTypes.",
|
|
3296
3723
|
"- GAME_FINISHED, FINAL_IDENTITY, and GAME_RESULT are never local outcome facts and cannot be the only outcome evidence.",
|
|
3297
|
-
"- behavior must describe only what actually happened at the anchor; never copy rule or alternativeAction into behavior as if it occurred.",
|
|
3298
|
-
"- The plugin stores behavior from the trusted anchor summary; model prose is
|
|
3724
|
+
"- behavior must describe only what actually happened at the anchor and must be supported by that anchor's actor, event type, target, polarity, and summary; never copy rule or alternativeAction into behavior as if it occurred.",
|
|
3725
|
+
"- The plugin stores behavior from the trusted anchor summary; unsupported model prose is rejected and never becomes the persisted fact source.",
|
|
3299
3726
|
"- alternativeAction must describe a counterfactual action that did not happen; never swap behavior and alternativeAction.",
|
|
3300
3727
|
"- observedLocalEffect must not contain the final winner or loser; describe only a later local effect backed by outcomeFactRefs.",
|
|
3301
3728
|
"- alternativeTargetSeat must agree with alternativeAction. Text that only waits, retains the vote, or chooses no target and names no later target cannot carry a seat.",
|
|
3302
3729
|
"- alternativeAction must contain exactly one counterfactual action, not a menu joined by or/\u6216\u8005/\u6216/\u4E8C\u9009\u4E00. A changed alternative target must not claim that the target stays unchanged.",
|
|
3303
3730
|
"- observedLocalEffect must state facts directly without claiming they prove an interpretation such as \u56E0\u6B64/\u7531\u6B64\u53EF\u89C1/therefore. Exact vote counts, unanimous votes, and vote-eliminated seats must match outcomeFactRefs.",
|
|
3731
|
+
"- A social-state interpretation such as cleared suspicion, shifted attention, consensus, or a unified stance requires a later speech fact whose actor, seats, and summary state that same local change; unrelated speech or DAY_RESOLVED is insufficient.",
|
|
3304
3732
|
"- Single-game claims must not use absolute strategy wording such as must, always, only valid, certain, or guaranteed. Hedged wording such as \u4E0D\u4E00\u5B9A\u5FC5\u987B is allowed.",
|
|
3305
3733
|
"- alternatives must contain at least one plausible alternative explanation. falsifier must state a concrete later observation that would disprove the rule.",
|
|
3306
3734
|
"Execution versus strategy contract:",
|
|
3307
3735
|
"- executionOperation must be one of the exact template operations. To claim execution risk, copy that template's operation, decisionType, trigger, rule, boundary, and alternativeAction exactly.",
|
|
3308
|
-
"- decisionType must match the lesson topic.
|
|
3736
|
+
"- decisionType must match the lesson topic. Role-report, vote-reason, wolf-target-reason, target-choice, witch, hunter, and last-word types are checked against their own action semantics; unsupported or unrelated topics are rejected.",
|
|
3737
|
+
"- AVOID_REPEATING_PRIOR_SPEAKERS must omit repeated content and add new information, not carry an unrelated speech strategy.",
|
|
3738
|
+
"- RETRACT_PUBLIC_JUDGMENT must retract or correct a prior public judgment. CHOOSE_ROLE_CLAIM_TIMING must decide when the actor makes or withholds their own role claim, not infer another seat's role.",
|
|
3309
3739
|
"- Strategy proposals must omit executionOperation. CHOOSE_VOTE_TARGET and CHOOSE_ROLE_CLAIM_TIMING are decision types, never executionOperation values.",
|
|
3310
3740
|
"Call werewolf_debrief_commit after checking the complete proposal against this contract.",
|
|
3311
|
-
"A rejected result with retryable=true means one field/semantic correction is allowed: correct only the reported issue using the same trusted window and call the tool once more. A rejected result with retryable=false is final; never call again.",
|
|
3741
|
+
"A rejected result with retryable=true means one field/semantic correction is allowed: correct only the reported issue using the same trusted window and call the tool once more. Never change the topic, source, or trusted window to bypass a rejection. A rejected result with retryable=false is final; never call again.",
|
|
3312
3742
|
"After a committed, duplicate, incident, or final rejected result, return exactly NO_REPLY. Never use a generic write tool or retry indefinitely.",
|
|
3313
3743
|
"Do not return NO_REPLY before werewolf_debrief_commit returns a result.",
|
|
3314
3744
|
"Never use generic write, edit, patch, shell, or memory-write tools for debrief state."
|
package/package.json
CHANGED