@clawtopia/werewolf-evolution 0.1.20 → 2.0.0-alpha.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/README.md +37 -54
- package/bin/werewolf-evolution.mjs +69 -0
- package/package.json +12 -66
- package/skills/werewolf-evolution/SKILL.md +64 -0
- package/skills/werewolf-evolution/VERSION +1 -0
- package/skills/werewolf-evolution/scripts/evo.mjs +330 -0
- package/skills/werewolf-evolution/scripts/lib/api.mjs +24 -0
- package/skills/werewolf-evolution/scripts/lib/baseline.mjs +46 -0
- package/skills/werewolf-evolution/scripts/lib/brief.mjs +109 -0
- package/skills/werewolf-evolution/scripts/lib/context.mjs +46 -0
- package/skills/werewolf-evolution/scripts/lib/facts.mjs +155 -0
- package/skills/werewolf-evolution/scripts/lib/lessons.mjs +362 -0
- package/skills/werewolf-evolution/scripts/lib/metrics.mjs +57 -0
- package/skills/werewolf-evolution/scripts/lib/notify.mjs +22 -0
- package/skills/werewolf-evolution/scripts/lib/outcomes.mjs +119 -0
- package/skills/werewolf-evolution/scripts/lib/pool.mjs +70 -0
- package/skills/werewolf-evolution/scripts/lib/projection.mjs +155 -0
- package/skills/werewolf-evolution/scripts/lib/projector.mjs +139 -0
- package/skills/werewolf-evolution/scripts/lib/seat.mjs +42 -0
- package/skills/werewolf-evolution/scripts/lib/store.mjs +82 -0
- package/skills/werewolf-evolution/scripts/lib/sync.mjs +157 -0
- package/skills/werewolf-evolution/seeds.json +62 -0
- package/dist/index.d.ts +0 -294
- package/dist/index.js +0 -4151
- package/openclaw.plugin.json +0 -19
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// 第一层:补账拉取对局、计算局部结果、落盘。不调用模型。
|
|
2
|
+
//
|
|
3
|
+
// 平台的 /records?agentId= 按“Agent 坐过的房间”过滤,会返回同房间里别人打的局;
|
|
4
|
+
// 详情接口的 playerAgentIds 也可能为空。因此只能用结果视图判断本 Agent 是否参赛,
|
|
5
|
+
// 不在座的局记入 notMine,之后不再拉取。
|
|
6
|
+
import { computeOutcome } from './outcomes.mjs';
|
|
7
|
+
import { findSeat } from './seat.mjs';
|
|
8
|
+
import { buildGameFacts, selfTimeouts } from './facts.mjs';
|
|
9
|
+
import { windowStats } from './baseline.mjs';
|
|
10
|
+
|
|
11
|
+
export const REFLECT_BATCH = 5;
|
|
12
|
+
// 每天最多复盘几次(按北京时间自然日,意外局提前触发也计入);复盘消耗的是主人的模型额度
|
|
13
|
+
export const DAILY_REFLECTIONS = 3;
|
|
14
|
+
const dayOf = (iso) => new Date(Date.parse(iso) + 8 * 3600 * 1000).toISOString().slice(0, 10);
|
|
15
|
+
export const reflectionsToday = (ledger, now) => (ledger.reflections ?? []).filter((r) => r.at && dayOf(r.at) === dayOf(now)).length;
|
|
16
|
+
// 上次复盘之后、当天最多要求几次复盘(sync 返回 next=brief 的次数;定时任务里模型自己还会再 sync 一次,
|
|
17
|
+
// 所以一次没完成的触发通常记 2 次)。模型额度用完、或模型同步完就停下没接着复盘时
|
|
18
|
+
// (10-25 wolf7 连续 13 个小时被触发),避免每小时都触发一次。复盘成功后重新计数。
|
|
19
|
+
export const DAILY_STALLED = 6;
|
|
20
|
+
export const stalledToday = (ledger, now) => {
|
|
21
|
+
const last = (ledger.reflections ?? []).reduce((m, r) => (r.at && r.at > m ? r.at : m), '');
|
|
22
|
+
return (ledger.dueRuns ?? []).filter((at) => at > last && dayOf(at) === dayOf(now)).length;
|
|
23
|
+
};
|
|
24
|
+
// 每次同步最多给多少局旧对局补算基线计数和超时次数(早期版本同步的局没有 wstats / timeouts)
|
|
25
|
+
export const WSTATS_BACKFILL = 40;
|
|
26
|
+
|
|
27
|
+
const wstatsOf = (replay, record, agentId) => windowStats(buildGameFacts(replay, record, agentId)?.windows ?? []);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {object} p
|
|
31
|
+
* @param {object} p.api createApi() 结果
|
|
32
|
+
* @param {object} p.ledger loadLedger() 结果,原地更新
|
|
33
|
+
* @param {string} p.agentId
|
|
34
|
+
* @param {number} p.backfill 首次运行最多回补的本人对局数
|
|
35
|
+
* @param {number} p.max 单次最多新增的本人对局数
|
|
36
|
+
* @param {number} p.scan 单次最多检查的对局数(含不在座的)
|
|
37
|
+
* @param {string} p.now ISO 时间
|
|
38
|
+
*/
|
|
39
|
+
export async function sync({ api, ledger, agentId, backfill = 20, max = 30, scan = 100, now }) {
|
|
40
|
+
ledger.notMine ??= [];
|
|
41
|
+
const notMine = new Set(ledger.notMine.map(String));
|
|
42
|
+
const known = (id) => ledger.games[id] || ledger.incidents[id] || notMine.has(id);
|
|
43
|
+
const firstRun = ledger.floorGameId == null;
|
|
44
|
+
const want = firstRun ? Math.min(backfill, max) : max;
|
|
45
|
+
const pageSize = 20;
|
|
46
|
+
const added = [], incidents = [], examined = [];
|
|
47
|
+
let newestSeen = null, error = null, own = 0, capped = false, oldestOpen = null;
|
|
48
|
+
const recentRooms = new Set();
|
|
49
|
+
// 上次完整扫过的位置:再往下的局都已处理过,不必再翻页(records 里大量是同房间别人的局,翻到 floor 要十几页)
|
|
50
|
+
const syncedThrough = Number(ledger.syncedThrough ?? 0);
|
|
51
|
+
|
|
52
|
+
// 至少读第一页,以便 backfill=0 时也能确定 floor
|
|
53
|
+
outer: for (let page = 1; page === 1 || (own < want && examined.length < scan); page += 1) {
|
|
54
|
+
let data;
|
|
55
|
+
try {
|
|
56
|
+
data = await api.records(agentId, page, pageSize);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
error = `records p${page}: ${e.message}`;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const all = data?.records ?? [];
|
|
62
|
+
if (newestSeen == null && all.length) newestSeen = Number(all[0].gameId);
|
|
63
|
+
if (page === 1) all.slice(0, 5).forEach((r) => r.roomId != null && recentRooms.add(String(r.roomId)));
|
|
64
|
+
for (const r of all) {
|
|
65
|
+
const id = String(r.gameId);
|
|
66
|
+
if (!firstRun && (Number(id) < ledger.floorGameId || Number(id) <= syncedThrough)) break outer;
|
|
67
|
+
if (r.gameType === 'WEREWOLF' && !r.endedAt) oldestOpen = Number(id);
|
|
68
|
+
if (r.gameType !== 'WEREWOLF' || !r.endedAt || known(id)) continue;
|
|
69
|
+
if (own >= want || examined.length >= scan) { capped = true; break outer; }
|
|
70
|
+
let replay;
|
|
71
|
+
try {
|
|
72
|
+
replay = await api.replayResult(id);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
error = `${id}: ${e.message}`;
|
|
75
|
+
break outer;
|
|
76
|
+
}
|
|
77
|
+
examined.push(Number(id));
|
|
78
|
+
const { outcome, incident } = computeOutcome(replay, agentId, r);
|
|
79
|
+
if (incident === 'SELF_NOT_SEATED' || incident === 'PARTICIPATION_UNKNOWN') {
|
|
80
|
+
notMine.add(id);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
own += 1;
|
|
84
|
+
if (incident) {
|
|
85
|
+
ledger.incidents[id] = { reason: incident, at: now };
|
|
86
|
+
incidents.push({ gameId: id, reason: incident });
|
|
87
|
+
} else {
|
|
88
|
+
outcome.wstats = wstatsOf(replay, r, agentId);
|
|
89
|
+
outcome.timeouts = selfTimeouts(replay, agentId);
|
|
90
|
+
ledger.games[id] = outcome;
|
|
91
|
+
added.push(outcome);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!all.length || page * pageSize >= (data.total ?? 0)) break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 给旧对局补算基线计数;失败不影响本次同步,下次再补
|
|
98
|
+
let rebased = 0;
|
|
99
|
+
if (!error) {
|
|
100
|
+
for (const o of Object.values(ledger.games)) {
|
|
101
|
+
if ((o.wstats && o.timeouts != null) || rebased >= WSTATS_BACKFILL) continue;
|
|
102
|
+
try {
|
|
103
|
+
const replay = await api.replayResult(String(o.gameId));
|
|
104
|
+
o.wstats = wstatsOf(replay, { gameId: o.gameId, result: o.result }, agentId);
|
|
105
|
+
o.timeouts = selfTimeouts(replay, agentId);
|
|
106
|
+
rebased += 1;
|
|
107
|
+
} catch {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (firstRun && (examined.length || !error)) {
|
|
114
|
+
// 回补到哪里,floor 就设在哪里;一局都没检查时只跟踪之后的新局
|
|
115
|
+
ledger.floorGameId = examined.length ? Math.min(...examined) : (newestSeen ?? 0) + 1;
|
|
116
|
+
}
|
|
117
|
+
// 本次从最新一路扫到了已处理的位置,才推进 syncedThrough;
|
|
118
|
+
// 出错或被 max/scan 截断时保持不动,下次照旧翻到 floor 补上。还没结束的局不能越过。
|
|
119
|
+
capped ||= !firstRun && (own >= want || examined.length >= scan);
|
|
120
|
+
if (!error && !capped && newestSeen != null && ledger.floorGameId != null) {
|
|
121
|
+
const through = oldestOpen != null ? Math.min(newestSeen, oldestOpen - 1) : newestSeen;
|
|
122
|
+
ledger.syncedThrough = Math.max(syncedThrough, through);
|
|
123
|
+
}
|
|
124
|
+
// notMine 只需保留 floor 以上的部分
|
|
125
|
+
ledger.notMine = [...notMine].filter((id) => Number(id) >= (ledger.floorGameId ?? 0)).sort((a, b) => a - b);
|
|
126
|
+
ledger.lastSyncAt = now;
|
|
127
|
+
|
|
128
|
+
const pending = Object.values(ledger.games).filter((o) => Number(o.gameId) > Number(ledger.reflectedThrough ?? 0));
|
|
129
|
+
const surprises = pending.filter((o) => o.surprise?.length);
|
|
130
|
+
const due = pending.length >= REFLECT_BATCH || surprises.length > 0;
|
|
131
|
+
const dailyLimit = reflectionsToday(ledger, now) >= DAILY_REFLECTIONS
|
|
132
|
+
? `今天已复盘 ${DAILY_REFLECTIONS} 次,明天再复盘`
|
|
133
|
+
: stalledToday(ledger, now) >= DAILY_STALLED ? `今天已要求复盘 ${DAILY_STALLED} 次都没有完成,明天再复盘` : null;
|
|
134
|
+
const wanted = !dailyLimit && due;
|
|
135
|
+
// 只有要复盘时才查座位,避免每次同步都扫房间;查询失败时保守地推迟
|
|
136
|
+
let seat = null;
|
|
137
|
+
if (wanted) {
|
|
138
|
+
try {
|
|
139
|
+
seat = await findSeat({ api, agentId, extraRoomIds: recentRooms });
|
|
140
|
+
} catch (e) {
|
|
141
|
+
seat = { seated: true, error: e.message };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const reflectionDue = wanted && !seat?.seated;
|
|
145
|
+
if (reflectionDue) ledger.dueRuns = [...(ledger.dueRuns ?? []), now].slice(-20);
|
|
146
|
+
return {
|
|
147
|
+
added: added.sort((a, b) => a.gameId - b.gameId),
|
|
148
|
+
incidents,
|
|
149
|
+
examined: examined.length,
|
|
150
|
+
rebased,
|
|
151
|
+
error,
|
|
152
|
+
pending: pending.length,
|
|
153
|
+
reflectionDue,
|
|
154
|
+
deferred: dailyLimit && due ? dailyLimit : wanted && seat?.seated ? (seat.error ? `座位检查失败:${seat.error}` : `已在房间 ${seat.roomId}(${seat.status})`) : null,
|
|
155
|
+
surpriseGames: surprises.map((o) => String(o.gameId)),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"note": "平台层种子经验:由全平台对局统计得出的候选假设(2026-10-20,19500~19751 共 231 局有预言家首日决策),合入各 Agent 经验库后和其他经验一样靠分配的窗口检验,不预设分数。",
|
|
4
|
+
"lessons": [
|
|
5
|
+
{
|
|
6
|
+
"id": "S-0001",
|
|
7
|
+
"layer": "L1",
|
|
8
|
+
"role": "SEER",
|
|
9
|
+
"decisionType": "SEER_CLAIM",
|
|
10
|
+
"trigger": "首日你是预言家、场上没有人对跳预言家时",
|
|
11
|
+
"rule": "起跳报验人结果的同时,公开下一晚准备验谁和理由;你夜里被刀没有遗言,好人可以据此优先关注这个人",
|
|
12
|
+
"boundary": "有人悍跳预言家时先正面对抗、讲清验人逻辑;公开的验人对象尽量选发言有争议的人",
|
|
13
|
+
"evidence": "8 人场没有警徽,夜里被刀(首夜除外)没有遗言;平台 230 局预言家首日决策里只有 3 局公开了下一晚验谁,只有 5% 能在两天里公开报出验人结果"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": "S-0002",
|
|
17
|
+
"layer": "L1",
|
|
18
|
+
"role": "SEER",
|
|
19
|
+
"decisionType": "SEER_CLAIM",
|
|
20
|
+
"trigger": "首日你是预言家、首夜只验出金水、场上没有人对跳时",
|
|
21
|
+
"rule": "首日先不起跳,像平民一样发言并记下可疑点;等验出查杀、有人悍跳或你被投票推出时再起跳报全部结果",
|
|
22
|
+
"boundary": "验出查杀时不适用;女巫已表明会保你、或场上局势需要你立刻带队时不适用",
|
|
23
|
+
"evidence": "与 S-0001 互为对照:首日报金水后多数次夜被刀、金水信息量低;但平台首日不起跳 18 局好人只胜 22%,需要检验"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "S-0003",
|
|
27
|
+
"layer": "L1",
|
|
28
|
+
"role": "ANY",
|
|
29
|
+
"camp": "GOOD",
|
|
30
|
+
"decisionType": "DAY_VOTE",
|
|
31
|
+
"trigger": "首日没有查杀、对跳等硬信息,多名玩家集中投一名只是发言少或模板化的玩家时",
|
|
32
|
+
"rule": "不要只因发言少跟票;优先投前后立场矛盾、强行带节奏或替别人急着辩护的玩家",
|
|
33
|
+
"boundary": "有预言家查杀或明确对跳时按硬信息投;残局人数很少时另议",
|
|
34
|
+
"evidence": "本机 4 个 Agent 各自学出了相近的首日投票经验(wolfkill1、wolf5、wolf8、wolf3,见方案 9.11)",
|
|
35
|
+
"platform": {
|
|
36
|
+
"status": "testing",
|
|
37
|
+
"n": 26,
|
|
38
|
+
"games": 19,
|
|
39
|
+
"z": 1.39,
|
|
40
|
+
"asOf": "2026-11-16"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "S-0004",
|
|
45
|
+
"layer": "L1",
|
|
46
|
+
"role": "WOLF",
|
|
47
|
+
"decisionType": "DAY_VOTE",
|
|
48
|
+
"trigger": "首日或次日上午场上没有查验、对跳等硬信息,狼队需要推出一名好人时",
|
|
49
|
+
"rule": "优先跟票或带票信息量最低、被点名仍不回应的玩家,用公开可见的行为理由包装,避免硬编逻辑",
|
|
50
|
+
"boundary": "目标已跳神职、被预言家给了金水,或你自己被点名时不适用",
|
|
51
|
+
"evidence": "wolf6 学出的 L1-0002,旧规则下 13 个证据窗口全为 good(需按基线重新检验)",
|
|
52
|
+
"platform": {
|
|
53
|
+
"status": "verified",
|
|
54
|
+
"n": 6,
|
|
55
|
+
"games": 5,
|
|
56
|
+
"z": 1.8,
|
|
57
|
+
"lift": 35,
|
|
58
|
+
"asOf": "2026-10-28"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { OpenClawPluginToolContext, OpenClawPluginDefinition, OpenClawPluginApi } from 'openclaw/plugin-sdk/core';
|
|
2
|
-
|
|
3
|
-
type FactVisibility = "PUBLIC" | "WOLF_TEAM" | `SEAT_${number}_ONLY` | "POSTGAME_ONLY";
|
|
4
|
-
interface DebriefFact {
|
|
5
|
-
factId: string;
|
|
6
|
-
anchor: string;
|
|
7
|
-
type: string;
|
|
8
|
-
visibility: FactVisibility;
|
|
9
|
-
availableAt: {
|
|
10
|
-
historyIndex: number;
|
|
11
|
-
round?: number;
|
|
12
|
-
phase?: string;
|
|
13
|
-
};
|
|
14
|
-
actorSeat?: number | null;
|
|
15
|
-
targetSeat?: number | null;
|
|
16
|
-
summary: string;
|
|
17
|
-
}
|
|
18
|
-
interface DecisionWindow {
|
|
19
|
-
decisionWindowId: string;
|
|
20
|
-
anchorFactId: string;
|
|
21
|
-
actorSeat: number;
|
|
22
|
-
actorRole: string;
|
|
23
|
-
phase: string;
|
|
24
|
-
actionType: string;
|
|
25
|
-
allowedDecisionTypes: string[];
|
|
26
|
-
availableActionTypes: string[];
|
|
27
|
-
availableTargetSeats?: number[];
|
|
28
|
-
}
|
|
29
|
-
interface DebriefEnvelope {
|
|
30
|
-
schemaVersion: 2;
|
|
31
|
-
debriefId: string;
|
|
32
|
-
game: {
|
|
33
|
-
gameId: string;
|
|
34
|
-
recipientAgentId: string;
|
|
35
|
-
recipientSeat: number;
|
|
36
|
-
reviewDate: string;
|
|
37
|
-
profile?: string;
|
|
38
|
-
normalEnd: boolean;
|
|
39
|
-
role: string;
|
|
40
|
-
team: string;
|
|
41
|
-
finalState: string;
|
|
42
|
-
result: string;
|
|
43
|
-
players: number;
|
|
44
|
-
systemHealthGate: "PASS" | "SKIP_REQUIRED";
|
|
45
|
-
timelineComplete: boolean;
|
|
46
|
-
voteConsistency: "CONSISTENT" | "INCONSISTENT" | "NOT_APPLICABLE";
|
|
47
|
-
};
|
|
48
|
-
facts: DebriefFact[];
|
|
49
|
-
decisionWindows: DecisionWindow[];
|
|
50
|
-
}
|
|
51
|
-
type ProposalAction = "SKIP" | "SUPPORT" | "COUNTER" | "REFINE" | "NEW";
|
|
52
|
-
type ProposalSource = "SELF" | "OBSERVED" | "EXEMPLAR";
|
|
53
|
-
type ExecutionOperation = "REPORT_DECIDED_ROLE_CLAIM" | "EXPLAIN_DECIDED_VOTE" | "RETRACT_PUBLIC_JUDGMENT" | "AVOID_REPEATING_PRIOR_SPEAKERS" | "EXPLAIN_DECIDED_WOLF_TARGET";
|
|
54
|
-
interface DebriefProposal {
|
|
55
|
-
schemaVersion: 1;
|
|
56
|
-
action: ProposalAction;
|
|
57
|
-
source: ProposalSource;
|
|
58
|
-
topicId?: string;
|
|
59
|
-
profile?: string;
|
|
60
|
-
decisionWindowId?: string;
|
|
61
|
-
decisionType?: string;
|
|
62
|
-
executionOperation?: ExecutionOperation;
|
|
63
|
-
alternativeActionType?: string;
|
|
64
|
-
alternativeTargetSeat?: number | null;
|
|
65
|
-
anchorFactId?: string;
|
|
66
|
-
knownFactRefs?: string[];
|
|
67
|
-
outcomeFactRefs?: string[];
|
|
68
|
-
trigger?: string;
|
|
69
|
-
rule?: string;
|
|
70
|
-
boundary?: string;
|
|
71
|
-
behavior?: string;
|
|
72
|
-
alternativeAction?: string;
|
|
73
|
-
expectedLocalEffect?: string;
|
|
74
|
-
observedLocalEffect?: string;
|
|
75
|
-
falsifier?: string;
|
|
76
|
-
alternatives?: string[];
|
|
77
|
-
skipReason?: string;
|
|
78
|
-
}
|
|
79
|
-
interface CapturedBase {
|
|
80
|
-
channelId: string;
|
|
81
|
-
accountId: string;
|
|
82
|
-
from: string;
|
|
83
|
-
sessionKey: string;
|
|
84
|
-
runId?: string;
|
|
85
|
-
conversationId?: string;
|
|
86
|
-
messageId?: string;
|
|
87
|
-
content: string;
|
|
88
|
-
capturedAt: number;
|
|
89
|
-
}
|
|
90
|
-
interface CapturedDebrief extends CapturedBase {
|
|
91
|
-
kind: "debrief";
|
|
92
|
-
bodyHash: string;
|
|
93
|
-
envelope: DebriefEnvelope;
|
|
94
|
-
conflict?: boolean;
|
|
95
|
-
}
|
|
96
|
-
interface CapturedSuggestionCommand extends CapturedBase {
|
|
97
|
-
kind: "suggestion-command";
|
|
98
|
-
suggestionId: string;
|
|
99
|
-
decision: "accept" | "reject";
|
|
100
|
-
}
|
|
101
|
-
type CapturedInbound = CapturedDebrief | CapturedSuggestionCommand;
|
|
102
|
-
interface BoundRun {
|
|
103
|
-
runId: string;
|
|
104
|
-
sessionKey: string;
|
|
105
|
-
agentId: string;
|
|
106
|
-
workspaceDir: string;
|
|
107
|
-
inbound: CapturedInbound;
|
|
108
|
-
senderId?: string;
|
|
109
|
-
senderIsOwner: boolean;
|
|
110
|
-
consumed: boolean;
|
|
111
|
-
proposalAttempts: number;
|
|
112
|
-
promptContext?: string;
|
|
113
|
-
terminalDiagnostic?: {
|
|
114
|
-
status: string;
|
|
115
|
-
code: string;
|
|
116
|
-
};
|
|
117
|
-
boundAt: number;
|
|
118
|
-
expiresAt: number;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
interface MessageReceivedLike {
|
|
122
|
-
from: string;
|
|
123
|
-
content: string;
|
|
124
|
-
messageId?: string;
|
|
125
|
-
sessionKey?: string;
|
|
126
|
-
runId?: string;
|
|
127
|
-
}
|
|
128
|
-
interface MessageContextLike {
|
|
129
|
-
channelId: string;
|
|
130
|
-
accountId?: string;
|
|
131
|
-
sessionKey?: string;
|
|
132
|
-
runId?: string;
|
|
133
|
-
conversationId?: string;
|
|
134
|
-
}
|
|
135
|
-
interface AgentRunEventLike {
|
|
136
|
-
channelId?: string;
|
|
137
|
-
accountId?: string;
|
|
138
|
-
senderId?: string;
|
|
139
|
-
senderIsOwner?: boolean;
|
|
140
|
-
}
|
|
141
|
-
interface AgentAccountBinding {
|
|
142
|
-
channelId: string;
|
|
143
|
-
accountId: string;
|
|
144
|
-
platformAgentId: string;
|
|
145
|
-
}
|
|
146
|
-
interface AgentRunContextLike {
|
|
147
|
-
runId?: string;
|
|
148
|
-
sessionKey?: string;
|
|
149
|
-
agentId?: string;
|
|
150
|
-
workspaceDir?: string;
|
|
151
|
-
}
|
|
152
|
-
declare class EvolutionContextStore {
|
|
153
|
-
private readonly inboundByRun;
|
|
154
|
-
private readonly inboundBySession;
|
|
155
|
-
private readonly inboundByStableKey;
|
|
156
|
-
private readonly stableKeyByInbound;
|
|
157
|
-
private readonly stableKeyExpiresAt;
|
|
158
|
-
private readonly boundTombstoneKeys;
|
|
159
|
-
private readonly releasedTombstones;
|
|
160
|
-
private readonly boundByRun;
|
|
161
|
-
private readonly hashByDebriefId;
|
|
162
|
-
private readonly toolCalls;
|
|
163
|
-
capture(event: MessageReceivedLike, ctx: MessageContextLike, now?: number): CapturedInbound | undefined;
|
|
164
|
-
getPending(runId?: string, sessionKey?: string, prompt?: string, now?: number): CapturedInbound | undefined;
|
|
165
|
-
private stableInboundKey;
|
|
166
|
-
private storeInbound;
|
|
167
|
-
private removeInbound;
|
|
168
|
-
private compactBoundTombstone;
|
|
169
|
-
bindAgentRun(event: AgentRunEventLike, ctx: AgentRunContextLike, binding: AgentAccountBinding | undefined, now?: number, explicitOwnerAuthorized?: boolean, pendingInbound?: CapturedInbound): BoundRun | undefined;
|
|
170
|
-
getBound(runId?: string, sessionKey?: string, now?: number): BoundRun | undefined;
|
|
171
|
-
getBoundForToolCall(runId: string | undefined, sessionKey: string | undefined, agentId: string | undefined, now?: number): BoundRun | undefined;
|
|
172
|
-
private resolveBoundForToolCall;
|
|
173
|
-
releaseRun(runId: string | undefined, sessionKey?: string): BoundRun | undefined;
|
|
174
|
-
consume(runId: string, sessionKey: string, now?: number): BoundRun;
|
|
175
|
-
authorizeToolCall(runId: string | undefined, sessionKey: string | undefined, toolCallId: string | undefined, now?: number, agentId?: string): BoundRun;
|
|
176
|
-
inspectAuthorizedToolCall(toolCallId: string, sessionKey: string | undefined, agentId: string | undefined, now?: number): BoundRun | undefined;
|
|
177
|
-
consumeToolCall(toolCallId: string, sessionKey?: string, now?: number): BoundRun;
|
|
178
|
-
beginProposalToolCall(toolCallId: string, sessionKey?: string, now?: number): BoundRun;
|
|
179
|
-
private beginToolCall;
|
|
180
|
-
cleanup(now?: number): void;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
interface TransactionHooks {
|
|
184
|
-
afterRename?: (committedCount: number) => void;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
interface CommitInput {
|
|
188
|
-
debriefId: string;
|
|
189
|
-
proposal: DebriefProposal;
|
|
190
|
-
}
|
|
191
|
-
interface SuggestionDecisionInput {
|
|
192
|
-
suggestionId: string;
|
|
193
|
-
decision: "accept" | "reject";
|
|
194
|
-
}
|
|
195
|
-
interface DebriefToolDiagnostic {
|
|
196
|
-
debriefId: string;
|
|
197
|
-
runId: string;
|
|
198
|
-
agentId: string;
|
|
199
|
-
}
|
|
200
|
-
interface PromptContextLike extends AgentRunContextLike {
|
|
201
|
-
}
|
|
202
|
-
interface PromptBuildEventLike {
|
|
203
|
-
prompt: string;
|
|
204
|
-
}
|
|
205
|
-
interface OrdinaryDirectMessage {
|
|
206
|
-
channelId: string;
|
|
207
|
-
accountId: string;
|
|
208
|
-
from: string;
|
|
209
|
-
sessionKey: string;
|
|
210
|
-
content: string;
|
|
211
|
-
capturedAt: number;
|
|
212
|
-
}
|
|
213
|
-
interface MessageSendingLike {
|
|
214
|
-
to: string;
|
|
215
|
-
content?: string;
|
|
216
|
-
}
|
|
217
|
-
interface InboundClaimLike {
|
|
218
|
-
senderId?: string;
|
|
219
|
-
content: string;
|
|
220
|
-
channel: string;
|
|
221
|
-
accountId?: string;
|
|
222
|
-
sessionKey?: string;
|
|
223
|
-
runId?: string;
|
|
224
|
-
messageId?: string;
|
|
225
|
-
conversationId?: string;
|
|
226
|
-
isGroup?: boolean;
|
|
227
|
-
}
|
|
228
|
-
interface InboundClaimContextLike {
|
|
229
|
-
channelId?: string;
|
|
230
|
-
accountId?: string;
|
|
231
|
-
sessionKey?: string;
|
|
232
|
-
runId?: string;
|
|
233
|
-
messageId?: string;
|
|
234
|
-
senderId?: string;
|
|
235
|
-
conversationId?: string;
|
|
236
|
-
}
|
|
237
|
-
declare class WerewolfEvolutionService {
|
|
238
|
-
readonly contexts: EvolutionContextStore;
|
|
239
|
-
private readonly version;
|
|
240
|
-
private readonly ordinaryDirectMessages;
|
|
241
|
-
private readonly ordinaryDirectMessagesBySession;
|
|
242
|
-
private readonly ownerDirectRuns;
|
|
243
|
-
private readonly observedRuns;
|
|
244
|
-
private readonly systemDebriefSessions;
|
|
245
|
-
constructor(version?: string);
|
|
246
|
-
private cleanupOrdinaryDirectMessages;
|
|
247
|
-
private cleanupSystemDebriefSessions;
|
|
248
|
-
private matchesSystemDebriefTarget;
|
|
249
|
-
captureMessage(event: MessageReceivedLike, ctx: MessageContextLike): CapturedInbound | undefined;
|
|
250
|
-
captureInboundClaim(event: InboundClaimLike, ctx?: InboundClaimContextLike): CapturedInbound | undefined;
|
|
251
|
-
isSystemDebriefMessage(event: MessageSendingLike, ctx: Pick<MessageContextLike, "channelId" | "accountId" | "sessionKey" | "conversationId">): boolean;
|
|
252
|
-
private pendingOrdinaryDirectMessage;
|
|
253
|
-
private consumeOrdinaryDirectMessage;
|
|
254
|
-
bindAgentRun(event: AgentRunEventLike, ctx: AgentRunContextLike, binding: AgentAccountBinding | undefined, explicitOwnerAuthorized?: boolean, pendingInbound?: CapturedDebrief | CapturedSuggestionCommand, pendingOrdinary?: OrdinaryDirectMessage): BoundRun | undefined;
|
|
255
|
-
bindPromptRun(event: PromptBuildEventLike, ctx: AgentRunContextLike, config: unknown): BoundRun | undefined;
|
|
256
|
-
recordTerminalDiagnostic(runId: string, sessionKey: string | undefined, terminal: {
|
|
257
|
-
status: string;
|
|
258
|
-
code: string;
|
|
259
|
-
}): BoundRun | undefined;
|
|
260
|
-
finishRun(ctx: Pick<AgentRunContextLike, "runId" | "sessionKey"> & {
|
|
261
|
-
success?: boolean;
|
|
262
|
-
}): {
|
|
263
|
-
bound: BoundRun;
|
|
264
|
-
terminalCreated: boolean;
|
|
265
|
-
} | undefined;
|
|
266
|
-
buildPromptContext(ctx: PromptContextLike, hooks?: TransactionHooks): {
|
|
267
|
-
prependContext: string;
|
|
268
|
-
} | undefined;
|
|
269
|
-
beforeToolCall(event: {
|
|
270
|
-
toolName: string;
|
|
271
|
-
params: Record<string, unknown>;
|
|
272
|
-
derivedPaths?: readonly string[];
|
|
273
|
-
toolCallId?: string;
|
|
274
|
-
runId?: string;
|
|
275
|
-
toolKind?: "code_mode_exec";
|
|
276
|
-
}, ctx: {
|
|
277
|
-
sessionKey?: string;
|
|
278
|
-
runId?: string;
|
|
279
|
-
toolCallId?: string;
|
|
280
|
-
agentId?: string;
|
|
281
|
-
}): {
|
|
282
|
-
block?: boolean;
|
|
283
|
-
blockReason?: string;
|
|
284
|
-
} | undefined;
|
|
285
|
-
inspectDebriefToolCall(toolCallId: string, ctx: Pick<OpenClawPluginToolContext, "sessionKey" | "agentId">): DebriefToolDiagnostic | undefined;
|
|
286
|
-
private persistIncident;
|
|
287
|
-
commit(toolCallId: string, ctx: OpenClawPluginToolContext, input: CommitInput, hooks?: TransactionHooks): Record<string, unknown>;
|
|
288
|
-
decideSuggestion(toolCallId: string, ctx: OpenClawPluginToolContext, input: SuggestionDecisionInput, hooks?: TransactionHooks): Record<string, unknown>;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
declare function registerWerewolfEvolution(api: OpenClawPluginApi, service?: WerewolfEvolutionService): void;
|
|
292
|
-
declare const entry: OpenClawPluginDefinition;
|
|
293
|
-
|
|
294
|
-
export { entry as default, registerWerewolfEvolution };
|