@myclaw163/clawclaw-cli 0.7.9 → 0.7.11

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.
Files changed (39) hide show
  1. package/QUICKSTART_OTHER.md +2 -2
  2. package/docs/configuration.md +1 -1
  3. package/package.json +1 -1
  4. package/scripts/check-skill-command-surface.mjs +2 -0
  5. package/skills/clawclaw/SKILL.md +64 -43
  6. package/skills/clawclaw/references/CHATTERBOX.md +1 -1
  7. package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +2 -2
  8. package/skills/clawclaw/references/COMMANDS.md +31 -19
  9. package/skills/clawclaw/references/GAME-MECHANICS.md +3 -3
  10. package/skills/clawclaw/references/STRATEGIES.md +1 -1
  11. package/skills/clawclaw/references/STREAM.md +3 -3
  12. package/src/cli.ts +7 -1
  13. package/src/commands/communication.test.ts +14 -3
  14. package/src/commands/communication.ts +12 -4
  15. package/src/commands/game/index.test.ts +198 -1
  16. package/src/commands/game/index.ts +229 -4
  17. package/src/commands/load.test.ts +68 -1
  18. package/src/commands/load.ts +26 -3
  19. package/src/pipeline/event-format.test.ts +0 -21
  20. package/src/pipeline/event-format.ts +0 -33
  21. package/src/pipeline/event-hints.test.ts +2 -5
  22. package/src/pipeline/event-hints.ts +0 -17
  23. package/src/pipeline/game-sync-event-normalization.test.ts +1 -12
  24. package/src/pipeline/game-sync-event-normalization.ts +0 -13
  25. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +11 -4
  26. package/src/runtime/clawclaw-event-catalog.ts +0 -2
  27. package/src/sdk/action.ts +9 -8
  28. package/src/sdk/strategy-plugin/index.test.ts +3 -3
  29. package/src/sdk/strategy-plugin/index.ts +25 -24
  30. package/src/strategies/custom-module.test.ts +1 -1
  31. package/src/strategies/game-utils.test.ts +8 -8
  32. package/src/strategies/game-utils.ts +39 -28
  33. package/src/strategies/goals/crab-octopus-reflexes.ts +11 -7
  34. package/src/strategies/goals/hide-top.ts +2 -1
  35. package/src/strategies/goals/kill-target-goal.ts +2 -1
  36. package/src/strategies/goals/kill-target-top.ts +3 -3
  37. package/src/strategies/goals/lone-kill-core.ts +3 -1
  38. package/src/strategies/goals/task-kill-report-top.ts +2 -1
  39. package/src/strategies/goals/warrior-shrimp-top.ts +2 -1
@@ -269,20 +269,6 @@ function formatVotes(votes: unknown, ctx: EventFormatContext): Record<string, st
269
269
  return out;
270
270
  }
271
271
 
272
- function teammateNames(event: Record<string, any>): string[] {
273
- const raw = Array.isArray(event.crab_teammates)
274
- ? event.crab_teammates
275
- : Array.isArray(event.teammates)
276
- ? event.teammates
277
- : [];
278
- const names: string[] = [];
279
- for (const teammate of raw) {
280
- const name = typeof teammate === 'string' ? teammate : teammate?.name;
281
- if (typeof name === 'string' && name.length > 0) names.push(name);
282
- }
283
- return names;
284
- }
285
-
286
272
  function teammateObjects(event: Record<string, any>, ctx: EventFormatContext): Record<string, any>[] {
287
273
  const raw = Array.isArray(event.crab_teammates)
288
274
  ? event.crab_teammates
@@ -471,10 +457,6 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
471
457
  const speakerSeat = firstNumber(event, ['speaker_seat', 'actor_seat', 'seat']);
472
458
  return `${playerLabel(speakerName, speakerSeat, ctx)}死亡弹幕:${truncate(event.text ?? event.message, maxTextLength)}`;
473
459
  }
474
- case 'crab_teammates': {
475
- const labels = teammateNames(event).map((name) => playerLabel(name, undefined, ctx));
476
- return labels.length > 0 ? `蟹队友:${labels.join('、')}。` : '蟹队友信息已更新。';
477
- }
478
460
  case 'wandering_speech':
479
461
  return `${text(event.actor_name, '你')}在${firstString(event, ['room'])}说:${truncate(event.text ?? event.message, maxTextLength)}`;
480
462
  case 'game_over':
@@ -663,20 +645,6 @@ function compactVoteCastForEvents(event: Record<string, any>, ctx: EventFormatCo
663
645
  });
664
646
  }
665
647
 
666
- function compactCrabTeammatesForEvents(event: Record<string, any>, ctx: EventFormatContext): FormattedEvent {
667
- const {
668
- teammates: _teammates,
669
- crab_teammates: _crabTeammates,
670
- ...rest
671
- } = event;
672
- return cleanObject({
673
- ...rest,
674
- type: text(rest.type, 'event'),
675
- tick: numberValue(rest.tick) ?? null,
676
- crab_teammates: teammateObjects(event, ctx),
677
- });
678
- }
679
-
680
648
  function compactMeetingResultForEvents(event: Record<string, any>, ctx: EventFormatContext): FormattedEvent {
681
649
  const {
682
650
  votes: _votes,
@@ -756,7 +724,6 @@ export function compactEventForEvents(
756
724
  }
757
725
 
758
726
  if (event.type === 'vote_cast') return compactVoteCastForEvents(event, ctx);
759
- if (event.type === 'crab_teammates') return compactCrabTeammatesForEvents(event, ctx);
760
727
  if (event.type === 'exile' || event.type === 'no_exile') return compactMeetingResultForEvents(event, ctx);
761
728
  if (event.type === 'players_changed') return compactPlayersChangedForEvents(event);
762
729
 
@@ -16,7 +16,7 @@ describe('Mailbox-owned Event hint registries', () => {
16
16
  BACKEND_EVENT_HINT_FORMATTERS[type] === undefined
17
17
  ));
18
18
 
19
- expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(31);
19
+ expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(30);
20
20
  expect(unregistered).toEqual([
21
21
  'task_completed',
22
22
  'task_sabotaged',
@@ -175,9 +175,6 @@ describe('Mailbox-owned Event hint registries', () => {
175
175
 
176
176
  it('preserves the useful incremental semantics from npm batch next_step routes', () => {
177
177
  expect(BACKEND_EVENT_HINT_FORMATTERS.game_started({}, {})).toContain('do not relaunch');
178
- expect(BACKEND_EVENT_HINT_FORMATTERS.crab_teammates({
179
- crab_teammates: [{ name: 'Bob', seat: 2 }],
180
- }, {})).toContain('avoid voting for or killing them');
181
178
 
182
179
  const normalGameOver = BACKEND_EVENT_HINT_FORMATTERS.game_over({
183
180
  winner: 'lobster',
@@ -250,7 +247,7 @@ describe('Mailbox-owned Event hint registries', () => {
250
247
  ...Object.values(DERIVED_EVENT_HINT_FORMATTERS).map((formatter) => formatter(sample, {})),
251
248
  ].filter((hint): hint is string => typeof hint === 'string');
252
249
 
253
- expect(hints).toHaveLength(51);
250
+ expect(hints).toHaveLength(50);
254
251
  for (const hint of hints) expect(hint).not.toMatch(/[一-鿿]/);
255
252
  });
256
253
  });
@@ -182,23 +182,6 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
182
182
  + 'If this is you, your influence is dead — tell your user and ask whether to spectate or leave.'
183
183
  ),
184
184
  no_exile: () => 'Meeting ended — no one was exiled. The table failed to strike, and every hidden threat gets another turn.',
185
- crab_teammates: (event) => {
186
- const raw = Array.isArray(event.crab_teammates)
187
- ? event.crab_teammates
188
- : Array.isArray(event.teammates)
189
- ? event.teammates
190
- : [];
191
- const labels = raw
192
- .map((teammate: any) => (
193
- typeof teammate === 'string'
194
- ? teammate
195
- : optionalSeatPlayerLabel(teammate?.name, teammate?.seat)
196
- ))
197
- .filter((label: string) => label.length > 0);
198
- return labels.length > 0
199
- ? `Your Crab teammate(s): ${labels.join(', ')}. Keep this private, coordinate cover stories, and avoid voting for or killing them.`
200
- : 'Your Crab teammate list is available. Keep it private and check the Event before voting or killing.';
201
- },
202
185
  meeting_briefing: (event) => meetingBriefingHint(event),
203
186
  speech_skipped: (event) => `${actorName(event, 'Someone')} lost the floor — silence becomes evidence`,
204
187
  speech_your_turn: () => 'Submit `ccl speak "<draft>"` immediately. Server skips you after 45s.',
@@ -245,7 +245,7 @@ describe('GameSync v2 Event normalization', () => {
245
245
  reported_corpses: [{ seat: 9, name: 'dead' }],
246
246
  speech_order: [{ seat: 1, name: 'caller' }, { seat: 2, name: 'next' }],
247
247
  dead_players: [{ seat: 9, name: 'dead' }],
248
- teammates: [{ seat: 3, name: 'crab' }],
248
+ crab_teammates: [{ seat: 3, name: 'crab' }],
249
249
  });
250
250
 
251
251
  expect(normalized.reported_corpses).toEqual([{ name: 'dead', seat: 9 }]);
@@ -255,7 +255,6 @@ describe('GameSync v2 Event normalization', () => {
255
255
  ]);
256
256
  expect(normalized.dead_players).toEqual([{ name: 'dead', seat: 9 }]);
257
257
  expect(normalized.crab_teammates).toEqual([{ name: 'crab', seat: 3 }]);
258
- expect(normalized).not.toHaveProperty('teammates');
259
258
 
260
259
  const presented = presentCanonicalEvent(canonical(normalized), null);
261
260
  expect(presented.speech_order).toEqual(normalized.speech_order);
@@ -292,16 +291,6 @@ describe('GameSync v2 Event normalization', () => {
292
291
  actor_seat: 2,
293
292
  current_speaker: 'caller',
294
293
  });
295
-
296
- expect(normalizeGameSyncEvent({
297
- event_id: 'teammates-current-dev',
298
- tick: 0,
299
- type: 'crab_teammates',
300
- actor: { seat: 1, name: 'self' },
301
- teammates: ['crab-a', 'crab-b'],
302
- })).toMatchObject({
303
- crab_teammates: ['crab-a', 'crab-b'],
304
- });
305
294
  });
306
295
 
307
296
  it('keeps the private self-repair marker and anonymizes every other emergency resolution', () => {
@@ -246,19 +246,6 @@ export function normalizeGameSyncEvent(value: unknown): Record<string, any> {
246
246
  throw new TypeError('GameSync Event.speech_order must be a string or PlayerRef array');
247
247
  }
248
248
 
249
- if (Object.hasOwn(normalized, 'teammates')) {
250
- if (!Array.isArray(normalized.teammates)) {
251
- throw new TypeError('GameSync Event.teammates must be an array');
252
- }
253
- // The current dev implementation emits the setup event as string[];
254
- // meeting briefings already use PlayerRef[]. Keep one canonical field.
255
- normalized.crab_teammates = normalized.teammates.map((item: unknown, index: number) => {
256
- if (typeof item === 'string' && item.length > 0) return item;
257
- return playerRef(item, `GameSync Event.teammates[${index}]`);
258
- });
259
- delete normalized.teammates;
260
- }
261
-
262
249
  return normalized;
263
250
  }
264
251
 
@@ -2,9 +2,9 @@ import type { ClawclawActionRequest } from '../action/index.js';
2
2
 
3
3
  const ACTION_FIELDS: Readonly<Record<string, readonly string[]>> = Object.freeze({
4
4
  move: ['action', 'target', 'target_x', 'target_y', 'stop_on_player', 'thinking_content'],
5
- kill: ['action', 'target', 'thinking_content'],
5
+ kill: ['action', 'target_seat', 'thinking_content'],
6
6
  speech: ['action', 'text', 'thinking_content'],
7
- vote: ['action', 'target', 'thinking_content'],
7
+ vote: ['action', 'target_seat', 'thinking_content'],
8
8
  task: ['action', 'task_name', 'thinking_content'],
9
9
  report: ['action', 'thinking_content'],
10
10
  think: ['action', 'thinking_content'],
@@ -52,9 +52,16 @@ export function normalizeClawclawStrategyAction(
52
52
  break;
53
53
  }
54
54
  case 'kill':
55
- case 'vote':
56
- if (!nonEmpty(value.target)) throw new Error('invalid_strategy_target');
55
+ case 'vote': {
56
+ const seat = value.target_seat;
57
+ const validSeat = typeof seat === 'number'
58
+ && Number.isInteger(seat)
59
+ && seat >= 0
60
+ && seat <= 10;
61
+ if (!validSeat) throw new Error('invalid_strategy_target');
62
+ if (actionType === 'kill' && seat === 0) throw new Error('invalid_strategy_target');
57
63
  break;
64
+ }
58
65
  case 'speech':
59
66
  if (!nonEmpty(value.text)) throw new Error('invalid_strategy_speech');
60
67
  break;
@@ -74,7 +74,6 @@ export const CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [
74
74
  'game_started',
75
75
  'game_over',
76
76
  'role_assigned',
77
- 'crab_teammates',
78
77
  'emergency_started',
79
78
  'emergency_resolved',
80
79
  'emergency_interrupted',
@@ -108,7 +107,6 @@ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
108
107
  'vote_speech_phase_ended',
109
108
  'death_speech',
110
109
  'wandering_speech',
111
- 'crab_teammates',
112
110
  'meeting_briefing',
113
111
  'speech',
114
112
  'speech_skipped',
package/src/sdk/action.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * @example
9
9
  * ```ts
10
10
  * return Action.move('kitchen').withThinking('Heading to the kitchen for my task.');
11
- * return Action.kill('PlayerB').withThinking('Alone with target — safe window.');
11
+ * return Action.kill(7).withThinking('Alone with target — safe window.');
12
12
  * ```
13
13
  */
14
14
  export class Action {
@@ -32,7 +32,7 @@ export class Action {
32
32
  * Attach (or replace) the spectator-visible thinking content.
33
33
  * Returns a **new** immutable `Action` — the original is unchanged.
34
34
  *
35
- * @example Action.kill('playerA').withThinking('Safe kill — only one witness.')
35
+ * @example Action.kill(7).withThinking('Safe kill — only one witness.')
36
36
  */
37
37
  withThinking(content: string): Action {
38
38
  return new Action(this.type, { ...this.payload }, content);
@@ -56,11 +56,12 @@ export class Action {
56
56
  }
57
57
 
58
58
  /**
59
- * Kill the named player.
59
+ * Kill the player at the given seat number.
60
60
  * Only succeeds when cooldown is ready, a kill use remains, and the target is in range.
61
+ * Seats are 1-based; the server resolves the target by `target_seat`.
61
62
  */
62
- static kill(target: string): Action {
63
- return new Action('kill', { target }, `击杀 ${target}`);
63
+ static kill(seat: number): Action {
64
+ return new Action('kill', { target_seat: seat }, `击杀 ${seat}号`);
64
65
  }
65
66
 
66
67
  /**
@@ -82,10 +83,10 @@ export class Action {
82
83
  /**
83
84
  * Cast a vote during the meeting vote sub-phase.
84
85
  *
85
- * @param target Name of the player to vote out.
86
+ * @param seat Seat number (1-based) of the player to vote out. `0` means skip.
86
87
  */
87
- static vote(target: string): Action {
88
- return new Action('vote', { target }, `投票 ${target}`);
88
+ static vote(seat: number): Action {
89
+ return new Action('vote', { target_seat: seat }, seat === 0 ? '投票 跳过' : `投票 ${seat}号`);
89
90
  }
90
91
 
91
92
  /**
@@ -368,7 +368,7 @@ describe('Strategy Plugin SDK', () => {
368
368
  },
369
369
  });
370
370
 
371
- expect(teammatesSeen).toEqual(['ally']);
371
+ expect(teammatesSeen).toEqual(['2']);
372
372
  });
373
373
 
374
374
  it('fails explicitly when a required task or map capability is unavailable', async () => {
@@ -747,7 +747,7 @@ describe('Strategy Plugin SDK', () => {
747
747
  create: () => ({
748
748
  name: 'unknown-kill',
749
749
  decide: () => [{
750
- action: Action.kill('目标'),
750
+ action: Action.kill(7),
751
751
  intent: { activity: 'acting', summary: '正在击杀7号目标。', targetPlayer: '目标' },
752
752
  }],
753
753
  }),
@@ -909,7 +909,7 @@ describe('Strategy Plugin SDK', () => {
909
909
  decide: (state) => [
910
910
  ...(state.all_players?.some(player => player.name === '目标' && player.is_alive !== false)
911
911
  ? [{
912
- action: Action.kill('目标'),
912
+ action: Action.kill(7),
913
913
  intent: { activity: 'acting' as const, summary: '正在击杀7号目标。', targetPlayer: '目标' },
914
914
  }]
915
915
  : []),
@@ -224,9 +224,9 @@ export type ClawclawStrategyAction =
224
224
  readonly target_y: number;
225
225
  readonly stop_on_player?: boolean;
226
226
  })
227
- | (ClawclawStrategyActionBase & { readonly action: 'kill'; readonly target: string })
227
+ | (ClawclawStrategyActionBase & { readonly action: 'kill'; readonly target_seat: number })
228
228
  | (ClawclawStrategyActionBase & { readonly action: 'speech'; readonly text: string })
229
- | (ClawclawStrategyActionBase & { readonly action: 'vote'; readonly target: string })
229
+ | (ClawclawStrategyActionBase & { readonly action: 'vote'; readonly target_seat: number })
230
230
  | (ClawclawStrategyActionBase & { readonly action: 'task'; readonly task_name?: string })
231
231
  | (ClawclawStrategyActionBase & { readonly action: 'report' })
232
232
  | (ClawclawStrategyActionBase & { readonly action: 'think' })
@@ -626,17 +626,17 @@ function fallbackActionIntent(state: GameState, action: Record<string, any>): St
626
626
  ...(task ? { task } : {}),
627
627
  };
628
628
  }
629
- if (action.action === 'kill' && typeof action.target === 'string') {
629
+ if (action.action === 'kill' && Number.isInteger(action.target_seat)) {
630
630
  const knownTarget = [...state.players, ...(state.all_players ?? [])]
631
- .find(player => player.name === action.target);
632
- const target = knownTarget?.seat != null
633
- ? `${knownTarget.seat}号${knownTarget.name}`
634
- : action.target;
631
+ .find(player => player.seat === action.target_seat);
632
+ const target = knownTarget?.name != null
633
+ ? `${action.target_seat}号${knownTarget.name}`
634
+ : `${action.target_seat}号`;
635
635
  return {
636
636
  activity: 'acting',
637
637
  summary: `正在击杀${target}。`,
638
638
  ...(room ? { room } : {}),
639
- targetPlayer: action.target,
639
+ ...(knownTarget?.name ? { targetPlayer: knownTarget.name } : {}),
640
640
  };
641
641
  }
642
642
  if (action.action === 'report') {
@@ -685,7 +685,7 @@ function nonIdempotentActionKey(action: Record<string, any>): string | null {
685
685
  const type = String(action.action ?? '');
686
686
  if (!NON_IDEMPOTENT_ACTIONS.has(type)) return null;
687
687
  switch (type) {
688
- case 'kill': return `kill:${JSON.stringify(action.target ?? '')}`;
688
+ case 'kill': return `kill:${JSON.stringify(action.target_seat ?? '')}`;
689
689
  case 'speech': return `speech:${JSON.stringify(action.text ?? '')}`;
690
690
  case 'task': return `task:${JSON.stringify(action.task_name ?? '')}`;
691
691
  case 'report': return 'report';
@@ -705,9 +705,9 @@ function authoritativeActionSignature(state: GameState, action: Record<string, a
705
705
  phase: state.phase,
706
706
  alive: state.you.is_alive,
707
707
  };
708
- if (action.action === 'kill') {
709
- const knownTarget = state.all_players?.find(player => player.name === action.target);
710
- const visibleTarget = state.players.find(player => player.name === action.target);
708
+ if (action.action === 'kill' && Number.isInteger(action.target_seat)) {
709
+ const knownTarget = state.all_players?.find(player => player.seat === action.target_seat);
710
+ const visibleTarget = state.players.find(player => player.seat === action.target_seat);
711
711
  return JSON.stringify({
712
712
  ...common,
713
713
  target_alive: knownTarget?.is_alive ?? (visibleTarget ? true : undefined),
@@ -996,24 +996,25 @@ export class ClawclawGoalStrategy extends ClawclawHybridStrategy<
996
996
  for (const player of state.all_players ?? state.players ?? []) {
997
997
  if (player.seat != null && player.name) this.context.playerNamesBySeat[String(player.seat)] = player.name;
998
998
  }
999
+ const teammateSeat = (teammate: unknown): string | null => {
1000
+ const ref = projectedPlayerRef(teammate);
1001
+ const seat = Number(ref.seat);
1002
+ return Number.isInteger(seat) && seat >= 1 ? String(seat) : null;
1003
+ };
999
1004
  for (const event of events) {
1000
1005
  if (event.type === 'octopus_time_start') this.context.octopusTimeActive = true;
1001
1006
  const eventTeammates = Array.isArray(event.crab_teammates)
1002
1007
  ? event.crab_teammates
1003
- : Array.isArray(event.teammates) ? event.teammates : [];
1008
+ : [];
1004
1009
  for (const teammate of eventTeammates) {
1005
- const name = typeof teammate === 'string'
1006
- ? teammate
1007
- : projectedPlayerRef(teammate).name;
1008
- if (typeof name === 'string' && name) this.context.teammates.add(name);
1010
+ const seat = teammateSeat(teammate);
1011
+ if (seat) this.context.teammates.add(seat);
1009
1012
  }
1010
1013
  }
1011
1014
  const stateTeammates = state.you.crab_teammates;
1012
1015
  for (const teammate of Array.isArray(stateTeammates) ? stateTeammates : []) {
1013
- const name = typeof teammate === 'string'
1014
- ? teammate
1015
- : projectedPlayerRef(teammate).name;
1016
- if (typeof name === 'string' && name) this.context.teammates.add(name);
1016
+ const seat = teammateSeat(teammate);
1017
+ if (seat) this.context.teammates.add(seat);
1017
1018
  }
1018
1019
  }
1019
1020
 
@@ -1194,11 +1195,11 @@ export class ClawclawGoalStrategy extends ClawclawHybridStrategy<
1194
1195
  this.context.alarmOnCooldown = definiteFailure && failureText.includes('on_cooldown');
1195
1196
  }
1196
1197
  if (definiteFailure && payload.action === 'kill' && failureText.includes('cannot_kill_teammate')) {
1197
- if (typeof payload.target === 'string') this.context.teammates.add(payload.target);
1198
+ if (Number.isInteger(payload.target_seat)) this.context.teammates.add(String(payload.target_seat));
1198
1199
  }
1199
- if (accepted && payload.action === 'kill' && typeof payload.target === 'string') {
1200
+ if (accepted && payload.action === 'kill' && Number.isInteger(payload.target_seat)) {
1200
1201
  this.context.recentlyKilledTargets?.set(
1201
- payload.target.trim().toLowerCase(),
1202
+ String(payload.target_seat),
1202
1203
  Date.now() + RECENT_KILL_IGNORE_MS,
1203
1204
  );
1204
1205
  }
@@ -8,7 +8,7 @@ function makeMoveDecision(): BehaviorDecision {
8
8
  }
9
9
 
10
10
  function makeKillDecision(): BehaviorDecision {
11
- return { action: Action.kill('target') };
11
+ return { action: Action.kill(3) };
12
12
  }
13
13
 
14
14
  class TestCustomModule implements CustomModule {
@@ -70,19 +70,19 @@ describe('CorpseMemory', () => {
70
70
  it('uses the last visible position immediately after a confirmed kill', () => {
71
71
  const memory = new CorpseMemory();
72
72
  memory.observe(state({
73
- players: [{ name: 'LocalBot_5', room: '居住区', x: 2058, y: 1594 }],
73
+ players: [{ name: 'LocalBot_5', seat: 5, room: '居住区', x: 2058, y: 1594 }],
74
74
  }));
75
75
 
76
76
  memory.observe(
77
77
  state({
78
78
  tick: 2,
79
- corpses: [{ name: 'LocalBot_5', room: '居住区', distance: 0 }],
79
+ corpses: [{ name: 'LocalBot_5', seat: 5, room: '居住区', distance: 0 }],
80
80
  }),
81
- new Map([['localbot_5', Date.now() + 3000]]),
81
+ new Map([['5', Date.now() + 3000]]),
82
82
  );
83
83
 
84
84
  expect(memory.list()).toEqual([
85
- { name: 'LocalBot_5', room: '居住区', x: 2058, y: 1594 },
85
+ { name: 'LocalBot_5', room: '居住区', x: 2058, y: 1594, seat: 5 },
86
86
  ]);
87
87
  expect(firstAvailableTask(
88
88
  [taskAt(2058, 1594)],
@@ -96,11 +96,11 @@ describe('CorpseMemory', () => {
96
96
  it('does not create a corpse for an unconfirmed or expired kill', () => {
97
97
  const memory = new CorpseMemory();
98
98
  memory.observe(state({
99
- players: [{ name: 'target', room: '居住区', x: 100, y: 100 }],
99
+ players: [{ name: 'target', seat: 2, room: '居住区', x: 100, y: 100 }],
100
100
  }));
101
101
 
102
102
  memory.observe(state({ tick: 2 }));
103
- memory.observe(state({ tick: 3 }), new Map([['target', Date.now() - 1]]));
103
+ memory.observe(state({ tick: 3 }), new Map([['2', Date.now() - 1]]));
104
104
 
105
105
  expect(memory.list()).toEqual([]);
106
106
  });
@@ -120,14 +120,14 @@ describe('CorpseMemory', () => {
120
120
  it('clears corpse and last-seen player memory after a meeting', () => {
121
121
  const memory = new CorpseMemory();
122
122
  memory.observe(state({
123
- players: [{ name: 'target', room: '居住区', x: 100, y: 100 }],
123
+ players: [{ name: 'target', seat: 2, room: '居住区', x: 100, y: 100 }],
124
124
  new_events: [
125
125
  { type: 'corpse_spotted', corpse_name: 'old', corpse_room: '居住区', corpse_x: 20, corpse_y: 20 },
126
126
  ],
127
127
  }));
128
128
 
129
129
  memory.reset();
130
- memory.observe(state({ tick: 2 }), new Map([['target', Date.now() + 3000]]));
130
+ memory.observe(state({ tick: 2 }), new Map([['2', Date.now() + 3000]]));
131
131
 
132
132
  expect(memory.list()).toEqual([]);
133
133
  });
@@ -600,6 +600,7 @@ export function spottedCorpsesFromEventList(events: any[] | undefined): CorpseTa
600
600
  export class CorpseMemory {
601
601
  private readonly seen: CorpseInfo[] = [];
602
602
  private readonly lastSeenPlayers = new Map<string, PlayerInfo>();
603
+ private readonly lastSeenPlayersBySeat = new Map<string, PlayerInfo>();
603
604
 
604
605
  /**
605
606
  * 每 tick 调用:缓存可见玩家位置,并入已确认击杀、当前视野尸体与本 tick 全部 corpse_spotted 事件。
@@ -623,9 +624,9 @@ export class CorpseMemory {
623
624
  }
624
625
 
625
626
  const now = Date.now();
626
- for (const [target, until] of recentlyKilledTargets ?? []) {
627
+ for (const [seat, until] of recentlyKilledTargets ?? []) {
627
628
  if (until <= now) continue;
628
- const player = this.lastSeenPlayers.get(target.trim().toLowerCase());
629
+ const player = this.lastSeenPlayersBySeat.get(seat);
629
630
  if (player) this.remember(player);
630
631
  }
631
632
 
@@ -654,11 +655,13 @@ export class CorpseMemory {
654
655
  reset(): void {
655
656
  this.seen.length = 0;
656
657
  this.lastSeenPlayers.clear();
658
+ this.lastSeenPlayersBySeat.clear();
657
659
  }
658
660
 
659
661
  private rememberPlayer(player: PlayerInfo): void {
660
662
  const key = player.name.trim().toLowerCase();
661
663
  if (key) this.lastSeenPlayers.set(key, player);
664
+ if (player.seat != null) this.lastSeenPlayersBySeat.set(String(player.seat), player);
662
665
  }
663
666
 
664
667
  private remember(corpse: { x?: number; y?: number; name?: string; room?: string; seat?: number }): void {
@@ -751,23 +754,41 @@ export function reportCorpseDecision(
751
754
  export function nonTeammatesVisible(state: GameState, ctx: StrategyContext): PlayerInfo[] {
752
755
  const players = visibleLivePlayers(state, ctx);
753
756
  return ctx.teammates.size > 0
754
- ? players.filter(p => !ctx.teammates.has(p.name))
757
+ ? players.filter(p => !(p.seat != null && ctx.teammates.has(String(p.seat))))
755
758
  : players;
756
759
  }
757
760
 
761
+ /**
762
+ * Resolve a target string (seat number or player name) to a seat number.
763
+ * Names are resolved through `ctx.playerNamesBySeat` (seat → name). Returns
764
+ * null when the target cannot be resolved to a seat (unknown name, empty input).
765
+ */
766
+ export function targetSeat(target: string, ctx: StrategyContext): number | null {
767
+ const trimmed = target.trim();
768
+ if (!trimmed) return null;
769
+ if (/^\d+$/.test(trimmed)) return Number(trimmed);
770
+ const folded = trimmed.toLowerCase();
771
+ for (const [seat, name] of Object.entries(ctx.playerNamesBySeat)) {
772
+ if (name && name.toLowerCase() === folded) return Number(seat);
773
+ }
774
+ return null;
775
+ }
776
+
758
777
  export function matchesTarget(
759
778
  target: string,
760
779
  player: { name?: string; seat?: number },
761
780
  ctx: StrategyContext,
762
781
  ): boolean {
763
- const normalized = target.trim().toLowerCase();
764
- if (player.name && player.name.toLowerCase() === normalized) return true;
765
- if (/^\d+$/.test(target.trim())) {
766
- const nameFromSeat = ctx.playerNamesBySeat[target.trim()];
782
+ const trimmed = target.trim();
783
+ const seat = targetSeat(trimmed, ctx);
784
+ if (seat != null && player.seat != null && player.seat === seat) return true;
785
+ if (seat != null) {
786
+ // 座位号参数对无名/缺 seat 的条目(如只有名字的尸体):经 seat→name 反查命中。
787
+ const nameFromSeat = ctx.playerNamesBySeat[String(seat)];
767
788
  if (nameFromSeat && player.name && player.name.toLowerCase() === nameFromSeat.toLowerCase()) return true;
768
- if (player.seat != null && String(player.seat) === target.trim()) return true;
769
789
  }
770
- return false;
790
+ const normalized = trimmed.toLowerCase();
791
+ return player.name != null && player.name.toLowerCase() === normalized;
771
792
  }
772
793
 
773
794
  export function matchesAnyTarget(
@@ -789,27 +810,15 @@ export function isTargetAlive(
789
810
  }
790
811
 
791
812
  export function isRecentlyKilledTarget(target: string, ctx: StrategyContext): boolean {
792
- const names = targetNames(target, ctx);
793
- for (const name of names) {
794
- const until = ctx.recentlyKilledTargets?.get(name);
795
- if (!until) continue;
796
- if (until > Date.now()) return true;
797
- ctx.recentlyKilledTargets?.delete(name);
798
- }
813
+ const seat = targetSeat(target, ctx);
814
+ if (seat == null) return false;
815
+ const until = ctx.recentlyKilledTargets?.get(String(seat));
816
+ if (until == null) return false;
817
+ if (until > Date.now()) return true;
818
+ ctx.recentlyKilledTargets?.delete(String(seat));
799
819
  return false;
800
820
  }
801
821
 
802
- function targetNames(target: string, ctx: StrategyContext): string[] {
803
- const normalized = target.trim().toLowerCase();
804
- if (!normalized) return [];
805
- const names = [normalized];
806
- if (/^\d+$/.test(target.trim())) {
807
- const nameFromSeat = ctx.playerNamesBySeat[target.trim()];
808
- if (nameFromSeat) names.push(nameFromSeat.toLowerCase());
809
- }
810
- return names;
811
- }
812
-
813
822
  export function visibleLivePlayers(state: GameState, ctx: StrategyContext): PlayerInfo[] {
814
823
  return state.players.filter(p => isTargetAlive(state, p.name, ctx));
815
824
  }
@@ -839,7 +848,9 @@ export function pursueVisibleTarget(
839
848
  const d = target.distance ?? dist(state.you.x, state.you.y, target.x, target.y);
840
849
  if (opts.kill && !hasKillUseRemaining(state)) return null;
841
850
  if (opts.kill && d <= killCommitRange(state.you.role) && canUseKill(state)) {
842
- return strategyDecision(Action.kill(target.name), playerStrategyIntent(target, '追杀', 'acting'));
851
+ // 杀必须用座位号:visible 玩家由服务端保证 seat(默认 0 表示缺失/不可杀)。
852
+ if (target.seat == null || target.seat <= 0) return null;
853
+ return strategyDecision(Action.kill(target.seat), playerStrategyIntent(target, '追杀', 'acting'));
843
854
  }
844
855
  if (d > opts.followDistance) {
845
856
  return strategyDecision(
@@ -10,6 +10,7 @@ import {
10
10
  reportCorpseDecision,
11
11
  playerStrategyIntent,
12
12
  strategyDecision,
13
+ targetSeat,
13
14
  } from '../game-utils.js';
14
15
  import type { BehaviorDecision, StrategyContext } from '../types.js';
15
16
 
@@ -82,21 +83,24 @@ export function immediateLoneKillDecision(
82
83
  if (skipTarget?.(target)) return null;
83
84
 
84
85
  ctx.notifications.push(`发现落单目标${target.name}就在身边,立刻出刀!`);
85
- return [strategyDecision(Action.kill(target.name), playerStrategyIntent(target, '追杀', 'acting'))];
86
+ if (target.seat == null || target.seat <= 0) return null;
87
+ return [strategyDecision(Action.kill(target.seat), playerStrategyIntent(target, '追杀', 'acting'))];
86
88
  }
87
89
 
88
90
  /**
89
- * 这具尸体是不是「自己刚才下的那一刀」。先按尸体名精确匹配 recentlyKilledTargets(刚杀过且未过期),
90
- * 名字对不上但近期确实杀过人时,冒出的尸体大概率也是自己造成的,按 true 处理(宁可多提醒一次)。
91
+ * 这具尸体是不是「自己刚才下的那一刀」。先按尸体座位号精确匹配 recentlyKilledTargets(刚杀过且未过期),
92
+ * 座位对不上但近期确实杀过人时,冒出的尸体大概率也是自己造成的,按 true 处理(宁可多提醒一次)。
91
93
  */
92
94
  function isRecentOwnKill(ctx: StrategyContext, corpseName: string): boolean {
93
95
  const map = ctx.recentlyKilledTargets;
94
96
  if (!map || map.size === 0) return false;
95
97
  const now = Date.now();
96
- const key = corpseName.trim().toLowerCase();
97
- if (key) {
98
- const until = map.get(key);
99
- if (until != null && until > now) return true;
98
+ if (corpseName) {
99
+ const seat = targetSeat(corpseName, ctx);
100
+ if (seat != null) {
101
+ const until = map.get(String(seat));
102
+ if (until != null && until > now) return true;
103
+ }
100
104
  }
101
105
  for (const until of map.values()) {
102
106
  if (until > now) return true;
@@ -126,9 +126,10 @@ export class HideTop extends Goal {
126
126
  const victim = this.corneredVictim(state, visible);
127
127
  if (victim) {
128
128
  if (this.subGoal) this.removeSubGoal();
129
+ if (victim.seat == null || victim.seat <= 0) return [];
129
130
  ctx.notifications.push(`被${victim.name}逼到无处可逃,出刀自保!`);
130
131
  return [strategyDecision(
131
- Action.kill(victim.name).withThinking(`被${victim.name}逼进出刀距离又逃不掉,先下手自保。`),
132
+ Action.kill(victim.seat).withThinking(`被${victim.name}逼进出刀距离又逃不掉,先下手自保。`),
132
133
  {
133
134
  activity: 'acting',
134
135
  summary: `被${strategyPlayerLabel(victim)}逼到无处可逃,正在出刀自保。`,