@myclaw163/clawclaw-cli 0.6.93 → 0.6.95
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/package.json +1 -1
- package/src/commands/account.test.ts +164 -1
- package/src/commands/account.ts +14 -2
- package/src/lib/hub-reminder.ts +10 -7
- package/src/strategies/game-utils.ts +7 -0
- package/src/strategies/goals/normal-shrimp-top.test.ts +17 -0
- package/src/strategies/goals/normal-shrimp-top.ts +7 -1
- package/src/strategies/goals/report-patrol-top.ts +6 -0
- package/src/strategies/meeting-gate.ts +5 -0
- package/src/strategies/new-events-backfill.ts +1 -1
- package/src/strategies/strategy-loop.ts +26 -0
- package/src/strategies/types.ts +7 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
3
3
|
import { tmpdir } from 'os';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import { createAccountCommand } from './account.js';
|
|
@@ -147,3 +147,166 @@ describe('account switch', () => {
|
|
|
147
147
|
expect(readAuth()).toEqual(before);
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
|
+
|
|
151
|
+
describe('account settlement hub reminder', () => {
|
|
152
|
+
let dir: string;
|
|
153
|
+
let oldWorkspace: string | undefined;
|
|
154
|
+
let logs: string[];
|
|
155
|
+
|
|
156
|
+
beforeEach(() => {
|
|
157
|
+
dir = mkdtempSync(join(tmpdir(), 'ccl-account-settlement-'));
|
|
158
|
+
oldWorkspace = process.env.CLAWCLAW_WORKSPACE_DIR;
|
|
159
|
+
process.env.CLAWCLAW_WORKSPACE_DIR = dir;
|
|
160
|
+
logs = [];
|
|
161
|
+
vi.spyOn(console, 'log').mockImplementation((...args) => { logs.push(args.join(' ')); });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
afterEach(() => {
|
|
165
|
+
if (oldWorkspace === undefined) delete process.env.CLAWCLAW_WORKSPACE_DIR;
|
|
166
|
+
else process.env.CLAWCLAW_WORKSPACE_DIR = oldWorkspace;
|
|
167
|
+
vi.unstubAllGlobals();
|
|
168
|
+
vi.restoreAllMocks();
|
|
169
|
+
rmSync(dir, { recursive: true, force: true });
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
function okResponse(data: Record<string, any>): Response {
|
|
173
|
+
return new Response(JSON.stringify({ success: true, data }), {
|
|
174
|
+
status: 200,
|
|
175
|
+
headers: { 'content-type': 'application/json' },
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function installActiveProfile(): void {
|
|
180
|
+
new AuthStore().addProfile({
|
|
181
|
+
agentName: 'settlement-agent',
|
|
182
|
+
apiKey: 'claw_settlement',
|
|
183
|
+
serverUrl: 'https://example.com/claw',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function mockSettlementFetch(gamesPlayed: number | 'fail'): ReturnType<typeof vi.fn> {
|
|
188
|
+
const fetchMock = vi.fn(async (url: string) => {
|
|
189
|
+
const rawUrl = String(url);
|
|
190
|
+
if (rawUrl.includes('/api/v1/game/settlement')) {
|
|
191
|
+
return okResponse({ game_id: 'game-1', your_result: { result: 'win' } });
|
|
192
|
+
}
|
|
193
|
+
if (rawUrl.includes('/api/v1/agents/me')) {
|
|
194
|
+
if (gamesPlayed === 'fail') {
|
|
195
|
+
return new Response(JSON.stringify({ success: false, error: { code: 'UPSTREAM' } }), {
|
|
196
|
+
status: 500,
|
|
197
|
+
headers: { 'content-type': 'application/json' },
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return okResponse({ games_played: gamesPlayed });
|
|
201
|
+
}
|
|
202
|
+
throw new Error(`unexpected url: ${rawUrl}`);
|
|
203
|
+
});
|
|
204
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
205
|
+
return fetchMock;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function runSettlement(): Promise<Record<string, any>> {
|
|
209
|
+
await createAccountCommand().parseAsync(['node', 'account', 'settlement'], { from: 'node' });
|
|
210
|
+
expect(logs).toHaveLength(1);
|
|
211
|
+
return JSON.parse(logs[0]);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function writeHubSkillLock(): void {
|
|
215
|
+
mkdirSync(join(dir, 'hub'), { recursive: true });
|
|
216
|
+
writeFileSync(join(dir, 'hub', 'installed.json'), JSON.stringify({
|
|
217
|
+
'skill/custom': { type: 'skill', id: 'custom', title: 'Custom Skill', path: 'skills/custom', installedAt: 'now' },
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function writeHubStrategyLock(): void {
|
|
222
|
+
mkdirSync(join(dir, 'user-data', 'hub'), { recursive: true });
|
|
223
|
+
writeFileSync(join(dir, 'user-data', 'hub', 'installed-strategies.json'), JSON.stringify({
|
|
224
|
+
'strategy/custom': { type: 'strategy', id: 'custom', title: 'Custom Strategy', path: 'strategies/custom.ts', installedAt: 'now' },
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function writeUserStrategy(fileName: string): void {
|
|
229
|
+
mkdirSync(join(dir, 'user-data', 'strategies'), { recursive: true });
|
|
230
|
+
writeFileSync(join(dir, 'user-data', 'strategies', fileName), 'export const strategy = {};');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
it('adds a debrief customization reminder in the first ten games when no custom skill or strategy is tracked', async () => {
|
|
234
|
+
installActiveProfile();
|
|
235
|
+
const fetchMock = mockSettlementFetch(6);
|
|
236
|
+
|
|
237
|
+
const out = await runSettlement();
|
|
238
|
+
|
|
239
|
+
expect(fetchMock.mock.calls.map(([url]) => String(url))).toEqual([
|
|
240
|
+
expect.stringContaining('/api/v1/game/settlement'),
|
|
241
|
+
expect.stringContaining('/api/v1/agents/me'),
|
|
242
|
+
]);
|
|
243
|
+
expect(out.data.game_id).toBe('game-1');
|
|
244
|
+
expect(out.hub_reminder).toContain('玩家已经玩了 6 局');
|
|
245
|
+
expect(out.hub_reminder).toContain('自定义 Skill 或策略');
|
|
246
|
+
expect(out.hub_reminder).toContain('根据复盘内容调整 Skill 或策略');
|
|
247
|
+
expect(out.next_step).toContain(out.hub_reminder);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('does not add the reminder after the first ten games', async () => {
|
|
251
|
+
installActiveProfile();
|
|
252
|
+
mockSettlementFetch(11);
|
|
253
|
+
|
|
254
|
+
const out = await runSettlement();
|
|
255
|
+
|
|
256
|
+
expect(out).not.toHaveProperty('hub_reminder');
|
|
257
|
+
expect(out).not.toHaveProperty('next_step');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('does not add the reminder when the latest games_played refresh fails', async () => {
|
|
261
|
+
installActiveProfile();
|
|
262
|
+
mockSettlementFetch('fail');
|
|
263
|
+
|
|
264
|
+
const out = await runSettlement();
|
|
265
|
+
|
|
266
|
+
expect(out.data.game_id).toBe('game-1');
|
|
267
|
+
expect(out).not.toHaveProperty('hub_reminder');
|
|
268
|
+
expect(out).not.toHaveProperty('next_step');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('does not add the reminder when a hub skill is tracked', async () => {
|
|
272
|
+
installActiveProfile();
|
|
273
|
+
writeHubSkillLock();
|
|
274
|
+
mockSettlementFetch(6);
|
|
275
|
+
|
|
276
|
+
const out = await runSettlement();
|
|
277
|
+
|
|
278
|
+
expect(out).not.toHaveProperty('hub_reminder');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('does not add the reminder when a hub strategy is tracked', async () => {
|
|
282
|
+
installActiveProfile();
|
|
283
|
+
writeHubStrategyLock();
|
|
284
|
+
mockSettlementFetch(6);
|
|
285
|
+
|
|
286
|
+
const out = await runSettlement();
|
|
287
|
+
|
|
288
|
+
expect(out).not.toHaveProperty('hub_reminder');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('does not add the reminder when a local user strategy exists', async () => {
|
|
292
|
+
installActiveProfile();
|
|
293
|
+
writeUserStrategy('custom.ts');
|
|
294
|
+
mockSettlementFetch(6);
|
|
295
|
+
|
|
296
|
+
const out = await runSettlement();
|
|
297
|
+
|
|
298
|
+
expect(out).not.toHaveProperty('hub_reminder');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('ignores non-user strategy helper files when checking local strategies', async () => {
|
|
302
|
+
installActiveProfile();
|
|
303
|
+
writeUserStrategy('_helper.ts');
|
|
304
|
+
writeUserStrategy('types.d.ts');
|
|
305
|
+
writeUserStrategy('custom.test.ts');
|
|
306
|
+
mockSettlementFetch(6);
|
|
307
|
+
|
|
308
|
+
const out = await runSettlement();
|
|
309
|
+
|
|
310
|
+
expect(out.hub_reminder).toContain('玩家已经玩了 6 局');
|
|
311
|
+
});
|
|
312
|
+
});
|
package/src/commands/account.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { AuthProfile } from '../lib/auth.js';
|
|
|
4
4
|
import { GameClient, ApiError } from '../lib/game-client.js';
|
|
5
5
|
import { createProfileDirs, cmdInit } from '../lib/init-command.js';
|
|
6
6
|
import { setMeta } from '../lib/command-meta.js';
|
|
7
|
-
import { hubReminder,
|
|
7
|
+
import { hubReminder, writeGamesPlayedCache } from '../lib/hub-reminder.js';
|
|
8
8
|
import {
|
|
9
9
|
missingInviteCodeMessage,
|
|
10
10
|
noAccountMessage,
|
|
@@ -20,6 +20,18 @@ import {
|
|
|
20
20
|
const DEFAULT_SERVER_URL = 'https://myclaw.163.com/claw';
|
|
21
21
|
const SERVER_URL_ENV = 'CLAWCLAW_SERVER_URL';
|
|
22
22
|
|
|
23
|
+
async function refreshGamesPlayedForReminder(client: GameClient): Promise<number | undefined> {
|
|
24
|
+
try {
|
|
25
|
+
const result = await client.getMe();
|
|
26
|
+
const gamesPlayed = result?.data?.games_played;
|
|
27
|
+
if (typeof gamesPlayed === 'number') {
|
|
28
|
+
writeGamesPlayedCache(gamesPlayed);
|
|
29
|
+
return gamesPlayed;
|
|
30
|
+
}
|
|
31
|
+
} catch {}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
23
35
|
function createClientForProfile(profile: AuthProfile): GameClient {
|
|
24
36
|
return new GameClient({
|
|
25
37
|
lobbyUrl: profile.serverUrl,
|
|
@@ -227,7 +239,7 @@ export function createAccountCommand(): Command {
|
|
|
227
239
|
// the reminder that rode in on the `game_over` push. Re-attach it here as
|
|
228
240
|
// the final fields (after `data`) so the nudge is the freshest thing in
|
|
229
241
|
// context the moment the agent writes the close.
|
|
230
|
-
const reminder = hubReminder(
|
|
242
|
+
const reminder = hubReminder(await refreshGamesPlayedForReminder(client));
|
|
231
243
|
const out: Record<string, any> = (result && typeof result === 'object' && !Array.isArray(result))
|
|
232
244
|
? { ...result }
|
|
233
245
|
: { result };
|
package/src/lib/hub-reminder.ts
CHANGED
|
@@ -12,12 +12,13 @@ import { ensureUserDataLayout, getUserDataStrategiesDir } from './user-data.js';
|
|
|
12
12
|
export const HUB_URL = 'https://myclaw.163.com/hub';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* True when
|
|
16
|
-
* hub-installed strategy and no user strategy file in
|
|
15
|
+
* True when CCL can only see the bundled default customization surface: no
|
|
16
|
+
* hub-installed skill, no hub-installed strategy, and no user strategy file in
|
|
17
|
+
* `<workspace>/user-data/strategies`.
|
|
17
18
|
*/
|
|
18
|
-
export function
|
|
19
|
+
export function usesOnlyDefaultSkillAndStrategies(): boolean {
|
|
19
20
|
try {
|
|
20
|
-
if (listInstalled().some((e) => e.type === 'strategy')) return false;
|
|
21
|
+
if (listInstalled().some((e) => e.type === 'skill' || e.type === 'strategy')) return false;
|
|
21
22
|
} catch {}
|
|
22
23
|
try {
|
|
23
24
|
const workspaceDir = getWorkspaceDir();
|
|
@@ -38,14 +39,16 @@ export function usesOnlyBuiltinStrategies(): boolean {
|
|
|
38
39
|
return true;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
export const usesOnlyBuiltinStrategies = usesOnlyDefaultSkillAndStrategies;
|
|
43
|
+
|
|
41
44
|
/**
|
|
42
45
|
* Agent-facing hub nudge for post-game debriefs / quit messages. The optional
|
|
43
46
|
* games-played count suppresses the nudge after the first stretch of games.
|
|
44
47
|
*/
|
|
45
48
|
export function hubReminder(gamesPlayed?: number): string | undefined {
|
|
46
|
-
if (!
|
|
47
|
-
if (typeof gamesPlayed
|
|
48
|
-
return
|
|
49
|
+
if (!usesOnlyDefaultSkillAndStrategies()) return undefined;
|
|
50
|
+
if (typeof gamesPlayed !== 'number' || gamesPlayed > 10) return undefined;
|
|
51
|
+
return `玩家已经玩了 ${gamesPlayed} 局,且还没有用过自定义 Skill 或策略。请在本局复盘后,提醒玩家可以根据复盘内容调整 Skill 或策略,让龙虾打法更符合玩家偏好。提醒要用第一人称龙虾身份融入收尾,语气温和,不要硬推。首轮建议表达为:“这已经是我们一起打的第 ${gamesPlayed} 局了。到目前为止,我一直用的是官方默认 Skill 和默认策略。如果你愿意,我们可以根据刚才这局的复盘调整 Skill 或策略,让我的打法更符合你的偏好。要不要我帮你看看怎么改?”如果玩家表示想了解或需要修改,再说明三种方式:我帮你浏览 Skill Hub 上的 Skill 或策略,按玩家想要的打法挑候选,玩家确认后再下载并安装;把 Skill Hub 链接 ${HUB_URL} 给玩家自行选择;告诉玩家当前游戏 Skill 和策略文件的存放路径,并根据本局复盘给出具体修改建议。路径信息只在玩家首次提出修改现有文件时主动给出;后续对局结束不要重复主动提示。`;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
const ACCOUNT_CACHE_FILE = 'account-cache.json';
|
|
@@ -593,6 +593,13 @@ export function reportCorpseDecision(
|
|
|
593
593
|
ctx: StrategyContext,
|
|
594
594
|
opts: { respectBlock?: boolean } = {},
|
|
595
595
|
): BehaviorDecision | null {
|
|
596
|
+
// 章鱼时间服务端禁用会议/报尸,任何 report 都会被 cannot_report_during_octopus_time 拒绝并陷入 5s 退避重试
|
|
597
|
+
// 循环;此时直接放弃报尸(含靠近尸体准备报告的 move),交由上层走生存/残局目标。一处即封住全部 6 个调用方,
|
|
598
|
+
// 也顺带让 corpseReportWithNonTeammate 因拿到 null 而不推「抢先报尸召集会议」的 agentAlert 叙事。
|
|
599
|
+
if (ctx.octopusTimeActive) {
|
|
600
|
+
ctx.reportCorpseTarget = null;
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
596
603
|
const reportBlocked = opts.respectBlock && Date.now() < ctx.reportBlockedUntil;
|
|
597
604
|
|
|
598
605
|
const reportable = nearestReportableCorpse(state);
|
|
@@ -77,4 +77,21 @@ describe('NormalShrimpTop vision thresholds', () => {
|
|
|
77
77
|
top.tick(stateWithStranger(300), ctx);
|
|
78
78
|
expect(top.subGoal).not.toBeInstanceOf(KeepAwayGoal);
|
|
79
79
|
});
|
|
80
|
+
|
|
81
|
+
it('does not keep corpse-report state or direct-report messaging during octopus time', () => {
|
|
82
|
+
const top = new NormalShrimpTop();
|
|
83
|
+
const ctx = context({
|
|
84
|
+
octopusTimeActive: true,
|
|
85
|
+
reportCorpseTarget: { name: 'body', room: 'control', x: 0, y: 0 },
|
|
86
|
+
knownCorpses: [{ name: 'body', room: 'control', x: 0, y: 0 }],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
top.tick({
|
|
90
|
+
...stateWithStranger(100),
|
|
91
|
+
corpses: [{ name: 'body', room: 'control', x: 0, y: 0, distance: 0 }],
|
|
92
|
+
}, ctx);
|
|
93
|
+
|
|
94
|
+
expect(ctx.reportCorpseTarget).toBeNull();
|
|
95
|
+
expect(ctx.notifications.join('\n')).not.toContain('直接报警');
|
|
96
|
+
});
|
|
80
97
|
});
|
|
@@ -75,7 +75,13 @@ export class NormalShrimpTop extends Goal {
|
|
|
75
75
|
if (greeting) decisions.push(greeting);
|
|
76
76
|
|
|
77
77
|
// ── P0 发现尸体 → 报警 ──
|
|
78
|
-
|
|
78
|
+
// 章鱼时间服务端禁用报尸,reportCorpseDecision 本就会返回 null;此处把整块 P0 一并跳过,否则
|
|
79
|
+
// notifyCorpseWitnesses 仍会推「尸体旁发现…,直接报警」这类提示,误导 Agent 以为仍应报尸召集会议。
|
|
80
|
+
// 跳过后落到后续 P1 躲避 / P3 任务巡逻的生存分支,同时清掉之前“靠近尸体准备报告”的残留状态。
|
|
81
|
+
if (ctx.octopusTimeActive) {
|
|
82
|
+
ctx.reportCorpseTarget = null;
|
|
83
|
+
this.corpseWitnessNotified.clear();
|
|
84
|
+
} else if (hasKnownCorpse(ctx)) {
|
|
79
85
|
// 「尸体旁目击者」只在此刻确实站在命案现场(当帧视野有尸体)时才标注——否则会把后来路上
|
|
80
86
|
// 遇见的人误报成目击者。报尸本身可以追着记忆里已离开视野的尸体走回去。
|
|
81
87
|
if (corpseAtScene(state)) this.notifyCorpseWitnesses(visible, ctx);
|
|
@@ -27,6 +27,12 @@ export class ReportPatrolTop extends Goal {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
private tryReport(state: GameState, ctx: StrategyContext): BehaviorDecision | null {
|
|
30
|
+
// 章鱼时间禁用报尸:不报、也不靠近尸体准备报告,落回巡逻(生存优先)。这条路径不走 reportCorpseDecision,需单独短路。
|
|
31
|
+
if (ctx.octopusTimeActive) {
|
|
32
|
+
this.lastCorpseNotified = false;
|
|
33
|
+
ctx.reportCorpseTarget = null;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
30
36
|
const reportable = nearestReportableCorpse(state);
|
|
31
37
|
if (reportable) {
|
|
32
38
|
ctx.reportCorpseTarget = null;
|
|
@@ -2,6 +2,7 @@ import type { GameState } from '../sdk/types.js';
|
|
|
2
2
|
|
|
3
3
|
const MEETING_END_EVENT_TYPES = new Set(['meeting_ended', 'meeting_result_pending']);
|
|
4
4
|
const MEETING_START_EVENT_TYPES = new Set(['meeting_start', 'meeting_started']);
|
|
5
|
+
const OCTOPUS_TIME_START_EVENT_TYPES = new Set(['octopus_time_start']);
|
|
5
6
|
|
|
6
7
|
export function meetingEndedInEvents(events: any[] | undefined): boolean {
|
|
7
8
|
return (events ?? []).some((e) => MEETING_END_EVENT_TYPES.has(e.type));
|
|
@@ -11,6 +12,10 @@ export function meetingStartedInEvents(events: any[] | undefined): boolean {
|
|
|
11
12
|
return (events ?? []).some((e) => MEETING_START_EVENT_TYPES.has(e.type));
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export function octopusTimeStartedInEvents(events: any[] | undefined): boolean {
|
|
16
|
+
return (events ?? []).some((e) => OCTOPUS_TIME_START_EVENT_TYPES.has(e.type));
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* Keep pausing while HTTP phase is still `meeting`.
|
|
16
21
|
* `releasedEarly` is set after we have seen meeting end once — avoids re-pausing
|
|
@@ -4,7 +4,7 @@ import { extractNewEvents } from '../pipeline/event-store.js';
|
|
|
4
4
|
const SUPPLEMENTAL_TYPES = new Set([
|
|
5
5
|
'corpse_spotted', 'crab_teammates',
|
|
6
6
|
'meeting_ended', 'meeting_result_pending', 'meeting_start', 'meeting_started',
|
|
7
|
-
'move_end', 'move_interrupted',
|
|
7
|
+
'move_end', 'move_interrupted', 'octopus_time_start',
|
|
8
8
|
'wandering_speech',
|
|
9
9
|
]);
|
|
10
10
|
|
|
@@ -14,6 +14,7 @@ import { CorpseMemory } from './game-utils.js';
|
|
|
14
14
|
import {
|
|
15
15
|
meetingEndedInEvents,
|
|
16
16
|
meetingStartedInEvents,
|
|
17
|
+
octopusTimeStartedInEvents,
|
|
17
18
|
shouldPauseForMeeting,
|
|
18
19
|
} from './meeting-gate.js';
|
|
19
20
|
import { createStrategyNewEventsBackfill } from './new-events-backfill.js';
|
|
@@ -41,6 +42,21 @@ export function eventsForStrategyStateLog(events: any): Record<string, any>[] {
|
|
|
41
42
|
return extractNewEvents(events).filter((event) => !SETUP_EVENTS_BACKFILLED_BY_STATE.has(event.type));
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
/** 章鱼时间进入提示,动作响应与主循环两条消费入口共用同一文案。 */
|
|
46
|
+
const OCTOPUS_TIME_START_NOTICE =
|
|
47
|
+
'章鱼时间开始,会议/报尸已禁用,切换到生存优先,不再报尸召集会议。';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 消费 octopus_time_start:置 ctx.octopusTimeActive 并提示一次。动作响应的 new_events 与主循环
|
|
51
|
+
* 补偿后的 state.new_events 两条入口都走它,避免置位/文案逻辑分叉。已在章鱼时间则幂等跳过,
|
|
52
|
+
* 因此同一事件经动作响应与日志补偿重复到达也只提示一次。
|
|
53
|
+
*/
|
|
54
|
+
function enterOctopusTimeIfStarted(ctx: StrategyContext, events: any[] | undefined): void {
|
|
55
|
+
if (ctx.octopusTimeActive || !octopusTimeStartedInEvents(events)) return;
|
|
56
|
+
ctx.octopusTimeActive = true;
|
|
57
|
+
ctx.notifications.push(OCTOPUS_TIME_START_NOTICE);
|
|
58
|
+
}
|
|
59
|
+
|
|
44
60
|
function getPidPath(): string {
|
|
45
61
|
const profile = new AuthStore().getActive();
|
|
46
62
|
if (!profile) throw new Error('Not logged in.');
|
|
@@ -334,6 +350,7 @@ export async function runStrategyLoop(strategyId: string, args?: string[]): Prom
|
|
|
334
350
|
taskLocalBlockedUntil: 0,
|
|
335
351
|
reportCorpseTarget: null,
|
|
336
352
|
reportBlockedUntil: 0,
|
|
353
|
+
octopusTimeActive: false,
|
|
337
354
|
notifications: [],
|
|
338
355
|
lastProgressNotifyAt: 0,
|
|
339
356
|
teammates,
|
|
@@ -396,6 +413,9 @@ export async function runStrategyLoop(strategyId: string, args?: string[]): Prom
|
|
|
396
413
|
// 那条通道会被 runtime WS listener 抢游标,这里补上避免尸体坐标漏记(ctx.knownCorpses 与 list() 同引用,立即可见)。
|
|
397
414
|
corpseMemory.ingestEvents(newEvents);
|
|
398
415
|
learnTeammatesFromEvents(newEvents, teammates);
|
|
416
|
+
// 章鱼时间可能只从本次动作响应的 new_events 到达(服务端游标一次性增量,下次 GET 不再重复);
|
|
417
|
+
// 立即消费,避免下一 tick 前仍走报尸分支,直到 report 被拒才靠错误文本兜底进入生存模式。
|
|
418
|
+
enterOctopusTimeIfStarted(ctx, newEvents);
|
|
399
419
|
if (currentRole === 'shrimp_pistol' && ownKillEvent(newEvents, currentPlayerName)) {
|
|
400
420
|
pistolKillUsed = true;
|
|
401
421
|
}
|
|
@@ -431,6 +451,10 @@ export async function runStrategyLoop(strategyId: string, args?: string[]): Prom
|
|
|
431
451
|
activeMoveTarget = null;
|
|
432
452
|
}
|
|
433
453
|
if (actionType === 'report') {
|
|
454
|
+
// 章鱼时间服务端禁用报尸,返回 cannot_report_during_octopus_time;漏掉 octopus_time_start 事件时靠它兜底进入生存模式。
|
|
455
|
+
if (failureText.includes('octopus')) {
|
|
456
|
+
ctx.octopusTimeActive = true;
|
|
457
|
+
}
|
|
434
458
|
// doing_task 型失败不是真报不了:服务端只是因正在做任务而拒绝,下一 tick 任务被 move 打断后即可补报。
|
|
435
459
|
// 这种情况不设 5 秒退避,否则会错过「目击者刚靠近尸体」的报尸自证窗口;其余原因(距离不够等)仍退避避免空报刷屏。
|
|
436
460
|
if (!failureText.includes('doing_task')) {
|
|
@@ -529,6 +553,7 @@ export async function runStrategyLoop(strategyId: string, args?: string[]): Prom
|
|
|
529
553
|
}
|
|
530
554
|
|
|
531
555
|
learnTeammatesFromEvents(state.new_events, teammates);
|
|
556
|
+
enterOctopusTimeIfStarted(ctx, state.new_events);
|
|
532
557
|
learnSeatNames(state.all_players, playerNamesBySeat);
|
|
533
558
|
const terminalMove = ownMovementTerminalEvent(state.new_events, state.you.name);
|
|
534
559
|
if (terminalMove) {
|
|
@@ -591,6 +616,7 @@ export async function runStrategyLoop(strategyId: string, args?: string[]): Prom
|
|
|
591
616
|
ctx.taskLocalBlockedUntil = 0;
|
|
592
617
|
ctx.reportCorpseTarget = null;
|
|
593
618
|
ctx.reportBlockedUntil = 0;
|
|
619
|
+
ctx.octopusTimeActive = false;
|
|
594
620
|
ctx.forcePatrolAdvance = false;
|
|
595
621
|
ctx.blockedMoveTarget = null;
|
|
596
622
|
// 开会后尸体清场:清空尸体记忆,避免回避/报告已不存在的尸体。
|
package/src/strategies/types.ts
CHANGED
|
@@ -72,6 +72,13 @@ export interface StrategyContext {
|
|
|
72
72
|
taskLocalBlockedUntil: number;
|
|
73
73
|
reportCorpseTarget: CorpseTarget | null;
|
|
74
74
|
reportBlockedUntil: number;
|
|
75
|
+
/**
|
|
76
|
+
* 章鱼时间(剩 3 人,服务端禁用会议/报尸,report 会被 `cannot_report_during_octopus_time` 拒绝)进行中。
|
|
77
|
+
* strategy-loop 见到 `octopus_time_start` 事件即置 true,report 因 octopus 相关错误失败时兜底置 true;每局
|
|
78
|
+
* 进程独立初始化为 false,会议恢复时一并清 false(章鱼时间不会开会,纯防御)。为 true 时所有报尸决策
|
|
79
|
+
* (reportCorpseDecision / ReportPatrolTop.tryReport / 经前者的 corpseReportWithNonTeammate)直接放弃,改生存优先。
|
|
80
|
+
*/
|
|
81
|
+
octopusTimeActive?: boolean;
|
|
75
82
|
notifications: string[];
|
|
76
83
|
lastProgressNotifyAt: number;
|
|
77
84
|
teammates: Set<string>;
|