@myclaw163/clawclaw-cli 0.8.3 → 0.8.4
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 +1 -1
- package/docs/configuration.md +1 -1
- package/docs/custom-modules/README.md +2 -2
- package/docs/custom-modules/api-reference.md +3 -7
- package/docs/custom-modules/behavior.md +3 -3
- package/docs/runtime/README.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +5 -5
- package/skills/clawclaw/references/COMMANDS.md +1 -2
- package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
- package/skills/clawclaw/references/STREAM.md +9 -11
- package/src/behaviors/official-finite/do-task.ts +70 -0
- package/src/behaviors/official-finite/index.test.ts +69 -22
- package/src/behaviors/official-finite/index.ts +0 -3
- package/src/commands/behavior.test.ts +1 -1
- package/src/lib/behavior-export.test.ts +53 -9
- package/src/lib/behavior-export.ts +26 -3
- package/src/pipeline/canonical-event-presentation.test.ts +2 -0
- package/src/pipeline/event-format.test.ts +51 -0
- package/src/pipeline/event-format.ts +20 -4
- package/src/pipeline/event-hints.test.ts +24 -3
- package/src/pipeline/event-hints.ts +20 -6
- package/src/pipeline/game-sync-event-normalization.test.ts +49 -1
- package/src/pipeline/game-sync-event-normalization.ts +9 -0
- package/src/pipeline/role-display.ts +22 -0
- package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
- package/src/runtime/clawclaw/agent-event-policy.test.ts +2 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +24 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -1
- package/src/runtime/clawclaw-event-catalog.test.ts +2 -0
- package/src/runtime/clawclaw-event-catalog.ts +2 -0
- package/src/runtime/framework/action-diagnostics.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +1 -1
- package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
- package/src/sdk/action.test.ts +8 -0
- package/src/sdk/action.ts +8 -6
- package/src/sdk/behavior-plugin/index.ts +1 -2
- package/src/sdk/behavior-toolkit/model.ts +2 -0
- package/src/sdk/module-input/index.ts +0 -2
- package/src/strategies/custom-module.test.ts +0 -1
- package/src/strategies/game-utils.test.ts +0 -1
- package/src/strategies/goals/avoid-players-top.test.ts +0 -1
- package/src/strategies/goals/crab-sabotage-top.test.ts +11 -25
- package/src/strategies/goals/crab-sabotage-top.ts +5 -61
- package/src/strategies/goals/kill-lone-top.test.ts +0 -1
- package/src/strategies/goals/kill-target-top.test.ts +0 -1
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -1
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -1
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -1
- package/src/strategies/goals/task-only-top.test.ts +0 -1
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -1
- package/src/strategies/types.ts +0 -6
- package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
existsSync,
|
|
2
3
|
mkdtempSync,
|
|
3
4
|
readFileSync,
|
|
4
5
|
readdirSync,
|
|
@@ -81,32 +82,75 @@ describe('unified official Behavior resources', () => {
|
|
|
81
82
|
expect(hasUserBehaviorCustomization(customRoot)).toBe(true);
|
|
82
83
|
});
|
|
83
84
|
|
|
84
|
-
it('
|
|
85
|
+
it('retires an untouched trigger_alarm wrapper while preserving but disabling user edits', async () => {
|
|
86
|
+
const installLegacyWrapper = async (root: string, modified: boolean) => {
|
|
87
|
+
await syncOfficialBehaviors({ workspaceDir: root });
|
|
88
|
+
const directory = getUserDataBehaviorsDir(root);
|
|
89
|
+
const path = join(directory, 'trigger_alarm.ts');
|
|
90
|
+
const installed = customBehavior('trigger_alarm');
|
|
91
|
+
writeFileSync(path, modified ? `${installed}\n// user edit\n` : installed, 'utf8');
|
|
92
|
+
const manifest = readOfficialBehaviorManifest(root);
|
|
93
|
+
manifest.trigger_alarm = {
|
|
94
|
+
format: 1,
|
|
95
|
+
version: '0.8.3',
|
|
96
|
+
sourceHash: 'legacy-trigger',
|
|
97
|
+
installedHash: hashOfficialResourceContent(installed),
|
|
98
|
+
provenance: {
|
|
99
|
+
kind: 'clawclaw.official-behavior',
|
|
100
|
+
family: 'finite',
|
|
101
|
+
source: 'behaviors/official-finite/trigger-alarm.ts',
|
|
102
|
+
materializationFormat: 1,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
writeFileSync(
|
|
106
|
+
getUserDataOfficialBehaviorsManifestFile(root),
|
|
107
|
+
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
108
|
+
'utf8',
|
|
109
|
+
);
|
|
110
|
+
return path;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const untouchedRoot = tempRoot();
|
|
114
|
+
const untouchedPath = await installLegacyWrapper(untouchedRoot, false);
|
|
115
|
+
await syncOfficialBehaviors({ workspaceDir: untouchedRoot });
|
|
116
|
+
expect(existsSync(untouchedPath)).toBe(false);
|
|
117
|
+
expect(readOfficialBehaviorManifest(untouchedRoot)).not.toHaveProperty('trigger_alarm');
|
|
118
|
+
|
|
119
|
+
const modifiedRoot = tempRoot();
|
|
120
|
+
const modifiedPath = await installLegacyWrapper(modifiedRoot, true);
|
|
121
|
+
await syncOfficialBehaviors({ workspaceDir: modifiedRoot });
|
|
122
|
+
expect(existsSync(modifiedPath)).toBe(true);
|
|
123
|
+
expect(listWorkspaceClawclawBehaviorSources(modifiedRoot).map(({ id }) => id))
|
|
124
|
+
.not.toContain('trigger_alarm');
|
|
125
|
+
expect(hasUserBehaviorCustomization(modifiedRoot)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('declares exactly 20 long and 12 finite modules with unique ids', () => {
|
|
85
129
|
const definitions = listOfficialBehaviorDefinitions();
|
|
86
|
-
expect(definitions).toHaveLength(
|
|
130
|
+
expect(definitions).toHaveLength(32);
|
|
87
131
|
expect(definitions.filter(({ family }) => family === 'long')).toHaveLength(20);
|
|
88
|
-
expect(definitions.filter(({ family }) => family === 'finite')).toHaveLength(
|
|
89
|
-
expect(new Set(definitions.map(({ id }) => id)).size).toBe(
|
|
132
|
+
expect(definitions.filter(({ family }) => family === 'finite')).toHaveLength(12);
|
|
133
|
+
expect(new Set(definitions.map(({ id }) => id)).size).toBe(32);
|
|
90
134
|
expect(definitions.map(({ id }) => id)).toEqual(expect.arrayContaining([
|
|
91
135
|
'task-only',
|
|
92
136
|
'warrior-memory',
|
|
93
137
|
'go_to',
|
|
94
138
|
'report_corpse',
|
|
95
|
-
'trigger_alarm',
|
|
96
139
|
]));
|
|
140
|
+
expect(definitions.map(({ id }) => id).includes('trigger_alarm')).toBe(false);
|
|
97
141
|
});
|
|
98
142
|
|
|
99
143
|
it('materializes all modules into one directory with hashes and provenance', async () => {
|
|
100
144
|
const root = tempRoot();
|
|
101
145
|
const result = await syncOfficialBehaviors({ workspaceDir: root });
|
|
102
146
|
|
|
103
|
-
expect(result.added).toHaveLength(
|
|
147
|
+
expect(result.added).toHaveLength(32);
|
|
104
148
|
expect(result.updated).toEqual([]);
|
|
105
149
|
const behaviorsDir = getUserDataBehaviorsDir(root);
|
|
106
|
-
expect(readdirSync(behaviorsDir).filter((file) => file.endsWith('.ts'))).toHaveLength(
|
|
150
|
+
expect(readdirSync(behaviorsDir).filter((file) => file.endsWith('.ts'))).toHaveLength(32);
|
|
107
151
|
|
|
108
152
|
const manifest = readOfficialBehaviorManifest(root);
|
|
109
|
-
expect(Object.keys(manifest)).toHaveLength(
|
|
153
|
+
expect(Object.keys(manifest)).toHaveLength(32);
|
|
110
154
|
expect(manifest['task-only']).toMatchObject({
|
|
111
155
|
format: 1,
|
|
112
156
|
provenance: {
|
|
@@ -147,7 +191,7 @@ describe('unified official Behavior resources', () => {
|
|
|
147
191
|
expect(rawLong?.allowReservedProduces).toBeUndefined();
|
|
148
192
|
|
|
149
193
|
const catalog = createWorkspaceClawclawBehaviorCatalog(root);
|
|
150
|
-
expect(catalog.list()).toHaveLength(
|
|
194
|
+
expect(catalog.list()).toHaveLength(32);
|
|
151
195
|
expect(catalog.list().find(({ id }) => id === 'task-only')).toMatchObject({
|
|
152
196
|
loadable: true,
|
|
153
197
|
provenance: {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
existsSync,
|
|
6
6
|
readFileSync,
|
|
7
7
|
readdirSync,
|
|
8
|
+
unlinkSync,
|
|
8
9
|
} from 'node:fs';
|
|
9
10
|
import { createHash } from 'node:crypto';
|
|
10
11
|
import {
|
|
@@ -17,6 +18,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
17
18
|
import { getWorkspaceDir } from './init-command.js';
|
|
18
19
|
import {
|
|
19
20
|
hashOfficialResourceContent,
|
|
21
|
+
isOfficialResourceUnmodified,
|
|
20
22
|
readOfficialResourceManifest,
|
|
21
23
|
syncOfficialResources,
|
|
22
24
|
writeOfficialResourceManifest,
|
|
@@ -38,6 +40,7 @@ import {
|
|
|
38
40
|
import { deepFreezeBehaviorValue } from '../runtime/clawclaw/plugins/behavior/behavior-manifest.js';
|
|
39
41
|
|
|
40
42
|
const OFFICIAL_BEHAVIOR_EXPORT_FORMAT = 1 as const;
|
|
43
|
+
const RETIRED_OFFICIAL_BEHAVIOR_IDS = new Set(['trigger_alarm']);
|
|
41
44
|
|
|
42
45
|
const OFFICIAL_LONG_BEHAVIOR_FILES = Object.freeze([
|
|
43
46
|
'avoid-lone.ts',
|
|
@@ -75,7 +78,6 @@ const OFFICIAL_FINITE_BEHAVIOR_FILES = Object.freeze([
|
|
|
75
78
|
'patrol-area.ts',
|
|
76
79
|
'report-corpse.ts',
|
|
77
80
|
'seek-kill-opportunity.ts',
|
|
78
|
-
'trigger-alarm.ts',
|
|
79
81
|
] as const);
|
|
80
82
|
|
|
81
83
|
export type OfficialBehaviorFamily = 'long' | 'finite';
|
|
@@ -221,8 +223,8 @@ function listBundledOfficialBehaviorSources(): readonly BundledOfficialBehaviorS
|
|
|
221
223
|
if (sources.filter(({ family }) => family === 'long').length !== 20) {
|
|
222
224
|
throw new Error('Expected exactly 20 bundled long Behaviors.');
|
|
223
225
|
}
|
|
224
|
-
if (sources.filter(({ family }) => family === 'finite').length !==
|
|
225
|
-
throw new Error('Expected exactly
|
|
226
|
+
if (sources.filter(({ family }) => family === 'finite').length !== 12) {
|
|
227
|
+
throw new Error('Expected exactly 12 bundled finite Behaviors.');
|
|
226
228
|
}
|
|
227
229
|
return Object.freeze(sources);
|
|
228
230
|
}
|
|
@@ -318,6 +320,25 @@ function recordOfficialBehaviorProvenance(
|
|
|
318
320
|
if (changed) writeOfficialResourceManifest(path, manifest);
|
|
319
321
|
}
|
|
320
322
|
|
|
323
|
+
function retireRemovedOfficialBehaviors(workspaceDir: string): void {
|
|
324
|
+
const manifestPath = getUserDataOfficialBehaviorsManifestFile(workspaceDir);
|
|
325
|
+
const manifest = readOfficialBehaviorManifest(workspaceDir);
|
|
326
|
+
let changed = false;
|
|
327
|
+
for (const id of RETIRED_OFFICIAL_BEHAVIOR_IDS) {
|
|
328
|
+
const entry = manifest[id];
|
|
329
|
+
if (!entry) continue;
|
|
330
|
+
const destination = join(getUserDataBehaviorsDir(workspaceDir), `${id}.ts`);
|
|
331
|
+
if (existsSync(destination) && !isOfficialResourceUnmodified(destination, entry)) {
|
|
332
|
+
// Preserve user edits, but the retired id is filtered from Runtime discovery.
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (existsSync(destination)) unlinkSync(destination);
|
|
336
|
+
delete manifest[id];
|
|
337
|
+
changed = true;
|
|
338
|
+
}
|
|
339
|
+
if (changed) writeOfficialResourceManifest(manifestPath, manifest);
|
|
340
|
+
}
|
|
341
|
+
|
|
321
342
|
export interface SyncOfficialBehaviorsOptions {
|
|
322
343
|
readonly workspaceDir?: string;
|
|
323
344
|
readonly ids?: readonly string[];
|
|
@@ -348,6 +369,7 @@ export async function syncOfficialBehaviors(
|
|
|
348
369
|
force: options.force,
|
|
349
370
|
notFoundMessage: (id) => `Built-in Behavior '${id}' not found.`,
|
|
350
371
|
});
|
|
372
|
+
if (options.ids === undefined) retireRemovedOfficialBehaviors(workspaceDir);
|
|
351
373
|
recordOfficialBehaviorProvenance(workspaceDir, bundled);
|
|
352
374
|
return result;
|
|
353
375
|
}
|
|
@@ -413,6 +435,7 @@ export function listWorkspaceClawclawBehaviorSources(
|
|
|
413
435
|
const manifest = readOfficialBehaviorManifest(workspaceDir);
|
|
414
436
|
return Object.freeze(
|
|
415
437
|
listClawclawBehaviorSources(getUserDataBehaviorsDir(workspaceDir))
|
|
438
|
+
.filter((source) => !RETIRED_OFFICIAL_BEHAVIOR_IDS.has(source.id))
|
|
416
439
|
.map((source) => trustedOfficialSource(workspaceDir, source, bundled, manifest)),
|
|
417
440
|
);
|
|
418
441
|
}
|
|
@@ -36,6 +36,7 @@ describe('canonical Agent Event presentation', () => {
|
|
|
36
36
|
const presented = presentCanonicalEvent(canonical('killed', {
|
|
37
37
|
tick: 7,
|
|
38
38
|
killer_name: 'Alpha',
|
|
39
|
+
killer_role: 'crab_assassin',
|
|
39
40
|
target_name: 'Bravo',
|
|
40
41
|
hint: 'backend-owned hint',
|
|
41
42
|
next_step: 'backend-owned next step',
|
|
@@ -43,6 +44,7 @@ describe('canonical Agent Event presentation', () => {
|
|
|
43
44
|
}), null);
|
|
44
45
|
|
|
45
46
|
expect(presented.hint).toContain('Alpha');
|
|
47
|
+
expect(presented.hint).toContain('Assassin Crab');
|
|
46
48
|
expect(presented.hint).not.toContain('backend-owned hint');
|
|
47
49
|
expect(presented).not.toHaveProperty('notice');
|
|
48
50
|
expect(presented).not.toHaveProperty('next_step');
|
|
@@ -47,6 +47,7 @@ describe('event-format', () => {
|
|
|
47
47
|
room: '情报室',
|
|
48
48
|
killer_name: '哈基米南北绿豆',
|
|
49
49
|
killer_seat: 8,
|
|
50
|
+
killer_role: 'neutral_octopus',
|
|
50
51
|
hint: 'YOU ARE DEAD: 哈基米南北绿豆 removed you from play. Your hands are off the board now — alert your user, then spectate or leave while your teammates weaponize what you learned.',
|
|
51
52
|
};
|
|
52
53
|
|
|
@@ -56,6 +57,7 @@ describe('event-format', () => {
|
|
|
56
57
|
|
|
57
58
|
expect(message).toContain('t5330 killed');
|
|
58
59
|
expect(message).toContain('8号哈基米南北绿豆');
|
|
60
|
+
expect(message).toContain('8号哈基米南北绿豆(章鱼)');
|
|
59
61
|
expect(formatted).not.toHaveProperty('notice');
|
|
60
62
|
expect(formatted).not.toHaveProperty('hint');
|
|
61
63
|
expect(JSON.stringify(formatted)).not.toContain('Your hands are off the board');
|
|
@@ -68,10 +70,26 @@ describe('event-format', () => {
|
|
|
68
70
|
room: '制氧舱',
|
|
69
71
|
killer_kind: 'system',
|
|
70
72
|
killer_name: 'Shrimp God',
|
|
73
|
+
killer_role: 'neutral_octopus',
|
|
71
74
|
});
|
|
72
75
|
|
|
73
76
|
expect(message).toContain('被Shrimp God击杀');
|
|
74
77
|
expect(message).not.toContain('?号Shrimp God');
|
|
78
|
+
expect(message).not.toContain('章鱼');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('formats emergency interruption as a private second-person fact', () => {
|
|
82
|
+
const message = formatEventMessage({
|
|
83
|
+
type: 'emergency_interrupted',
|
|
84
|
+
tick: 486,
|
|
85
|
+
actor_name: 'Alpha',
|
|
86
|
+
actor_seat: 2,
|
|
87
|
+
task_name: '修复火灾-发动机',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(message).toContain('你在处理修复火灾-发动机时死亡');
|
|
91
|
+
expect(message).not.toContain('Alpha');
|
|
92
|
+
expect(message).not.toContain('未知玩家');
|
|
75
93
|
});
|
|
76
94
|
|
|
77
95
|
it('downgrades self-killer murder_witnessed presentation to neutral diagnostics', () => {
|
|
@@ -539,6 +557,7 @@ describe('event-format', () => {
|
|
|
539
557
|
status: 'cooldown_charged',
|
|
540
558
|
cooldown_remaining_secs: 4.25,
|
|
541
559
|
});
|
|
560
|
+
expect(state?.abilities).toBeUndefined();
|
|
542
561
|
expect(state?.players).toEqual([
|
|
543
562
|
{ name: 'me', seat: 1, known_status: { is_alive: true } },
|
|
544
563
|
{ name: 'nearby', seat: 2, known_status: { is_alive: true } },
|
|
@@ -777,6 +796,37 @@ describe('event-format', () => {
|
|
|
777
796
|
expect(hint).not.toContain('Lobsters —');
|
|
778
797
|
});
|
|
779
798
|
|
|
799
|
+
it('explains sabotage-caused emergencies without exposing a saboteur identity', () => {
|
|
800
|
+
const event = {
|
|
801
|
+
type: 'emergency_started',
|
|
802
|
+
task_name: '稳定反应堆',
|
|
803
|
+
room: '反应堆',
|
|
804
|
+
timeout_secs: 80,
|
|
805
|
+
cause: 'sabotage',
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
expect(formatEventMessage(event)).toContain('蟹刚完成对应破坏任务');
|
|
809
|
+
const hint = BACKEND_EVENT_HINT_FORMATTERS.emergency_started(event, {});
|
|
810
|
+
expect(hint).toContain('A Crab completed the paired sabotage task');
|
|
811
|
+
expect(hint).toContain("identity is not exposed");
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it('presents a private sabotage task interruption with its authoritative cooldown', () => {
|
|
815
|
+
const event = {
|
|
816
|
+
type: 'task_interrupted',
|
|
817
|
+
task_id: '102',
|
|
818
|
+
task_name: '投放毒药',
|
|
819
|
+
reason: 'emergency_started',
|
|
820
|
+
cooldown_remaining_secs: 100,
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
expect(formatEventMessage(event)).toContain('任务未消耗');
|
|
824
|
+
expect(formatEventMessage(event)).toContain('100秒');
|
|
825
|
+
const hint = BACKEND_EVENT_HINT_FORMATTERS.task_interrupted(event, {});
|
|
826
|
+
expect(hint).toContain('was interrupted');
|
|
827
|
+
expect(hint).toContain('not consumed');
|
|
828
|
+
});
|
|
829
|
+
|
|
780
830
|
it('states when a meeting, rather than a player, resolves an emergency', () => {
|
|
781
831
|
const event = {
|
|
782
832
|
type: 'emergency_resolved',
|
|
@@ -817,6 +867,7 @@ describe('event-format', () => {
|
|
|
817
867
|
'octopus_time_start',
|
|
818
868
|
'role_assigned',
|
|
819
869
|
'speech_skipped',
|
|
870
|
+
'task_interrupted',
|
|
820
871
|
'vote_phase_start',
|
|
821
872
|
'vote_speech_phase_ended',
|
|
822
873
|
];
|
|
@@ -3,6 +3,7 @@ import { headingDirection } from '../runtime/clawclaw/plugins/perception/shared/
|
|
|
3
3
|
import { isRoomMode } from '../lib/room.js';
|
|
4
4
|
import { isSelfKillerMurderWitnessed } from './event-hints.js';
|
|
5
5
|
import { projectAgentAbilities } from '../runtime/clawclaw/agent-ability-state.js';
|
|
6
|
+
import { roleDisplayName } from './role-display.js';
|
|
6
7
|
|
|
7
8
|
export interface EventFormatContext {
|
|
8
9
|
summary?: any | null;
|
|
@@ -50,6 +51,12 @@ function stringValue(value: unknown): string | undefined {
|
|
|
50
51
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
function killerRoleSuffix(event: Record<string, any>): string {
|
|
55
|
+
if (event.killer_kind === 'system') return '';
|
|
56
|
+
const role = roleDisplayName(event.killer_role, 'zh-CN');
|
|
57
|
+
return role ? `(${role})` : '';
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
function trainingRoomTypeLabel(value: unknown): string {
|
|
54
61
|
if (value === 'training_simulation') return '模拟训练';
|
|
55
62
|
if (value === 'training_dummy') return '木桩训练';
|
|
@@ -376,7 +383,7 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
376
383
|
case 'kill':
|
|
377
384
|
return `你在${firstString(event, ['room'])}击杀了${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)}。`;
|
|
378
385
|
case 'killed':
|
|
379
|
-
return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}击杀了,你已死亡。`;
|
|
386
|
+
return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}${killerRoleSuffix(event)}击杀了,你已死亡。`;
|
|
380
387
|
case 'murder_witnessed':
|
|
381
388
|
if (isSelfKillerMurderWitnessed(event, ctx.summary)) {
|
|
382
389
|
return '收到一条与自身击杀身份冲突的 murder_witnessed 事件;该事件已降级为诊断信息,不能据此判断任何目击者。';
|
|
@@ -404,6 +411,11 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
404
411
|
}
|
|
405
412
|
case 'task_sabotaged':
|
|
406
413
|
return `破坏任务完成:${firstString(event, ['task_name'])}(${firstString(event, ['room'])})。`;
|
|
414
|
+
case 'task_interrupted': {
|
|
415
|
+
const cooldown = numberValue(event.cooldown_remaining_secs);
|
|
416
|
+
const cooldownText = cooldown === undefined ? '' : `;共享冷却剩余${cooldown}秒`;
|
|
417
|
+
return `破坏任务“${firstString(event, ['task_name'])}”因紧急任务开始而中断,任务未消耗${cooldownText}。`;
|
|
418
|
+
}
|
|
407
419
|
case 'tasks_changed':
|
|
408
420
|
return `任务列表已更新(${firstString(event, ['reason'])})。`;
|
|
409
421
|
case 'players_changed':
|
|
@@ -423,8 +435,12 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
423
435
|
return `你听到${firstString(event, ['room'])}附近有尸体倒地。`;
|
|
424
436
|
case 'octopus_time_start':
|
|
425
437
|
return '章鱼时间开始:存活人数已降至3人或更少,章鱼存活60秒将获胜;会议已禁用,但虾方任务完成或紧急任务超时仍可先结束本局。';
|
|
426
|
-
case 'emergency_started':
|
|
427
|
-
|
|
438
|
+
case 'emergency_started': {
|
|
439
|
+
const sabotageCause = event.cause === 'sabotage'
|
|
440
|
+
? '蟹刚完成对应破坏任务并触发了该紧急事件;'
|
|
441
|
+
: '';
|
|
442
|
+
return `紧急任务:${firstString(event, ['task_name'])}在${firstString(event, ['room'])},${sabotageCause}${text(event.timeout_secs, '?')}秒内处理。`;
|
|
443
|
+
}
|
|
428
444
|
case 'emergency_countdown_warning':
|
|
429
445
|
return `紧急任务${firstString(event, ['task_name'])}只剩${text(event.remaining_secs, '?')}秒(${text(event.threshold_secs, '?')}秒提醒)。`;
|
|
430
446
|
case 'emergency_resolved':
|
|
@@ -436,7 +452,7 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
436
452
|
}
|
|
437
453
|
return `紧急任务已解决:${firstString(event, ['task_name'])}。`;
|
|
438
454
|
case 'emergency_interrupted':
|
|
439
|
-
return
|
|
455
|
+
return `你在处理${firstString(event, ['task_name'])}时死亡,紧急任务仍未解除。`;
|
|
440
456
|
case 'ability.ready':
|
|
441
457
|
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”现在可以使用。`;
|
|
442
458
|
case 'ability.remaining_uses_changed':
|
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
} from './event-hints.js';
|
|
12
12
|
|
|
13
13
|
describe('Mailbox-owned Event hint registries', () => {
|
|
14
|
-
it('keeps
|
|
14
|
+
it('keeps 31 backend hint formatters and classifies 15 Agent Events as unregistered', () => {
|
|
15
15
|
const unregistered = CLAWCLAW_BACKEND_AGENT_EVENT_TYPES.filter((type) => (
|
|
16
16
|
BACKEND_EVENT_HINT_FORMATTERS[type] === undefined
|
|
17
17
|
));
|
|
18
18
|
|
|
19
|
-
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(
|
|
19
|
+
expect(Object.keys(BACKEND_EVENT_HINT_FORMATTERS)).toHaveLength(31);
|
|
20
20
|
expect(unregistered).toEqual([
|
|
21
21
|
'task_completed',
|
|
22
22
|
'task_sabotaged',
|
|
@@ -56,6 +56,27 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
56
56
|
)).toContain('Do not retry matchmaking');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
it('uses private second-person emergency guidance and authoritative killer roles', () => {
|
|
60
|
+
expect(formatCanonicalEventHint(
|
|
61
|
+
{ producer: 'backend_push' },
|
|
62
|
+
{
|
|
63
|
+
type: 'emergency_interrupted',
|
|
64
|
+
actor_name: 'Alpha',
|
|
65
|
+
task_name: 'repair reactor',
|
|
66
|
+
},
|
|
67
|
+
)).toBe('You died while resolving repair reactor. The emergency is still active and needs another response.');
|
|
68
|
+
expect(formatCanonicalEventHint(
|
|
69
|
+
{ producer: 'backend_push' },
|
|
70
|
+
{
|
|
71
|
+
type: 'killed',
|
|
72
|
+
killer_kind: 'player',
|
|
73
|
+
killer_name: 'Alpha',
|
|
74
|
+
killer_seat: 2,
|
|
75
|
+
killer_role: 'crab_assassin',
|
|
76
|
+
},
|
|
77
|
+
)).toBe('YOU ARE DEAD: seat 2 Alpha (Assassin Crab) removed you from play.');
|
|
78
|
+
});
|
|
79
|
+
|
|
59
80
|
it('classifies Source and Derived lifecycle Events with list changes factual-only', () => {
|
|
60
81
|
const excluded = new Set(['robot_speak_rule', 'strategy_alert']);
|
|
61
82
|
const sourceTypes = CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter((type) => (
|
|
@@ -310,7 +331,7 @@ describe('Mailbox-owned Event hint registries', () => {
|
|
|
310
331
|
...Object.values(DERIVED_EVENT_HINT_FORMATTERS).map((formatter) => formatter(sample, {})),
|
|
311
332
|
].filter((hint): hint is string => typeof hint === 'string');
|
|
312
333
|
|
|
313
|
-
expect(hints).toHaveLength(
|
|
334
|
+
expect(hints).toHaveLength(51);
|
|
314
335
|
for (const hint of hints) expect(hint).not.toMatch(/[一-鿿]/);
|
|
315
336
|
});
|
|
316
337
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRoomMode, isTrainingRoomMode } from '../lib/room.js';
|
|
2
|
+
import { roleDisplayName } from './role-display.js';
|
|
2
3
|
|
|
3
4
|
export interface EventHintContext {
|
|
4
5
|
summary?: any | null;
|
|
@@ -38,6 +39,12 @@ function nonEmptyString(value: unknown): string | undefined {
|
|
|
38
39
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function killerRoleSuffix(event: Record<string, any>): string {
|
|
43
|
+
if (event.killer_kind === 'system') return '';
|
|
44
|
+
const role = roleDisplayName(event.killer_role, 'en');
|
|
45
|
+
return role ? ` (${role})` : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
/** Defensive recipient check for a backend event that contradicts witness semantics. */
|
|
42
49
|
export function isSelfKillerMurderWitnessed(
|
|
43
50
|
event: Record<string, any>,
|
|
@@ -168,7 +175,7 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
168
175
|
+ "Blood is on the floor, one voice is gone, and the killer's side moves closer to victory."
|
|
169
176
|
),
|
|
170
177
|
killed: (event) => (
|
|
171
|
-
`YOU ARE DEAD: ${optionalSeatPlayerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']))} removed you from play.`
|
|
178
|
+
`YOU ARE DEAD: ${optionalSeatPlayerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']))}${killerRoleSuffix(event)} removed you from play.`
|
|
172
179
|
),
|
|
173
180
|
murder_witnessed: (event, ctx) => (
|
|
174
181
|
isSelfKillerMurderWitnessed(event, ctx.summary)
|
|
@@ -188,11 +195,18 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
188
195
|
octopus_time_start: () => (
|
|
189
196
|
'⚠️ OCTOPUS TIME. At most three players remain; if the Octopus survives 60 seconds, it wins. Meetings are disabled, but Lobster task completion or an emergency timeout can still end the match first.'
|
|
190
197
|
),
|
|
191
|
-
|
|
192
|
-
`
|
|
193
|
-
+ `
|
|
194
|
-
+ `${text(event.timeout_secs, '30')}s until Crabs turn sabotage into victory. Any surviving role can complete this real emergency repair; act according to your win condition now.`
|
|
198
|
+
task_interrupted: (event) => (
|
|
199
|
+
`Your sabotage task ${text(event.task_name, 'your task')} was interrupted because an emergency started. `
|
|
200
|
+
+ `The task was not consumed; wait for the authoritative shared cooldown${event.cooldown_remaining_secs === undefined ? '' : ` (${text(event.cooldown_remaining_secs)}s remaining)`}.`
|
|
195
201
|
),
|
|
202
|
+
emergency_started: (event) => {
|
|
203
|
+
const cause = event.cause === 'sabotage'
|
|
204
|
+
? "A Crab completed the paired sabotage task here and activated this emergency; the saboteur's identity is not exposed. "
|
|
205
|
+
: '';
|
|
206
|
+
return `EMERGENCY: ${text(event.task_name, 'A sabotage')} detonated in ${text(event.room, 'somewhere')} `
|
|
207
|
+
+ `at ${coordPair(event.x ?? event.task_x, event.y ?? event.task_y)}. ${cause}`
|
|
208
|
+
+ `${text(event.timeout_secs, '30')}s until Crabs turn sabotage into victory. Any surviving role can complete this real emergency repair; act according to your win condition now.`;
|
|
209
|
+
},
|
|
196
210
|
emergency_resolved: (event) => {
|
|
197
211
|
const taskName = text(event.task_name, 'The emergency');
|
|
198
212
|
if (event.reason === 'meeting_started') {
|
|
@@ -204,7 +218,7 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
204
218
|
return `${taskName} was resolved. The repairer's identity is not visible to you. Crab pressure collapses, for now.`;
|
|
205
219
|
},
|
|
206
220
|
emergency_interrupted: (event) => (
|
|
207
|
-
|
|
221
|
+
`You died while resolving ${text(event.task_name, 'the emergency')}. `
|
|
208
222
|
+ 'The emergency is still active and needs another response.'
|
|
209
223
|
),
|
|
210
224
|
exile: (event) => (
|
|
@@ -139,6 +139,43 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
139
139
|
expect(wire.target).toEqual({ seat: 5, name: 'agent_5' });
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
+
it('preserves sabotage cause and private task interruption facts without internal routing fields', () => {
|
|
143
|
+
expect(normalizeGameSyncEvent({
|
|
144
|
+
event_id: 'emergency-1',
|
|
145
|
+
tick: 70,
|
|
146
|
+
type: 'emergency_started',
|
|
147
|
+
actor: null,
|
|
148
|
+
cause: 'sabotage',
|
|
149
|
+
task_id: '1011',
|
|
150
|
+
task_name: '稳定反应堆',
|
|
151
|
+
})).toMatchObject({
|
|
152
|
+
tick: 70,
|
|
153
|
+
type: 'emergency_started',
|
|
154
|
+
cause: 'sabotage',
|
|
155
|
+
task_id: '1011',
|
|
156
|
+
task_name: '稳定反应堆',
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const interrupted = normalizeGameSyncEvent({
|
|
160
|
+
event_id: 'interrupted-1',
|
|
161
|
+
tick: 70,
|
|
162
|
+
type: 'task_interrupted',
|
|
163
|
+
task_id: '102',
|
|
164
|
+
task_name: '投放毒药',
|
|
165
|
+
reason: 'emergency_started',
|
|
166
|
+
cooldown_remaining_secs: 100,
|
|
167
|
+
});
|
|
168
|
+
expect(interrupted).toEqual({
|
|
169
|
+
tick: 70,
|
|
170
|
+
type: 'task_interrupted',
|
|
171
|
+
task_id: '102',
|
|
172
|
+
task_name: '投放毒药',
|
|
173
|
+
reason: 'emergency_started',
|
|
174
|
+
cooldown_remaining_secs: 100,
|
|
175
|
+
});
|
|
176
|
+
expect(interrupted).not.toHaveProperty('_recipient_agent_id');
|
|
177
|
+
});
|
|
178
|
+
|
|
142
179
|
it('projects every semantic single-player field without retaining wire objects', () => {
|
|
143
180
|
const normalized = normalizeGameSyncEvent({
|
|
144
181
|
event_id: '6e1ec10d-77a3-4632-935d-b12e8a894fef',
|
|
@@ -182,6 +219,8 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
182
219
|
type: 'killed',
|
|
183
220
|
actor: { seat: 4, name: 'victim' },
|
|
184
221
|
killer: { kind: 'player', player: { seat: 2, name: 'killer' } },
|
|
222
|
+
killer_role: 'crab_assassin',
|
|
223
|
+
killer_faction: 'crab',
|
|
185
224
|
room: 'engine',
|
|
186
225
|
});
|
|
187
226
|
expect(playerKilled).toMatchObject({
|
|
@@ -190,10 +229,12 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
190
229
|
killer_kind: 'player',
|
|
191
230
|
killer_name: 'killer',
|
|
192
231
|
killer_seat: 2,
|
|
232
|
+
killer_role: 'crab_assassin',
|
|
233
|
+
killer_faction: 'crab',
|
|
193
234
|
});
|
|
194
235
|
expect(playerKilled).not.toHaveProperty('killer');
|
|
195
236
|
expect(presentCanonicalEvent(canonical(playerKilled), null).hint)
|
|
196
|
-
.toBe('YOU ARE DEAD: seat 2 killer removed you from play.');
|
|
237
|
+
.toBe('YOU ARE DEAD: seat 2 killer (Assassin Crab) removed you from play.');
|
|
197
238
|
|
|
198
239
|
const systemKilled = normalizeGameSyncEvent({
|
|
199
240
|
event_id: 'system-killed',
|
|
@@ -215,6 +256,13 @@ describe('GameSync v2 Event normalization', () => {
|
|
|
215
256
|
.toBe('YOU ARE DEAD: Shrimp God removed you from play.');
|
|
216
257
|
});
|
|
217
258
|
|
|
259
|
+
it('rejects malformed killed role metadata', () => {
|
|
260
|
+
expect(() => normalizeGameSyncEvent({ type: 'killed', killer_role: {} }))
|
|
261
|
+
.toThrow('GameSync Event.killer_role must be a non-empty string');
|
|
262
|
+
expect(() => normalizeGameSyncEvent({ type: 'killed', killer_faction: '' }))
|
|
263
|
+
.toThrow('GameSync Event.killer_faction must be a non-empty string');
|
|
264
|
+
});
|
|
265
|
+
|
|
218
266
|
it('rejects malformed structured killers', () => {
|
|
219
267
|
expect(() => normalizeGameSyncEvent({
|
|
220
268
|
type: 'killed', killer: { kind: 'player', player: { seat: 2 } },
|
|
@@ -194,6 +194,15 @@ export function normalizeGameSyncEvent(value: unknown): Record<string, any> {
|
|
|
194
194
|
if (raw !== null && raw !== undefined) Object.assign(normalized, projectKiller(raw));
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
if (normalized.type === 'killed') {
|
|
198
|
+
for (const field of ['killer_role', 'killer_faction'] as const) {
|
|
199
|
+
if (!Object.hasOwn(normalized, field)) continue;
|
|
200
|
+
if (typeof normalized[field] !== 'string' || normalized[field].length === 0) {
|
|
201
|
+
throw new TypeError(`GameSync Event.${field} must be a non-empty string`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
197
206
|
for (const field of PLAYER_REF_ARRAY_FIELDS) {
|
|
198
207
|
if (!Object.hasOwn(normalized, field)) continue;
|
|
199
208
|
normalized[field] = playerRefArray(normalized[field], `GameSync Event.${field}`);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type RoleDisplayLocale = 'en' | 'zh-CN';
|
|
2
|
+
|
|
3
|
+
const ROLE_DISPLAY_NAMES: Readonly<Record<string, Readonly<Record<RoleDisplayLocale, string>>>> = Object.freeze({
|
|
4
|
+
generic: { en: 'Generic', 'zh-CN': '通用身份' },
|
|
5
|
+
shrimp_generic: { en: 'Shrimp', 'zh-CN': '普通虾' },
|
|
6
|
+
shrimp_warrior: { en: 'Warrior Shrimp', 'zh-CN': '武士虾' },
|
|
7
|
+
shrimp_pistol: { en: 'Pistol Shrimp', 'zh-CN': '枪虾' },
|
|
8
|
+
shrimp_krill: { en: 'Krill', 'zh-CN': '磷虾' },
|
|
9
|
+
shrimp_pipi: { en: 'Mantis Shrimp', 'zh-CN': '皮皮虾' },
|
|
10
|
+
crab_generic: { en: 'Crab', 'zh-CN': '蟹' },
|
|
11
|
+
crab_assassin: { en: 'Assassin Crab', 'zh-CN': '刺客蟹' },
|
|
12
|
+
crab_honest: { en: 'Honest Crab', 'zh-CN': '诚实蟹' },
|
|
13
|
+
crab_spy: { en: 'Spy Crab', 'zh-CN': '间谍蟹' },
|
|
14
|
+
neutral_paradise_fish: { en: 'Paradise Fish', 'zh-CN': '天堂鱼' },
|
|
15
|
+
neutral_jellyfish: { en: 'Jellyfish', 'zh-CN': '水母' },
|
|
16
|
+
neutral_octopus: { en: 'Octopus', 'zh-CN': '章鱼' },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function roleDisplayName(value: unknown, locale: RoleDisplayLocale): string | undefined {
|
|
20
|
+
if (typeof value !== 'string' || value.length === 0) return undefined;
|
|
21
|
+
return ROLE_DISPLAY_NAMES[value]?.[locale] ?? value;
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type AgentAbilityId = 'kill'
|
|
1
|
+
export type AgentAbilityId = 'kill';
|
|
2
2
|
|
|
3
3
|
export interface AgentAbilityState extends Record<string, unknown> {
|
|
4
4
|
id: AgentAbilityId;
|
|
@@ -65,25 +65,5 @@ export function projectAgentAbilities(summary: Record<string, any>): AgentAbilit
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const sabotage = summary.crab_sabotage
|
|
69
|
-
&& typeof summary.crab_sabotage === 'object'
|
|
70
|
-
&& !Array.isArray(summary.crab_sabotage)
|
|
71
|
-
? summary.crab_sabotage as Record<string, any>
|
|
72
|
-
: null;
|
|
73
|
-
const sabotageStatus = nonEmptyString(sabotage?.status);
|
|
74
|
-
if (sabotageStatus) {
|
|
75
|
-
const cooldown = finiteNumber(sabotage?.cooldown_remaining_secs);
|
|
76
|
-
abilities.push({
|
|
77
|
-
id: 'trigger_alarm',
|
|
78
|
-
name: '触发警报',
|
|
79
|
-
ready: actionablePhase && alive && sabotageStatus === 'ready',
|
|
80
|
-
...(cooldown === undefined
|
|
81
|
-
? {}
|
|
82
|
-
: { cooldown_remaining_secs: Math.max(0, cooldown) }),
|
|
83
|
-
remaining_uses: null,
|
|
84
|
-
status: sabotageStatus,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
68
|
return abilities.length > 0 ? abilities : undefined;
|
|
89
69
|
}
|
|
@@ -52,6 +52,8 @@ describe('ClawClaw Monitor Event policy', () => {
|
|
|
52
52
|
it('does not hold decision Events behind an artificial delay', () => {
|
|
53
53
|
expect(clawclawMonitorDelayMs('kill')).toBe(0);
|
|
54
54
|
expect(clawclawMonitorDelayMs('emergency_started')).toBe(0);
|
|
55
|
+
expect(clawclawMonitorPriority('task_interrupted')).toBe(95);
|
|
56
|
+
expect(clawclawMonitorDelayMs('task_interrupted')).toBe(0);
|
|
55
57
|
expect(clawclawMonitorDelayMs('corpse_spotted')).toBe(0);
|
|
56
58
|
expect(clawclawMonitorDelayMs('speech')).toBe(0);
|
|
57
59
|
});
|