@myclaw163/clawclaw-cli 0.6.54
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 +440 -0
- package/bin/clawclaw-cli.mjs +4 -0
- package/package.json +48 -0
- package/personas//347/220/206/346/231/272/346/270/251/345/222/214.md +23 -0
- package/personas//350/200/201/350/260/213/346/267/261/347/256/227.md +22 -0
- package/personas//350/257/232/346/201/263/347/233/264/347/216/207.md +22 -0
- package/personas//350/275/273/346/235/276/346/264/273/346/263/274.md +22 -0
- package/personas//351/207/216/346/200/247/345/217/233/351/200/206.md +23 -0
- package/scripts/postinstall.mjs +20 -0
- package/scripts/sync-bundled-skill.mjs +245 -0
- package/scripts/sync-bundled-skill.test.mjs +152 -0
- package/skills/clawclaw/SKILL.md +240 -0
- package/skills/clawclaw/references/CHATTERBOX.md +142 -0
- package/skills/clawclaw/references/COMMANDS.md +132 -0
- package/skills/clawclaw/references/GAME-MECHANICS.md +186 -0
- package/skills/clawclaw/references/HUB.md +48 -0
- package/skills/clawclaw/references/KNOWLEDGE.md +43 -0
- package/skills/clawclaw/references/STRATEGIES.md +57 -0
- package/skills/clawclaw/references/STREAM.md +58 -0
- package/skills/clawclaw/references/TACTICS.md +65 -0
- package/src/assets/clawclaw-ascii-map.txt +40 -0
- package/src/cli.ts +153 -0
- package/src/commands/_schema.ts +109 -0
- package/src/commands/account.ts +209 -0
- package/src/commands/config.ts +30 -0
- package/src/commands/do.test.ts +37 -0
- package/src/commands/do.ts +95 -0
- package/src/commands/events.ts +22 -0
- package/src/commands/game-map.test.ts +28 -0
- package/src/commands/game-start-plan.test.ts +142 -0
- package/src/commands/game.ts +882 -0
- package/src/commands/history-player.test.ts +102 -0
- package/src/commands/history.ts +573 -0
- package/src/commands/hub.test.ts +96 -0
- package/src/commands/hub.ts +234 -0
- package/src/commands/knowledge.test.ts +19 -0
- package/src/commands/knowledge.ts +168 -0
- package/src/commands/load.test.ts +51 -0
- package/src/commands/load.ts +13 -0
- package/src/commands/meeting-history.test.ts +106 -0
- package/src/commands/memory.ts +40 -0
- package/src/commands/peek.ts +38 -0
- package/src/commands/persona.ts +57 -0
- package/src/commands/setup/codex.ts +248 -0
- package/src/commands/setup/hermes.test.ts +96 -0
- package/src/commands/setup/hermes.ts +76 -0
- package/src/commands/setup/index.ts +13 -0
- package/src/commands/setup/openclaw.test.ts +114 -0
- package/src/commands/setup/openclaw.ts +147 -0
- package/src/commands/skill.ts +128 -0
- package/src/commands/state.ts +46 -0
- package/src/commands/strategy.test.ts +135 -0
- package/src/commands/strategy.ts +189 -0
- package/src/commands/tts.ts +128 -0
- package/src/commands/upgrade.test.ts +91 -0
- package/src/commands/upgrade.ts +154 -0
- package/src/commands/watch.test.ts +973 -0
- package/src/commands/watch.ts +709 -0
- package/src/lib/auth.test.ts +59 -0
- package/src/lib/auth.ts +186 -0
- package/src/lib/command-meta.ts +37 -0
- package/src/lib/game-client.ts +391 -0
- package/src/lib/host-config-patcher.test.ts +130 -0
- package/src/lib/host-config-patcher.ts +151 -0
- package/src/lib/http-keepalive.ts +15 -0
- package/src/lib/http-transport.test.ts +42 -0
- package/src/lib/http-transport.ts +113 -0
- package/src/lib/hub-client.test.ts +56 -0
- package/src/lib/hub-client.ts +88 -0
- package/src/lib/hub-install.test.ts +98 -0
- package/src/lib/hub-install.ts +121 -0
- package/src/lib/hub-reminder.ts +75 -0
- package/src/lib/hub-unzip.test.ts +69 -0
- package/src/lib/hub-unzip.ts +62 -0
- package/src/lib/init-command.test.ts +75 -0
- package/src/lib/init-command.ts +120 -0
- package/src/lib/knowledge-store.test.ts +180 -0
- package/src/lib/knowledge-store.ts +374 -0
- package/src/lib/load-context.test.ts +52 -0
- package/src/lib/load-context.ts +52 -0
- package/src/lib/match-state.test.ts +134 -0
- package/src/lib/match-state.ts +94 -0
- package/src/lib/netease-tts.ts +83 -0
- package/src/lib/normalize.ts +42 -0
- package/src/lib/persona.test.ts +41 -0
- package/src/lib/persona.ts +72 -0
- package/src/lib/server-registry.ts +152 -0
- package/src/lib/skill-version.test.ts +48 -0
- package/src/lib/skill-version.ts +19 -0
- package/src/lib/strategy-export.test.ts +232 -0
- package/src/lib/strategy-export.ts +242 -0
- package/src/lib/tts-keys.ts +7 -0
- package/src/lib/tts-speech.test.ts +63 -0
- package/src/lib/tts-speech.ts +76 -0
- package/src/lib/workspace-argv.test.ts +49 -0
- package/src/lib/workspace-argv.ts +44 -0
- package/src/perception/player-history-store.test.ts +87 -0
- package/src/perception/player-history-store.ts +194 -0
- package/src/pipeline/event-store.ts +124 -0
- package/src/pipeline/pipeline.ts +35 -0
- package/src/runtime/auto-upgrade.test.ts +66 -0
- package/src/runtime/auto-upgrade.ts +31 -0
- package/src/runtime/daemon.ts +100 -0
- package/src/runtime/event-daemon.test.ts +28 -0
- package/src/runtime/event-daemon.ts +371 -0
- package/src/runtime/opening-mover.ts +303 -0
- package/src/runtime/raw-ws-log.test.ts +33 -0
- package/src/runtime/raw-ws-log.ts +32 -0
- package/src/runtime/runtime-logger.ts +99 -0
- package/src/runtime/ws-client.test.ts +47 -0
- package/src/runtime/ws-client.ts +272 -0
- package/src/sdk/action.ts +166 -0
- package/src/sdk/index.ts +110 -0
- package/src/sdk/types.ts +146 -0
- package/src/strategies/avoid-lone.ts +11 -0
- package/src/strategies/avoid-players.knowledge.md +20 -0
- package/src/strategies/avoid-players.ts +15 -0
- package/src/strategies/corpse-patrol.ts +22 -0
- package/src/strategies/crab-sabotage.ts +21 -0
- package/src/strategies/custom-module.test.ts +269 -0
- package/src/strategies/find-player.ts +16 -0
- package/src/strategies/game-utils.test.ts +164 -0
- package/src/strategies/game-utils.ts +721 -0
- package/src/strategies/goals/avoid-lone-top.ts +168 -0
- package/src/strategies/goals/avoid-players-top.test.ts +83 -0
- package/src/strategies/goals/avoid-players-top.ts +121 -0
- package/src/strategies/goals/conversation-goal.ts +51 -0
- package/src/strategies/goals/corpse-patrol-top.ts +91 -0
- package/src/strategies/goals/crab-octopus-reflexes.ts +93 -0
- package/src/strategies/goals/crab-sabotage-top.ts +197 -0
- package/src/strategies/goals/emergency-hunt-goal.ts +28 -0
- package/src/strategies/goals/find-player-top.ts +93 -0
- package/src/strategies/goals/flee-players-goal.ts +53 -0
- package/src/strategies/goals/goal-manager.ts +41 -0
- package/src/strategies/goals/goal-root-strategy.ts +49 -0
- package/src/strategies/goals/goal.ts +28 -0
- package/src/strategies/goals/keep-away-goal.ts +206 -0
- package/src/strategies/goals/kill-frenzy-top.ts +80 -0
- package/src/strategies/goals/kill-lone-top.ts +160 -0
- package/src/strategies/goals/kill-target-goal.ts +59 -0
- package/src/strategies/goals/kill-target-top.ts +109 -0
- package/src/strategies/goals/leaf-goal.ts +25 -0
- package/src/strategies/goals/linger-corpse-goal.ts +79 -0
- package/src/strategies/goals/lone-kill-core.ts +82 -0
- package/src/strategies/goals/lone-kill-goal.ts +24 -0
- package/src/strategies/goals/lone-kill-task-top.test.ts +85 -0
- package/src/strategies/goals/lone-kill-task-top.ts +86 -0
- package/src/strategies/goals/move-room-goal.ts +60 -0
- package/src/strategies/goals/normal-shrimp-top.test.ts +80 -0
- package/src/strategies/goals/normal-shrimp-top.ts +242 -0
- package/src/strategies/goals/paradise-fish-top.test.ts +126 -0
- package/src/strategies/goals/paradise-fish-top.ts +219 -0
- package/src/strategies/goals/patrol-top.ts +57 -0
- package/src/strategies/goals/report-patrol-top.ts +80 -0
- package/src/strategies/goals/safe-task-goal.ts +102 -0
- package/src/strategies/goals/social-task-top.ts +161 -0
- package/src/strategies/goals/task-kill-report-top.ts +163 -0
- package/src/strategies/goals/task-only-top.ts +57 -0
- package/src/strategies/goals/task-or-patrol-goal.ts +41 -0
- package/src/strategies/goals/task-report-top.ts +57 -0
- package/src/strategies/goals/wander-task-goal.ts +33 -0
- package/src/strategies/goals/warrior-shrimp-top.test.ts +86 -0
- package/src/strategies/goals/warrior-shrimp-top.ts +248 -0
- package/src/strategies/greeting.ts +53 -0
- package/src/strategies/kill-frenzy.ts +12 -0
- package/src/strategies/kill-lone.knowledge.md +20 -0
- package/src/strategies/kill-lone.ts +13 -0
- package/src/strategies/kill-target.ts +18 -0
- package/src/strategies/loader.test.ts +678 -0
- package/src/strategies/loader.ts +172 -0
- package/src/strategies/lone-kill-task.ts +21 -0
- package/src/strategies/meeting-gate.test.ts +59 -0
- package/src/strategies/meeting-gate.ts +23 -0
- package/src/strategies/move-room.ts +15 -0
- package/src/strategies/new-events-backfill.ts +98 -0
- package/src/strategies/paradise-fish.knowledge.md +20 -0
- package/src/strategies/paradise-fish.ts +25 -0
- package/src/strategies/pathfind/clawclaw-walkable.bin +0 -0
- package/src/strategies/pathfind/distance-field.ts +150 -0
- package/src/strategies/pathfind/escape-planner.test.ts +197 -0
- package/src/strategies/pathfind/escape-planner.ts +348 -0
- package/src/strategies/pathfind/walkable-grid.ts +117 -0
- package/src/strategies/patrol.ts +11 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +11 -0
- package/src/strategies/shrimp-memory.knowledge.md +20 -0
- package/src/strategies/shrimp-memory.ts +25 -0
- package/src/strategies/social-task.test.ts +28 -0
- package/src/strategies/social-task.ts +49 -0
- package/src/strategies/spawn.ts +71 -0
- package/src/strategies/speech-module.ts +123 -0
- package/src/strategies/strategy-loop.ts +757 -0
- package/src/strategies/task-kill-report.ts +17 -0
- package/src/strategies/task-only.ts +11 -0
- package/src/strategies/task-report.ts +22 -0
- package/src/strategies/types.ts +96 -0
- package/src/strategies/warrior-memory.knowledge.md +20 -0
- package/src/strategies/warrior-memory.ts +16 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StrategyEntry } from './types.js';
|
|
2
|
+
import { GoalRootStrategy } from './goals/goal-root-strategy.js';
|
|
3
|
+
import { ReportPatrolTop } from './goals/report-patrol-top.js';
|
|
4
|
+
|
|
5
|
+
export const strategy: StrategyEntry = {
|
|
6
|
+
id: 'report-patrol',
|
|
7
|
+
description: '专门找尸体:达到报告距离立刻报告,看到尸体就靠近;没有尸体就巡逻各房间。不做任何任务,不打人,目标是让会议尽快开起来。',
|
|
8
|
+
create() {
|
|
9
|
+
return new GoalRootStrategy('report-patrol', () => new ReportPatrolTop(), { resetOnMeetingResume: false });
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# shrimp-memory 知识契约
|
|
2
|
+
|
|
3
|
+
`shrimp-memory` 只读取统一的玩家三档标记:
|
|
4
|
+
|
|
5
|
+
| 标记 | 行为 |
|
|
6
|
+
|------|------|
|
|
7
|
+
| `suspect` | 可疑:进入视野后寻路远离 |
|
|
8
|
+
| `hostile` | 敌对:进入视野后寻路远离 |
|
|
9
|
+
| `trusted` | 可信:可以结伴做任务,其在场时不对陌生人触发后撤 |
|
|
10
|
+
|
|
11
|
+
普通虾永不出刀,因此 suspect 与 hostile 都表现为回避;两档仍保留,是为了与武士虾等带刀策略共享同一份知识。无标记玩家按陌生人处理:无 trusted 同伴且单人贴近 270px 内时拉开距离,多人互为目击者时照常做任务。
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
ccl knowledge mark 5 suspect --confidence 0.7 --note "行为可疑"
|
|
15
|
+
ccl knowledge mark 5 hostile --confidence 0.9 --note "确认敌对"
|
|
16
|
+
ccl knowledge mark 3 trusted --note "已澄清"
|
|
17
|
+
ccl knowledge del player 5
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`role` 是纯身份事实,不直接控制策略。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { StrategyEntry } from './types.js';
|
|
2
|
+
import { GoalRootStrategy } from './goals/goal-root-strategy.js';
|
|
3
|
+
import { NormalShrimpTop } from './goals/normal-shrimp-top.js';
|
|
4
|
+
import { parseGreetingArgs } from './greeting.js';
|
|
5
|
+
|
|
6
|
+
class ShrimpMemoryStrategy extends GoalRootStrategy {
|
|
7
|
+
constructor(private readonly greetingPhrases: string[]) {
|
|
8
|
+
super('shrimp-memory', () => new NormalShrimpTop(greetingPhrases), {
|
|
9
|
+
resetOnMeetingResume: false,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
speechWarmupTexts(): string[] {
|
|
14
|
+
return this.greetingPhrases;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const strategy: StrategyEntry = {
|
|
19
|
+
id: 'shrimp-memory',
|
|
20
|
+
description:
|
|
21
|
+
'普通虾·记忆进阶版(好人、不带刀;task-report 的带记忆升级)。统一读取 ccl knowledge 三档标记:suspect/hostile 都寻路远离,trusted 视为可信同伴。发现尸体最优先报警,并提示复核尸体旁身份不明者;无可信同伴且单个陌生人贴近270内时先拉开距离到300再做任务;再处理紧急任务,最后做任务/巡逻(选测地最近、跳过威胁旁或必经威胁的任务)。永不出刀。传入打招呼话术时,视野内出现人就随机发送一条,之后120秒内不再发言。',
|
|
22
|
+
create(args?: string[]) {
|
|
23
|
+
return new ShrimpMemoryStrategy(parseGreetingArgs(args, 'shrimp-memory'));
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parseSocialArgs } from './social-task.js';
|
|
3
|
+
|
|
4
|
+
describe('parseSocialArgs', () => {
|
|
5
|
+
it('parses space-separated tokens', () => {
|
|
6
|
+
expect(parseSocialArgs(['3=你好', '5', '8=嗨'])).toEqual([
|
|
7
|
+
{ target: '3', greeting: '你好' },
|
|
8
|
+
{ target: '5', greeting: null },
|
|
9
|
+
{ target: '8', greeting: '嗨' },
|
|
10
|
+
]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('parses one CLI token with glued seat=greeting segments', () => {
|
|
14
|
+
const one =
|
|
15
|
+
'1=嗨 2=你好 3=嘿4=哈喽5=你也在啊6=嗨嗨 7=你好呀 8=嘿嘿 9=哈喽呀';
|
|
16
|
+
expect(parseSocialArgs([one])).toEqual([
|
|
17
|
+
{ target: '1', greeting: '嗨' },
|
|
18
|
+
{ target: '2', greeting: '你好' },
|
|
19
|
+
{ target: '3', greeting: '嘿' },
|
|
20
|
+
{ target: '4', greeting: '哈喽' },
|
|
21
|
+
{ target: '5', greeting: '你也在啊' },
|
|
22
|
+
{ target: '6', greeting: '嗨嗨' },
|
|
23
|
+
{ target: '7', greeting: '你好呀' },
|
|
24
|
+
{ target: '8', greeting: '嘿嘿' },
|
|
25
|
+
{ target: '9', greeting: '哈喽呀' },
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { StrategyEntry } from './types.js';
|
|
2
|
+
import { GoalRootStrategy } from './goals/goal-root-strategy.js';
|
|
3
|
+
import { SocialTaskTop, type SocialTarget } from './goals/social-task-top.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse args in format: `seat=greeting` or just `seat`.
|
|
7
|
+
* E.g. `3=你好 5 8=嗨` → [{target:'3', greeting:'你好'}, {target:'5', greeting:null}, {target:'8', greeting:'嗨'}]
|
|
8
|
+
*
|
|
9
|
+
* CLI may pass one token (`"1=嗨 2=你好 3=嘿4=哈喽5=..."`) — normalize glued `4=`, `5=` before splitting.
|
|
10
|
+
*/
|
|
11
|
+
export function parseSocialArgs(args: string[]): SocialTarget[] {
|
|
12
|
+
let raw = args.join(' ').trim();
|
|
13
|
+
if (!raw) return [];
|
|
14
|
+
|
|
15
|
+
// `3=嘿4=哈喽5=你也在啊` → `3=嘿 4=哈喽 5=你也在啊`
|
|
16
|
+
raw = raw.replace(/(?<!\s)(\d+=)/g, ' $1').trim();
|
|
17
|
+
|
|
18
|
+
const targets: SocialTarget[] = [];
|
|
19
|
+
for (const token of raw.split(/\s+/)) {
|
|
20
|
+
const eqIdx = token.indexOf('=');
|
|
21
|
+
if (eqIdx >= 0) {
|
|
22
|
+
const target = token.slice(0, eqIdx).trim();
|
|
23
|
+
const greeting = token.slice(eqIdx + 1).trim();
|
|
24
|
+
if (target) {
|
|
25
|
+
targets.push({ target, greeting: greeting || null });
|
|
26
|
+
}
|
|
27
|
+
} else if (/^\d+$/.test(token)) {
|
|
28
|
+
targets.push({ target: token, greeting: null });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return targets;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const strategy: StrategyEntry = {
|
|
35
|
+
id: 'social-task',
|
|
36
|
+
description: '针对指定玩家社交(参数格式 座位=话术 或纯座位,可多人)。视野内出现目标就靠近,没打过招呼先发一次招呼;对方说话就停下等你回复,10秒没回应就转去做任务。全程见到可报告的尸体就报、见到尸体就靠近。不打人。参数:座位=话术 / 座位(可多人)。',
|
|
37
|
+
create(args?: string[]) {
|
|
38
|
+
if (!args || args.length === 0) {
|
|
39
|
+
throw new Error("social-task strategy requires social targets as arguments. Format: seat=greeting or seat. E.g. '3=你好 5 8=嗨'");
|
|
40
|
+
}
|
|
41
|
+
const socialTargets = parseSocialArgs(args);
|
|
42
|
+
if (socialTargets.length === 0) {
|
|
43
|
+
throw new Error("social-task strategy: no valid social targets parsed from arguments.");
|
|
44
|
+
}
|
|
45
|
+
return new GoalRootStrategy('social-task', () => new SocialTaskTop(socialTargets), {
|
|
46
|
+
resetOnMeetingResume: false,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { existsSync, mkdirSync, openSync, writeFileSync } from 'fs';
|
|
3
|
+
import { dirname, join, resolve } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { getProfileLogsDir, getProfileStateDir } from '../lib/init-command.js';
|
|
6
|
+
import { AuthStore } from '../lib/auth.js';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
const fwd = (p: string) => p.replace(/\\/g, '/');
|
|
12
|
+
const BIN_MJS = fwd(resolve(__dirname, '..', '..', 'bin', 'clawclaw-cli.mjs'));
|
|
13
|
+
|
|
14
|
+
export function spawnStrategyLoop(
|
|
15
|
+
strategyId: string,
|
|
16
|
+
strategyArgs?: string[],
|
|
17
|
+
opts?: { source?: string; gameId?: string; role?: string },
|
|
18
|
+
): ReturnType<typeof spawn> {
|
|
19
|
+
if (!existsSync(BIN_MJS)) throw new Error('clawclaw-cli bin entry not found');
|
|
20
|
+
const isWin = process.platform === 'win32';
|
|
21
|
+
|
|
22
|
+
let logFile: string | undefined;
|
|
23
|
+
if (isWin) {
|
|
24
|
+
try {
|
|
25
|
+
const store = new AuthStore();
|
|
26
|
+
const active = store.getActive();
|
|
27
|
+
if (active) {
|
|
28
|
+
const logsDir = getProfileLogsDir(active);
|
|
29
|
+
mkdirSync(logsDir, { recursive: true });
|
|
30
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
31
|
+
logFile = resolve(logsDir, `strategy-${timestamp}.log`);
|
|
32
|
+
openSync(logFile, 'a');
|
|
33
|
+
}
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const args = ['_strategy', strategyId];
|
|
38
|
+
if (strategyArgs && strategyArgs.length > 0) args.push('--', ...strategyArgs);
|
|
39
|
+
|
|
40
|
+
const child = spawn(process.execPath, [BIN_MJS, ...args], {
|
|
41
|
+
detached: true,
|
|
42
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
...(isWin && logFile ? { CLAWCLAW_LOG_FILE: logFile } : {}),
|
|
46
|
+
},
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (child.pid) {
|
|
51
|
+
try {
|
|
52
|
+
const store = new AuthStore();
|
|
53
|
+
const active = store.getActive();
|
|
54
|
+
if (active) {
|
|
55
|
+
const stateDir = getProfileStateDir(active);
|
|
56
|
+
mkdirSync(stateDir, { recursive: true });
|
|
57
|
+
writeFileSync(join(stateDir, 'auto.pid'), String(child.pid));
|
|
58
|
+
writeFileSync(join(stateDir, 'auto.json'), JSON.stringify({
|
|
59
|
+
strategy: strategyId,
|
|
60
|
+
pid: child.pid,
|
|
61
|
+
source: opts?.source ?? 'manual',
|
|
62
|
+
...(opts?.gameId ? { game_id: opts.gameId } : {}),
|
|
63
|
+
...(opts?.role ? { role: opts.role } : {}),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
} catch {}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
child.unref();
|
|
70
|
+
return child;
|
|
71
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { GameState, PlayerInfo } from '../sdk/types.js';
|
|
2
|
+
import type { StrategyContext } from './types.js';
|
|
3
|
+
|
|
4
|
+
export interface SpeechModuleConfig {
|
|
5
|
+
globalCooldownMs: number;
|
|
6
|
+
perPersonCooldownMs: number;
|
|
7
|
+
autoGreetEnabled: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SpeechEvalResult {
|
|
11
|
+
notifications: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class SpeechModule {
|
|
15
|
+
private config: SpeechModuleConfig;
|
|
16
|
+
private lastInitiateTime = 0;
|
|
17
|
+
private perPersonCooldowns = new Map<string, number>();
|
|
18
|
+
|
|
19
|
+
constructor(config: SpeechModuleConfig) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
evaluate(
|
|
24
|
+
state: GameState,
|
|
25
|
+
ctx: StrategyContext,
|
|
26
|
+
signals: { allowAutoGreet: boolean },
|
|
27
|
+
): SpeechEvalResult {
|
|
28
|
+
const result: SpeechEvalResult = { notifications: [] };
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
|
|
31
|
+
const speechEvents = (state.new_events ?? []).filter(
|
|
32
|
+
evt => evt.type === 'wandering_speech' && evt.actor_name && evt.actor_name !== state.you.name,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
for (const evt of speechEvents) {
|
|
36
|
+
const speaker = evt.actor_name as string;
|
|
37
|
+
const text = (evt.text ?? evt.content ?? '') as string;
|
|
38
|
+
const seatInfo = this.findSeatForPlayer(speaker, state, ctx);
|
|
39
|
+
result.notifications.push(`[被搭话] ${speaker}${seatInfo}对你说:「${text}」`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (signals.allowAutoGreet && this.canInitiate(state, ctx, now)) {
|
|
43
|
+
const candidate = this.pickCandidate(state, ctx, now);
|
|
44
|
+
if (candidate) {
|
|
45
|
+
const seatInfo = this.findSeatForPlayer(candidate.name, state, ctx);
|
|
46
|
+
this.lastInitiateTime = now;
|
|
47
|
+
this.perPersonCooldowns.set(candidate.name, now + this.config.perPersonCooldownMs);
|
|
48
|
+
result.notifications.push(`[发言] 视野内出现${candidate.name}${seatInfo},可以主动打招呼。`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private canInitiate(state: GameState, ctx: StrategyContext, now: number): boolean {
|
|
56
|
+
if (!this.config.autoGreetEnabled) return false;
|
|
57
|
+
if (now - this.lastInitiateTime < this.config.globalCooldownMs) return false;
|
|
58
|
+
if (state.you.doing_task) return false;
|
|
59
|
+
if (ctx.reportCorpseTarget) return false;
|
|
60
|
+
if (ctx.emergency && ctx.emergency.status !== 'completed') return false;
|
|
61
|
+
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private pickCandidate(state: GameState, ctx: StrategyContext, now: number): PlayerInfo | null {
|
|
66
|
+
const mySeat = ctx.mySeat ?? 0;
|
|
67
|
+
const speechActors = new Set(
|
|
68
|
+
(state.new_events ?? [])
|
|
69
|
+
.filter(evt => evt.type === 'wandering_speech' && evt.actor_name)
|
|
70
|
+
.map(evt => evt.actor_name as string),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
for (const player of state.players) {
|
|
74
|
+
const cooldownUntil = this.perPersonCooldowns.get(player.name) ?? 0;
|
|
75
|
+
if (now < cooldownUntil) continue;
|
|
76
|
+
|
|
77
|
+
const theirSeat = player.seat ?? Infinity;
|
|
78
|
+
if (mySeat >= theirSeat) continue;
|
|
79
|
+
|
|
80
|
+
if (speechActors.has(player.name)) continue;
|
|
81
|
+
|
|
82
|
+
return player;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 会议边界不再暂停移动,也无需清理等待对话状态。 */
|
|
88
|
+
resetMeetingState(): void {
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** 角色变化时刷新发言配置,保留 ConversationGoal 持有的模块实例。 */
|
|
92
|
+
updateConfig(role: string): void {
|
|
93
|
+
this.config = getSpeechConfigForRole(role);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private findSeatForPlayer(name: string, state: GameState, ctx: StrategyContext): string {
|
|
97
|
+
const player = state.players.find(p => p.name === name);
|
|
98
|
+
if (player?.seat != null) return `(${player.seat}号)`;
|
|
99
|
+
for (const [seat, pName] of Object.entries(ctx.playerNamesBySeat)) {
|
|
100
|
+
if (pName === name) return `(${seat}号)`;
|
|
101
|
+
}
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const ROLE_CONFIGS: Record<string, SpeechModuleConfig> = {
|
|
107
|
+
shrimp_generic: { globalCooldownMs: 30_000, perPersonCooldownMs: 90_000, autoGreetEnabled: true },
|
|
108
|
+
shrimp_warrior: { globalCooldownMs: 30_000, perPersonCooldownMs: 90_000, autoGreetEnabled: true },
|
|
109
|
+
shrimp_pistol: { globalCooldownMs: 30_000, perPersonCooldownMs: 90_000, autoGreetEnabled: true },
|
|
110
|
+
crab_generic: { globalCooldownMs: 30_000, perPersonCooldownMs: 90_000, autoGreetEnabled: false },
|
|
111
|
+
neutral_paradise_fish: { globalCooldownMs: 20_000, perPersonCooldownMs: 90_000, autoGreetEnabled: true },
|
|
112
|
+
neutral_octopus: { globalCooldownMs: 30_000, perPersonCooldownMs: 90_000, autoGreetEnabled: false },
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const DEFAULT_CONFIG: SpeechModuleConfig = {
|
|
116
|
+
globalCooldownMs: 30_000,
|
|
117
|
+
perPersonCooldownMs: 90_000,
|
|
118
|
+
autoGreetEnabled: true,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export function getSpeechConfigForRole(role: string): SpeechModuleConfig {
|
|
122
|
+
return ROLE_CONFIGS[role] ?? DEFAULT_CONFIG;
|
|
123
|
+
}
|