@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
|
@@ -301,4 +301,28 @@ describe('ClawclawActionPlugin automated provider FIFO', () => {
|
|
|
301
301
|
error: { error: { code: 'STALE_BEHAVIOR_ACTION' } },
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
|
+
|
|
305
|
+
it('rejects the removed trigger_alarm action locally without calling the backend', () => {
|
|
306
|
+
const client = {
|
|
307
|
+
prepareActionForConfirmedSubmission: vi.fn(),
|
|
308
|
+
submitPreparedActionConfirmed: vi.fn(),
|
|
309
|
+
} as unknown as GameClient;
|
|
310
|
+
const plugin = new ClawclawActionPlugin(client);
|
|
311
|
+
(plugin as any).connection = 'connected';
|
|
312
|
+
(plugin as any).stage = 'game';
|
|
313
|
+
const perform = (plugin as any).perform.bind(plugin) as (
|
|
314
|
+
action: ClawclawActionRequest,
|
|
315
|
+
actionScope: ScopeRef,
|
|
316
|
+
caller: ActionCaller,
|
|
317
|
+
context: ActionExecutionContext,
|
|
318
|
+
) => { status: string; error?: unknown };
|
|
319
|
+
|
|
320
|
+
expect(perform({ route: 'game', action: { action: 'trigger_alarm' } }, scope, {
|
|
321
|
+
kind: 'agent', id: 'agent-1',
|
|
322
|
+
}, actionContext())).toMatchObject({
|
|
323
|
+
status: 'failure',
|
|
324
|
+
error: { error: { code: 'TRIGGER_ALARM_REMOVED_USE_TASK' } },
|
|
325
|
+
});
|
|
326
|
+
expect(client.prepareActionForConfirmedSubmission).not.toHaveBeenCalled();
|
|
327
|
+
});
|
|
304
328
|
});
|
|
@@ -45,7 +45,6 @@ export function describeClawclawActionControl(
|
|
|
45
45
|
case 'task':
|
|
46
46
|
case 'kill':
|
|
47
47
|
case 'report':
|
|
48
|
-
case 'trigger_alarm':
|
|
49
48
|
domains = ['physical'];
|
|
50
49
|
break;
|
|
51
50
|
case 'speech':
|
|
@@ -370,6 +369,14 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
370
369
|
const staleAtStart = this.automationSafetyRejection(request, scope, actionId, caller, context);
|
|
371
370
|
if (staleAtStart) return staleAtStart;
|
|
372
371
|
const action = { ...request.action };
|
|
372
|
+
if (action.action === 'trigger_alarm') {
|
|
373
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
374
|
+
error: {
|
|
375
|
+
code: 'TRIGGER_ALARM_REMOVED_USE_TASK',
|
|
376
|
+
message: 'Crab sabotage emergencies now start when an assigned sabotage task completes.',
|
|
377
|
+
},
|
|
378
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
379
|
+
}
|
|
373
380
|
const route = request.route === 'auto'
|
|
374
381
|
? (this.stage === 'room' && action.action === 'speech' ? 'room_chat' : 'game')
|
|
375
382
|
: request.route ?? 'game';
|
|
@@ -5,7 +5,6 @@ const ACTION_FIELDS: Readonly<Record<string, readonly string[]>> = Object.freeze
|
|
|
5
5
|
task: ['action', 'task_name', 'thinking_content'],
|
|
6
6
|
report: ['action', 'thinking_content'],
|
|
7
7
|
think: ['action', 'thinking_content'],
|
|
8
|
-
trigger_alarm: ['action', 'thinking_content'],
|
|
9
8
|
});
|
|
10
9
|
|
|
11
10
|
const ERRORS: Readonly<{
|
|
@@ -27,6 +27,9 @@ describe('normalizeClawclawBehaviorAction', () => {
|
|
|
27
27
|
expect(() => normalizeClawclawBehaviorAction({
|
|
28
28
|
action: 'vote', target_seat: 3,
|
|
29
29
|
}, 12, 4, 1)).toThrowError('unsupported_behavior_action');
|
|
30
|
+
expect(() => normalizeClawclawBehaviorAction({
|
|
31
|
+
action: 'trigger_alarm',
|
|
32
|
+
}, 12, 4, 1)).toThrowError('unsupported_behavior_action');
|
|
30
33
|
});
|
|
31
34
|
|
|
32
35
|
it('requires epoch, safety, and activation-generation fences', () => {
|
|
@@ -318,13 +318,6 @@ function fallbackActionIntent(state: GoalGameState, action: Record<string, any>)
|
|
|
318
318
|
...(room ? { room } : {}),
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
|
-
if (action.action === 'trigger_alarm') {
|
|
322
|
-
return {
|
|
323
|
-
activity: 'acting',
|
|
324
|
-
summary: '正在触发紧急警报。',
|
|
325
|
-
...(room ? { room } : {}),
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
321
|
if (action.action === 'speech') {
|
|
329
322
|
return {
|
|
330
323
|
activity: 'acting',
|
|
@@ -390,8 +383,6 @@ export class OfficialGoalBehavior {
|
|
|
390
383
|
notifications: [],
|
|
391
384
|
lastProgressNotifyAt: 0,
|
|
392
385
|
teammates: new Set(),
|
|
393
|
-
alarmDone: false,
|
|
394
|
-
alarmOnCooldown: false,
|
|
395
386
|
rooms: [],
|
|
396
387
|
playerNamesBySeat: {},
|
|
397
388
|
forcePatrolAdvance: false,
|
|
@@ -143,7 +143,6 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
143
143
|
['task', ['physical']],
|
|
144
144
|
['kill', ['physical']],
|
|
145
145
|
['report', ['physical']],
|
|
146
|
-
['trigger_alarm', ['physical']],
|
|
147
146
|
['speech', ['communication']],
|
|
148
147
|
['vote', ['meeting_vote']],
|
|
149
148
|
['think', []],
|
|
@@ -40,6 +40,7 @@ describe('ClawClaw Event Catalog', () => {
|
|
|
40
40
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room_destroyed');
|
|
41
41
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('players_changed');
|
|
42
42
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('tasks_changed');
|
|
43
|
+
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('task_interrupted');
|
|
43
44
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('emergency_countdown_warning');
|
|
44
45
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('ability.ready');
|
|
45
46
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('ability.remaining_uses_changed');
|
|
@@ -65,6 +66,7 @@ describe('ClawClaw Event Catalog', () => {
|
|
|
65
66
|
}
|
|
66
67
|
for (const type of [
|
|
67
68
|
'emergency_interrupted',
|
|
69
|
+
'task_interrupted',
|
|
68
70
|
'octopus_time_win',
|
|
69
71
|
'win_blocked_by_octopus',
|
|
70
72
|
'exile_game_over',
|
|
@@ -52,6 +52,7 @@ export const CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [
|
|
|
52
52
|
'task_started',
|
|
53
53
|
'task_progress',
|
|
54
54
|
'task_completed',
|
|
55
|
+
'task_interrupted',
|
|
55
56
|
'task_sabotaged',
|
|
56
57
|
'task_assigned',
|
|
57
58
|
'kill',
|
|
@@ -100,6 +101,7 @@ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
|
|
|
100
101
|
'murder_witnessed',
|
|
101
102
|
'warrior_shrimp_self_destruct',
|
|
102
103
|
'task_completed',
|
|
104
|
+
'task_interrupted',
|
|
103
105
|
'task_sabotaged',
|
|
104
106
|
'body_dropped',
|
|
105
107
|
'corpse_spotted',
|
|
@@ -233,7 +233,7 @@ describe('runtime module loader', () => {
|
|
|
233
233
|
'task-only', 'task-report', 'warrior-memory',
|
|
234
234
|
'do_task', 'evade', 'find_player', 'follow_player', 'go_to',
|
|
235
235
|
'hide_temporarily', 'hold_position', 'hunt_player', 'inspect_corpse',
|
|
236
|
-
'patrol_area', 'report_corpse', 'seek_kill_opportunity',
|
|
236
|
+
'patrol_area', 'report_corpse', 'seek_kill_opportunity',
|
|
237
237
|
];
|
|
238
238
|
const directory = await mkdtemp(join(tmpdir(), 'clawclaw-runtime-official-worker-'));
|
|
239
239
|
temporaryDirectories.push(directory);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { Action } from './action.js';
|
|
3
|
+
|
|
4
|
+
describe('Action compatibility shims', () => {
|
|
5
|
+
it('rejects the removed triggerAlarm helper locally with migration guidance', () => {
|
|
6
|
+
expect(() => Action.triggerAlarm()).toThrow('trigger_alarm_removed_use_task');
|
|
7
|
+
});
|
|
8
|
+
});
|
package/src/sdk/action.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Action — an immutable, typed game command sent to the server each tick.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* instances.
|
|
4
|
+
* Active static factories (`move`, `kill`, `speech`, …) return frozen `Action`
|
|
5
|
+
* instances. Retired compatibility helpers throw migration errors locally.
|
|
6
|
+
* Attach spectator-visible reasoning with `.withThinking(content)`,
|
|
6
7
|
* which returns a new `Action` without mutating the original.
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
@@ -121,11 +122,12 @@ export class Action {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
125
|
+
* @deprecated Sabotage emergencies now start automatically when a Crab
|
|
126
|
+
* completes one of its assigned sabotage tasks. Submit the existing task
|
|
127
|
+
* action instead.
|
|
126
128
|
*/
|
|
127
|
-
static triggerAlarm():
|
|
128
|
-
|
|
129
|
+
static triggerAlarm(): never {
|
|
130
|
+
throw new Error('trigger_alarm_removed_use_task');
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
/**
|
|
@@ -204,8 +204,7 @@ export type GameAction =
|
|
|
204
204
|
| (GameActionBase & { readonly action: 'speech'; readonly text: string })
|
|
205
205
|
| (GameActionBase & { readonly action: 'task'; readonly task_name?: string })
|
|
206
206
|
| (GameActionBase & { readonly action: 'report' })
|
|
207
|
-
| (GameActionBase & { readonly action: 'think' })
|
|
208
|
-
| (GameActionBase & { readonly action: 'trigger_alarm' });
|
|
207
|
+
| (GameActionBase & { readonly action: 'think' });
|
|
209
208
|
|
|
210
209
|
/** Module status published beside Game State; it never patches authoritative Game State. */
|
|
211
210
|
export interface BehaviorStatus {
|
|
@@ -29,6 +29,7 @@ export interface BehaviorTaskPoint extends Position {
|
|
|
29
29
|
readonly name: string;
|
|
30
30
|
readonly room?: string;
|
|
31
31
|
readonly status?: string;
|
|
32
|
+
readonly isFakeShrimp?: boolean;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export interface NamedPoint extends Position {
|
|
@@ -165,6 +166,7 @@ function taskPoint(task: Readonly<GameTask>): BehaviorTaskPoint {
|
|
|
165
166
|
x: task.x,
|
|
166
167
|
y: task.y,
|
|
167
168
|
...(task.status ? { status: task.status } : {}),
|
|
169
|
+
isFakeShrimp: task.is_fake_shrimp,
|
|
168
170
|
};
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -35,7 +35,6 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
35
35
|
notifications: [],
|
|
36
36
|
lastProgressNotifyAt: Date.now(),
|
|
37
37
|
teammates: new Set(),
|
|
38
|
-
alarmDone: false,
|
|
39
38
|
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
40
39
|
playerNamesBySeat: {},
|
|
41
40
|
forcePatrolAdvance: false,
|
|
@@ -3,7 +3,7 @@ import type { GameState, TaskInfo } from '../../sdk/types.js';
|
|
|
3
3
|
import type { StrategyContext } from '../types.js';
|
|
4
4
|
import { CrabSabotageTop } from './crab-sabotage-top.js';
|
|
5
5
|
|
|
6
|
-
type SabotageStatus = '
|
|
6
|
+
type SabotageStatus = 'ready' | 'cooldown_charged' | 'emergency_active';
|
|
7
7
|
|
|
8
8
|
function state(status: SabotageStatus): GameState {
|
|
9
9
|
return {
|
|
@@ -52,7 +52,6 @@ function context(tasks: TaskInfo[] = []): StrategyContext {
|
|
|
52
52
|
notifications: [],
|
|
53
53
|
lastProgressNotifyAt: Date.now(),
|
|
54
54
|
teammates: new Set(),
|
|
55
|
-
alarmDone: false,
|
|
56
55
|
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
57
56
|
playerNamesBySeat: {},
|
|
58
57
|
forcePatrolAdvance: false,
|
|
@@ -70,40 +69,28 @@ function selectedAction(top: CrabSabotageTop, game: GameState, ctx: StrategyCont
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
describe('CrabSabotageTop shared sabotage state', () => {
|
|
73
|
-
it('
|
|
72
|
+
it('moves toward an assigned sabotage task while authoritative state is ready', () => {
|
|
74
73
|
const top = new CrabSabotageTop();
|
|
75
74
|
const game = state('ready');
|
|
76
|
-
const ctx = context();
|
|
75
|
+
const ctx = context([task()]);
|
|
77
76
|
|
|
78
77
|
const action = selectedAction(top, game, ctx);
|
|
79
78
|
|
|
80
|
-
expect(action?.type).toBe('
|
|
81
|
-
expect(
|
|
79
|
+
expect(action?.type).toBe('move');
|
|
80
|
+
expect(action?.payload).toMatchObject({ target_x: 100, target_y: 0 });
|
|
82
81
|
});
|
|
83
82
|
|
|
84
|
-
it('
|
|
83
|
+
it('submits the existing task action at a sabotage point and never emits trigger_alarm', () => {
|
|
85
84
|
const top = new CrabSabotageTop();
|
|
86
85
|
const game = state('ready');
|
|
87
|
-
const ctx = context();
|
|
86
|
+
const ctx = context([task({ x: 5 })]);
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
expect(
|
|
88
|
+
const action = selectedAction(top, game, ctx);
|
|
89
|
+
expect(action?.type).toBe('task');
|
|
90
|
+
expect(action?.payload).toMatchObject({ task_name: 'charge-alarm' });
|
|
91
|
+
expect(action?.type).not.toBe('trigger_alarm');
|
|
91
92
|
});
|
|
92
93
|
|
|
93
|
-
it.each(['unprepared', 'cooldown_unprepared'] as const)(
|
|
94
|
-
'continues preparing the shared sabotage while status is %s',
|
|
95
|
-
status => {
|
|
96
|
-
const top = new CrabSabotageTop();
|
|
97
|
-
const game = state(status);
|
|
98
|
-
const ctx = context([task()]);
|
|
99
|
-
|
|
100
|
-
const action = selectedAction(top, game, ctx);
|
|
101
|
-
|
|
102
|
-
expect(action?.type).toBe('move');
|
|
103
|
-
expect(action?.payload).toMatchObject({ target_x: 100, target_y: 0 });
|
|
104
|
-
},
|
|
105
|
-
);
|
|
106
|
-
|
|
107
94
|
it('skips personal sabotage work while shared charge is waiting on cooldown', () => {
|
|
108
95
|
const top = new CrabSabotageTop();
|
|
109
96
|
const game = state('cooldown_charged');
|
|
@@ -139,7 +126,6 @@ describe('CrabSabotageTop shared sabotage state', () => {
|
|
|
139
126
|
|
|
140
127
|
const action = selectedAction(top, game, ctx);
|
|
141
128
|
|
|
142
|
-
expect(action?.type).not.toBe('trigger_alarm');
|
|
143
129
|
expect(action?.type).not.toBe('task');
|
|
144
130
|
});
|
|
145
131
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { GameState, TaskInfo } from '../../sdk/types.js';
|
|
2
|
-
import { Action } from '../../sdk/action.js';
|
|
3
2
|
import {
|
|
4
3
|
approachOrDoTaskStep,
|
|
5
4
|
firstAvailableTask,
|
|
@@ -7,7 +6,6 @@ import {
|
|
|
7
6
|
nonTeammatesVisible,
|
|
8
7
|
PatrolState,
|
|
9
8
|
PROGRESS_INTERVAL_MS,
|
|
10
|
-
strategyDecision,
|
|
11
9
|
} from '../game-utils.js';
|
|
12
10
|
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
13
11
|
import { Goal } from './goal.js';
|
|
@@ -18,10 +16,6 @@ import { EmergencyHuntGoal } from './emergency-hunt-goal.js';
|
|
|
18
16
|
import { emitLeaf, setBehavior, URGENT_GOAL_PRIORITY, WANDER_GOAL_PRIORITY } from './leaf-goal.js';
|
|
19
17
|
import { corpseReportWithNonTeammate, immediateLoneKillDecision } from './crab-octopus-reflexes.js';
|
|
20
18
|
|
|
21
|
-
// 撞上 trigger_alarm 的 20s 阵营共享 CD 被服务端拒(on_cooldown)后,本地退避多久再补打。
|
|
22
|
-
// 退避期下沉去做任务/猎杀,避免原地空刷 trigger_alarm;远小于 CD,故 CD 一到很快补上。
|
|
23
|
-
const ALARM_RETRY_BACKOFF_MS = 4_000;
|
|
24
|
-
|
|
25
19
|
/**
|
|
26
20
|
* 蟹的「破坏 + 落单猎杀 + 任务伪装」编排 top。本身不产决策,每 tick 自上而下判定该走哪条分支、
|
|
27
21
|
* 把对应**叶子子目标**挂为唯一子目标(产出动作的是叶子;URGENT/WANDER 优先级供 ConversationGoal 判断):
|
|
@@ -29,9 +23,8 @@ const ALARM_RETRY_BACKOFF_MS = 4_000;
|
|
|
29
23
|
* 0a. 反射·立刻出刀(crab-octopus-reflexes,URGENT):落单非队友贴脸(出刀范围内)且刀好 → 立刻出刀,
|
|
30
24
|
* 无视暂停窗口、不管自己是否正在做破坏任务。
|
|
31
25
|
* 0b. 反射·报尸(crab-octopus-reflexes,URGENT):有尸体且附近有非队友 → 报警/靠近报警,不管尸体是谁造成的。
|
|
32
|
-
* 1a.
|
|
33
|
-
* 1b.
|
|
34
|
-
* 1c. 正在做任务(doing_task)→ 本 tick 不产决策,不撇下任务去猎杀(0a 的贴脸反射刀仍生效)。
|
|
26
|
+
* 1a. 服务端状态 ready → 去做真实破坏任务;完成后服务端自动触发一一对应的紧急任务。
|
|
27
|
+
* 1b. 正在做任务(doing_task)→ 本 tick 不产决策,不撇下任务去猎杀(0a 的贴脸反射刀仍生效)。
|
|
35
28
|
* 2. 落单猎杀(LoneKillGoal,URGENT):assess 判 hunt(刀好且有落单目标)→ 叶子 pursue;
|
|
36
29
|
* 刀在冷却时 assess 返回 idle,不追不等,直接下沉到破坏/任务/巡逻。
|
|
37
30
|
* 3. 紧急期搜猎(EmergencyHuntGoal,URGENT):往人少处找真正落单的,永远有动作(不在人前乱杀)。
|
|
@@ -40,9 +33,6 @@ const ALARM_RETRY_BACKOFF_MS = 4_000;
|
|
|
40
33
|
export class CrabSabotageTop extends Goal {
|
|
41
34
|
private readonly killCore = new LoneKillCore();
|
|
42
35
|
private readonly patrol = new PatrolState();
|
|
43
|
-
// state.crab_sabotage.ready 可能跨多个 tick 保持不变;同一 ready 阶段只提交一次。
|
|
44
|
-
private alarmTriggeredForCurrentReady = false;
|
|
45
|
-
private alarmRetryBlockedUntil = 0;
|
|
46
36
|
private readonly loneKillGoal = new LoneKillGoal(this.killCore);
|
|
47
37
|
private readonly emergencyHuntGoal = new EmergencyHuntGoal(this.killCore, this.patrol);
|
|
48
38
|
private readonly wanderGoal = new WanderTaskGoal(
|
|
@@ -59,9 +49,6 @@ export class CrabSabotageTop extends Goal {
|
|
|
59
49
|
|
|
60
50
|
onMeetingResume(): void {
|
|
61
51
|
this.killCore.reset();
|
|
62
|
-
// 散会会重置阵营共享 CD;下一次权威状态变为 ready 时必须允许重新触发。
|
|
63
|
-
this.alarmTriggeredForCurrentReady = false;
|
|
64
|
-
this.alarmRetryBlockedUntil = 0;
|
|
65
52
|
}
|
|
66
53
|
|
|
67
54
|
tick(state: GameState, ctx: StrategyContext): BehaviorDecision[] {
|
|
@@ -73,11 +60,7 @@ export class CrabSabotageTop extends Goal {
|
|
|
73
60
|
const corpseReport = corpseReportWithNonTeammate(state, ctx);
|
|
74
61
|
if (corpseReport) return emitLeaf(this, corpseReport, URGENT_GOAL_PRIORITY);
|
|
75
62
|
|
|
76
|
-
// 1a.
|
|
77
|
-
const alarm = this.trySabotageAlarm(state, ctx);
|
|
78
|
-
if (alarm) return emitLeaf(this, alarm, URGENT_GOAL_PRIORITY);
|
|
79
|
-
|
|
80
|
-
// 1b. 去做真实破坏任务(游走类工作;到点遇阻返回 null → 下沉去猎杀,故可回退)
|
|
63
|
+
// 1a. ready 表示当前可执行蟹破坏任务;任务完成后服务端自动触发紧急任务。
|
|
81
64
|
const crabTask = this.tryCrabTask(state, ctx);
|
|
82
65
|
if (crabTask) return emitLeaf(this, crabTask, WANDER_GOAL_PRIORITY);
|
|
83
66
|
|
|
@@ -100,45 +83,7 @@ export class CrabSabotageTop extends Goal {
|
|
|
100
83
|
return setBehavior(this, this.wanderGoal, WANDER_GOAL_PRIORITY);
|
|
101
84
|
}
|
|
102
85
|
|
|
103
|
-
// ── 1a.
|
|
104
|
-
private trySabotageAlarm(state: GameState, ctx: StrategyContext): BehaviorDecision[] | null {
|
|
105
|
-
if (state.you.faction !== 'crab') return null;
|
|
106
|
-
if (ctx.emergency) return null;
|
|
107
|
-
|
|
108
|
-
const now = Date.now();
|
|
109
|
-
|
|
110
|
-
// 上一发 trigger_alarm 撞了阵营共享 CD:撤掉本地 ready 阶段去重并退避几秒。
|
|
111
|
-
// 服务端会在共享 CD 结束后把状态切回 ready,届时再补打;退避期继续做别的,不原地空刷。
|
|
112
|
-
if (ctx.alarmOnCooldown) {
|
|
113
|
-
this.alarmTriggeredForCurrentReady = false;
|
|
114
|
-
this.alarmRetryBlockedUntil = now + ALARM_RETRY_BACKOFF_MS;
|
|
115
|
-
// 一次性事件信号,消费即清:否则重试因破坏被解/开会/正做任务而没再提交下一发时,标记会滞留 true。
|
|
116
|
-
ctx.alarmOnCooldown = false;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const sabotageStatus = state.crab_sabotage?.status;
|
|
120
|
-
if (sabotageStatus !== 'ready') {
|
|
121
|
-
// cooldown_charged 表示共享破坏已装填但仍在冷却;不再要求本人完成一项破坏任务。
|
|
122
|
-
// unprepared/cooldown_unprepared 才由 tryCrabTask 继续准备;emergency_active 也不触发。
|
|
123
|
-
this.alarmTriggeredForCurrentReady = false;
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
if (now < this.alarmRetryBlockedUntil) return null;
|
|
127
|
-
if (this.alarmTriggeredForCurrentReady) return null;
|
|
128
|
-
|
|
129
|
-
if (!state.you.doing_task) {
|
|
130
|
-
this.alarmTriggeredForCurrentReady = true;
|
|
131
|
-
ctx.alarmDone = true;
|
|
132
|
-
ctx.notifications.push('阵营共享破坏已装填,触发紧急警报(撞阵营冷却会被拒、冷却好自动补打);警报期照样会被举报,只清落单目标。');
|
|
133
|
-
return [strategyDecision(Action.triggerAlarm(), {
|
|
134
|
-
activity: 'acting',
|
|
135
|
-
summary: '阵营共享破坏已装填,正在触发紧急警报。',
|
|
136
|
-
})];
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ── 1b. 去做真实破坏任务(破坏点紧挨已知尸体时跳过;到点遇阻返回 null,让上层回退去猎杀)──
|
|
86
|
+
// ── 1a. 去做真实破坏任务(破坏点紧挨已知尸体时跳过;到点遇阻返回 null,让上层回退去猎杀)──
|
|
142
87
|
private tryCrabTask(state: GameState, ctx: StrategyContext): BehaviorDecision[] | null {
|
|
143
88
|
if (state.you.faction !== 'crab') return null;
|
|
144
89
|
if (ctx.emergency) return null;
|
|
@@ -161,8 +106,7 @@ export class CrabSabotageTop extends Goal {
|
|
|
161
106
|
}
|
|
162
107
|
|
|
163
108
|
private shouldPrepareSabotage(state: GameState): boolean {
|
|
164
|
-
|
|
165
|
-
return status === 'unprepared' || status === 'cooldown_unprepared';
|
|
109
|
+
return state.crab_sabotage?.status === 'ready';
|
|
166
110
|
}
|
|
167
111
|
|
|
168
112
|
private emitProgress(state: GameState, ctx: StrategyContext): void {
|
|
@@ -42,7 +42,6 @@ function context(): StrategyContext {
|
|
|
42
42
|
notifications: [],
|
|
43
43
|
lastProgressNotifyAt: Date.now(),
|
|
44
44
|
teammates: new Set(),
|
|
45
|
-
alarmDone: false,
|
|
46
45
|
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
47
46
|
playerNamesBySeat: { '2': 'target', '3': 'witness' },
|
|
48
47
|
forcePatrolAdvance: false,
|
|
@@ -47,7 +47,6 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
47
47
|
notifications: [],
|
|
48
48
|
lastProgressNotifyAt: Date.now(),
|
|
49
49
|
teammates: new Set(),
|
|
50
|
-
alarmDone: false,
|
|
51
50
|
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
52
51
|
playerNamesBySeat: {},
|
|
53
52
|
forcePatrolAdvance: false,
|
|
@@ -35,7 +35,6 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
35
35
|
notifications: [],
|
|
36
36
|
lastProgressNotifyAt: Date.now(),
|
|
37
37
|
teammates: new Set(),
|
|
38
|
-
alarmDone: false,
|
|
39
38
|
rooms: [],
|
|
40
39
|
playerNamesBySeat: { '2': 'stranger' },
|
|
41
40
|
forcePatrolAdvance: false,
|
|
@@ -35,7 +35,6 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
35
35
|
notifications: [],
|
|
36
36
|
lastProgressNotifyAt: Date.now(),
|
|
37
37
|
teammates: new Set(),
|
|
38
|
-
alarmDone: false,
|
|
39
38
|
rooms: [
|
|
40
39
|
{ name: 'danger-route', x: 1602, y: 1402 },
|
|
41
40
|
{ name: 'safe-route', x: 2602, y: 586 },
|
|
@@ -39,7 +39,6 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
39
39
|
notifications: [],
|
|
40
40
|
lastProgressNotifyAt: Date.now(),
|
|
41
41
|
teammates: new Set(),
|
|
42
|
-
alarmDone: false,
|
|
43
42
|
rooms: [{ name: 'patrol', x: 500, y: 0 }],
|
|
44
43
|
playerNamesBySeat: { '2': 'target' },
|
|
45
44
|
forcePatrolAdvance: false,
|
package/src/strategies/types.ts
CHANGED
|
@@ -86,12 +86,6 @@ export interface StrategyContext {
|
|
|
86
86
|
notifications: string[];
|
|
87
87
|
lastProgressNotifyAt: number;
|
|
88
88
|
teammates: Set<string>;
|
|
89
|
-
alarmDone: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* loop→蟹策略回传:上一发 trigger_alarm 是否撞了 20s 阵营共享 CD 被服务端拒(on_cooldown)。
|
|
92
|
-
* 蟹策略据此撤销乐观去重标记并退避补打;仅 crab-sabotage 用,其余策略不涉及,故可选。
|
|
93
|
-
*/
|
|
94
|
-
alarmOnCooldown?: boolean;
|
|
95
89
|
rooms: RoomTarget[];
|
|
96
90
|
playerNamesBySeat: Record<string, string>;
|
|
97
91
|
/** Set by the Goal strategy host when a move target is repeatedly unreachable. */
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawBehavior,
|
|
3
|
-
type BehaviorInput,
|
|
4
|
-
type BehaviorNormalizationApi,
|
|
5
|
-
type ClawclawBehaviorManifest,
|
|
6
|
-
} from '../../sdk/behavior-plugin/index.js';
|
|
7
|
-
import { behaviorHasEvent } from '../../sdk/behavior-toolkit/index.js';
|
|
8
|
-
import { finished, running } from './shared.js';
|
|
9
|
-
|
|
10
|
-
type AlarmInput = Readonly<Record<string, unknown>> & { readonly timeout_ms?: number };
|
|
11
|
-
|
|
12
|
-
export default class TriggerAlarmBehavior extends ClawclawBehavior<AlarmInput> {
|
|
13
|
-
static override readonly manifest = {
|
|
14
|
-
apiVersion: 3,
|
|
15
|
-
id: 'trigger_alarm',
|
|
16
|
-
name: 'Trigger Alarm',
|
|
17
|
-
description: 'Submit one role-valid shared emergency alarm and await authority.',
|
|
18
|
-
localizations: { 'zh-CN': { name: '触发警报', description: '提交一次角色允许的共享紧急警报并等待权威结果。' } },
|
|
19
|
-
inputs: [],
|
|
20
|
-
execution: 'serial',
|
|
21
|
-
runtime: { defaultMs: 10_000, deadlineOutcome: 'failed' },
|
|
22
|
-
} as const satisfies ClawclawBehaviorManifest;
|
|
23
|
-
|
|
24
|
-
private submitted = false;
|
|
25
|
-
|
|
26
|
-
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): AlarmInput {
|
|
27
|
-
return { ...api.timing(input) };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
override decide(input: Readonly<BehaviorInput<AlarmInput>>) {
|
|
31
|
-
if (this.submitted) {
|
|
32
|
-
if (
|
|
33
|
-
input.gameState.emergency?.active === true
|
|
34
|
-
|| input.gameState.crab_sabotage?.status === 'emergency_active'
|
|
35
|
-
|| behaviorHasEvent(input.events, ['emergency_started'])
|
|
36
|
-
) return finished('completed', 'alarm_triggered', '蟹阵营紧急警报已经触发。');
|
|
37
|
-
return running('等待警报触发的权威状态;不会重复提交。', 'acting');
|
|
38
|
-
}
|
|
39
|
-
if (input.gameState.you?.faction !== 'crab') {
|
|
40
|
-
return finished('failed', 'role_cannot_trigger_alarm', '只有蟹阵营可以触发共享紧急警报。');
|
|
41
|
-
}
|
|
42
|
-
if (
|
|
43
|
-
input.gameState.emergency?.active === true
|
|
44
|
-
|| input.gameState.crab_sabotage?.status === 'emergency_active'
|
|
45
|
-
) return finished('failed', 'emergency_already_active', '当前已经有紧急事件。');
|
|
46
|
-
if (input.gameState.crab_sabotage?.status !== 'ready') {
|
|
47
|
-
return finished('failed', 'alarm_not_ready', `蟹阵营共享警报尚未就绪(${input.gameState.crab_sabotage?.status ?? 'unknown'})。`);
|
|
48
|
-
}
|
|
49
|
-
this.submitted = true;
|
|
50
|
-
const summary = '共享警报已就绪,正在触发并等待权威结果。';
|
|
51
|
-
return running(summary, 'acting', [{ action: 'trigger_alarm', thinking_content: summary }]);
|
|
52
|
-
}
|
|
53
|
-
}
|