@myclaw163/clawclaw-cli 0.8.15 → 0.8.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/docs/configuration.md +7 -3
  2. package/package.json +1 -1
  3. package/scripts/sync-bundled-skill.mjs +28 -57
  4. package/skills/clawclaw/SKILL.md +23 -4
  5. package/skills/clawclaw/references/COMMANDS.md +8 -4
  6. package/skills/clawclaw/references/HUB.md +2 -1
  7. package/src/commands/account.ts +45 -1
  8. package/src/commands/behavior.ts +17 -17
  9. package/src/commands/capability.ts +39 -26
  10. package/src/commands/load.ts +156 -8
  11. package/src/commands/perception.ts +17 -16
  12. package/src/commands/persona.ts +24 -6
  13. package/src/lib/agent-workspace-client.ts +2 -0
  14. package/src/lib/agent-workspace-runtime.ts +12 -3
  15. package/src/lib/agent-workspace-skills.ts +241 -23
  16. package/src/lib/agent-workspace-sync.ts +54 -10
  17. package/src/lib/capability-cloud-presence.ts +179 -0
  18. package/src/lib/capability-cloud-refresh.ts +43 -21
  19. package/src/lib/capability-cloud-sync.ts +165 -8
  20. package/src/lib/capability-selection.ts +62 -0
  21. package/src/lib/capability-workspace.ts +6 -0
  22. package/src/lib/game-client.ts +10 -0
  23. package/src/lib/hub-client.ts +75 -0
  24. package/src/lib/persona.ts +14 -1
  25. package/src/pipeline/event-hints.ts +1 -1
  26. package/src/runtime/clawclaw/owner.ts +25 -4
  27. package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +107 -0
  28. package/src/runtime/clawclaw/plugins/mailbox/index.ts +1 -0
  29. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +12 -0
  30. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +10 -3
  31. package/src/runtime/game-sync-protocol.ts +47 -0
  32. package/src/runtime/ws-client.ts +7 -0
@@ -13,6 +13,7 @@ import {
13
13
  } from '../runtime/ws-client.js';
14
14
  import { RuntimeLogger } from '../runtime/runtime-logger.js';
15
15
  import type { RawWsMessageSink } from '../runtime/raw-ws-log.js';
16
+ import type { GameSyncPerceptionReport } from '../runtime/game-sync-protocol.js';
16
17
  import type { QueueMode } from './competition.js';
17
18
  import type {
18
19
  CreateRoomOptions,
@@ -514,6 +515,15 @@ export class GameClient {
514
515
  this.rememberGameSyncResumeState(this.ws?.resumeState);
515
516
  }
516
517
 
518
+ /** Send display-only perception output over the active GameSync connection. */
519
+ reportGameSyncPerceptions(perceptions: readonly GameSyncPerceptionReport[]): boolean {
520
+ return this.ws?.reportPerceptions(perceptions) ?? false;
521
+ }
522
+
523
+ get gameSyncLocale(): 'zh-CN' | 'en-US' {
524
+ return this.ws?.resumeState?.locale ?? this.gameSyncResumeState?.locale ?? 'zh-CN';
525
+ }
526
+
517
527
  /**
518
528
  * Try to discover game server from /queue/status.
519
529
  * If found and WS is enabled, reconnects WS to the game server.
@@ -29,6 +29,8 @@ export interface ResourceSummary {
29
29
  isInstalled: boolean;
30
30
  isOfficial: boolean;
31
31
  versionId: string;
32
+ versionNumber?: string;
33
+ versionDescription?: string;
32
34
  }
33
35
 
34
36
  export interface ResourceDetail extends ResourceSummary {
@@ -65,6 +67,13 @@ export interface WorkspaceResourceSummary {
65
67
  versionId: string;
66
68
  equipped: boolean;
67
69
  hasUpdate: boolean;
70
+ kind: 'owned' | 'installed';
71
+ isCreatedByMe: boolean;
72
+ owner: {
73
+ id: string;
74
+ name: string | null;
75
+ isOfficial: boolean;
76
+ };
68
77
  }
69
78
 
70
79
  export interface WorkspaceListResult {
@@ -74,6 +83,13 @@ export interface WorkspaceListResult {
74
83
  limit: number;
75
84
  }
76
85
 
86
+ export interface WorkspaceLoadoutUpdate {
87
+ skillItemIds?: readonly string[];
88
+ strategyItemIds?: readonly string[];
89
+ personaItemIds?: readonly string[];
90
+ perceptionItemIds?: readonly string[];
91
+ }
92
+
77
93
  const BASE = '/api/v1/hub';
78
94
 
79
95
  /** Parse a `<type>/<id>` resource ref. */
@@ -98,6 +114,8 @@ interface RawFileEntry {
98
114
 
99
115
  interface RawVersion {
100
116
  id: string;
117
+ version_number?: string;
118
+ version_description?: string;
101
119
  title: string;
102
120
  description: string;
103
121
  icon_url?: string | null;
@@ -130,6 +148,9 @@ interface RawWorkspaceItem {
130
148
  version_id: string;
131
149
  is_equipped?: boolean;
132
150
  has_update?: boolean;
151
+ kind?: 'owned' | 'installed';
152
+ is_created_by_me?: boolean;
153
+ owner?: { id?: string; name?: string | null; is_official?: boolean };
133
154
  }
134
155
 
135
156
  export interface HubSourceFileUpload {
@@ -181,6 +202,8 @@ function toSummary(resource: RawResource): ResourceSummary {
181
202
  isInstalled: resource.is_installed === true,
182
203
  isOfficial: resource.is_official === true || owner.is_official === true,
183
204
  versionId: version.id,
205
+ versionNumber: version.version_number,
206
+ versionDescription: version.version_description,
184
207
  };
185
208
  }
186
209
 
@@ -296,6 +319,13 @@ export class HubClient {
296
319
  versionId: item.version_id,
297
320
  equipped: item.is_equipped === true,
298
321
  hasUpdate: item.has_update === true,
322
+ kind: item.kind === 'owned' ? 'owned' : 'installed',
323
+ isCreatedByMe: item.is_created_by_me === true,
324
+ owner: {
325
+ id: item.owner?.id ?? '',
326
+ name: item.owner?.name ?? null,
327
+ isOfficial: item.owner?.is_official === true,
328
+ },
299
329
  })),
300
330
  nextCursor: response.data.next_cursor,
301
331
  hasMore: response.data.has_more,
@@ -322,6 +352,42 @@ export class HubClient {
322
352
  return { updated: response.data.updated, versionId: response.data.version_id };
323
353
  }
324
354
 
355
+ async updateWorkspaceEquipment(
356
+ workspaceItemId: string,
357
+ equipped: boolean,
358
+ ): Promise<{ workspaceItemId: string; equipped: boolean; revision: number; changed: boolean }> {
359
+ const response = await this.http.post<Envelope<{
360
+ workspace_item_id: string;
361
+ is_equipped: boolean;
362
+ revision: number;
363
+ changed: boolean;
364
+ }>>(`${BASE}/workspace/equipment/update`, {
365
+ workspace_item_id: workspaceItemId,
366
+ is_equipped: equipped,
367
+ });
368
+ return {
369
+ workspaceItemId: response.data.workspace_item_id,
370
+ equipped: response.data.is_equipped,
371
+ revision: response.data.revision,
372
+ changed: response.data.changed,
373
+ };
374
+ }
375
+
376
+ async updateWorkspaceLoadout(
377
+ input: WorkspaceLoadoutUpdate,
378
+ ): Promise<{ revision: number; changed: boolean }> {
379
+ const body: Record<string, readonly string[]> = {};
380
+ if (input.skillItemIds !== undefined) body.skill_item_ids = input.skillItemIds;
381
+ if (input.strategyItemIds !== undefined) body.strategy_item_ids = input.strategyItemIds;
382
+ if (input.personaItemIds !== undefined) body.persona_item_ids = input.personaItemIds;
383
+ if (input.perceptionItemIds !== undefined) body.perception_item_ids = input.perceptionItemIds;
384
+ const response = await this.http.post<Envelope<{ revision: number; changed: boolean }>>(
385
+ `${BASE}/workspace/loadout/update`,
386
+ body,
387
+ );
388
+ return { revision: response.data.revision, changed: response.data.changed };
389
+ }
390
+
325
391
  async deleteWorkspaceItem(workspaceItemId: string): Promise<void> {
326
392
  await this.http.post(`${BASE}/workspace/delete`, { workspace_item_id: workspaceItemId });
327
393
  }
@@ -384,6 +450,7 @@ export class HubClient {
384
450
  sourceFiles: readonly HubUploadedSourceFile[];
385
451
  packageFileId?: string;
386
452
  forkFromWorkspaceItemId?: string;
453
+ strategyKind?: 'long' | 'short';
387
454
  }): Promise<HubResourceMutationResult> {
388
455
  const response = await this.http.post<Envelope<{
389
456
  resource_id: string;
@@ -391,6 +458,9 @@ export class HubClient {
391
458
  workspace_item_id?: string;
392
459
  }>>(`${BASE}/resources/create`, {
393
460
  resource_type: input.resourceType,
461
+ version_number: '1.0.0',
462
+ version_description: '本地修改同步',
463
+ ...(input.resourceType === 'strategy' ? { strategy_kind: input.strategyKind ?? 'long' } : {}),
394
464
  title: input.title,
395
465
  description: input.description,
396
466
  icon_url: null,
@@ -412,6 +482,8 @@ export class HubClient {
412
482
  description: string;
413
483
  sourceFiles: readonly HubUploadedSourceFile[];
414
484
  packageFileId?: string;
485
+ versionNumber: string;
486
+ strategyKind?: 'long' | 'short';
415
487
  }): Promise<HubResourceMutationResult> {
416
488
  const response = await this.http.post<Envelope<{
417
489
  resource_id: string;
@@ -419,6 +491,9 @@ export class HubClient {
419
491
  }>>(`${BASE}/resources/version/create`, {
420
492
  resource_id: input.resourceId,
421
493
  base_version_id: input.baseVersionId,
494
+ version_number: input.versionNumber,
495
+ version_description: '本地修改同步',
496
+ ...(input.strategyKind ? { strategy_kind: input.strategyKind } : {}),
422
497
  title: input.title,
423
498
  description: input.description,
424
499
  icon_url: null,
@@ -15,6 +15,8 @@ import {
15
15
  resolveLocalAgentWorkspaceWorkingCopyPath,
16
16
  type LocalAgentWorkspaceSnapshot,
17
17
  } from './agent-workspace-sync.js';
18
+ import { filterInactiveAgentWorkspaceSnapshot } from './capability-cloud-presence.js';
19
+ import { capabilityEntryForPath, readCapabilityWorkspaceRegistry, capabilityWorkspacePath } from './capability-workspace.js';
18
20
 
19
21
  export interface PersonaPreset {
20
22
  id: string;
@@ -148,14 +150,25 @@ export function resolveActivePersonaFile(authStore = new AuthStore()): ResolvedP
148
150
  if (!profile) throw new Error('Not logged in.');
149
151
  const workspaceDir = getWorkspaceDir();
150
152
  ensureAccountUserDataLayout(workspaceDir, profile);
151
- const snapshot = readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
153
+ const snapshot = filterInactiveAgentWorkspaceSnapshot(
154
+ workspaceDir,
155
+ profile,
156
+ readLocalAgentWorkspaceSnapshot(workspaceDir, profile),
157
+ );
152
158
  const selectedHub = hubPersona(workspaceDir, profile, snapshot);
153
159
  const selection = readPersonaSelection(workspaceDir, profile)
154
160
  ?? (selectedHub ? { source: 'hub' as const } : { source: 'none' as const });
155
161
  if (selection?.source === 'local') {
156
162
  const preset = findPersonaPreset(selection.id, getUserDataAccountPersonasDir(workspaceDir, profile));
163
+ const entry = preset ? capabilityEntryForPath(workspaceDir, profile, 'persona', preset.path) : undefined;
164
+ if (entry?.hub) return selectedHub ?? { path: null, source: 'none' };
165
+ if (entry && entry.selection !== 'equipped') return selectedHub ?? { path: null, source: 'none' };
157
166
  return { path: preset?.path ?? null, source: 'local', id: selection.id };
158
167
  }
168
+ if (selectedHub) return selectedHub;
169
+ const local = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
170
+ .find(entry => entry.type === 'persona' && !entry.hub && entry.selection === 'equipped');
171
+ if (local) return { path: capabilityWorkspacePath(workspaceDir, profile, local), source: 'local', id: local.runtimeId };
159
172
  if (selection?.source === 'none') return { path: null, source: 'none' };
160
173
  return selectedHub ?? { path: null, source: 'none' };
161
174
  }
@@ -104,7 +104,7 @@ function coordPair(x: unknown, y: unknown): string {
104
104
  function roleAssignedHint(event: Record<string, any>): string {
105
105
  const role = text(event.role_display_name ?? event.role_display ?? event.role, '?');
106
106
  const faction = text(event.faction, '?');
107
- return `You are ${role} (${faction}). Read \`references/GAME-MECHANICS.md\` for the exact rules, then tell your user your role, faction, win condition, and first plan.`;
107
+ return `You are ${role} (${faction}). Tell your user your role, faction, win condition, and first plan.`;
108
108
  }
109
109
 
110
110
  function meetingBriefingHint(event: Record<string, any>): string | undefined {
@@ -76,6 +76,7 @@ import {
76
76
  ClaudeChannelMailboxAdapter,
77
77
  ClaudeChannelSocketSink,
78
78
  DesktopEventSocketSink,
79
+ GameSyncPerceptionReportAdapter,
79
80
  AgentMailboxCoordinator,
80
81
  clawclawEventRequiresDetails,
81
82
  MailboxEventBatchPump,
@@ -92,6 +93,7 @@ import {
92
93
  readLocalAgentWorkspaceSnapshot,
93
94
  resolveLocalAgentWorkspaceSnapshot,
94
95
  } from '../../lib/agent-workspace-sync.js';
96
+ import { filterInactiveAgentWorkspaceSnapshot } from '../../lib/capability-cloud-presence.js';
95
97
  import {
96
98
  listAgentWorkspaceBehaviorSources,
97
99
  listAgentWorkspacePerceptionSources,
@@ -724,9 +726,13 @@ export async function runClawclawOwner(
724
726
  const perceptionConfig = readWorkspacePerceptionConfig();
725
727
  const gameplayConfig = readGameplayConfig(workspaceDir, options.profile);
726
728
  const storedAgentWorkspace = readLocalAgentWorkspaceSnapshot(workspaceDir, options.profile);
727
- const agentWorkspace = storedAgentWorkspace
728
- ? resolveLocalAgentWorkspaceSnapshot(workspaceDir, options.profile, storedAgentWorkspace)
729
- : undefined;
729
+ const agentWorkspace = filterInactiveAgentWorkspaceSnapshot(
730
+ workspaceDir,
731
+ options.profile,
732
+ storedAgentWorkspace
733
+ ? resolveLocalAgentWorkspaceSnapshot(workspaceDir, options.profile, storedAgentWorkspace)
734
+ : undefined,
735
+ );
730
736
  const configurationWarning: ConfigurationWarning = (code, details) => {
731
737
  telemetry?.log('warn', `runtime.configuration.${code}`, details, {
732
738
  component: 'runtime.behavior',
@@ -741,6 +747,7 @@ export async function runClawclawOwner(
741
747
  discoveredLocalCapabilities.behaviors
742
748
  .filter(({ source, entry }) => (
743
749
  entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
750
+ && !agentWorkspace?.items.strategy.some(item => item.resourceId === entry.hub?.resourceId)
744
751
  ))
745
752
  .map(({ source }) => source),
746
753
  agentBehaviorSources,
@@ -773,6 +780,7 @@ export async function runClawclawOwner(
773
780
  const localPerceptionSources = discoveredLocalCapabilities.perceptions
774
781
  .filter(({ source, entry }) => (
775
782
  entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
783
+ && !agentWorkspace?.items.perception.some(item => item.resourceId === entry.hub?.resourceId)
776
784
  ))
777
785
  .map(({ source }) => source);
778
786
  const perceptionSources = mergeAgentWorkspacePerceptionSources(
@@ -898,7 +906,20 @@ export async function runClawclawOwner(
898
906
  monitorEnabled: !!options.notificationHost,
899
907
  diagnostic: (name, attributes, severity) => runtime?.diagnostic(name, attributes, severity),
900
908
  });
901
- const mailboxDrivers: ClawclawMailboxDriver[] = [mailboxService, cclEventsMailbox];
909
+ const perceptionReportAdapter = new GameSyncPerceptionReportAdapter({
910
+ producerPluginId: assembly.perception.id,
911
+ descriptor: (eventType) => assembly.perception.localizedModuleDescriptorForEvent(
912
+ eventType,
913
+ client.gameSyncLocale,
914
+ ),
915
+ send: (reports) => client.reportGameSyncPerceptions(reports),
916
+ diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
917
+ });
918
+ const mailboxDrivers: ClawclawMailboxDriver[] = [
919
+ mailboxService,
920
+ cclEventsMailbox,
921
+ perceptionReportAdapter,
922
+ ];
902
923
  if (options.desktopEvents) {
903
924
  desktopMailbox = new AgentMailboxCoordinator({
904
925
  repository: mailboxRepository,
@@ -0,0 +1,107 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type { GameSyncPerceptionReport } from '../../../../game-sync-protocol.js';
3
+ import type { CanonicalEvent } from '../../../../framework/events/index.js';
4
+ import type {
5
+ ClawclawMailboxAdapterDescriptor,
6
+ ClawclawMailboxDriver,
7
+ } from '../mailbox-plugin.js';
8
+
9
+ const GAME_SYNC_PERCEPTION_REPORT_BATCH_SIZE = 20;
10
+ const PERCEPTION_REPORT_UUID_NAMESPACE = Buffer.from(
11
+ '3c45fc594dd54a59a22185085c1096d1',
12
+ 'hex',
13
+ );
14
+
15
+ export interface GameSyncPerceptionDescriptor {
16
+ readonly perceptionId: string;
17
+ readonly name: string;
18
+ }
19
+
20
+ export interface GameSyncPerceptionReportAdapterOptions {
21
+ readonly send: (reports: readonly GameSyncPerceptionReport[]) => boolean;
22
+ readonly descriptor: (eventType: string) => GameSyncPerceptionDescriptor | undefined;
23
+ readonly producerPluginId: string;
24
+ readonly diagnostic?: (
25
+ name: string,
26
+ attributes?: Readonly<Record<string, unknown>>,
27
+ ) => void;
28
+ }
29
+
30
+ function uuidForEvent(event: CanonicalEvent): string {
31
+ const bytes = createHash('sha1')
32
+ .update(PERCEPTION_REPORT_UUID_NAMESPACE)
33
+ .update(event.sessionId)
34
+ .update('\0')
35
+ .update(event.eventId)
36
+ .digest()
37
+ .subarray(0, 16);
38
+ bytes[6] = (bytes[6]! & 0x0f) | 0x50;
39
+ bytes[8] = (bytes[8]! & 0x3f) | 0x80;
40
+ const hex = bytes.toString('hex');
41
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
42
+ }
43
+
44
+ function sourceTick(event: CanonicalEvent): number | undefined {
45
+ for (const candidate of [event.payload.to_tick, event.payload.source_tick, event.payload.tick]) {
46
+ if (Number.isSafeInteger(candidate) && Number(candidate) >= 0) return Number(candidate);
47
+ }
48
+ return undefined;
49
+ }
50
+
51
+ /** Best-effort Mailbox fan-out to the active GameSync connection. */
52
+ export class GameSyncPerceptionReportAdapter implements ClawclawMailboxDriver {
53
+ readonly adapter: ClawclawMailboxAdapterDescriptor = {
54
+ id: 'clawclaw.mailbox.adapter.game-sync-perception-report',
55
+ acknowledgement: 'none',
56
+ };
57
+
58
+ private stopped = false;
59
+
60
+ constructor(private readonly options: GameSyncPerceptionReportAdapterOptions) {}
61
+
62
+ observeEvents(events: readonly CanonicalEvent[]): void {
63
+ if (this.stopped) return;
64
+ let skipped = 0;
65
+ const reports: GameSyncPerceptionReport[] = [];
66
+ for (const event of events) {
67
+ if (
68
+ event.producerPluginId !== this.options.producerPluginId
69
+ || event.deliveryClass === 'internal_only'
70
+ ) continue;
71
+ const descriptor = this.options.descriptor(event.type);
72
+ const output = typeof event.payload.text === 'string' ? event.payload.text.trim() : '';
73
+ const tick = sourceTick(event);
74
+ if (!descriptor || !descriptor.name.trim() || !output || tick === undefined) {
75
+ skipped += 1;
76
+ continue;
77
+ }
78
+ reports.push({
79
+ id: uuidForEvent(event),
80
+ name: descriptor.name.trim(),
81
+ output,
82
+ source_tick: tick,
83
+ });
84
+ }
85
+ if (skipped > 0) {
86
+ this.options.diagnostic?.('runtime.mailbox.perception_report_skipped', {
87
+ event_count: skipped,
88
+ error_code: 'PERCEPTION_REPORT_FIELDS_MISSING',
89
+ });
90
+ }
91
+ for (let index = 0; index < reports.length; index += GAME_SYNC_PERCEPTION_REPORT_BATCH_SIZE) {
92
+ const batch = reports.slice(index, index + GAME_SYNC_PERCEPTION_REPORT_BATCH_SIZE);
93
+ if (!this.options.send(batch)) {
94
+ this.options.diagnostic?.('runtime.mailbox.perception_report_dropped', {
95
+ event_count: batch.length,
96
+ error_code: 'GAME_SYNC_NOT_CONNECTED',
97
+ });
98
+ }
99
+ }
100
+ }
101
+
102
+ async flush(): Promise<void> {}
103
+
104
+ async stop(): Promise<void> {
105
+ this.stopped = true;
106
+ }
107
+ }
@@ -1,6 +1,7 @@
1
1
  export * from './agent-mailbox-coordinator.js';
2
2
  export * from './adapters/claude-channel-adapter.js';
3
3
  export * from './adapters/claude-channel-socket.js';
4
+ export * from './adapters/game-sync-perception-report-adapter.js';
4
5
  export * from './consumer-ids.js';
5
6
  export * from './desktop-event-socket.js';
6
7
  export * from './mailbox-event-batch-delivery.js';
@@ -821,6 +821,18 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
821
821
  return this.modules.map(({ manifest }) => resolveClawclawResourceMetadata(manifest, locale));
822
822
  }
823
823
 
824
+ localizedModuleDescriptorForEvent(
825
+ type: string,
826
+ locale: string,
827
+ ): (ClawclawResolvedResourceMetadata & { perceptionId: string }) | undefined {
828
+ const module = this.modules.find(({ manifest }) => manifest.produces.includes(type));
829
+ if (!module) return undefined;
830
+ return {
831
+ ...resolveClawclawResourceMetadata(module.manifest, locale),
832
+ perceptionId: module.manifest.id,
833
+ };
834
+ }
835
+
824
836
  localizedEventDescriptors(locale: string): LocalizedPerceptionEventDescriptor[] {
825
837
  return this.modules.flatMap(({ manifest }) => manifest.produces.flatMap((type) => {
826
838
  const metadata = manifest.eventMetadata?.[type];
@@ -179,6 +179,7 @@ interface LagSnapshot {
179
179
  }
180
180
 
181
181
  const DEFAULT_PLUGIN_TIMEOUT_MS = 1_000;
182
+ const PLUGIN_START_TIMEOUT_MS = 10_000;
182
183
  const DEFAULT_MAX_CATCH_UP_EPOCHS = 10;
183
184
  const MAX_PLUGIN_IN_FLIGHT = 10;
184
185
  const DEFAULT_RETRY_ATTEMPTS = 3;
@@ -643,9 +644,15 @@ export class RuntimePluginScheduler<
643
644
  for (const layer of this.layers) {
644
645
  await Promise.all(layer.map(async (plugin) => {
645
646
  const startController = new AbortController();
646
- await this.withDeadline(plugin, startController, () => plugin.start?.(
647
- this.context(plugin, scope, startController.signal, 0),
648
- ));
647
+ await this.withDeadline(
648
+ plugin,
649
+ startController,
650
+ () => plugin.start?.(this.context(plugin, scope, startController.signal, 0)),
651
+ undefined,
652
+ false,
653
+ undefined,
654
+ PLUGIN_START_TIMEOUT_MS,
655
+ );
649
656
  const recoverController = new AbortController();
650
657
  await this.withDeadline(
651
658
  plugin,
@@ -31,6 +31,20 @@ export interface GameSyncErrorData {
31
31
  readonly message?: string;
32
32
  }
33
33
 
34
+ export interface GameSyncPerceptionReport {
35
+ readonly id: string;
36
+ readonly name: string;
37
+ readonly output: string;
38
+ readonly source_tick: number;
39
+ }
40
+
41
+ export interface GameSyncPerceptionReportMessage {
42
+ readonly type: 'game.sync.perception.report';
43
+ readonly data: {
44
+ readonly perceptions: readonly GameSyncPerceptionReport[];
45
+ };
46
+ }
47
+
34
48
  export type GameSyncServerMessage =
35
49
  | { readonly type: 'game.sync.snapshot'; readonly data: GameSyncSnapshotData }
36
50
  | { readonly type: 'game.sync.update'; readonly data: GameSyncUpdateData }
@@ -71,6 +85,39 @@ function eventArray(value: unknown, field: string): Record<string, any>[] {
71
85
  });
72
86
  }
73
87
 
88
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
89
+
90
+ /** Build one client perception report frame using the backend's all-or-nothing validation rules. */
91
+ export function gameSyncPerceptionReportMessage(
92
+ perceptions: readonly GameSyncPerceptionReport[],
93
+ ): GameSyncPerceptionReportMessage {
94
+ if (perceptions.length < 1 || perceptions.length > 20) {
95
+ throw new TypeError('GameSync perception report must contain between 1 and 20 items');
96
+ }
97
+ const ids = new Set<string>();
98
+ const detached = perceptions.map((perception, index) => {
99
+ if (!UUID_PATTERN.test(perception.id)) {
100
+ throw new TypeError(`GameSync perception report[${index}].id must be a UUID`);
101
+ }
102
+ if (ids.has(perception.id)) {
103
+ throw new TypeError('GameSync perception report IDs must be unique within a batch');
104
+ }
105
+ ids.add(perception.id);
106
+ if (typeof perception.name !== 'string' || perception.name.length === 0) {
107
+ throw new TypeError(`GameSync perception report[${index}].name must be a non-empty string`);
108
+ }
109
+ if (typeof perception.output !== 'string') {
110
+ throw new TypeError(`GameSync perception report[${index}].output must be a string`);
111
+ }
112
+ integer(perception.source_tick, `GameSync perception report[${index}].source_tick`);
113
+ return { ...perception };
114
+ });
115
+ return {
116
+ type: 'game.sync.perception.report',
117
+ data: { perceptions: detached },
118
+ };
119
+ }
120
+
74
121
  /** Validate only the envelope and sequencing fields CCL must trust. */
75
122
  export function parseGameSyncMessage(value: unknown): GameSyncServerMessage {
76
123
  const envelope = record(value, 'GameSync message');
@@ -7,9 +7,11 @@ import { WsConnectionState } from '../sdk/types.js';
7
7
  import type { RawWsMessageSink } from './raw-ws-log.js';
8
8
  import {
9
9
  applyGameSyncDelta,
10
+ gameSyncPerceptionReportMessage,
10
11
  gameSyncUrl,
11
12
  parseGameSyncMessage,
12
13
  type GameSyncErrorData,
14
+ type GameSyncPerceptionReport,
13
15
  } from './game-sync-protocol.js';
14
16
 
15
17
  export interface GameSyncResumeState {
@@ -163,6 +165,11 @@ export class WsClient {
163
165
  return this.committedBaseline ? structuredClone(this.committedBaseline) : undefined;
164
166
  }
165
167
 
168
+ /** Best-effort perception output; the server intentionally sends no acknowledgement. */
169
+ reportPerceptions(perceptions: readonly GameSyncPerceptionReport[]): boolean {
170
+ return this.send(gameSyncPerceptionReportMessage(perceptions));
171
+ }
172
+
166
173
  /**
167
174
  * Advance the resume/ACK watermark only after Source has durably accepted the
168
175
  * matching frame. Reading a socket frame is not sufficient authority.