@clawtopia/werewolf-evolution 0.1.14 → 0.1.15
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 +136 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -764,6 +764,11 @@ var STRATEGY_LANGUAGE = /(?:改变|改投|改票|转票|投给|投票目标|查
|
|
|
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
766
|
var NO_TARGET_ALTERNATIVE_LANGUAGE = /(?:保留投票权|等待更多信息|暂不(?:投票|选择|行动)|弃票|不选(?:择)?(?:任何)?(?:目标|座位)|不指定目标|不设目标|继续观望|\b(?:wait for more information|abstain|hold (?:the )?vote|choose no target)\b)/i;
|
|
767
|
+
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
|
+
var TARGET_UNCHANGED_LANGUAGE = /(?:不|不得|不会)(?:改变|更改|调整|切换)(?:当前|原有|既定)?(?:的)?(?:行动|投票|查验|刀人|用药|开枪)?目标|(?:保持|维持)(?:原有|原定|既定|当前|相同)(?:的)?(?:行动|投票|查验|刀人|用药|开枪)?目标/i;
|
|
769
|
+
var RETAINED_TARGET_SEAT_LANGUAGE = /(?:行动|投票|查验|刀人|用药|开枪)?目标\s*(?:仍(?:然)?|依然|依旧|继续|保持|维持|不变)\s*(?:是|为)?\s*([1-9][0-9]*)\s*号/i;
|
|
770
|
+
var LOCAL_OUTCOME_INFERENCE_LANGUAGE = /(?:,|;|。|,|;)\s*(?:(?:由此|因此|从而|所以)(?:可见|可知|可判断|说明|证明|表明|意味着)?|(?:这)?(?:说明|证明|表明|意味着|可见|足以(?:说明|证明|表明))|\b(?:therefore|thus|this (?:proves?|shows?|means?))\b)/i;
|
|
771
|
+
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;
|
|
767
772
|
var EXPLICIT_TARGET_LANGUAGE = /(?:(?:改投|改票(?:到|给)?|归票|票投|投票(?:给|到)?|投(?:给|到)?|查验|验|刀|毒|救|开枪带走|目标(?:改为|是)?)\s*|target(?:\s+seat)?[^0-9]{0,6})([1-9][0-9]*)\s*(?:号|座|\b)/gi;
|
|
768
773
|
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;
|
|
769
774
|
var SEAT_REFERENCE_LANGUAGE = /([1-9][0-9]*)\s*号(?:玩家)?/g;
|
|
@@ -1001,6 +1006,127 @@ function assertAlternativeTargetConsistent(proposal) {
|
|
|
1001
1006
|
);
|
|
1002
1007
|
}
|
|
1003
1008
|
}
|
|
1009
|
+
function assertCounterfactualCoherence(proposal, anchor) {
|
|
1010
|
+
const alternative = proposal.alternativeAction ?? "";
|
|
1011
|
+
if (AMBIGUOUS_ALTERNATIVE_LANGUAGE.test(alternative)) {
|
|
1012
|
+
throw new ProposalError(
|
|
1013
|
+
"ALTERNATIVE_ACTION_AMBIGUOUS",
|
|
1014
|
+
"alternativeAction must contain exactly one counterfactual action"
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
const target = proposal.alternativeTargetSeat;
|
|
1018
|
+
const boundary = proposal.boundary ?? "";
|
|
1019
|
+
const retainedTarget = RETAINED_TARGET_SEAT_LANGUAGE.exec(boundary);
|
|
1020
|
+
if (target != null && (target !== anchor.targetSeat && TARGET_UNCHANGED_LANGUAGE.test(boundary) || retainedTarget && (Number(retainedTarget[1]) !== anchor.targetSeat || Number(retainedTarget[1]) !== target))) {
|
|
1021
|
+
throw new ProposalError(
|
|
1022
|
+
"ALTERNATIVE_BOUNDARY_CONTRADICTION",
|
|
1023
|
+
"A changed alternative target contradicts a boundary that preserves the target"
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function assertNoAbsoluteStrategyClaim(proposal) {
|
|
1028
|
+
const causalClaim = [proposal.rule, proposal.expectedLocalEffect, proposal.falsifier].filter((value) => typeof value === "string").join("\u3002").replace(/(?:(?:不一定|未必|并非|不是)\s*(?:必须|必然|绝对|肯定|一定|只能|只能够|唯一(?:正确|合理)?(?:的)?(?:选择|做法))?|not (?:always|necessarily)(?:\s+(?:must|always|certain|guaranteed|the only (?:choice|option)))?)/gi, "");
|
|
1029
|
+
if (ABSOLUTE_STRATEGY_LANGUAGE.test(causalClaim)) {
|
|
1030
|
+
throw new ProposalError(
|
|
1031
|
+
"SINGLE_GAME_ABSOLUTE_CLAIM",
|
|
1032
|
+
"A single review cannot establish an absolute cross-game strategy claim"
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
function assertDecisionTypeSemantics(proposal) {
|
|
1037
|
+
if (proposal.decisionType !== "AVOID_REPEATING_PRIOR_SPEAKERS") return;
|
|
1038
|
+
const topic = [proposal.rule, proposal.alternativeAction].filter((value) => typeof value === "string").join("\u3002 ");
|
|
1039
|
+
const omitsRepeatedContent = /(?:省略|删去|跳过|避免|减少|不(?:再|要)?)[^。;,,!!]{0,8}(?:复述|重复)|\b(?:omit|skip|remove|avoid|reduce|do not)\b[^.;]{0,20}\b(?:repeat|duplicate)/i.test(topic);
|
|
1040
|
+
const addsNewInformation = /(?:(?:补充|新增)[^。;,,!!]{0,8}(?:信息|观点|判断|依据|逻辑|内容)|新(?:的)?(?:信息|观点|判断|依据|逻辑|内容)|相对于前置(?:发言|内容))|\b(?:add|provide|state|include)\b[^.;]{0,20}\bnew (?:information|reasoning|judgment|evidence)/i.test(topic);
|
|
1041
|
+
if (!omitsRepeatedContent || !addsNewInformation) {
|
|
1042
|
+
throw new ProposalError(
|
|
1043
|
+
"DECISION_TYPE_SEMANTICS_MISMATCH",
|
|
1044
|
+
"AVOID_REPEATING_PRIOR_SPEAKERS must describe omitting repeated content and adding new information"
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function parseVoteCounts(summary) {
|
|
1049
|
+
const match = /DAY_(?:RE)?VOTE_COUNT:\s*\{?([^}\r\n]*)\}?/i.exec(summary);
|
|
1050
|
+
if (!match) return void 0;
|
|
1051
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1052
|
+
const body = match[1].trim();
|
|
1053
|
+
if (!body) return counts;
|
|
1054
|
+
for (const token of body.split(",")) {
|
|
1055
|
+
const pair = /^\s*([1-9][0-9]*)\s*=\s*([0-9]+)\s*$/.exec(token);
|
|
1056
|
+
if (!pair || counts.has(Number(pair[1]))) return void 0;
|
|
1057
|
+
counts.set(Number(pair[1]), Number(pair[2]));
|
|
1058
|
+
}
|
|
1059
|
+
return counts;
|
|
1060
|
+
}
|
|
1061
|
+
function assertedVoteCounts(observed) {
|
|
1062
|
+
const claims = /* @__PURE__ */ new Map();
|
|
1063
|
+
for (const match of observed.matchAll(/([1-9][0-9]*)\s*号(?:玩家)?[^。;,,!!]{0,12}(?:获得|得到|拿到|有|被)\s*([0-9]+)\s*票/g)) {
|
|
1064
|
+
claims.set(Number(match[1]), Number(match[2]));
|
|
1065
|
+
}
|
|
1066
|
+
for (const section of observed.matchAll(/(?:投票计数|票数|票型)[^。;]*/g)) {
|
|
1067
|
+
for (const match of section[0].matchAll(/([1-9][0-9]*)\s*号?\s*=\s*([0-9]+)/g)) {
|
|
1068
|
+
claims.set(Number(match[1]), Number(match[2]));
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
for (const match of observed.matchAll(/(?:seat\s*)?([1-9][0-9]*)\s+(?:received|got|had)\s+([0-9]+)\s+votes?/gi)) {
|
|
1072
|
+
claims.set(Number(match[1]), Number(match[2]));
|
|
1073
|
+
}
|
|
1074
|
+
return [...claims].map(([seat, count]) => ({ seat, count }));
|
|
1075
|
+
}
|
|
1076
|
+
function assertedUnanimousSeat(observed) {
|
|
1077
|
+
const afterSeat = /([1-9][0-9]*)\s*号(?:玩家)?[^。;,,!!]{0,12}(?:全票|一致投票)/.exec(observed);
|
|
1078
|
+
if (afterSeat) return Number(afterSeat[1]);
|
|
1079
|
+
const beforeSeat = /(?:全票|一致投票)[^。;,,!!]{0,12}([1-9][0-9]*)\s*号/.exec(observed);
|
|
1080
|
+
if (beforeSeat) return Number(beforeSeat[1]);
|
|
1081
|
+
const collective = /(?:所有(?:玩家|人)|全部(?:玩家|人)|全体玩家)(?:都|一致)?[^。;,,!!]{0,12}(?:投票?(?:给|到)|投向|把票投给)\s*([1-9][0-9]*)\s*号/.exec(observed);
|
|
1082
|
+
if (collective) return Number(collective[1]);
|
|
1083
|
+
const unanimous = /(?:全部人)?一致投(?:票)?(?:给|到)\s*([1-9][0-9]*)\s*号/.exec(observed);
|
|
1084
|
+
if (unanimous) return Number(unanimous[1]);
|
|
1085
|
+
const english = /(?:all players|everyone)\s+(?:unanimously\s+)?voted\s+for\s+(?:seat\s*)?([1-9][0-9]*)/i.exec(observed);
|
|
1086
|
+
return english ? Number(english[1]) : void 0;
|
|
1087
|
+
}
|
|
1088
|
+
function assertedEliminatedSeats(observed) {
|
|
1089
|
+
const seats = [...observed.matchAll(/([1-9][0-9]*)\s*号(?:玩家)?[^。;,,!!]{0,12}(?:被(?:投出|放逐|票出|投票淘汰|冲出|冲出去))/g)].map((match) => Number(match[1]));
|
|
1090
|
+
for (const match of observed.matchAll(/seat\s*([1-9][0-9]*)[^.;]{0,16}(?:was\s+)?(?:voted out|eliminated by vote)/gi)) {
|
|
1091
|
+
seats.push(Number(match[1]));
|
|
1092
|
+
}
|
|
1093
|
+
return seats;
|
|
1094
|
+
}
|
|
1095
|
+
function assertObservedOutcomeSemantics(observed, outcomeFacts) {
|
|
1096
|
+
if (LOCAL_OUTCOME_INFERENCE_LANGUAGE.test(observed)) {
|
|
1097
|
+
throw new ProposalError(
|
|
1098
|
+
"LOCAL_OUTCOME_INFERENCE",
|
|
1099
|
+
"observedLocalEffect must state later facts directly instead of claiming they prove an interpretation"
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
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);
|
|
1103
|
+
for (const claim of assertedVoteCounts(observed)) {
|
|
1104
|
+
if (!countFacts.some((counts) => counts.get(claim.seat) === claim.count)) {
|
|
1105
|
+
throw new ProposalError(
|
|
1106
|
+
"OUTCOME_FACT_SEMANTICS_MISMATCH",
|
|
1107
|
+
"An asserted vote count does not match the referenced vote facts"
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
const unanimousSeat = assertedUnanimousSeat(observed);
|
|
1112
|
+
if (unanimousSeat !== void 0 && !countFacts.some((counts) => {
|
|
1113
|
+
const positive = [...counts].filter(([, count]) => count > 0);
|
|
1114
|
+
return positive.length === 1 && positive[0][0] === unanimousSeat;
|
|
1115
|
+
})) {
|
|
1116
|
+
throw new ProposalError(
|
|
1117
|
+
"OUTCOME_FACT_SEMANTICS_MISMATCH",
|
|
1118
|
+
"An asserted unanimous vote does not match the referenced vote facts"
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
for (const seat of assertedEliminatedSeats(observed)) {
|
|
1122
|
+
if (!outcomeFacts.some((fact) => (fact.type === "DAY_VOTE_ELIMINATED" || fact.type === "DAY_REVOTE_ELIMINATED") && fact.targetSeat === seat)) {
|
|
1123
|
+
throw new ProposalError(
|
|
1124
|
+
"OUTCOME_FACT_SEMANTICS_MISMATCH",
|
|
1125
|
+
"An asserted elimination does not match the referenced elimination facts"
|
|
1126
|
+
);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1004
1130
|
function assertLocalOutcomeEvidence(outcomeCount, localOutcomeCount, observed) {
|
|
1005
1131
|
if (outcomeCount === 0 || localOutcomeCount === 0) {
|
|
1006
1132
|
throw new ProposalError(
|
|
@@ -1221,6 +1347,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1221
1347
|
if (FIXED_RULE_LANGUAGE.test(rule)) {
|
|
1222
1348
|
throw new ProposalError("FIXED_RULE_NOT_LEARNABLE", "Permanent safety and protocol rules cannot be learned");
|
|
1223
1349
|
}
|
|
1350
|
+
assertNoAbsoluteStrategyClaim(proposal);
|
|
1224
1351
|
const facts = new Map(envelope.facts.map((fact) => [fact.factId, fact]));
|
|
1225
1352
|
const anchor = facts.get(anchorFactId);
|
|
1226
1353
|
if (!anchor || anchor.visibility === "POSTGAME_ONLY") {
|
|
@@ -1228,6 +1355,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1228
1355
|
}
|
|
1229
1356
|
assertBehaviorIsObserved(proposal);
|
|
1230
1357
|
proposal.behavior = anchor.summary;
|
|
1358
|
+
assertCounterfactualCoherence(proposal, anchor);
|
|
1231
1359
|
const known = proposal.knownFactRefs ?? [];
|
|
1232
1360
|
const outcomes = proposal.outcomeFactRefs ?? [];
|
|
1233
1361
|
const knownFacts = [];
|
|
@@ -1251,6 +1379,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1251
1379
|
knownFacts.push(fact);
|
|
1252
1380
|
}
|
|
1253
1381
|
let localOutcomeCount = 0;
|
|
1382
|
+
const outcomeFacts = [];
|
|
1254
1383
|
for (const ref of outcomes) {
|
|
1255
1384
|
const fact = facts.get(ref);
|
|
1256
1385
|
if (!fact) throw new ProposalError("OUTCOME_FACT_NOT_FOUND", `Unknown outcomeFactRef: ${ref}`);
|
|
@@ -1260,9 +1389,12 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1260
1389
|
if (LOCAL_OUTCOME_FACT_TYPES.has(fact.type)) {
|
|
1261
1390
|
localOutcomeCount++;
|
|
1262
1391
|
}
|
|
1392
|
+
outcomeFacts.push(fact);
|
|
1263
1393
|
}
|
|
1264
1394
|
assertActionTimeSemantics(proposal, window, anchor, knownFacts);
|
|
1395
|
+
assertDecisionTypeSemantics(proposal);
|
|
1265
1396
|
assertLocalOutcomeEvidence(outcomes.length, localOutcomeCount, observed);
|
|
1397
|
+
assertObservedOutcomeSemantics(observed, outcomeFacts);
|
|
1266
1398
|
const allRefs = /* @__PURE__ */ new Set([...known, ...outcomes]);
|
|
1267
1399
|
if (allRefs.size !== known.length + outcomes.length) {
|
|
1268
1400
|
throw new ProposalError("FACT_ROLE_CONFLICT", "A fact cannot be both known information and an outcome");
|
|
@@ -3133,9 +3265,13 @@ var WerewolfEvolutionService = class {
|
|
|
3133
3265
|
"- alternativeAction must describe a counterfactual action that did not happen; never swap behavior and alternativeAction.",
|
|
3134
3266
|
"- observedLocalEffect must not contain the final winner or loser; describe only a later local effect backed by outcomeFactRefs.",
|
|
3135
3267
|
"- 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.",
|
|
3268
|
+
"- 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.",
|
|
3269
|
+
"- 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.",
|
|
3270
|
+
"- 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.",
|
|
3136
3271
|
"- alternatives must contain at least one plausible alternative explanation. falsifier must state a concrete later observation that would disprove the rule.",
|
|
3137
3272
|
"Execution versus strategy contract:",
|
|
3138
3273
|
"- 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.",
|
|
3274
|
+
"- decisionType must match the lesson topic. In particular, AVOID_REPEATING_PRIOR_SPEAKERS must omit repeated content and add new information, not carry an unrelated speech strategy.",
|
|
3139
3275
|
"- Strategy proposals must omit executionOperation. CHOOSE_VOTE_TARGET and CHOOSE_ROLE_CLAIM_TIMING are decision types, never executionOperation values.",
|
|
3140
3276
|
"Call werewolf_debrief_commit after checking the complete proposal against this contract.",
|
|
3141
3277
|
"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.",
|
package/package.json
CHANGED