@myclaw163/clawclaw-cli 0.8.34 → 0.8.35
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/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -1
- package/skills/clawclaw/references/COMMANDS.md +2 -0
- package/skills/clawclaw/references/STREAM.md +2 -0
- package/src/commands/load.ts +6 -0
- package/src/runtime/clawclaw/behavior-input.ts +5 -3
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +64 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +3 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +3 -1
- package/src/runtime/clawclaw/runtime-state.ts +4 -2
- package/src/runtime/clawclaw/task-choice-projection.ts +93 -0
- package/src/sdk/module-input/index.ts +1 -0
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始或继续普通匹配、创建或加入好友房,以及进入模拟训练或木桩训练。Use when the user asks to play/start/join/continue a ClawClaw match, friend room, or training room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”“训练一下”“模拟训练”“木桩测试”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.109
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -136,6 +136,8 @@ ccl load
|
|
|
136
136
|
|
|
137
137
|
`ccl load` 返回紧凑的 `ccl.load.v2` JSON:`{ schema, context, sync, changes?, capabilities, configuration_warnings, participation }`。`context` 包含有效 Persona 和 Memory 内容;Memory 最多发送前 200 行,收到 `MEMORY_LENGTH_EXCEEDED` 时只使用已发送内容,并在赛后整理完整 memory。`sync` 表示 Hub Workspace 新鲜度;`changes.cloud_sync` 报告 CCL 自动创建私有资源、新版本或 fork 的成功、失败与冲突;Agent 不执行上传,也不在上传前询问。`capabilities.selection_required` 是首次发现的纯本地资源:先用 `declared_id`、`working_copy_path`、`resource_id` 和作者信息确认玩家指的是哪一项,只询问一次是否装配,再执行返回 guidance 中带 `selection_ref` 的 `ccl capability equip` 或 `ccl capability unequip`,保存后不重复询问。资源展示优先使用英文 metadata,只有中文 metadata 时保留中文原文。本地修改优先使用;普通资源无并发差异时 CCL 自动上传。云端直接 fork 出自己的 B 而原 A 有 B 尚未包含的本地修改时,即使 B 仍是旧版,也保留本地并让玩家选择 `ccl capability resolve ... --use local|cloud|later`。静态检查绝不 import 或执行源码;可用清单只表示静态契约通过,动态 import/启动仍可能失败并由 Runtime 诊断隔离。`participation` 是执行当刻的后端快照;字段缺失时不要猜。
|
|
138
138
|
|
|
139
|
+
`capabilities.skills` 列出当前账号已装配的辅助 Skill 名称。先与当前可用 Skill 列表按名称匹配,只对匹配到的 Skill 按宿主正常 Skill 读取流程逐个阅读。不在可用列表中的直接忽略,不尝试读取或自行查找文件;可简短告知玩家,不阻塞开局。
|
|
140
|
+
|
|
139
141
|
`ccl load` 的同步结果按下面规则处理,不自行扩展状态机:
|
|
140
142
|
|
|
141
143
|
- `changes.skills.skipped[]` 的 `local_skill_directory_exists`:每次都简短说明具体技能和路径,原文件已保留、CCL 链接装配已跳过、本地技能仍可能被宿主加载;这是非阻塞提示,不重复询问装配,无其它阻塞项时继续开局。equip/unequip 返回同类 `skipped[]` 时也如此处理。
|
|
@@ -52,6 +52,8 @@ ccl trigger disable <id> # 禁用并尝试热应用到当前
|
|
|
52
52
|
|
|
53
53
|
`ccl load` 返回紧凑的 `ccl.load.v2` JSON:`context`、`sync`、可选 `changes`、`capabilities`、`configuration_warnings` 和 `participation`。`changes.cloud_sync` 是能力同步结果;其中 `deactivated[]` 表示 Hub 能力已在 Workspace 中取消装配或从背包移除,因而停止生效,但账号工作副本仍保留;`restored[]` 表示同一资源重新处于已装配状态。资源是否公开不单独决定本地是否激活。`skipped[].reason=local_origin_unrecognized` 表示本地副本缺少可信来源基线,继续使用但不自动上传。`capabilities.selection_required` 是只需选择一次的本地装配项。`capabilities.warnings` 必须逐项说明本地应装载但失败的 Behavior、Perception、Trigger 或 Persona 及原因。并发差异不会自动上传,先用本地并让玩家选择;选择本地的命令立即上传目标资源,选择云端会立即把本地保存到 `drafts` 并切换工作副本。`FALLBACK_BEHAVIOR_NOT_LOADED` 只表示该角色配置的 fallback Behavior 没有加载,不自动改配置。这些命令只静态读取 Manifest,绝不 import 或执行源码;可用清单不代表模块已经运行。
|
|
54
54
|
|
|
55
|
+
`capabilities.skills` 每次返回当前账号已装配的辅助 Skill 名称数组,无装配时为 `[]`。先与当前可用 Skill 列表按名称匹配,只对匹配到的 Skill 按宿主正常 Skill 读取流程逐个阅读。不在可用列表中的直接忽略,不尝试读取或自行查找文件;可简短告知玩家,不阻塞开局。
|
|
56
|
+
|
|
55
57
|
用户提示规则固定为:`conflicts` / `selection_required` 必须说明并等待选择;`warnings` / `failed` 必须说明具体资源和原因,但非必需资源失败不阻塞开局;`workspace_updated` / `downloaded` / `uploaded` 必须简短说明同步结果;`deactivated` 必须说明已停止生效但本地副本保留,`restored` 简短说明恢复;`skipped: local_origin_unrecognized` 必须说明继续使用本地且未上传。
|
|
56
58
|
|
|
57
59
|
`WORKSPACE_SYNC_FAILED` 会说明 Workspace 同步错误及旧快照回退;`WORKSPACE_INVENTORY_UNAVAILABLE` 表示本次无法确认背包,自动云端写入暂停。`uploaded` 和 `failed: equipment` 同时出现表示内容已保存、装配未完成,不应重复创建资源。失败的装配请求不会自动重放覆盖后来的 Hub 选择;重新 equip/unequip 后再次 load。自己的资源自动更新递增 patch 版本,更新说明为“本地修改同步”。
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# 流与事件查询
|
|
2
2
|
|
|
3
|
+
当前 CCL 的公开任务视图会结合破坏技能状态筛选:蟹的破坏技能未就绪(冷却、紧急任务期间或状态未知)时,未开始的破坏任务不作为 Agent、Behavior 或任务查询的可选项。伪装任务和紧急维修保留;正在执行、已完成的条目用于结果确认,不能当作新任务重做。技能恢复 ready 后,仍分配的未完成破坏任务自动重新出现。后端原始完整分配清单仍保存在 Runtime 数据中,不因这个公开视图过滤而删除。
|
|
4
|
+
|
|
3
5
|
## 1. 一条长流、一种 Monitor 输出
|
|
4
6
|
|
|
5
7
|
`ccl start match`、`ccl start room`、`ccl start training`、`ccl join` 和 `ccl join room` 都会启动当前参与的唯一前台 Runtime 长进程。它在同一个进程生命周期中持有后端连接、事件、Behavior 控制栈和通知输出。不要为同一账号重复启动,也不要用轮询代替它。
|
package/src/commands/load.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
capabilityWorkspacePath,
|
|
61
61
|
classifyStrategyLifecycle,
|
|
62
62
|
pendingCapabilitySelections,
|
|
63
|
+
readCapabilityWorkspaceRegistry,
|
|
63
64
|
registerDiscoveredCapability,
|
|
64
65
|
capabilityEntryForPath,
|
|
65
66
|
capabilityEntryForHubResource,
|
|
@@ -897,6 +898,10 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
897
898
|
unchanged: cloudChanges?.unchanged ?? [],
|
|
898
899
|
} : undefined;
|
|
899
900
|
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
901
|
+
const skills = [...new Set(Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
902
|
+
.filter((entry) => entry.type === 'skill' && entry.selection === 'equipped'
|
|
903
|
+
&& !entry.hub?.cloudStatus && entry.runtimeId !== 'clawclaw')
|
|
904
|
+
.map((entry) => entry.runtimeId))].sort();
|
|
900
905
|
console.log(JSON.stringify({
|
|
901
906
|
schema: LOAD_SCHEMA,
|
|
902
907
|
context: {
|
|
@@ -916,6 +921,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
916
921
|
} : {}),
|
|
917
922
|
capabilities: {
|
|
918
923
|
summary: capabilitySummary,
|
|
924
|
+
skills,
|
|
919
925
|
behaviors: behaviors.map((entry) => {
|
|
920
926
|
const source = behaviorSourceById.get(entry.id)!;
|
|
921
927
|
const localized = resolveClawclawResourceMetadata(source, LOAD_DISPLAY_LOCALE);
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
} from '../../sdk/module-input/index.js';
|
|
8
8
|
import type { RuntimeEpochPluginInput } from '../framework/plugins/contracts.js';
|
|
9
9
|
import { isClawclawRuntimeState } from './runtime-state.js';
|
|
10
|
+
import { projectTaskChoiceGameState, projectTaskChoiceEventPayload } from './task-choice-projection.js';
|
|
10
11
|
|
|
11
12
|
function deepFreeze<T>(value: T): T {
|
|
12
13
|
if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
|
|
@@ -17,13 +18,14 @@ function deepFreeze<T>(value: T): T {
|
|
|
17
18
|
|
|
18
19
|
function behaviorEvents(
|
|
19
20
|
input: RuntimeEpochPluginInput<Record<string, any>>,
|
|
21
|
+
gameState: GameState,
|
|
20
22
|
): readonly Readonly<GameEvent>[] {
|
|
21
23
|
return input.pendingEvents.map((event) => ({
|
|
22
24
|
eventId: event.eventId,
|
|
23
25
|
...(event.epochSeq === undefined ? {} : { epochId: event.epochSeq }),
|
|
24
26
|
type: event.type,
|
|
25
27
|
occurredAt: event.occurredAt,
|
|
26
|
-
payload:
|
|
28
|
+
payload: projectTaskChoiceEventPayload(gameState, event.type, event.payload),
|
|
27
29
|
}));
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -32,7 +34,7 @@ export function createCanonicalGameState(
|
|
|
32
34
|
source: Readonly<Record<string, unknown>>,
|
|
33
35
|
domainTick?: unknown,
|
|
34
36
|
): GameState {
|
|
35
|
-
const gameState =
|
|
37
|
+
const gameState = projectTaskChoiceGameState(source) as unknown as GameState;
|
|
36
38
|
if (typeof domainTick === 'number' && Number.isFinite(domainTick)) {
|
|
37
39
|
(gameState as { tick?: number }).tick = domainTick;
|
|
38
40
|
}
|
|
@@ -68,7 +70,7 @@ export function createBehaviorInput<
|
|
|
68
70
|
},
|
|
69
71
|
nowMs: input.frame.observedAtMs ?? input.frame.receivedAtMs,
|
|
70
72
|
gameState,
|
|
71
|
-
events: behaviorEvents(input),
|
|
73
|
+
events: behaviorEvents(input, gameState),
|
|
72
74
|
input: structuredClone(behaviorInput),
|
|
73
75
|
// The Owner ring exposes one recursively immutable snapshot. Serial modules
|
|
74
76
|
// can share it directly; Worker postMessage performs the one required clone.
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
RuntimeEpochPluginResult,
|
|
22
22
|
} from '../../../framework/plugins/index.js';
|
|
23
23
|
import { isClawclawRuntimeState, type ClawclawRuntimeStage } from '../../runtime-state.js';
|
|
24
|
+
import { sabotageTaskActionBlocked } from '../../task-choice-projection.js';
|
|
24
25
|
|
|
25
26
|
export const CLAWCLAW_ACTION_PLUGIN_ID = 'clawclaw.action';
|
|
26
27
|
export const CLAWCLAW_ACTION_CAPABILITY = 'clawclaw.action';
|
|
@@ -271,6 +272,11 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
271
272
|
private connection: 'connected' | 'reconnecting' | 'disconnected' = 'disconnected';
|
|
272
273
|
private noteAgentActivity?: () => void;
|
|
273
274
|
private diagnostic?: RuntimeEpochPluginContext<Record<string, any>>['diagnostic'];
|
|
275
|
+
private latestTaskGameState?: {
|
|
276
|
+
scopeKey: string;
|
|
277
|
+
epochSeq: number;
|
|
278
|
+
state: Record<string, any>;
|
|
279
|
+
};
|
|
274
280
|
private readonly ownedSettlements = new Map<string, Promise<ActionResult>>();
|
|
275
281
|
/**
|
|
276
282
|
* Automated callers may receive a queued receipt before HTTP settlement.
|
|
@@ -290,6 +296,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
290
296
|
|
|
291
297
|
start(context: RuntimeEpochPluginContext<Record<string, any>>): void {
|
|
292
298
|
if (this.unregister) throw new Error('Clawclaw Action Plugin is already started.');
|
|
299
|
+
this.latestTaskGameState = undefined;
|
|
293
300
|
this.stage = context.currentSegment().kind === 'room_lobby' ? 'room' : 'matching';
|
|
294
301
|
this.diagnostic = context.diagnostic;
|
|
295
302
|
this.detailCapture = new DetailCapture('actions', context.diagnostic);
|
|
@@ -303,9 +310,14 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
303
310
|
}
|
|
304
311
|
|
|
305
312
|
update(input: RuntimeEpochPluginInput<Record<string, any>>): RuntimeEpochPluginResult {
|
|
313
|
+
const scopeKey = this.automatedProviderQueueKey(input.epoch.scope);
|
|
314
|
+
if (this.latestTaskGameState?.scopeKey !== scopeKey) this.latestTaskGameState = undefined;
|
|
306
315
|
if (isClawclawRuntimeState(input.epoch.state)) {
|
|
307
316
|
this.stage = input.epoch.state.stage;
|
|
308
317
|
this.connection = input.epoch.state.connection;
|
|
318
|
+
if (input.epoch.state.game_snapshot.status === 'fresh') {
|
|
319
|
+
this.rememberTaskGameState(input.epoch.scope, input.epoch.epochSeq, input.epoch.state.game_snapshot.state);
|
|
320
|
+
}
|
|
309
321
|
}
|
|
310
322
|
return { outcome: 'noop', reason: 'no_action_request' };
|
|
311
323
|
}
|
|
@@ -314,6 +326,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
314
326
|
this.unregister?.();
|
|
315
327
|
this.unregister = undefined;
|
|
316
328
|
this.diagnostic = undefined;
|
|
329
|
+
this.latestTaskGameState = undefined;
|
|
317
330
|
this.automatedProviderStarts.clear();
|
|
318
331
|
this.automatedProviderQueueDepths.clear();
|
|
319
332
|
}
|
|
@@ -322,6 +335,53 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
322
335
|
return `${scope.sessionId}:${scope.segmentId}`;
|
|
323
336
|
}
|
|
324
337
|
|
|
338
|
+
private rememberTaskGameState(scope: ScopeRef, epochSeq: number, state: Record<string, any>): void {
|
|
339
|
+
const scopeKey = this.automatedProviderQueueKey(scope);
|
|
340
|
+
if (this.latestTaskGameState?.scopeKey === scopeKey
|
|
341
|
+
&& this.latestTaskGameState.epochSeq > epochSeq) return;
|
|
342
|
+
this.latestTaskGameState = { scopeKey, epochSeq, state: structuredClone(state) };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private taskAdmissionRejection(
|
|
346
|
+
request: ClawclawActionRequest,
|
|
347
|
+
scope: ScopeRef,
|
|
348
|
+
actionId: string,
|
|
349
|
+
context: ActionExecutionContext,
|
|
350
|
+
): ActionResult | undefined {
|
|
351
|
+
if (request.action.action !== 'task') return undefined;
|
|
352
|
+
const scopeKey = this.automatedProviderQueueKey(scope);
|
|
353
|
+
if (this.latestTaskGameState?.scopeKey !== scopeKey) this.latestTaskGameState = undefined;
|
|
354
|
+
const latest = context.latestAcceptedState();
|
|
355
|
+
const runtimeState = latest?.state;
|
|
356
|
+
let game: Record<string, any> | undefined;
|
|
357
|
+
if (isClawclawRuntimeState(runtimeState)) {
|
|
358
|
+
if (runtimeState.game_snapshot.status === 'fresh') {
|
|
359
|
+
game = runtimeState.game_snapshot.state;
|
|
360
|
+
this.rememberTaskGameState(scope, latest!.epochSeq, game);
|
|
361
|
+
} else if (runtimeState.game_snapshot.status === 'not_updated'
|
|
362
|
+
&& runtimeState.connection === 'connected') {
|
|
363
|
+
// Control-only epochs retain the last authoritative game observation.
|
|
364
|
+
game = this.latestTaskGameState?.state;
|
|
365
|
+
}
|
|
366
|
+
if (runtimeState.connection !== 'connected') game = undefined;
|
|
367
|
+
} else if (runtimeState) {
|
|
368
|
+
game = runtimeState;
|
|
369
|
+
this.rememberTaskGameState(scope, latest!.epochSeq, game);
|
|
370
|
+
}
|
|
371
|
+
// An unavailable snapshot may retain task identity for rejection, but can
|
|
372
|
+
// never borrow a previous ready status to authorize sabotage.
|
|
373
|
+
if (!game && this.latestTaskGameState) {
|
|
374
|
+
game = { ...this.latestTaskGameState.state, crab_sabotage: undefined };
|
|
375
|
+
}
|
|
376
|
+
if (!sabotageTaskActionBlocked(game, request.action.task_name)) return undefined;
|
|
377
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
378
|
+
error: {
|
|
379
|
+
code: 'SABOTAGE_NOT_READY',
|
|
380
|
+
message: 'The sabotage task requires the current shared sabotage state to be ready.',
|
|
381
|
+
},
|
|
382
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
383
|
+
}
|
|
384
|
+
|
|
325
385
|
private enqueueAutomatedSubmission(
|
|
326
386
|
request: ClawclawActionRequest,
|
|
327
387
|
scope: ScopeRef,
|
|
@@ -472,6 +532,8 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
472
532
|
): ActionResult | undefined {
|
|
473
533
|
const stale = this.automationSafetyRejection(request, scope, actionId, caller, context);
|
|
474
534
|
if (stale) return stale;
|
|
535
|
+
const taskRejected = this.taskAdmissionRejection(request, scope, actionId, context);
|
|
536
|
+
if (taskRejected) return taskRejected;
|
|
475
537
|
if (caller.kind === 'behavior') {
|
|
476
538
|
// A queued Behavior Action is owned by its exact activation controller
|
|
477
539
|
// until the endpoint starts. Suspension, replacement, or restart must
|
|
@@ -519,6 +581,8 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
519
581
|
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
520
582
|
}
|
|
521
583
|
} else {
|
|
584
|
+
const taskRejected = this.taskAdmissionRejection(request, scope, actionId, context);
|
|
585
|
+
if (taskRejected) return taskRejected;
|
|
522
586
|
const targetPreparation = prepareActionTarget(action);
|
|
523
587
|
if ('failure' in targetPreparation) {
|
|
524
588
|
return actionResult(scope, actionId, 'failure', undefined, {
|
|
@@ -4,6 +4,7 @@ import type { ReminderInput, ReminderResult, ReminderTopic, ReminderTaskChange }
|
|
|
4
4
|
import type { ResolvedClawclawPerceptionSource } from '../perception/perception-source.js';
|
|
5
5
|
import { freshClawclawGameState } from '../../runtime-state.js';
|
|
6
6
|
import { createCanonicalGameState } from '../../behavior-input.js';
|
|
7
|
+
import { projectTaskChoiceEventPayload } from '../../task-choice-projection.js';
|
|
7
8
|
import { ObservationFrameProjector } from '../../observation-frame-projector.js';
|
|
8
9
|
import { REMINDER_EVENT_TYPES, REMINDER_EVENT_TYPE_BY_TOPIC, REMINDER_FACT_TYPES, REMINDER_TOPICS } from './reminder-rules.js';
|
|
9
10
|
import { ReminderRunner } from './reminder-runner.js';
|
|
@@ -90,7 +91,8 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
|
|
|
90
91
|
next.previousTick = undefined; next.previousConnectionId = undefined;
|
|
91
92
|
}
|
|
92
93
|
next.previousConnectionId = input.epoch.connectionId;
|
|
93
|
-
const facts = input.pendingEvents
|
|
94
|
+
const facts = input.pendingEvents.map(event => ({ ...event,
|
|
95
|
+
payload: projectTaskChoiceEventPayload(game, event.type, event.payload) }));
|
|
94
96
|
const events: RuntimeEventProposal[] = [];
|
|
95
97
|
const taskChanges: ReminderTaskChange[] = facts.filter(e => e.type === 'tasks_changed').flatMap(e => {
|
|
96
98
|
const delta = Array.isArray(e.payload.delta) ? e.payload.delta : [];
|
|
@@ -11,6 +11,7 @@ import type {
|
|
|
11
11
|
RuntimeEpochPluginResult,
|
|
12
12
|
} from '../../../framework/plugins/index.js';
|
|
13
13
|
import { isClawclawRuntimeState } from '../../runtime-state.js';
|
|
14
|
+
import { projectTaskChoices, projectTaskChoiceLocations } from '../../task-choice-projection.js';
|
|
14
15
|
import {
|
|
15
16
|
CLAWCLAW_MAP_CAPABILITY,
|
|
16
17
|
CLAWCLAW_PATH_DISTANCE_CAPABILITY,
|
|
@@ -63,7 +64,7 @@ export function clawclawTasksFromGameState(
|
|
|
63
64
|
gameState: Record<string, any> | null | undefined,
|
|
64
65
|
): readonly Record<string, any>[] | null {
|
|
65
66
|
const tasks = gameState?.you?.tasks;
|
|
66
|
-
return Array.isArray(tasks) ? structuredClone(tasks) : null;
|
|
67
|
+
return Array.isArray(tasks) ? structuredClone(projectTaskChoices(gameState, tasks)) : null;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
function clawclawPlayersFromGameState(
|
|
@@ -84,6 +85,7 @@ export function clawclawMapFromGameState(
|
|
|
84
85
|
const tasks = clawclawTasksFromGameState(gameState);
|
|
85
86
|
return {
|
|
86
87
|
...structuredClone(PACKAGED_MAP),
|
|
88
|
+
all_task_locations: structuredClone(projectTaskChoiceLocations(gameState, PACKAGED_MAP.all_task_locations)),
|
|
87
89
|
all_players: clawclawPlayersFromGameState(gameState),
|
|
88
90
|
...(tasks === null ? {} : { your_tasks: tasks }),
|
|
89
91
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { projectTaskChoiceGameState } from './task-choice-projection.js';
|
|
2
|
+
|
|
1
3
|
export type ClawclawRuntimeStage =
|
|
2
4
|
| 'matching'
|
|
3
5
|
| 'room'
|
|
@@ -80,9 +82,9 @@ export function isClawclawRuntimeState(value: unknown): value is ClawclawRuntime
|
|
|
80
82
|
export function projectClawclawCurrentState(
|
|
81
83
|
state: Record<string, any>,
|
|
82
84
|
): Record<string, any> | null {
|
|
83
|
-
if (!isClawclawRuntimeState(state)) return state;
|
|
85
|
+
if (!isClawclawRuntimeState(state)) return projectTaskChoiceGameState(state);
|
|
84
86
|
if (state.connection !== 'connected') return null;
|
|
85
|
-
if (state.game_snapshot.status === 'fresh') return
|
|
87
|
+
if (state.game_snapshot.status === 'fresh') return projectTaskChoiceGameState(state.game_snapshot.state);
|
|
86
88
|
if (state.stage === 'room' && state.room) return structuredClone(state.room);
|
|
87
89
|
if (state.stage === 'matching' && state.queue) return structuredClone(state.queue);
|
|
88
90
|
return null;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { loadClawclawMapAsset } from '../../lib/game-context.js';
|
|
2
|
+
|
|
3
|
+
type RecordValue = Readonly<Record<string, any>>;
|
|
4
|
+
const record = (value: unknown): RecordValue => value && typeof value === 'object' && !Array.isArray(value)
|
|
5
|
+
? value as RecordValue : {};
|
|
6
|
+
const label = (value: unknown): string => typeof value === 'string' ? value.trim().normalize('NFC').toLocaleLowerCase() : '';
|
|
7
|
+
const taskName = (task: RecordValue): string => label(task.name ?? task.task_name);
|
|
8
|
+
const catalog = (loadClawclawMapAsset().tasks ?? []) as readonly RecordValue[];
|
|
9
|
+
|
|
10
|
+
export function isCrabPlayer(game: unknown): boolean {
|
|
11
|
+
const self = record(record(game).you);
|
|
12
|
+
return self.faction === 'crab' || self.role === 'crab_generic';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function crabSabotageReady(game: unknown): boolean {
|
|
16
|
+
const state = record(game), sabotage = record(state.crab_sabotage);
|
|
17
|
+
return sabotage.status === 'ready' && record(state.emergency).active !== true
|
|
18
|
+
&& !(typeof sabotage.cooldown_remaining_secs === 'number' && sabotage.cooldown_remaining_secs > 0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function staticTaskType(task: RecordValue): number | undefined {
|
|
22
|
+
const name = taskName(task);
|
|
23
|
+
if (!name) return undefined;
|
|
24
|
+
const matches = catalog.filter(candidate => label(candidate.name) === name);
|
|
25
|
+
const room = label(task.room);
|
|
26
|
+
const selected = matches.find(candidate => room && label(candidate.room) === room) ?? (matches.length === 1 ? matches[0] : undefined);
|
|
27
|
+
return selected ? Number(selected.task_type) : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Classify this player's task, not another player's role or a shared coordinate. */
|
|
31
|
+
export function isSabotageTask(game: unknown, value: unknown): boolean {
|
|
32
|
+
if (!isCrabPlayer(game)) return false;
|
|
33
|
+
const task = record(value), emergency = record(record(game).emergency);
|
|
34
|
+
if (task.is_fake_shrimp === true) return false;
|
|
35
|
+
if (emergency.active === true && taskName(task) && taskName(task) === label(emergency.task_name)) return false;
|
|
36
|
+
const type = staticTaskType(task);
|
|
37
|
+
if (type === 0 || type === 2) return false;
|
|
38
|
+
if (type === 1 || task.faction === 'crab' || task.task_type === 1) return true;
|
|
39
|
+
// GameSync's crab assignments are sabotage or fake shrimp, plus active repair.
|
|
40
|
+
// The false marker also covers renamed/localized sabotage names absent from the packaged map.
|
|
41
|
+
return task.is_fake_shrimp === false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ongoingTask(game: unknown, task: RecordValue): boolean {
|
|
45
|
+
const activity = record(record(record(game).you).activity);
|
|
46
|
+
return activity.kind === 'task' && taskName(task) && taskName(task) === label(activity.task_name) ? true : false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Keep execution/completion facts; omit unstarted sabotage choices until authoritative readiness. */
|
|
50
|
+
export function projectTaskChoices<T extends RecordValue>(game: unknown, tasks: readonly T[]): T[] {
|
|
51
|
+
return tasks.flatMap(task => {
|
|
52
|
+
if (!isSabotageTask(game, task) || crabSabotageReady(game)) return [task];
|
|
53
|
+
if (task.status === 'completed' || task.status === 'in_progress') return [task];
|
|
54
|
+
// Activity is an authoritative execution fact even if its task-status update lags.
|
|
55
|
+
if (ongoingTask(game, task)) return [{ ...task, status: 'in_progress' } as T];
|
|
56
|
+
return [];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A public projection only. Persisted Source snapshots and task-change history remain untouched. */
|
|
61
|
+
export function projectTaskChoiceGameState<T extends Record<string, any>>(source: T): T {
|
|
62
|
+
const game: Record<string, any> = structuredClone(source);
|
|
63
|
+
if (Array.isArray(game.you?.tasks)) game.you.tasks = projectTaskChoices(source, game.you.tasks);
|
|
64
|
+
return game as T;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Map task locations are not assignments, but must not recreate blocked sabotage choices. */
|
|
68
|
+
export function projectTaskChoiceLocations<T extends RecordValue>(game: unknown, locations: readonly T[]): T[] {
|
|
69
|
+
return locations.filter(task => !isSabotageTask(game, task) || crabSabotageReady(game));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Current assignment arrays in module input follow the same policy; occurrence facts survive. */
|
|
73
|
+
export function projectTaskChoiceEventPayload(game: unknown, type: string, payload: RecordValue): Record<string, any> {
|
|
74
|
+
const result: Record<string, any> = structuredClone(payload);
|
|
75
|
+
if (type === 'tasks_changed') {
|
|
76
|
+
if (Array.isArray(result.tasks)) result.tasks = projectTaskChoices(game, result.tasks);
|
|
77
|
+
if (Array.isArray(result.delta)) result.delta = result.delta.filter(change =>
|
|
78
|
+
change.change === 'removed' || projectTaskChoices(game, [record(change.task)]).length > 0);
|
|
79
|
+
}
|
|
80
|
+
if (result.newly_assigned_task && projectTaskChoices(game, [record(result.newly_assigned_task)]).length === 0) {
|
|
81
|
+
delete result.newly_assigned_task;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Also reject stale/remembered task names at the Action boundary, before HTTP submission. */
|
|
87
|
+
export function sabotageTaskActionBlocked(game: unknown, name: unknown): boolean {
|
|
88
|
+
if (!isCrabPlayer(game) || crabSabotageReady(game) || !label(name)) return false;
|
|
89
|
+
const state = record(game), tasks = record(state.you).tasks;
|
|
90
|
+
const assigned = Array.isArray(tasks) ? tasks.filter(task => taskName(record(task)) === label(name)) : [];
|
|
91
|
+
if (assigned.length) return assigned.some(task => isSabotageTask(game, task));
|
|
92
|
+
return isSabotageTask(game, { name });
|
|
93
|
+
}
|
|
@@ -44,6 +44,7 @@ export interface GameSelf {
|
|
|
44
44
|
readonly kills_remaining?: number | null;
|
|
45
45
|
readonly activity?: Readonly<GamePlayerActivity>;
|
|
46
46
|
readonly crab_teammates?: readonly Readonly<PlayerRef>[];
|
|
47
|
+
/** Current task choices and execution/completion facts. Unstarted crab sabotage is omitted until ready. */
|
|
47
48
|
readonly tasks?: readonly Readonly<GameTask>[];
|
|
48
49
|
}
|
|
49
50
|
|