@myclaw163/clawclaw-cli 0.7.8 → 0.7.10

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 (52) hide show
  1. package/docs/desktop-event-push.md +14 -2
  2. package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +15 -1
  3. package/package.json +1 -1
  4. package/skills/clawclaw/SKILL.md +5 -5
  5. package/skills/clawclaw/references/COMMANDS.md +4 -4
  6. package/skills/clawclaw/references/GAME-MECHANICS.md +1 -1
  7. package/src/commands/communication.test.ts +14 -3
  8. package/src/commands/communication.ts +12 -4
  9. package/src/pipeline/event-format.test.ts +0 -21
  10. package/src/pipeline/event-format.ts +0 -33
  11. package/src/pipeline/event-hints.test.ts +2 -5
  12. package/src/pipeline/event-hints.ts +0 -17
  13. package/src/pipeline/game-sync-event-normalization.test.ts +34 -12
  14. package/src/pipeline/game-sync-event-normalization.ts +52 -22
  15. package/src/runtime/clawclaw/owner.ts +8 -0
  16. package/src/runtime/clawclaw/plugins/assembly.test.ts +13 -0
  17. package/src/runtime/clawclaw/plugins/assembly.ts +10 -0
  18. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +17 -5
  19. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +37 -3
  20. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +49 -14
  21. package/src/runtime/clawclaw/plugins/perception/contracts.ts +1 -0
  22. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +16 -0
  23. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +16 -0
  24. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +16 -0
  25. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +23 -0
  26. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +16 -0
  27. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +16 -0
  28. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +23 -0
  29. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +19 -0
  30. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +41 -0
  31. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +49 -0
  32. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +105 -5
  33. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +174 -0
  34. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +146 -66
  35. package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +11 -4
  36. package/src/runtime/clawclaw-event-catalog.ts +0 -2
  37. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +36 -0
  38. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +0 -5
  39. package/src/sdk/action.ts +9 -8
  40. package/src/sdk/perception-plugin/index.ts +8 -0
  41. package/src/sdk/strategy-plugin/index.test.ts +3 -3
  42. package/src/sdk/strategy-plugin/index.ts +25 -24
  43. package/src/strategies/custom-module.test.ts +1 -1
  44. package/src/strategies/game-utils.test.ts +8 -8
  45. package/src/strategies/game-utils.ts +39 -28
  46. package/src/strategies/goals/crab-octopus-reflexes.ts +11 -7
  47. package/src/strategies/goals/hide-top.ts +2 -1
  48. package/src/strategies/goals/kill-target-goal.ts +2 -1
  49. package/src/strategies/goals/kill-target-top.ts +3 -3
  50. package/src/strategies/goals/lone-kill-core.ts +3 -1
  51. package/src/strategies/goals/task-kill-report-top.ts +2 -1
  52. package/src/strategies/goals/warrior-shrimp-top.ts +2 -1
@@ -1929,6 +1929,42 @@ describe('RuntimePluginScheduler', () => {
1929
1929
  expect(stopped).toEqual(['shutdown']);
1930
1930
  });
1931
1931
 
1932
+ it('logs a plugin flush failure without failing shutdown or skipping peer plugins', async () => {
1933
+ const flushed: string[] = [];
1934
+ const test = harness([{
1935
+ kind: 'epoch',
1936
+ id: 'flush-failure',
1937
+ version: '1',
1938
+ update: () => ({ outcome: 'noop' }),
1939
+ flush() {
1940
+ flushed.push('flush-failure');
1941
+ throw new Error('broken plugin flush');
1942
+ },
1943
+ }, {
1944
+ kind: 'epoch',
1945
+ id: 'flush-peer',
1946
+ version: '1',
1947
+ update: () => ({ outcome: 'noop' }),
1948
+ flush() {
1949
+ flushed.push('flush-peer');
1950
+ },
1951
+ }]);
1952
+
1953
+ await test.scheduler.enqueue(test.work(1));
1954
+ await expect(test.scheduler.close()).resolves.toBeUndefined();
1955
+
1956
+ expect(flushed).toEqual(['flush-failure', 'flush-peer']);
1957
+ expect(test.diagnostics).toContainEqual(expect.objectContaining({
1958
+ name: 'runtime.plugin.flush_failed',
1959
+ severity: 'error',
1960
+ attributes: expect.objectContaining({
1961
+ plugin_id: 'flush-failure',
1962
+ reason: 'shutdown',
1963
+ error_code: 'RUNTIME_PLUGIN_FLUSH_FAILED',
1964
+ }),
1965
+ }));
1966
+ });
1967
+
1932
1968
  it('drains buffered parallel work in order when a failure pauses the plugin', async () => {
1933
1969
  let releaseFirst!: () => void;
1934
1970
  const firstGate = new Promise<void>((resolve) => { releaseFirst = resolve; });
@@ -563,7 +563,6 @@ export class RuntimePluginScheduler<
563
563
  await this.waitForIdle();
564
564
  const scope = this.activeScope;
565
565
  if (!scope) return;
566
- const failures: unknown[] = [];
567
566
  for (const layer of this.layers) {
568
567
  await Promise.all(layer.map(async (plugin) => {
569
568
  if (!plugin.flush) return;
@@ -586,7 +585,6 @@ export class RuntimePluginScheduler<
586
585
  reason,
587
586
  }, scope);
588
587
  } catch (error) {
589
- failures.push(error);
590
588
  this.onDiagnostic?.('runtime.plugin.flush_failed', {
591
589
  plugin_id: plugin.id,
592
590
  reason,
@@ -595,9 +593,6 @@ export class RuntimePluginScheduler<
595
593
  }
596
594
  }));
597
595
  }
598
- if (failures.length > 0) {
599
- throw new AggregateError(failures, `${failures.length} Runtime Epoch Plugin flush operation(s) failed.`);
600
- }
601
596
  }
602
597
 
603
598
  waitForIdle(): Promise<void> {
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
  /**
@@ -160,6 +160,12 @@ export interface PerceptionApi {
160
160
  readonly spatial: PerceptionSpatialApi;
161
161
  }
162
162
 
163
+ export interface ClawclawPerceptionEventMetadata {
164
+ readonly name: string;
165
+ readonly description: string;
166
+ readonly localizations?: ClawclawResourceLocalizations;
167
+ }
168
+
163
169
  /**
164
170
  * Immutable, epoch-bound input for one fresh parallel analyzer instance.
165
171
  * Frames may be skipped and different inputs may be analyzed concurrently.
@@ -205,6 +211,8 @@ export interface ClawclawPerceptionManifest {
205
211
  /** Describes Event subjects; every module still receives self as a spatial reference. */
206
212
  readonly subjectScope: PerceptionSubjectScope;
207
213
  readonly produces: readonly string[];
214
+ /** Optional display metadata for every Event in `produces`. */
215
+ readonly eventMetadata?: Readonly<Record<string, ClawclawPerceptionEventMetadata>>;
208
216
  /**
209
217
  * Omit for the main-thread, persistent, ordered `update()` contract.
210
218
  * `parallel_analysis` batches every enabled parallel module for one frame on
@@ -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)}逼到无处可逃,正在出刀自保。`,
@@ -34,8 +34,9 @@ export class KillVisibleTargetGoal extends Goal {
34
34
 
35
35
  if (d <= killCommitRange(state.you.role)) {
36
36
  if (canUseKill(state)) {
37
+ if (target.seat == null || target.seat <= 0) return [];
37
38
  ctx.notifications.push(`发现追杀目标${target.name},出刀!`);
38
- return [strategyDecision(Action.kill(target.name), playerStrategyIntent(target, '追杀', 'acting'))];
39
+ return [strategyDecision(Action.kill(target.seat), playerStrategyIntent(target, '追杀', 'acting'))];
39
40
  }
40
41
  if (d > LONE_FOLLOW_DISTANCE) {
41
42
  return [strategyDecision(Action.move({ x: target.x, y: target.y }), playerStrategyIntent(target, '追杀', 'moving'))];
@@ -15,6 +15,7 @@ import {
15
15
  pursueVisibleTarget,
16
16
  setStrategyIntent,
17
17
  strategyPlayerLabel,
18
+ targetSeat,
18
19
  } from '../game-utils.js';
19
20
  import type { BehaviorDecision, StrategyContext } from '../types.js';
20
21
  import { Goal } from './goal.js';
@@ -92,9 +93,8 @@ export class KillTargetTop extends Goal {
92
93
 
93
94
  private isValidTarget(t: string, state: GameState, ctx: StrategyContext): boolean {
94
95
  if (!isTargetAlive(state, t, ctx)) return false;
95
- const nameFromSeat = /^\d+$/.test(t.trim()) ? ctx.playerNamesBySeat[t.trim()] : null;
96
- const resolvedName = nameFromSeat ?? t.trim();
97
- return !ctx.teammates.has(resolvedName);
96
+ const seat = targetSeat(t, ctx);
97
+ return !(seat != null && ctx.teammates.has(String(seat)));
98
98
  }
99
99
 
100
100
  private allTargetsDeadInState(state: GameState, ctx: StrategyContext): boolean {
@@ -76,7 +76,9 @@ export class LoneKillCore {
76
76
  const d = target.distance ?? dist(state.you.x, state.you.y, target.x, target.y);
77
77
  if (d <= killCommitRange(state.you.role) && canUseKill(state)) {
78
78
  ctx.notifications.push(`发现落单目标${target.name},出刀!`);
79
- return strategyDecision(Action.kill(target.name), playerStrategyIntent(target, '追杀', 'acting'));
79
+ if (target.seat != null && target.seat > 0) {
80
+ return strategyDecision(Action.kill(target.seat), playerStrategyIntent(target, '追杀', 'acting'));
81
+ }
80
82
  }
81
83
  if (d > killCommitRange(state.you.role)) ctx.notifications.push(`发现落单目标${target.name},正在靠近!`);
82
84
  return strategyDecision(Action.move({ x: target.x, y: target.y }), playerStrategyIntent(target, '追杀', 'moving'));
@@ -64,8 +64,9 @@ export class TaskKillReportTop extends Goal {
64
64
 
65
65
  if (nearest.dist <= killCommitRange(state.you.role) && killReady) {
66
66
  ctx.notifications.push(`嫌疑目标${nearest.player.name}在攻击范围内,出刀!`);
67
+ if (nearest.player.seat == null || nearest.player.seat <= 0) return this.emitDecisions(state, ctx, [], URGENT_GOAL_PRIORITY);
67
68
  return this.emitDecisions(state, ctx, [strategyDecision(
68
- Action.kill(nearest.player.name),
69
+ Action.kill(nearest.player.seat),
69
70
  playerStrategyIntent(nearest.player, '追杀', 'acting'),
70
71
  )], URGENT_GOAL_PRIORITY);
71
72
  }
@@ -87,7 +87,8 @@ export class WarriorShrimpTop extends Goal {
87
87
  ?? (CORPSE_SCENE_KILL_ENABLED ? this.nearestKillable(state, ctx, visible, false) : null);
88
88
  if (victim) {
89
89
  this.clearSub();
90
- return [strategyDecision(Action.kill(victim.name), playerStrategyIntent(victim, '追杀', 'acting'))];
90
+ if (victim.seat == null || victim.seat <= 0) return [];
91
+ return [strategyDecision(Action.kill(victim.seat), playerStrategyIntent(victim, '追杀', 'acting'))];
91
92
  }
92
93
  }
93
94