@myclaw163/clawclaw-cli 0.6.95 → 0.6.100

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 (55) hide show
  1. package/package.json +1 -1
  2. package/skills/clawclaw/SKILL.md +26 -10
  3. package/skills/clawclaw/references/CLAUDE-CODE-MONITOR.md +1 -1
  4. package/skills/clawclaw/references/COMMANDS.md +17 -5
  5. package/skills/clawclaw/references/STREAM.md +15 -12
  6. package/src/commands/account.test.ts +20 -0
  7. package/src/commands/account.ts +16 -0
  8. package/src/commands/do.test.ts +27 -1
  9. package/src/commands/do.ts +61 -0
  10. package/src/commands/events.test.ts +21 -3
  11. package/src/commands/events.ts +8 -2
  12. package/src/commands/game-start-plan.test.ts +158 -0
  13. package/src/commands/game.ts +670 -64
  14. package/src/commands/history-player.test.ts +3 -0
  15. package/src/commands/knowledge.ts +41 -4
  16. package/src/commands/strategy.ts +11 -0
  17. package/src/commands/watch.test.ts +272 -0
  18. package/src/commands/watch.ts +185 -25
  19. package/src/lib/game-client.ts +34 -0
  20. package/src/lib/room.test.ts +74 -0
  21. package/src/lib/room.ts +129 -0
  22. package/src/lib/server-registry.test.ts +54 -0
  23. package/src/lib/server-registry.ts +35 -2
  24. package/src/perception/player-history-store.test.ts +92 -2
  25. package/src/perception/player-history-store.ts +68 -0
  26. package/src/pipeline/event-format.test.ts +61 -1
  27. package/src/pipeline/event-format.ts +88 -0
  28. package/src/pipeline/event-hints.ts +10 -1
  29. package/src/runtime/event-daemon.test.ts +43 -0
  30. package/src/runtime/event-daemon.ts +8 -4
  31. package/src/runtime/room-lobby-runtime.test.ts +95 -0
  32. package/src/runtime/room-lobby-runtime.ts +367 -0
  33. package/src/sdk/index.ts +8 -3
  34. package/src/strategies/avoid-lone.ts +2 -0
  35. package/src/strategies/avoid-players.ts +2 -0
  36. package/src/strategies/corpse-patrol.ts +2 -0
  37. package/src/strategies/crab-sabotage.ts +2 -0
  38. package/src/strategies/find-player.ts +2 -0
  39. package/src/strategies/hide.ts +2 -0
  40. package/src/strategies/kill-frenzy.ts +2 -0
  41. package/src/strategies/kill-lone.ts +2 -0
  42. package/src/strategies/kill-target.ts +2 -0
  43. package/src/strategies/knowledge-contract.ts +85 -0
  44. package/src/strategies/lone-kill-task.ts +2 -0
  45. package/src/strategies/move-room.ts +2 -0
  46. package/src/strategies/paradise-fish.ts +2 -0
  47. package/src/strategies/patrol.ts +2 -0
  48. package/src/strategies/report-patrol.ts +2 -0
  49. package/src/strategies/shrimp-memory.ts +2 -0
  50. package/src/strategies/social-task.ts +2 -0
  51. package/src/strategies/task-kill-report.ts +2 -0
  52. package/src/strategies/task-only.ts +2 -0
  53. package/src/strategies/task-report.ts +2 -0
  54. package/src/strategies/types.ts +37 -1
  55. package/src/strategies/warrior-memory.ts +2 -0
@@ -18,10 +18,13 @@ function baseData(frames: VisibleFrame[]): PlayerHistoryData {
18
18
  return {
19
19
  time: iso(0),
20
20
  visible_frames: frames,
21
+ self_frames: [],
21
22
  seats: { A: 1, B: 2, C: 3 },
22
23
  lobster_tasks: [],
23
24
  last_raw_frame: null,
24
25
  last_history_tick: frames[frames.length - 1]?.tick ?? null,
26
+ last_self_tick: null,
27
+ tick_interval_ms: 100,
25
28
  };
26
29
  }
27
30
 
@@ -1,5 +1,8 @@
1
1
  import { Command } from 'commander';
2
2
  import { DROPPED_PLAYER_MARK_TAGS, KnowledgeStore, type KnowledgeSetInput, type PlayerMark } from '../lib/knowledge-store.js';
3
+ import { AuthStore } from '../lib/auth.js';
4
+ import { getProfileStateDir } from '../lib/init-command.js';
5
+ import { sendOwnerControlRequest } from '../runtime/owner-control.js';
3
6
 
4
7
  // 玩家只标两档:hostile(坏人)/ trusted(好人)。未标记的默认「被怀疑」,无需也无法显式标。
5
8
  const PLAYER_MARKS = new Set<PlayerMark>(['hostile', 'trusted']);
@@ -47,6 +50,38 @@ function setPlayerMark(store: KnowledgeStore, player: string, mark: PlayerMark,
47
50
  });
48
51
  }
49
52
 
53
+ /** 通过 owner-control snapshot 拿当前正在运行的策略 id;无 owner / 未在跑策略时返回 null。 */
54
+ async function currentStrategyId(): Promise<string | null> {
55
+ try {
56
+ const profile = new AuthStore().getActive();
57
+ if (!profile) return null;
58
+ const res = await sendOwnerControlRequest(getProfileStateDir(profile), 'snapshot');
59
+ const strategy = res?.summary?.automation?.strategy;
60
+ return typeof strategy === 'string' ? strategy : null;
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * 按当前策略校验一条待写入知识。校验不通过返回 warning 文本(写入照常发生,只提示玩家
68
+ * 这条对当前策略无效);通过、拿不到当前策略 / 策略未实现校验、或校验器抛错时返回 undefined(放行)。
69
+ */
70
+ async function knowledgeWarning(input: KnowledgeSetInput): Promise<string | undefined> {
71
+ const id = await currentStrategyId();
72
+ if (!id) return undefined;
73
+ const { getStrategyEntry } = await import('../strategies/loader.js');
74
+ const entry = await getStrategyEntry(id);
75
+ if (!entry?.validateKnowledge) return undefined;
76
+ try {
77
+ const result = entry.validateKnowledge(input);
78
+ return result.ok ? undefined : (result.message ?? `当前策略「${entry.name ?? id}」不会使用这条知识。`);
79
+ } catch {
80
+ // 用户策略的校验器抛错不能阻断写入(契约:ok:false 时写入照常发生),视为放行,与 reviewKnowledge 的容错一致。
81
+ return undefined;
82
+ }
83
+ }
84
+
50
85
  export function createKnowledgeCommand(): Command {
51
86
  const cmd = new Command('knowledge')
52
87
  .alias('kn')
@@ -58,7 +93,7 @@ export function createKnowledgeCommand(): Command {
58
93
  .option('--tag <tag>', 'Custom tag, repeatable', collectTag, [])
59
94
  .option('--note <text>', 'Free-text reason')
60
95
  .option('--json <json>', 'Provide the whole input object as JSON instead of positional args')
61
- .action((type: string | undefined, selector: string | undefined, key: string | undefined, value: string | undefined, opts: {
96
+ .action(async (type: string | undefined, selector: string | undefined, key: string | undefined, value: string | undefined, opts: {
62
97
  tag: string[]; note?: string; json?: string;
63
98
  }) => {
64
99
  try {
@@ -79,8 +114,9 @@ export function createKnowledgeCommand(): Command {
79
114
  note: opts.note,
80
115
  };
81
116
  }
117
+ const warning = await knowledgeWarning(input);
82
118
  const entry = store.set(input);
83
- print({ ok: true, gameId: store.gameId ?? null, subject: entry });
119
+ print({ ok: !warning, gameId: store.gameId ?? null, subject: entry, ...(warning ? { warning } : {}) });
84
120
  } catch (e) {
85
121
  fail('knowledge_set_failed', e instanceof Error ? e.message : String(e));
86
122
  }
@@ -90,13 +126,14 @@ export function createKnowledgeCommand(): Command {
90
126
  .command('mark <player> <mark>')
91
127
  .description('Set the strategy mark for a player: hostile | trusted (unmarked players are suspected by default)')
92
128
  .option('--note <text>', 'Free-text reason')
93
- .action((player: string, rawMark: string, opts: { note?: string }) => {
129
+ .action(async (player: string, rawMark: string, opts: { note?: string }) => {
94
130
  const mark = normalizePlayerMark(rawMark);
95
131
  if (!mark) fail('invalid_mark', `Unknown mark '${rawMark}'. Use: hostile | trusted. (Unmarked = suspected by default.)`);
96
132
  try {
97
133
  const store = KnowledgeStore.forActiveAccount();
134
+ const warning = await knowledgeWarning({ type: 'player', selector: player, tags: [mark] });
98
135
  const entry = setPlayerMark(store, player, mark, opts);
99
- print({ ok: true, gameId: store.gameId ?? null, mark, subject: entry });
136
+ print({ ok: !warning, gameId: store.gameId ?? null, mark, subject: entry, ...(warning ? { warning } : {}) });
100
137
  } catch (e) {
101
138
  fail('knowledge_mark_failed', e instanceof Error ? e.message : String(e));
102
139
  }
@@ -4,6 +4,8 @@ import { getProfileStateDir, getWorkspaceDir } from '../lib/init-command.js';
4
4
  import { AuthStore } from '../lib/auth.js';
5
5
  import { sendOwnerControlRequest } from '../runtime/owner-control.js';
6
6
  import { ensureUserDataLayout, getUserDataStrategiesDir } from '../lib/user-data.js';
7
+ import { KnowledgeStore, buildKnowledgeView } from '../lib/knowledge-store.js';
8
+ import type { KnowledgeReview } from '../strategies/types.js';
7
9
 
8
10
  const KILL_STRATEGIES = new Set([
9
11
  'kill-frenzy', 'kill-lone', 'kill-target', 'warrior-memory',
@@ -171,11 +173,20 @@ Custom strategies:
171
173
  }, null, 2));
172
174
  process.exit(1);
173
175
  }
176
+ // knowledge 不随切换策略清空(按对局作用域)。让新策略审视现有知识,告知玩家哪些已失效。
177
+ let knowledgeReview: KnowledgeReview | undefined;
178
+ if (entry.reviewKnowledge) {
179
+ try {
180
+ const review = entry.reviewKnowledge(buildKnowledgeView(KnowledgeStore.forActiveAccount().list()));
181
+ if ((review.stale?.length ?? 0) > 0 || (review.notes?.length ?? 0) > 0) knowledgeReview = review;
182
+ } catch {}
183
+ }
174
184
  console.log(JSON.stringify({
175
185
  message: `Strategy started: ${entry.id}`,
176
186
  name: entry.name ?? entry.id,
177
187
  description: entry.description,
178
188
  pid: response.pid,
189
+ ...(knowledgeReview ? { knowledge_review: knowledgeReview } : {}),
179
190
  }, null, 2));
180
191
  });
181
192
 
@@ -8,6 +8,7 @@ import {
8
8
  MONITOR_EVENT_CONFIG,
9
9
  NOTABLE_EVENT_TYPES,
10
10
  nextStepFor,
11
+ nextStepForTriggers,
11
12
  POLL_INTERVAL_MS,
12
13
  readFeedSummary,
13
14
  runStreaming,
@@ -102,6 +103,13 @@ describe('classifyEvent + NOTABLE_EVENT_TYPES', () => {
102
103
  expect(eventKey(a)).not.toBe(eventKey(c));
103
104
  });
104
105
 
106
+ it('eventKey keeps room events distinct even without game ticks', () => {
107
+ const a = { type: 'room.member_joined', seat: 1, name: 'a', ts: '2026-07-03T01:00:00Z' };
108
+ const b = { type: 'room.member_joined', seat: 2, name: 'b', ts: '2026-07-03T01:00:01Z' };
109
+
110
+ expect(eventKey(a)).not.toBe(eventKey(b));
111
+ });
112
+
105
113
  it('classifyEvent returns notable=false for non-notable types regardless of actor', () => {
106
114
  expect(classifyEvent({ type: 'heartbeat', tick: 1, actor_name: 'them' }, 'me').notable).toBe(false);
107
115
  expect(classifyEvent({ type: 'heartbeat', tick: 1, actor_name: 'me' }, 'me').notable).toBe(false);
@@ -746,6 +754,27 @@ describe('runStreaming — game_over exits', () => {
746
754
  expect(lines.some((l) => JSON.parse(l).events?.includes('game_over'))).toBe(true);
747
755
  });
748
756
 
757
+ it('uses room-mode wording and next_step for room game_over', async () => {
758
+ const { feedPath, sessionPath } = makeTmpFiles();
759
+ writeFileSync(feedPath, JSON.stringify({
760
+ phase: 'game_over',
761
+ you: { name: 'me' },
762
+ game: { mode: 'room' },
763
+ meeting: {},
764
+ urgent: {},
765
+ }));
766
+ const lines: string[] = [];
767
+ const run = runStreaming({ feedPath, sessionPath, stdout: (s) => lines.push(s), pollIntervalMs: 20 });
768
+ await new Promise((r) => setTimeout(r, 30));
769
+ appendFileSync(sessionPath, JSON.stringify({ type: 'game_over', tick: 1, game_mode: 'room', reason: 'game_timeout' }) + '\n');
770
+ await Promise.race([run, new Promise((_, rej) => setTimeout(() => rej(new Error('did not exit')), 3000))]);
771
+
772
+ const notice = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('game_over'));
773
+ expect(notice.messages).toContain('t1 game_over 本轮房间对局结束,将回到房间等待。');
774
+ expect(notice.next_step).toBe('This room match round has ended. Wait for the room stream to resume; do not start normal matchmaking.');
775
+ expect(notice.game_mode).toBe('room');
776
+ });
777
+
749
778
  it('returns from the loop after a user_left_game event', async () => {
750
779
  const { feedPath, sessionPath } = makeTmpFiles();
751
780
  writeFileSync(feedPath, JSON.stringify({ phase: 'user_left_game', you: { name: 'me' }, meeting: {}, urgent: {} }));
@@ -760,6 +789,21 @@ describe('runStreaming — game_over exits', () => {
760
789
  expect(notice.messages.some((message: string) => message.includes('The user left the game from the web page. This match has ended; stop playing and do not restart unless the user asks.'))).toBe(true);
761
790
  expect(notice.state).toContain('user_left_game');
762
791
  });
792
+
793
+ it('returns from the loop after a room.self_left event', async () => {
794
+ const { feedPath, sessionPath } = makeTmpFiles();
795
+ writeFileSync(feedPath, JSON.stringify({ phase: 'room_left', you: { name: 'me' }, room: null, recent_events: [] }));
796
+ const lines: string[] = [];
797
+ const run = runStreaming({ feedPath, sessionPath, stdout: (s) => lines.push(s), pollIntervalMs: 20 });
798
+ await new Promise((r) => setTimeout(r, 30));
799
+ appendFileSync(sessionPath, JSON.stringify({ type: 'room.self_left' }) + '\n');
800
+ await Promise.race([run, new Promise((_, rej) => setTimeout(() => rej(new Error('did not exit')), 3000))]);
801
+
802
+ const notice = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('room.self_left'));
803
+ expect(notice).toBeTruthy();
804
+ expect(notice.messages.some((message: string) => message.includes('The user left the room from the web page, or the current CLI quit command has left the room. Stop the room flow and do not create or join another room unless the user asks.'))).toBe(true);
805
+ expect(notice.state).toContain('room_left');
806
+ });
763
807
  });
764
808
 
765
809
  describe('runStreaming — NDJSON discipline', () => {
@@ -808,6 +852,138 @@ describe('runStreaming — matchmaking synthetic events', () => {
808
852
  });
809
853
  });
810
854
 
855
+ describe('room ready routing', () => {
856
+ it('asks for user confirmation before starting a full room', () => {
857
+ expect(nextStepForTriggers(['room_ready_to_start'])).toBe('Room is full. Ask the user whether to start now before running `ccl game start-room`.');
858
+ expect(nextStepForTriggers(['room.full'])).toBe('Room is full. Ask the user whether to start now before running `ccl game start-room`.');
859
+ });
860
+
861
+ it('routes room.game_finished without ending the room stream', () => {
862
+ expect(classifyEvent({ type: 'room.game_finished', game_id: 'game-1' }).notable).toBe(true);
863
+ expect(nextStepForTriggers(['room.game_finished'])).toContain('上一轮房间对局已结束');
864
+ });
865
+ });
866
+
867
+ describe('runStreaming — room heartbeat snapshots', () => {
868
+ it('emits room.game_finished as a notable room event', async () => {
869
+ const { feedPath, sessionPath } = makeTmpFiles();
870
+ writeFileSync(feedPath, JSON.stringify({
871
+ phase: 'room_waiting',
872
+ you: { name: 'me', seat: 1, is_owner: false },
873
+ room: { room_code: '123456', status: 'waiting', member_count: 10, members: [] },
874
+ recent_events: [],
875
+ }));
876
+ const lines: string[] = [];
877
+ const ctrl = new AbortController();
878
+ const run = runStreaming({
879
+ feedPath,
880
+ sessionPath,
881
+ stdout: (s) => lines.push(s),
882
+ signal: ctrl.signal,
883
+ pollIntervalMs: 10,
884
+ heartbeatIntervalMs: 0,
885
+ });
886
+
887
+ await new Promise((r) => setTimeout(r, 20));
888
+ appendFileSync(sessionPath, JSON.stringify({ type: 'room.game_finished', game_id: 'game-1' }) + '\n');
889
+ await new Promise((r) => setTimeout(r, 60));
890
+ ctrl.abort(); await run;
891
+
892
+ const notice = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('room.game_finished'));
893
+ expect(notice).toBeTruthy();
894
+ expect(notice.messages[0]).toContain('上一轮房间对局已结束');
895
+ expect(notice.state).toContain('room=123456');
896
+ });
897
+
898
+ it('emits a room waiting snapshot when room events are quiet', async () => {
899
+ const { feedPath, sessionPath } = makeTmpFiles();
900
+ writeFileSync(feedPath, JSON.stringify({
901
+ phase: 'room_waiting',
902
+ you: { name: 'me', seat: 1, is_owner: false },
903
+ room: { room_code: '123456', status: 'waiting', member_count: 6, members: [] },
904
+ recent_events: [],
905
+ }));
906
+ const lines: string[] = [];
907
+ const ctrl = new AbortController();
908
+ const run = runStreaming({
909
+ feedPath,
910
+ sessionPath,
911
+ stdout: (s) => lines.push(s),
912
+ signal: ctrl.signal,
913
+ pollIntervalMs: 10,
914
+ heartbeatIntervalMs: 30,
915
+ });
916
+
917
+ await new Promise((r) => setTimeout(r, 80));
918
+ ctrl.abort(); await run;
919
+
920
+ const heartbeat = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('heartbeat'));
921
+ expect(heartbeat).toBeTruthy();
922
+ expect(heartbeat.messages[0]).toContain('房间 123456 当前 6/10 人');
923
+ expect(heartbeat.messages[0]).toContain('正在等待更多玩家加入');
924
+ expect(heartbeat.state).toContain('room=123456');
925
+ expect(heartbeat.state).toContain('members=6/10');
926
+ });
927
+
928
+ it('does not tell the agent to confirm starting from a full-room heartbeat', async () => {
929
+ const { feedPath, sessionPath } = makeTmpFiles();
930
+ writeFileSync(feedPath, JSON.stringify({
931
+ phase: 'room_waiting',
932
+ you: { name: 'me', seat: 1, is_owner: true },
933
+ room: { room_code: '123456', status: 'waiting', member_count: 10, is_owner: true, ready_to_start: true, members: [] },
934
+ recent_events: [],
935
+ }));
936
+ const lines: string[] = [];
937
+ const ctrl = new AbortController();
938
+ const run = runStreaming({
939
+ feedPath,
940
+ sessionPath,
941
+ stdout: (s) => lines.push(s),
942
+ signal: ctrl.signal,
943
+ pollIntervalMs: 10,
944
+ heartbeatIntervalMs: 30,
945
+ });
946
+
947
+ await new Promise((r) => setTimeout(r, 80));
948
+ ctrl.abort(); await run;
949
+
950
+ const heartbeat = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('heartbeat'));
951
+ expect(heartbeat).toBeTruthy();
952
+ expect(heartbeat.messages[0]).toContain('房间 123456 当前 10/10 人');
953
+ expect(heartbeat.messages[0]).toContain('等待房主操作');
954
+ expect(heartbeat.messages[0]).not.toContain('用户确认');
955
+ expect(heartbeat.messages[0]).not.toContain('start-room');
956
+ });
957
+
958
+ it('describes room playing as waiting for other players to finish', async () => {
959
+ const { feedPath, sessionPath } = makeTmpFiles();
960
+ writeFileSync(feedPath, JSON.stringify({
961
+ phase: 'room_playing',
962
+ you: { name: 'me', seat: 1, is_owner: false },
963
+ room: { room_code: '123456', status: 'playing', member_count: 10, members: [] },
964
+ recent_events: [],
965
+ }));
966
+ const lines: string[] = [];
967
+ const ctrl = new AbortController();
968
+ const run = runStreaming({
969
+ feedPath,
970
+ sessionPath,
971
+ stdout: (s) => lines.push(s),
972
+ signal: ctrl.signal,
973
+ pollIntervalMs: 10,
974
+ heartbeatIntervalMs: 30,
975
+ });
976
+
977
+ await new Promise((r) => setTimeout(r, 80));
978
+ ctrl.abort(); await run;
979
+
980
+ const heartbeat = lines.map((l) => JSON.parse(l)).find((line) => line.events?.includes('heartbeat'));
981
+ expect(heartbeat).toBeTruthy();
982
+ expect(heartbeat.messages[0]).toContain('上一轮对局仍在进行');
983
+ expect(heartbeat.messages[0]).toContain('正在等待其他玩家结束');
984
+ });
985
+ });
986
+
811
987
  describe('runStreaming — speech_your_turn fires as notable event', () => {
812
988
  it('fires speech_your_turn as exit_reason when speech_your_turn event arrives', async () => {
813
989
  const { feedPath, sessionPath } = makeTmpFiles();
@@ -997,6 +1173,64 @@ describe('runStreaming startup monitor payload', () => {
997
1173
  expect(first.messages[0]).toContain('game_start');
998
1174
  });
999
1175
 
1176
+ it('does not emit a synthetic game_start when startup emission is disabled', async () => {
1177
+ const { feedPath, sessionPath } = makeTmpFiles();
1178
+ writeFileSync(
1179
+ feedPath,
1180
+ JSON.stringify({ you: { name: 'me' }, phase: 'room_waiting', room: { room_code: '123456' }, urgent: {}, meeting: null }),
1181
+ );
1182
+ const lines: string[] = [];
1183
+ const ctrl = new AbortController();
1184
+
1185
+ const run = runStreaming({
1186
+ feedPath,
1187
+ sessionPath,
1188
+ stdout: (s) => lines.push(s),
1189
+ signal: ctrl.signal,
1190
+ pollIntervalMs: 20,
1191
+ emitGameStart: false,
1192
+ heartbeatIntervalMs: 0,
1193
+ });
1194
+
1195
+ await new Promise((r) => setTimeout(r, 80));
1196
+ ctrl.abort();
1197
+ await run;
1198
+
1199
+ expect(lines).toEqual([]);
1200
+ });
1201
+
1202
+ it('final-drains written room events before an intentional stream handoff exits', async () => {
1203
+ const { feedPath, sessionPath } = makeTmpFiles();
1204
+ writeFileSync(
1205
+ feedPath,
1206
+ JSON.stringify({ you: { name: 'me' }, phase: 'room_waiting', room: { room_code: '123456' }, urgent: {}, meeting: null }),
1207
+ );
1208
+ const lines: string[] = [];
1209
+ const ctrl = new AbortController();
1210
+
1211
+ const run = runStreaming({
1212
+ feedPath,
1213
+ sessionPath,
1214
+ stdout: (s) => lines.push(s),
1215
+ signal: ctrl.signal,
1216
+ pollIntervalMs: 1000,
1217
+ emitGameStart: false,
1218
+ heartbeatIntervalMs: 0,
1219
+ finalDrainOnAbort: true,
1220
+ finalDrainTimeoutMs: 500,
1221
+ });
1222
+
1223
+ await new Promise((r) => setTimeout(r, 50));
1224
+ appendFileSync(sessionPath, JSON.stringify({ type: 'room.game_started', game_id: 'game-1' }) + '\n');
1225
+ ctrl.abort();
1226
+ await run;
1227
+
1228
+ expect(lines.length).toBe(1);
1229
+ const notice = JSON.parse(lines[0]);
1230
+ expect(notice.events).toEqual(['room.game_started']);
1231
+ expect(notice.messages[0]).toContain('room.game_started');
1232
+ });
1233
+
1000
1234
  it('compacts role_assigned inside caught_up notable events', async () => {
1001
1235
  const { feedPath, sessionPath } = makeTmpFiles();
1002
1236
  writeFileSync(
@@ -1038,4 +1272,42 @@ describe('runStreaming startup monitor payload', () => {
1038
1272
  expect(first.messages[0]).toContain('role_assigned');
1039
1273
  expect(first).not.toHaveProperty('caught_up');
1040
1274
  });
1275
+
1276
+ it('does not replay room waiting events when a game-stage session is attached', async () => {
1277
+ const { dir, feedPath, sessionPath: gameSessionPath } = makeTmpFiles();
1278
+ const roomSessionPath = join(dir, 'room-session.jsonl');
1279
+ writeFileSync(
1280
+ feedPath,
1281
+ JSON.stringify({ you: { name: 'me' }, phase: 'preparing', urgent: {}, meeting: null }),
1282
+ );
1283
+ appendFileSync(roomSessionPath, JSON.stringify({ type: 'room_ready_to_start', room_code: '123456' }) + '\n');
1284
+ appendFileSync(roomSessionPath, JSON.stringify({ type: 'room.full', room_code: '123456' }) + '\n');
1285
+ appendFileSync(gameSessionPath, JSON.stringify({
1286
+ type: 'role_assigned',
1287
+ tick: 0,
1288
+ role: 'shrimp_generic',
1289
+ faction: 'lobster',
1290
+ }) + '\n');
1291
+ const lines: string[] = [];
1292
+ const ctrl = new AbortController();
1293
+
1294
+ const run = runStreaming({
1295
+ feedPath,
1296
+ sessionPath: gameSessionPath,
1297
+ getSessionPath: () => gameSessionPath,
1298
+ stdout: (s) => lines.push(s),
1299
+ signal: ctrl.signal,
1300
+ pollIntervalMs: 20,
1301
+ });
1302
+
1303
+ await new Promise((r) => setTimeout(r, 60));
1304
+ ctrl.abort();
1305
+ await run;
1306
+
1307
+ const first = JSON.parse(lines[0]);
1308
+ expect(first.events).toEqual(['role_assigned']);
1309
+ expect(first.messages[0]).toContain('role_assigned');
1310
+ expect(first.events).not.toContain('room_ready_to_start');
1311
+ expect(first.events).not.toContain('room.full');
1312
+ });
1041
1313
  });