@myclaw163/clawclaw-cli 0.8.2 → 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 +4 -4
- package/docs/custom-modules/api-reference.md +20 -10
- package/docs/custom-modules/behavior.md +10 -6
- package/docs/custom-modules/perception.md +26 -3
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/behavior-runtime.md +6 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +30 -37
- package/skills/clawclaw/references/COMMANDS.md +2 -3
- package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
- package/skills/clawclaw/references/STREAM.md +25 -10
- 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/commands/load.ts +8 -3
- package/src/commands/trigger.ts +12 -5
- package/src/lib/behavior-export.test.ts +53 -9
- package/src/lib/behavior-export.ts +26 -3
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +21 -0
- package/src/lib/trigger-export.test.ts +80 -0
- package/src/lib/trigger-export.ts +210 -0
- package/src/lib/user-data.test.ts +4 -0
- package/src/lib/user-data.ts +4 -0
- package/src/pipeline/canonical-event-presentation.test.ts +2 -0
- package/src/pipeline/event-format.test.ts +113 -0
- package/src/pipeline/event-format.ts +51 -5
- package/src/pipeline/event-hints.test.ts +28 -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 +69 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +6 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +5 -0
- package/src/runtime/clawclaw/behavior-decision.test.ts +14 -0
- package/src/runtime/clawclaw/behavior-decision.ts +8 -1
- package/src/runtime/clawclaw/behavior-input.test.ts +22 -0
- package/src/runtime/clawclaw/behavior-input.ts +3 -0
- package/src/runtime/clawclaw/owner.test.ts +16 -0
- package/src/runtime/clawclaw/owner.ts +21 -8
- 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/activation-manager.ts +1 -1
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +246 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +135 -6
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +118 -1
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +13 -2
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +156 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -1
- package/src/runtime/clawclaw-event-catalog.test.ts +6 -0
- package/src/runtime/clawclaw-event-catalog.ts +6 -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 +11 -2
- package/src/sdk/behavior-toolkit/model.ts +2 -0
- package/src/sdk/module-input/index.ts +16 -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
|
@@ -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,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ClawclawDerivedEventPlugin,
|
|
9
9
|
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
10
10
|
} from './derived-event-plugin.js';
|
|
11
|
+
import { EmergencyCountdownDerivedEventRule } from './derived-event-rules.js';
|
|
11
12
|
|
|
12
13
|
function roomState(ready: boolean, roomType = 'casual'): Record<string, any> {
|
|
13
14
|
return {
|
|
@@ -31,7 +32,11 @@ function roomState(ready: boolean, roomType = 'casual'): Record<string, any> {
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function gameState(
|
|
35
|
+
function gameState(
|
|
36
|
+
tick: number,
|
|
37
|
+
meeting?: Record<string, any>,
|
|
38
|
+
state: Record<string, any> = {},
|
|
39
|
+
): Record<string, any> {
|
|
35
40
|
return {
|
|
36
41
|
schema: 'clawclaw.runtime-state.v1',
|
|
37
42
|
stage: meeting ? 'meeting' : 'game',
|
|
@@ -43,12 +48,23 @@ function gameState(tick: number, meeting?: Record<string, any>): Record<string,
|
|
|
43
48
|
state: {
|
|
44
49
|
tick,
|
|
45
50
|
phase: meeting ? 'meeting' : 'wandering',
|
|
51
|
+
...state,
|
|
46
52
|
...(meeting ? { meeting } : {}),
|
|
47
53
|
},
|
|
48
54
|
},
|
|
49
55
|
};
|
|
50
56
|
}
|
|
51
57
|
|
|
58
|
+
function storedGameFrame(tick: number, state: Record<string, any>): any {
|
|
59
|
+
return {
|
|
60
|
+
frameSeq: tick,
|
|
61
|
+
epochSeq: tick,
|
|
62
|
+
state: gameState(tick, undefined, state),
|
|
63
|
+
observedAtMs: tick * 1_000,
|
|
64
|
+
receivedAtMs: tick * 1_000,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
async function fixture(kind: 'room' | 'game') {
|
|
53
69
|
const events = new MemoryEventRepository();
|
|
54
70
|
const runtime = new Runtime({
|
|
@@ -141,10 +157,111 @@ describe('ClawclawDerivedEventPlugin', () => {
|
|
|
141
157
|
await runtime.close();
|
|
142
158
|
});
|
|
143
159
|
|
|
160
|
+
it('emits emergency countdown warnings once at 30s and 20s', async () => {
|
|
161
|
+
const { runtime, events, submit } = await fixture('game');
|
|
162
|
+
const emergency = (remainingSecs: number) => ({
|
|
163
|
+
emergency: {
|
|
164
|
+
active: true,
|
|
165
|
+
task_name: '修复供氧',
|
|
166
|
+
room: '制氧舱',
|
|
167
|
+
remaining_secs: remainingSecs,
|
|
168
|
+
},
|
|
169
|
+
you: { is_alive: true },
|
|
170
|
+
});
|
|
171
|
+
await submit(gameState(1, undefined, emergency(31)));
|
|
172
|
+
await submit(gameState(2, undefined, emergency(29.8)));
|
|
173
|
+
await submit(gameState(3, undefined, emergency(25)));
|
|
174
|
+
await submit(gameState(4, undefined, emergency(19.7)));
|
|
175
|
+
await submit(gameState(5, undefined, emergency(18)));
|
|
176
|
+
await runtime.flush();
|
|
177
|
+
|
|
178
|
+
const warnings = events.listCommittedEvents({
|
|
179
|
+
sessionId: runtime.scope().sessionId,
|
|
180
|
+
types: ['emergency_countdown_warning'],
|
|
181
|
+
order: 'asc',
|
|
182
|
+
});
|
|
183
|
+
expect(warnings.map((event) => event.payload)).toMatchObject([{
|
|
184
|
+
tick: 2,
|
|
185
|
+
threshold_secs: 30,
|
|
186
|
+
remaining_secs: 29.8,
|
|
187
|
+
}, {
|
|
188
|
+
tick: 4,
|
|
189
|
+
threshold_secs: 20,
|
|
190
|
+
remaining_secs: 19.7,
|
|
191
|
+
}]);
|
|
192
|
+
expect(warnings.every((event) => (
|
|
193
|
+
event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
|
|
194
|
+
))).toBe(true);
|
|
195
|
+
await runtime.close();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('rebuilds countdown rule state without replay and preserves a two-threshold leap', () => {
|
|
199
|
+
const emergency = (remainingSecs: number) => ({
|
|
200
|
+
emergency: { active: true, task_name: '维修', remaining_secs: remainingSecs },
|
|
201
|
+
you: { is_alive: true },
|
|
202
|
+
});
|
|
203
|
+
const recovered = new EmergencyCountdownDerivedEventRule();
|
|
204
|
+
recovered.inspect(storedGameFrame(1, emergency(31)));
|
|
205
|
+
recovered.inspect(storedGameFrame(2, emergency(29)));
|
|
206
|
+
expect(recovered.inspect(storedGameFrame(3, emergency(25)))).toEqual([]);
|
|
207
|
+
expect(recovered.inspect(storedGameFrame(4, emergency(19))).map((event) => (
|
|
208
|
+
event.payload.threshold_secs
|
|
209
|
+
))).toEqual([20]);
|
|
210
|
+
|
|
211
|
+
const skipped = new EmergencyCountdownDerivedEventRule();
|
|
212
|
+
skipped.inspect(storedGameFrame(1, emergency(31)));
|
|
213
|
+
expect(skipped.inspect(storedGameFrame(2, emergency(19))).map((event) => (
|
|
214
|
+
event.payload.threshold_secs
|
|
215
|
+
))).toEqual([30, 20]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('emits ability readiness and finite-use changes from authoritative State transitions', async () => {
|
|
219
|
+
const { runtime, events, submit } = await fixture('game');
|
|
220
|
+
const pistol = (cooldown: number, remaining: number) => ({
|
|
221
|
+
you: {
|
|
222
|
+
role: 'shrimp_pistol',
|
|
223
|
+
is_alive: true,
|
|
224
|
+
kill_cooldown_secs: cooldown,
|
|
225
|
+
kills_remaining: remaining,
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
await submit(gameState(1, undefined, pistol(1, 1)));
|
|
229
|
+
await submit(gameState(2, undefined, pistol(0, 1)));
|
|
230
|
+
await submit(gameState(3, undefined, pistol(20, 0)));
|
|
231
|
+
await runtime.flush();
|
|
232
|
+
|
|
233
|
+
const abilityEvents = events.listCommittedEvents({
|
|
234
|
+
sessionId: runtime.scope().sessionId,
|
|
235
|
+
types: ['ability.ready', 'ability.exhausted'],
|
|
236
|
+
order: 'asc',
|
|
237
|
+
});
|
|
238
|
+
expect(abilityEvents.map((event) => ({ type: event.type, payload: event.payload })))
|
|
239
|
+
.toMatchObject([{
|
|
240
|
+
type: 'ability.ready',
|
|
241
|
+
payload: { tick: 2, ability_id: 'kill', remaining_uses: 1 },
|
|
242
|
+
}, {
|
|
243
|
+
type: 'ability.exhausted',
|
|
244
|
+
payload: {
|
|
245
|
+
tick: 3,
|
|
246
|
+
ability_id: 'kill',
|
|
247
|
+
previous_remaining_uses: 1,
|
|
248
|
+
remaining_uses: 0,
|
|
249
|
+
},
|
|
250
|
+
}]);
|
|
251
|
+
expect(abilityEvents.every((event) => (
|
|
252
|
+
event.producerPluginId === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID
|
|
253
|
+
))).toBe(true);
|
|
254
|
+
await runtime.close();
|
|
255
|
+
});
|
|
256
|
+
|
|
144
257
|
it('does not claim backend-owned terminal or turn Events', () => {
|
|
145
258
|
expect(new ClawclawDerivedEventPlugin().produces.events).toEqual([
|
|
146
259
|
'room_ready_to_start',
|
|
147
260
|
'meeting_state',
|
|
261
|
+
'emergency_countdown_warning',
|
|
262
|
+
'ability.ready',
|
|
263
|
+
'ability.remaining_uses_changed',
|
|
264
|
+
'ability.exhausted',
|
|
148
265
|
]);
|
|
149
266
|
});
|
|
150
267
|
});
|
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
} from '../../../framework/plugins/index.js';
|
|
8
8
|
import type { StoredStateFrame } from '../../../framework/state/index.js';
|
|
9
9
|
import {
|
|
10
|
+
AbilityStateDerivedEventRule,
|
|
11
|
+
EmergencyCountdownDerivedEventRule,
|
|
10
12
|
MeetingStateDerivedEventRule,
|
|
11
13
|
RoomReadyDerivedEventRule,
|
|
12
14
|
type ClawclawDerivedEventRule,
|
|
@@ -18,9 +20,16 @@ export class ClawclawDerivedEventPlugin
|
|
|
18
20
|
implements RuntimeEpochPlugin<Record<string, any>> {
|
|
19
21
|
readonly kind = 'epoch' as const;
|
|
20
22
|
readonly id = CLAWCLAW_DERIVED_EVENT_PLUGIN_ID;
|
|
21
|
-
readonly version = '
|
|
23
|
+
readonly version = '2';
|
|
22
24
|
readonly produces = {
|
|
23
|
-
events: [
|
|
25
|
+
events: [
|
|
26
|
+
'room_ready_to_start',
|
|
27
|
+
'meeting_state',
|
|
28
|
+
'emergency_countdown_warning',
|
|
29
|
+
'ability.ready',
|
|
30
|
+
'ability.remaining_uses_changed',
|
|
31
|
+
'ability.exhausted',
|
|
32
|
+
],
|
|
24
33
|
} as const;
|
|
25
34
|
readonly catchUp = 'every_epoch' as const;
|
|
26
35
|
readonly timeoutMs = 1_000;
|
|
@@ -30,6 +39,8 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
30
39
|
|
|
31
40
|
constructor(rules?: readonly ClawclawDerivedEventRule[]) {
|
|
32
41
|
this.rules = [...(rules ?? [
|
|
42
|
+
new AbilityStateDerivedEventRule(),
|
|
43
|
+
new EmergencyCountdownDerivedEventRule(),
|
|
33
44
|
new RoomReadyDerivedEventRule(),
|
|
34
45
|
new MeetingStateDerivedEventRule(),
|
|
35
46
|
])].sort((left, right) => left.id.localeCompare(right.id));
|
|
@@ -2,6 +2,10 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import type { RuntimeEventProposal } from '../../../framework/plugins/index.js';
|
|
3
3
|
import type { StoredStateFrame } from '../../../framework/state/index.js';
|
|
4
4
|
import { isClawclawRuntimeState } from '../../runtime-state.js';
|
|
5
|
+
import {
|
|
6
|
+
projectAgentAbilities,
|
|
7
|
+
type AgentAbilityState,
|
|
8
|
+
} from '../../agent-ability-state.js';
|
|
5
9
|
|
|
6
10
|
type UnknownRecord = Record<string, unknown>;
|
|
7
11
|
|
|
@@ -30,6 +34,10 @@ function sourceIdentity(frame: StoredStateFrame<Record<string, any>>): number {
|
|
|
30
34
|
return frame.epochSeq ?? frame.frameSeq;
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
function finiteNumber(value: unknown): number | undefined {
|
|
38
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
function roomSnapshot(
|
|
34
42
|
frame: StoredStateFrame<Record<string, any>>,
|
|
35
43
|
): UnknownRecord | null | undefined {
|
|
@@ -111,6 +119,154 @@ function freshGameSnapshot(
|
|
|
111
119
|
return record(state.game_snapshot.state);
|
|
112
120
|
}
|
|
113
121
|
|
|
122
|
+
const EMERGENCY_WARNING_THRESHOLDS = [30, 20] as const;
|
|
123
|
+
|
|
124
|
+
export class EmergencyCountdownDerivedEventRule implements ClawclawDerivedEventRule {
|
|
125
|
+
readonly id = 'emergency-countdown';
|
|
126
|
+
readonly eventTypes = ['emergency_countdown_warning'] as const;
|
|
127
|
+
private emergencyKey = '';
|
|
128
|
+
private remainingSecs?: number;
|
|
129
|
+
private readonly emittedThresholds = new Set<number>();
|
|
130
|
+
|
|
131
|
+
reset(): void {
|
|
132
|
+
this.emergencyKey = '';
|
|
133
|
+
this.remainingSecs = undefined;
|
|
134
|
+
this.emittedThresholds.clear();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
inspect(frame: StoredStateFrame<Record<string, any>>): RuntimeEventProposal[] {
|
|
138
|
+
const game = freshGameSnapshot(frame);
|
|
139
|
+
if (game === undefined) return [];
|
|
140
|
+
const emergency = record(game?.emergency);
|
|
141
|
+
if (emergency?.active !== true) {
|
|
142
|
+
this.reset();
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const key = JSON.stringify([
|
|
147
|
+
emergency.task_name ?? null,
|
|
148
|
+
emergency.room ?? null,
|
|
149
|
+
finiteNumber(emergency.x) ?? null,
|
|
150
|
+
finiteNumber(emergency.y) ?? null,
|
|
151
|
+
]);
|
|
152
|
+
const remainingSecs = finiteNumber(emergency.remaining_secs);
|
|
153
|
+
const sameEmergency = this.emergencyKey === key;
|
|
154
|
+
let crossed: number[] = [];
|
|
155
|
+
if (!sameEmergency) {
|
|
156
|
+
this.emergencyKey = key;
|
|
157
|
+
this.remainingSecs = undefined;
|
|
158
|
+
this.emittedThresholds.clear();
|
|
159
|
+
if (remainingSecs !== undefined) {
|
|
160
|
+
// A recovered Runtime may first observe an incident after one or more
|
|
161
|
+
// thresholds. Wake only for the nearest still-relevant threshold.
|
|
162
|
+
const nearest = [...EMERGENCY_WARNING_THRESHOLDS]
|
|
163
|
+
.reverse()
|
|
164
|
+
.find((threshold) => remainingSecs <= threshold);
|
|
165
|
+
if (nearest !== undefined) crossed = [nearest];
|
|
166
|
+
}
|
|
167
|
+
} else if (remainingSecs !== undefined && this.remainingSecs !== undefined) {
|
|
168
|
+
crossed = EMERGENCY_WARNING_THRESHOLDS.filter((threshold) => (
|
|
169
|
+
this.remainingSecs! > threshold
|
|
170
|
+
&& remainingSecs <= threshold
|
|
171
|
+
&& !this.emittedThresholds.has(threshold)
|
|
172
|
+
));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.remainingSecs = remainingSecs;
|
|
176
|
+
for (const threshold of crossed) this.emittedThresholds.add(threshold);
|
|
177
|
+
if (game?.you && record(game.you)?.is_alive === false) return [];
|
|
178
|
+
|
|
179
|
+
return crossed.map((threshold) => {
|
|
180
|
+
const payload: UnknownRecord = {
|
|
181
|
+
threshold_secs: threshold,
|
|
182
|
+
remaining_secs: remainingSecs,
|
|
183
|
+
};
|
|
184
|
+
for (const field of ['task_name', 'room'] as const) {
|
|
185
|
+
if (typeof emergency[field] === 'string') payload[field] = emergency[field];
|
|
186
|
+
}
|
|
187
|
+
if (typeof game?.tick === 'number' || typeof game?.tick === 'string') payload.tick = game.tick;
|
|
188
|
+
return {
|
|
189
|
+
type: 'emergency_countdown_warning',
|
|
190
|
+
dedupeKey: `emergency-countdown:${sourceIdentity(frame)}:${threshold}:${stableHash(key)}`,
|
|
191
|
+
dedupeScope: 'segment' as const,
|
|
192
|
+
payload,
|
|
193
|
+
occurredAt: occurredAt(frame),
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export class AbilityStateDerivedEventRule implements ClawclawDerivedEventRule {
|
|
200
|
+
readonly id = 'ability-state';
|
|
201
|
+
readonly eventTypes = [
|
|
202
|
+
'ability.ready',
|
|
203
|
+
'ability.remaining_uses_changed',
|
|
204
|
+
'ability.exhausted',
|
|
205
|
+
] as const;
|
|
206
|
+
private initialized = false;
|
|
207
|
+
private abilities: AgentAbilityState[] = [];
|
|
208
|
+
|
|
209
|
+
reset(): void {
|
|
210
|
+
this.initialized = false;
|
|
211
|
+
this.abilities = [];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
inspect(frame: StoredStateFrame<Record<string, any>>): RuntimeEventProposal[] {
|
|
215
|
+
const game = freshGameSnapshot(frame);
|
|
216
|
+
if (game === undefined) return [];
|
|
217
|
+
const current = projectAgentAbilities(game as Record<string, any>) ?? [];
|
|
218
|
+
if (!this.initialized) {
|
|
219
|
+
this.initialized = true;
|
|
220
|
+
this.abilities = structuredClone(current);
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const previousById = new Map(this.abilities.map((ability) => [ability.id, ability]));
|
|
225
|
+
const proposals: RuntimeEventProposal[] = [];
|
|
226
|
+
for (const ability of current) {
|
|
227
|
+
const previous = previousById.get(ability.id);
|
|
228
|
+
if (!previous) continue;
|
|
229
|
+
const base: UnknownRecord = {
|
|
230
|
+
ability_id: ability.id,
|
|
231
|
+
ability_name: ability.name,
|
|
232
|
+
};
|
|
233
|
+
if (typeof game?.tick === 'number' || typeof game?.tick === 'string') base.tick = game.tick;
|
|
234
|
+
if (ability.effective_range_px !== undefined) {
|
|
235
|
+
base.effective_range_px = ability.effective_range_px;
|
|
236
|
+
}
|
|
237
|
+
if (!previous.ready && ability.ready) {
|
|
238
|
+
proposals.push({
|
|
239
|
+
type: 'ability.ready',
|
|
240
|
+
dedupeKey: `ability-ready:${sourceIdentity(frame)}:${ability.id}`,
|
|
241
|
+
dedupeScope: 'segment',
|
|
242
|
+
payload: { ...base, remaining_uses: ability.remaining_uses },
|
|
243
|
+
occurredAt: occurredAt(frame),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (
|
|
247
|
+
typeof previous.remaining_uses === 'number'
|
|
248
|
+
&& typeof ability.remaining_uses === 'number'
|
|
249
|
+
&& previous.remaining_uses !== ability.remaining_uses
|
|
250
|
+
) {
|
|
251
|
+
const exhausted = ability.remaining_uses === 0;
|
|
252
|
+
proposals.push({
|
|
253
|
+
type: exhausted ? 'ability.exhausted' : 'ability.remaining_uses_changed',
|
|
254
|
+
dedupeKey: `ability-uses:${sourceIdentity(frame)}:${ability.id}:${ability.remaining_uses}`,
|
|
255
|
+
dedupeScope: 'segment',
|
|
256
|
+
payload: {
|
|
257
|
+
...base,
|
|
258
|
+
previous_remaining_uses: previous.remaining_uses,
|
|
259
|
+
remaining_uses: ability.remaining_uses,
|
|
260
|
+
},
|
|
261
|
+
occurredAt: occurredAt(frame),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
this.abilities = structuredClone(current);
|
|
266
|
+
return proposals;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
114
270
|
export class MeetingStateDerivedEventRule implements ClawclawDerivedEventRule {
|
|
115
271
|
readonly id = 'meeting-state';
|
|
116
272
|
readonly eventTypes = ['meeting_state'] as const;
|
|
@@ -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,11 @@ 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');
|
|
44
|
+
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('emergency_countdown_warning');
|
|
45
|
+
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('ability.ready');
|
|
46
|
+
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('ability.remaining_uses_changed');
|
|
47
|
+
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('ability.exhausted');
|
|
43
48
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).not.toContain('task_assigned');
|
|
44
49
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).not.toContain('heartbeat');
|
|
45
50
|
expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).not.toContain('room.snapshot');
|
|
@@ -61,6 +66,7 @@ describe('ClawClaw Event Catalog', () => {
|
|
|
61
66
|
}
|
|
62
67
|
for (const type of [
|
|
63
68
|
'emergency_interrupted',
|
|
69
|
+
'task_interrupted',
|
|
64
70
|
'octopus_time_win',
|
|
65
71
|
'win_blocked_by_octopus',
|
|
66
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',
|
|
@@ -179,6 +181,10 @@ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [
|
|
|
179
181
|
'behavior.replaced',
|
|
180
182
|
'players_changed',
|
|
181
183
|
'tasks_changed',
|
|
184
|
+
'emergency_countdown_warning',
|
|
185
|
+
'ability.ready',
|
|
186
|
+
'ability.remaining_uses_changed',
|
|
187
|
+
'ability.exhausted',
|
|
182
188
|
] as const;
|
|
183
189
|
|
|
184
190
|
/** Durable inputs used by projectors, but never sent directly to the Agent. */
|
|
@@ -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
|
/**
|
|
@@ -18,6 +18,8 @@ export type {
|
|
|
18
18
|
} from '../resource-metadata.js';
|
|
19
19
|
|
|
20
20
|
export type {
|
|
21
|
+
BehaviorContinuation,
|
|
22
|
+
BehaviorDelegatedBehaviorResult,
|
|
21
23
|
BehaviorInput,
|
|
22
24
|
BehaviorScope,
|
|
23
25
|
GameEvent,
|
|
@@ -202,8 +204,7 @@ export type GameAction =
|
|
|
202
204
|
| (GameActionBase & { readonly action: 'speech'; readonly text: string })
|
|
203
205
|
| (GameActionBase & { readonly action: 'task'; readonly task_name?: string })
|
|
204
206
|
| (GameActionBase & { readonly action: 'report' })
|
|
205
|
-
| (GameActionBase & { readonly action: 'think' })
|
|
206
|
-
| (GameActionBase & { readonly action: 'trigger_alarm' });
|
|
207
|
+
| (GameActionBase & { readonly action: 'think' });
|
|
207
208
|
|
|
208
209
|
/** Module status published beside Game State; it never patches authoritative Game State. */
|
|
209
210
|
export interface BehaviorStatus {
|
|
@@ -222,11 +223,19 @@ export interface BehaviorEventProposal {
|
|
|
222
223
|
readonly occurredAt?: string;
|
|
223
224
|
}
|
|
224
225
|
|
|
226
|
+
/** Starts one finite short Behavior from the currently running long Behavior. */
|
|
227
|
+
export interface BehaviorDelegation {
|
|
228
|
+
readonly behavior: string;
|
|
229
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
230
|
+
}
|
|
231
|
+
|
|
225
232
|
/** All semantic effects of one Behavior decision. */
|
|
226
233
|
export interface BehaviorDecision {
|
|
227
234
|
readonly actions?: readonly Readonly<GameAction>[];
|
|
228
235
|
readonly status?: Readonly<BehaviorStatus>;
|
|
229
236
|
readonly events?: readonly Readonly<BehaviorEventProposal>[];
|
|
237
|
+
/** Suspends this long Activation and starts one validated short Activation. */
|
|
238
|
+
readonly delegate?: Readonly<BehaviorDelegation>;
|
|
230
239
|
/** Ends this Activation after the Decision's preceding effects are committed. */
|
|
231
240
|
readonly finish?: Readonly<BehaviorFinish>;
|
|
232
241
|
}
|
|
@@ -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
|
|
|
@@ -88,9 +88,7 @@ export interface GameEmergency {
|
|
|
88
88
|
|
|
89
89
|
export interface GameCrabSabotage {
|
|
90
90
|
readonly status:
|
|
91
|
-
| 'unprepared'
|
|
92
91
|
| 'ready'
|
|
93
|
-
| 'cooldown_unprepared'
|
|
94
92
|
| 'cooldown_charged'
|
|
95
93
|
| 'emergency_active';
|
|
96
94
|
readonly cooldown_remaining_secs?: number;
|
|
@@ -215,6 +213,20 @@ export interface BehaviorScope {
|
|
|
215
213
|
readonly segmentId: string;
|
|
216
214
|
}
|
|
217
215
|
|
|
216
|
+
/** Runtime-owned terminal result of a short Behavior delegated by a long Behavior. */
|
|
217
|
+
export interface BehaviorDelegatedBehaviorResult {
|
|
218
|
+
readonly activationId: string;
|
|
219
|
+
readonly behavior: string;
|
|
220
|
+
readonly outcome: 'completed' | 'failed' | 'cancelled' | 'replaced';
|
|
221
|
+
readonly reason: string;
|
|
222
|
+
readonly summary?: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** One-shot input delivered when a long Behavior resumes after delegated work. */
|
|
226
|
+
export interface BehaviorContinuation {
|
|
227
|
+
readonly delegatedBehavior: Readonly<BehaviorDelegatedBehaviorResult>;
|
|
228
|
+
}
|
|
229
|
+
|
|
218
230
|
/** The input envelope shared by finite and continuous Behaviors. */
|
|
219
231
|
export interface BehaviorInput<
|
|
220
232
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
@@ -226,4 +238,6 @@ export interface BehaviorInput<
|
|
|
226
238
|
readonly gameState: Readonly<GameState>;
|
|
227
239
|
readonly events: readonly Readonly<GameEvent>[];
|
|
228
240
|
readonly input: Readonly<TInput>;
|
|
241
|
+
/** Present for the first committed decision after delegated short work ends. */
|
|
242
|
+
readonly continuation?: Readonly<BehaviorContinuation>;
|
|
229
243
|
}
|
|
@@ -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,
|