@myclaw163/clawclaw-cli 0.8.7 → 0.8.9

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.
@@ -1,10 +1,13 @@
1
1
  import { Command } from 'commander';
2
- import { basename, resolve } from 'node:path';
2
+ import { basename, extname, resolve } from 'node:path';
3
3
  import { loadContext } from '../lib/load-context.js';
4
4
  import { AuthStore } from '../lib/auth.js';
5
5
  import { noAccountMessage } from '../lib/account-guidance.js';
6
6
  import { runAutoUpgradeOnLoad } from '../runtime/auto-upgrade.js';
7
- import { CLAWCLAW_ROLE_IDS, readGameplayConfig } from '../lib/gameplay-config.js';
7
+ import {
8
+ CLAWCLAW_ROLE_IDS,
9
+ readGameplayConfig,
10
+ } from '../lib/gameplay-config.js';
8
11
  import { getWorkspaceDir } from '../lib/init-command.js';
9
12
  import {
10
13
  ensureAccountUserDataLayout,
@@ -49,6 +52,10 @@ import {
49
52
  type CapabilityLoadWarning,
50
53
  type ModuleCapabilityType,
51
54
  } from '../lib/capability-load-diagnostics.js';
55
+ import { resolveClawclawResourceMetadata } from '../sdk/resource-metadata.js';
56
+
57
+ const LOAD_SCHEMA = 'ccl.load.v2';
58
+ const LOAD_DISPLAY_LOCALE = 'en-US';
52
59
 
53
60
  export interface LoadCommandDependencies {
54
61
  clientFactory?: () => ParticipationStatusClient;
@@ -107,6 +114,70 @@ function missingProjectionWarning(
107
114
  };
108
115
  }
109
116
 
117
+ function compactCapabilityWarning(warning: CapabilityLoadWarning): Record<string, unknown> {
118
+ const keys = [
119
+ 'code',
120
+ 'capability_type',
121
+ 'source',
122
+ 'reason',
123
+ 'stage',
124
+ 'id',
125
+ 'file',
126
+ 'expected_import',
127
+ 'received_imports',
128
+ ] as const;
129
+ return Object.fromEntries(keys.flatMap((key) => (
130
+ warning[key] === undefined ? [] : [[key, warning[key]]]
131
+ )));
132
+ }
133
+
134
+ function compactSkillChanges(changes: ReturnType<typeof syncAgentWorkspaceSkills>) {
135
+ const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed'] as const;
136
+ const value = Object.fromEntries(keys.flatMap((key) => (
137
+ changes[key].length === 0 ? [] : [[key, changes[key]]]
138
+ )));
139
+ return Object.keys(value).length > 0 || changes.requiresUserConfirmation
140
+ ? {
141
+ ...value,
142
+ ...(changes.requiresUserConfirmation ? { requires_user_confirmation: true } : {}),
143
+ }
144
+ : undefined;
145
+ }
146
+
147
+ function compactConfigurationWarnings(warnings: readonly Record<string, unknown>[]) {
148
+ return warnings.map((warning) => {
149
+ if (
150
+ warning.code !== 'DEFAULT_LONG_BEHAVIOR_UNAVAILABLE'
151
+ || typeof warning.behavior_id !== 'string'
152
+ || typeof warning.role !== 'string'
153
+ ) {
154
+ return { ...warning };
155
+ }
156
+ return {
157
+ code: 'FALLBACK_BEHAVIOR_NOT_LOADED',
158
+ role: warning.role,
159
+ behavior_id: warning.behavior_id,
160
+ message: `Fallback Behavior ${warning.behavior_id} configured for role ${warning.role} is not loaded.`,
161
+ };
162
+ });
163
+ }
164
+
165
+ function compactParticipation(value: object): Record<string, unknown> {
166
+ const { schema: _schema, ...participation } = value as Record<string, unknown>;
167
+ return participation;
168
+ }
169
+
170
+ function compactPersona(snapshot: ReturnType<typeof loadContext>['persona']) {
171
+ if (!snapshot.exists) return null;
172
+ const name = snapshot.id
173
+ ?? (snapshot.path ? basename(snapshot.path, extname(snapshot.path)) : 'persona');
174
+ return {
175
+ name,
176
+ content: snapshot.content,
177
+ source: snapshot.source ?? 'none',
178
+ };
179
+ }
180
+
110
181
  export function createLoadCommand(dependencies: LoadCommandDependencies = {}): Command {
111
182
  return new Command('load')
112
183
  .description('Read active account context, configured gameplay resources, and backend participation')
@@ -406,40 +477,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
406
477
  const message = error instanceof Error ? error.message : String(error);
407
478
  console.error(`[clawclaw-cli] participation status unavailable: ${message}`);
408
479
  }
409
- console.log(JSON.stringify({
410
- ...snapshot,
411
- workspace_config: {
412
- sync: {
413
- status: workspaceSyncStatus,
414
- revision: activeWorkspace?.revision ?? null,
415
- ...(workspaceResult?.previous
416
- ? { previous_revision: workspaceResult.previous.revision }
417
- : {}),
418
- ...(workspaceSyncError ? { error: workspaceSyncError } : {}),
419
- },
420
- items: activeWorkspace
421
- ? Object.fromEntries(Object.entries(activeWorkspace.items).map(([type, items]) => [
422
- type,
423
- items.map((item) => ({
424
- resource_id: item.resourceId,
425
- version_id: item.versionId,
426
- content_digest: item.contentDigest,
427
- resolution: item.resolution ?? 'hub',
428
- ...(item.localContentDigest ? { local_content_digest: item.localContentDigest } : {}),
429
- })),
430
- ]))
431
- : { skill: [], strategy: [], persona: [], perception: [] },
432
- skill_changes: skillChanges,
433
- persona: {
434
- source: snapshot.persona.source ?? 'none',
435
- path: snapshot.persona.path,
436
- exists: snapshot.persona.exists,
437
- ...(snapshot.persona.id ? { id: snapshot.persona.id } : {}),
438
- ...(snapshot.persona.resource_id ? { resource_id: snapshot.persona.resource_id } : {}),
439
- },
440
- requires_user_confirmation: skillChanges.requiresUserConfirmation,
441
- },
442
- capability_summary: {
480
+ const capabilitySummary = {
443
481
  behavior: {
444
482
  selected_hub: activeWorkspace?.items.strategy.length ?? 0,
445
483
  eligible_local: expectedLocalBehaviors,
@@ -472,16 +510,60 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
472
510
  capability_type === 'persona'
473
511
  )).length,
474
512
  },
513
+ };
514
+ const behaviorSourceById = new Map(enabledBehaviors.map((source) => [source.id, source]));
515
+ const perceptionSourceById = new Map(enabledPerceptions.map((source) => [source.id, source]));
516
+ const triggerSourceById = new Map(enabledTriggers.map((source) => [source.id, source]));
517
+ const skillChangeSummary = compactSkillChanges(skillChanges);
518
+ console.log(JSON.stringify({
519
+ schema: LOAD_SCHEMA,
520
+ context: {
521
+ persona: compactPersona(snapshot.persona),
522
+ memory: snapshot.memory.content,
523
+ },
524
+ sync: {
525
+ status: workspaceSyncStatus,
526
+ revision: activeWorkspace?.revision ?? null,
527
+ ...(workspaceSyncError ? { error: workspaceSyncError } : {}),
528
+ },
529
+ ...(skillChangeSummary ? { changes: { skills: skillChangeSummary } } : {}),
530
+ capabilities: {
531
+ summary: capabilitySummary,
532
+ behaviors: behaviors.map((entry) => {
533
+ const source = behaviorSourceById.get(entry.id)!;
534
+ const localized = resolveClawclawResourceMetadata(source, LOAD_DISPLAY_LOCALE);
535
+ return {
536
+ id: entry.id,
537
+ name: localized.name,
538
+ description: localized.description,
539
+ source: entry.source,
540
+ };
541
+ }),
542
+ perceptions: perceptions.map((entry) => {
543
+ const source = perceptionSourceById.get(entry.id)!;
544
+ const localized = resolveClawclawResourceMetadata(source.manifest, LOAD_DISPLAY_LOCALE);
545
+ return {
546
+ id: entry.id,
547
+ name: localized.name,
548
+ description: localized.description,
549
+ source: entry.source,
550
+ };
551
+ }),
552
+ triggers: triggers.map((entry) => {
553
+ const source = triggerSourceById.get(entry.id)!;
554
+ const localized = resolveClawclawResourceMetadata(source.manifest, LOAD_DISPLAY_LOCALE);
555
+ return {
556
+ id: entry.id,
557
+ name: localized.name,
558
+ description: localized.description,
559
+ source: entry.source,
560
+ behavior_id: entry.behavior_id,
561
+ };
562
+ }),
563
+ warnings: capabilityWarnings.map(compactCapabilityWarning),
475
564
  },
476
- capability_warnings: capabilityWarnings,
477
- behaviors,
478
- incompatible_behaviors: incompatibleBehaviors,
479
- perceptions,
480
- incompatible_perceptions: incompatiblePerceptions,
481
- triggers,
482
- incompatible_triggers: incompatibleTriggers,
483
- configuration_warnings: configurationWarnings,
484
- participation,
565
+ configuration_warnings: compactConfigurationWarnings(configurationWarnings),
566
+ participation: compactParticipation(participation),
485
567
  }, null, 2));
486
568
  });
487
569
  }
@@ -445,12 +445,6 @@ export function ensureAccountUserDataLayout(
445
445
  copyLegacyLocalModules(from, to);
446
446
  result.copied.push(`user-data/${label} -> user-data/accounts/<account-hash>/<type>/local`);
447
447
  }
448
- const legacyGameplay = getUserDataGameplayConfigFile(workspaceDir);
449
- const accountGameplay = getUserDataAccountGameplayConfigFile(workspaceDir, profile);
450
- if (existsSync(legacyGameplay) && !existsSync(accountGameplay)) {
451
- copyFileSync(legacyGameplay, accountGameplay);
452
- result.copied.push('user-data/gameplay.json -> user-data/accounts/<account-hash>/gameplay.json');
453
- }
454
448
  writeJson(marker, {
455
449
  format: 2,
456
450
  migrated_at: new Date().toISOString(),
@@ -20,6 +20,11 @@ function object(value: unknown): Record<string, any> | null {
20
20
  : null;
21
21
  }
22
22
 
23
+ function backendRoomOrFallback(item: Record<string, any>): string | null {
24
+ if (typeof item.room === 'string' && item.room.trim().length > 0) return item.room;
25
+ return resolveRoom({ x: item.x, y: item.y });
26
+ }
27
+
23
28
  interface PlayerRef {
24
29
  name: string;
25
30
  seat: number;
@@ -88,7 +93,7 @@ export class ObservationFrameProjector {
88
93
  : { alive: true }),
89
94
  x: item.x,
90
95
  y: item.y,
91
- room: resolveRoom({ x: item.x, y: item.y }),
96
+ room: backendRoomOrFallback(item),
92
97
  };
93
98
  }
94
99
 
@@ -109,7 +114,7 @@ export class ObservationFrameProjector {
109
114
  } : {}),
110
115
  x: item.x,
111
116
  y: item.y,
112
- room: resolveRoom({ x: item.x, y: item.y }),
117
+ room: backendRoomOrFallback(item),
113
118
  });
114
119
  }
115
120
  return corpses;
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'fs';
2
+ import { inflateSync } from 'node:zlib';
2
3
  import type { VisualPosition } from './contracts.js';
3
4
  import { createSpatialApi, type SpatialFacts } from '../../spatial-api.js';
4
5
 
@@ -22,6 +23,15 @@ interface RawSpatialFacts {
22
23
  player_body: {
23
24
  body_length_px: number;
24
25
  };
26
+ room_lookup: {
27
+ encoding: 'row-major-zlib-uint8-v1';
28
+ width_tiles: number;
29
+ height_tiles: number;
30
+ tile_width_px: number;
31
+ tile_height_px: number;
32
+ room_names: string[];
33
+ data_base64: string;
34
+ };
25
35
  rooms: MapRoomArea[];
26
36
  room_transitions: SpatialTransition[];
27
37
  }
@@ -34,6 +44,19 @@ function loadSpatialFacts(): RawSpatialFacts {
34
44
  parsed.schema_version !== 2
35
45
  || parsed.coordinates?.x_positive !== 'right'
36
46
  || parsed.coordinates?.y_positive !== 'down'
47
+ || parsed.room_lookup?.encoding !== 'row-major-zlib-uint8-v1'
48
+ || !Number.isInteger(parsed.room_lookup.width_tiles)
49
+ || parsed.room_lookup.width_tiles <= 0
50
+ || !Number.isInteger(parsed.room_lookup.height_tiles)
51
+ || parsed.room_lookup.height_tiles <= 0
52
+ || !Number.isFinite(parsed.room_lookup.tile_width_px)
53
+ || parsed.room_lookup.tile_width_px <= 0
54
+ || !Number.isFinite(parsed.room_lookup.tile_height_px)
55
+ || parsed.room_lookup.tile_height_px <= 0
56
+ || !Array.isArray(parsed.room_lookup.room_names)
57
+ || parsed.room_lookup.room_names.length === 0
58
+ || typeof parsed.room_lookup.data_base64 !== 'string'
59
+ || parsed.room_lookup.data_base64.length === 0
37
60
  ) {
38
61
  throw new Error('Unsupported ClawClaw spatial facts');
39
62
  }
@@ -43,6 +66,21 @@ function loadSpatialFacts(): RawSpatialFacts {
43
66
  export const CLAWCLAW_SPATIAL_FACTS = loadSpatialFacts();
44
67
  export const PLAYER_BODY_LENGTH_PX = CLAWCLAW_SPATIAL_FACTS.player_body.body_length_px;
45
68
 
69
+ const RAW_ROOM_LOOKUP = CLAWCLAW_SPATIAL_FACTS.room_lookup;
70
+ const ROOM_LOOKUP_CELL_COUNT = RAW_ROOM_LOOKUP.width_tiles * RAW_ROOM_LOOKUP.height_tiles;
71
+ const ROOM_LOOKUP_BUFFER = inflateSync(Buffer.from(RAW_ROOM_LOOKUP.data_base64, 'base64'));
72
+ if (ROOM_LOOKUP_BUFFER.byteLength !== ROOM_LOOKUP_CELL_COUNT) {
73
+ throw new Error('Invalid ClawClaw room lookup size');
74
+ }
75
+ const ROOM_LOOKUP = new Uint8Array(
76
+ ROOM_LOOKUP_BUFFER.buffer,
77
+ ROOM_LOOKUP_BUFFER.byteOffset,
78
+ ROOM_LOOKUP_BUFFER.byteLength,
79
+ );
80
+ if (ROOM_LOOKUP.some((roomIndex) => roomIndex >= RAW_ROOM_LOOKUP.room_names.length)) {
81
+ throw new Error('Invalid ClawClaw room lookup index');
82
+ }
83
+
46
84
  const ROOM_BY_NAME = new Map(
47
85
  CLAWCLAW_SPATIAL_FACTS.rooms.map((room) => [room.name, room] as const),
48
86
  );
@@ -68,7 +106,17 @@ export function roomAt(x: number, y: number): MapRoomArea | null {
68
106
  }
69
107
 
70
108
  export function resolveRoom(position: Pick<VisualPosition, 'x' | 'y'>): string | null {
71
- return roomAt(position.x, position.y)?.name ?? null;
109
+ if (!Number.isFinite(position.x) || !Number.isFinite(position.y)) return null;
110
+ const tileX = Math.max(0, Math.min(
111
+ RAW_ROOM_LOOKUP.width_tiles - 1,
112
+ Math.floor(position.x / RAW_ROOM_LOOKUP.tile_width_px),
113
+ ));
114
+ const tileY = Math.max(0, Math.min(
115
+ RAW_ROOM_LOOKUP.height_tiles - 1,
116
+ Math.floor(position.y / RAW_ROOM_LOOKUP.tile_height_px),
117
+ ));
118
+ const roomIndex = ROOM_LOOKUP[tileY * RAW_ROOM_LOOKUP.width_tiles + tileX];
119
+ return RAW_ROOM_LOOKUP.room_names[roomIndex] ?? null;
72
120
  }
73
121
 
74
122
  export function sideInRoom(position: VisualPosition): string | null {