@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
@@ -37,6 +37,7 @@ import {
37
37
  resolveLocalAgentWorkspaceSnapshot,
38
38
  syncAgentWorkspaceConfig,
39
39
  type AgentWorkspaceSyncResult,
40
+ type LocalAgentWorkspaceSnapshot,
40
41
  } from '../lib/agent-workspace-sync.js';
41
42
  import { syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
42
43
  import {
@@ -64,6 +65,12 @@ import {
64
65
  refreshCapabilitiesFromCloud,
65
66
  syncInstalledCapabilityUpdates,
66
67
  } from '../lib/capability-cloud-refresh.js';
68
+ import {
69
+ filterInactiveAgentWorkspaceSnapshot,
70
+ reconcileCapabilityWorkspacePresence,
71
+ reconcileCapabilityLoadout,
72
+ type CapabilityPresenceResult,
73
+ } from '../lib/capability-cloud-presence.js';
67
74
 
68
75
  const LOAD_SCHEMA = 'ccl.load.v2';
69
76
  const LOAD_DISPLAY_LOCALE = 'en-US';
@@ -78,6 +85,55 @@ export interface LoadCommandDependencies {
78
85
  cloudSync?: typeof syncCapabilitiesToCloud;
79
86
  }
80
87
 
88
+ interface WorkspaceVersionUpdate {
89
+ type: string;
90
+ resource_id: string;
91
+ workspace_item_id: string;
92
+ version_id: string;
93
+ from_version?: string;
94
+ }
95
+
96
+ function inferredWorkspaceVersionUpdates(
97
+ current: LocalAgentWorkspaceSnapshot | undefined,
98
+ previous: LocalAgentWorkspaceSnapshot | undefined,
99
+ ): WorkspaceVersionUpdate[] {
100
+ if (!current || !previous) return [];
101
+ const previousByResource = new Map(
102
+ Object.values(previous.items).flat().map((item) => [
103
+ `${item.resourceType}:${item.resourceId}`,
104
+ item,
105
+ ]),
106
+ );
107
+ return Object.values(current.items).flat().flatMap((item) => {
108
+ const before = previousByResource.get(`${item.resourceType}:${item.resourceId}`);
109
+ if (
110
+ !before
111
+ || before.versionId === item.versionId
112
+ || (item.resolution !== 'hub' && item.resolution !== 'known_online_old')
113
+ ) return [];
114
+ return [{
115
+ type: item.resourceType,
116
+ resource_id: item.resourceId,
117
+ workspace_item_id: item.workspaceItemId,
118
+ from_version: before.versionId,
119
+ version_id: item.versionId,
120
+ }];
121
+ });
122
+ }
123
+
124
+ function mergeWorkspaceVersionUpdates(
125
+ reported: readonly WorkspaceVersionUpdate[],
126
+ inferred: readonly WorkspaceVersionUpdate[],
127
+ ): WorkspaceVersionUpdate[] {
128
+ const merged = new Map<string, WorkspaceVersionUpdate>();
129
+ for (const item of inferred) merged.set(`${item.type}:${item.resource_id}`, { ...item });
130
+ for (const item of reported) {
131
+ const key = `${item.type}:${item.resource_id}`;
132
+ merged.set(key, { ...merged.get(key), ...item });
133
+ }
134
+ return [...merged.values()];
135
+ }
136
+
81
137
  function compatibilityWarning(
82
138
  type: ModuleCapabilityType,
83
139
  source: 'hub' | 'local',
@@ -203,12 +259,16 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
203
259
  if (!profile) throw new Error(noAccountMessage('load'));
204
260
  ensureAccountUserDataLayout(workspaceDir, profile);
205
261
 
206
- let cloudWorkspaceUpdates = { updated: [], failed: [] } as Awaited<ReturnType<typeof syncInstalledCapabilityUpdates>>;
262
+ let cloudWorkspaceUpdates = {
263
+ updated: [], failed: [], inventory: [], inventoryComplete: false,
264
+ } as Awaited<ReturnType<typeof syncInstalledCapabilityUpdates>>;
265
+ let inventoryReadFailed = false;
207
266
  try {
208
267
  cloudWorkspaceUpdates = await (
209
268
  dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates
210
269
  )(profile);
211
270
  } catch (error) {
271
+ inventoryReadFailed = true;
212
272
  console.error(`[clawclaw-cli] Hub workspace update check unavailable: ${
213
273
  error instanceof Error ? error.message : String(error)
214
274
  }`);
@@ -231,12 +291,28 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
231
291
  console.error(`[clawclaw-cli] Agent workspace sync unavailable: ${workspaceSyncError}`);
232
292
  }
233
293
 
234
- const cloudRefreshChanges = await (dependencies.cloudRefresh ?? refreshCapabilitiesFromCloud)(
294
+ let cloudPresence: CapabilityPresenceResult = cloudWorkspaceUpdates.inventoryComplete
295
+ ? reconcileCapabilityWorkspacePresence(workspaceDir, profile, cloudWorkspaceUpdates.inventory, workspaceResult?.snapshot)
296
+ : workspaceResult?.snapshot
297
+ ? reconcileCapabilityLoadout(workspaceDir, profile, workspaceResult.snapshot)
298
+ : { deactivated: [], restored: [], inactiveResourceIds: [] };
299
+ activeWorkspace = filterInactiveAgentWorkspaceSnapshot(
300
+ workspaceDir,
301
+ profile,
302
+ activeWorkspace,
303
+ cloudPresence.inactiveResourceIds,
304
+ );
305
+
306
+ const cloudRefreshChanges = inventoryReadFailed
307
+ ? { downloaded: [], conflicts: [], failed: [], unchanged: [] }
308
+ : await (dependencies.cloudRefresh ?? refreshCapabilitiesFromCloud)(
235
309
  workspaceDir,
236
310
  profile,
237
311
  activeWorkspace,
238
312
  );
239
313
 
314
+ let firstSkillChanges: ReturnType<typeof syncAgentWorkspaceSkills> | undefined;
315
+ const renderFinalContext = async (completedSync?: Awaited<ReturnType<typeof syncCapabilitiesToCloud>>): Promise<void> => {
240
316
  let snapshot;
241
317
  try {
242
318
  snapshot = loadContext(authStore);
@@ -246,6 +322,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
246
322
  }
247
323
  throw error;
248
324
  }
325
+ if (
326
+ snapshot.persona.source === 'hub'
327
+ && snapshot.persona.resource_id
328
+ && cloudPresence.inactiveResourceIds.includes(snapshot.persona.resource_id)
329
+ ) {
330
+ snapshot.persona = { path: null, exists: false, content: '', source: 'none' };
331
+ }
249
332
 
250
333
  const gameplay = readGameplayConfig(workspaceDir, profile);
251
334
  const discoveredLocal = discoverLocalCapabilities(workspaceDir, profile);
@@ -277,6 +360,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
277
360
  workspaceItemId: item.workspaceItemId,
278
361
  publisher: item.hub?.publisher ?? 'community',
279
362
  baseSha256: item.sourceFiles[0]?.sha256,
363
+ localOriginUnrecognized: item.resolution === 'local_origin_unrecognized'
364
+ ? true
365
+ : undefined,
280
366
  },
281
367
  });
282
368
  }
@@ -286,6 +372,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
286
372
  const localBehaviors = discoveredLocal.behaviors
287
373
  .filter(({ source, entry }) => (
288
374
  entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
375
+ && !activeWorkspace?.items.strategy.some(item => item.resourceId === entry.hub?.resourceId)
289
376
  ))
290
377
  .map(({ source }) => source);
291
378
  const localBehaviorSourcePaths = new Set(allLocalBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
@@ -374,6 +461,14 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
374
461
  capabilityWarnings.push(compatibilityWarning('behavior', 'local', source, reason));
375
462
  }
376
463
  const configurationWarnings: Array<Record<string, unknown>> = [];
464
+ if (workspaceSyncError) configurationWarnings.push({
465
+ code: 'WORKSPACE_SYNC_FAILED', message: workspaceSyncError,
466
+ using_previous_snapshot: !!activeWorkspace,
467
+ });
468
+ if (inventoryReadFailed) configurationWarnings.push({
469
+ code: 'WORKSPACE_INVENTORY_UNAVAILABLE',
470
+ message: 'Backpack could not be verified; automatic cloud writes and inactive-resource refresh were skipped.',
471
+ });
377
472
  if (snapshot.memory.truncated) {
378
473
  configurationWarnings.push({
379
474
  code: 'MEMORY_LENGTH_EXCEEDED',
@@ -405,7 +500,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
405
500
  && resolveLocalAgentWorkspacePath(
406
501
  workspaceDir,
407
502
  profile,
408
- activeWorkspace,
503
+ activeWorkspace!,
409
504
  candidate.runtimeEntryPath,
410
505
  ) === source.sourcePath
411
506
  ));
@@ -426,6 +521,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
426
521
  workspaceItemId: item.workspaceItemId,
427
522
  publisher: item.hub?.publisher ?? 'community',
428
523
  baseSha256: item.sourceFiles[0]?.sha256,
524
+ localOriginUnrecognized: item.resolution === 'local_origin_unrecognized'
525
+ ? true
526
+ : undefined,
429
527
  },
430
528
  });
431
529
  }
@@ -436,6 +534,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
436
534
  const localPerceptions = discoveredLocal.perceptions
437
535
  .filter(({ source, entry }) => (
438
536
  entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
537
+ && !activeWorkspace?.items.perception.some(item => item.resourceId === entry.hub?.resourceId)
439
538
  ))
440
539
  .map(({ source }) => source);
441
540
  const localPerceptionSourcePaths = new Set(
@@ -613,16 +712,45 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
613
712
  workspaceItemId: hubPersonaItem.workspaceItemId,
614
713
  publisher: hubPersonaItem.hub?.publisher ?? 'community',
615
714
  baseSha256: hubPersonaItem.sourceFiles[0]?.sha256,
715
+ localOriginUnrecognized: hubPersonaItem.resolution === 'local_origin_unrecognized'
716
+ ? true
717
+ : undefined,
616
718
  },
617
719
  });
618
720
  }
619
- const cloudChanges = activeWorkspace
721
+ const cloudChanges = completedSync ?? (activeWorkspace && !inventoryReadFailed
620
722
  ? await (dependencies.cloudSync ?? syncCapabilitiesToCloud)(
621
723
  workspaceDir,
622
724
  profile,
623
725
  activeWorkspace,
624
726
  )
625
- : undefined;
727
+ : undefined);
728
+ if (!completedSync && cloudChanges && (
729
+ cloudChanges.uploaded.length > 0 || cloudChanges.equipmentChanged
730
+ || cloudChanges.failed.some(item => item.action === 'equipment')
731
+ )) {
732
+ firstSkillChanges = skillChanges;
733
+ try {
734
+ const updatedInventory = await (dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates)(profile);
735
+ workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile);
736
+ activeWorkspace = workspaceResult.snapshot;
737
+ workspaceSyncStatus = workspaceResult.status;
738
+ if (updatedInventory.inventoryComplete) {
739
+ const presence = reconcileCapabilityWorkspacePresence(workspaceDir, profile, updatedInventory.inventory, activeWorkspace);
740
+ cloudPresence = {
741
+ deactivated: [...cloudPresence.deactivated, ...presence.deactivated],
742
+ restored: [...cloudPresence.restored, ...presence.restored],
743
+ inactiveResourceIds: presence.inactiveResourceIds,
744
+ };
745
+ }
746
+ activeWorkspace = filterInactiveAgentWorkspaceSnapshot(workspaceDir, profile, activeWorkspace, cloudPresence.inactiveResourceIds);
747
+ } catch (error) {
748
+ workspaceSyncStatus = 'stale_fallback';
749
+ workspaceSyncError = `post_upload_workspace_refresh_failed:${error instanceof Error ? error.message : String(error)}`;
750
+ console.error(`[clawclaw-cli] ${workspaceSyncError}`);
751
+ }
752
+ return renderFinalContext(cloudChanges);
753
+ }
626
754
  let participation;
627
755
  try {
628
756
  const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
@@ -673,7 +801,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
673
801
  const behaviorSourceById = new Map(enabledBehaviors.map((source) => [source.id, source]));
674
802
  const perceptionSourceById = new Map(enabledPerceptions.map((source) => [source.id, source]));
675
803
  const triggerSourceById = new Map(enabledTriggers.map((source) => [source.id, source]));
676
- const skillChangeSummary = compactSkillChanges(skillChanges);
804
+ const skillChangeSummary = compactSkillChanges(firstSkillChanges ? {
805
+ ...skillChanges,
806
+ added: [...new Set([...firstSkillChanges.added, ...skillChanges.added])],
807
+ updated: [...new Set([...firstSkillChanges.updated, ...skillChanges.updated])],
808
+ removed: [...new Set([...firstSkillChanges.removed, ...skillChanges.removed])],
809
+ failed: [...firstSkillChanges.failed, ...skillChanges.failed],
810
+ } : skillChanges);
677
811
  const cloudConflicts = [...cloudRefreshChanges.conflicts, ...(cloudChanges?.conflicts ?? [])]
678
812
  .filter((value, index, values) => values.findIndex((candidate) => (
679
813
  candidate.type === value.type
@@ -681,20 +815,30 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
681
815
  && candidate.resource_id === value.resource_id
682
816
  )) === index);
683
817
  const cloudFailures = [...cloudRefreshChanges.failed, ...(cloudChanges?.failed ?? [])];
818
+ const workspaceVersionUpdates = mergeWorkspaceVersionUpdates(
819
+ cloudWorkspaceUpdates.updated,
820
+ inferredWorkspaceVersionUpdates(activeWorkspace, workspaceResult?.previous),
821
+ );
684
822
  const cloudChangeSummary = (
685
- cloudWorkspaceUpdates.updated.length > 0
823
+ workspaceVersionUpdates.length > 0
686
824
  || cloudWorkspaceUpdates.failed.length > 0
687
825
  || cloudRefreshChanges.downloaded.length > 0
688
826
  || (cloudChanges?.uploaded.length ?? 0) > 0
827
+ || (cloudChanges?.skipped.length ?? 0) > 0
689
828
  || cloudConflicts.length > 0
690
829
  || cloudFailures.length > 0
830
+ || cloudPresence.deactivated.length > 0
831
+ || cloudPresence.restored.length > 0
691
832
  ) ? {
692
- workspace_updated: cloudWorkspaceUpdates.updated,
833
+ workspace_updated: workspaceVersionUpdates,
693
834
  workspace_update_failed: cloudWorkspaceUpdates.failed,
694
835
  downloaded: cloudRefreshChanges.downloaded,
695
836
  uploaded: cloudChanges?.uploaded ?? [],
837
+ skipped: cloudChanges?.skipped ?? [],
696
838
  conflicts: cloudConflicts,
697
839
  failed: cloudFailures,
840
+ deactivated: cloudPresence.deactivated,
841
+ restored: cloudPresence.restored,
698
842
  unchanged: cloudChanges?.unchanged ?? [],
699
843
  } : undefined;
700
844
  const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
@@ -726,6 +870,8 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
726
870
  description: localized.description,
727
871
  source: entry.source,
728
872
  strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, 'utf8')),
873
+ ...(source.management.versionNumber ? { version_number: source.management.versionNumber,
874
+ version_description: source.management.versionDescription ?? '' } : {}),
729
875
  };
730
876
  }),
731
877
  perceptions: perceptions.map((entry) => {
@@ -760,5 +906,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
760
906
  configuration_warnings: compactConfigurationWarnings(configurationWarnings),
761
907
  participation: compactParticipation(participation),
762
908
  }, null, 2));
909
+ };
910
+ await renderFinalContext();
763
911
  });
764
912
  }
@@ -11,6 +11,7 @@ import {
11
11
  getUserDataAccountPerceptionsDir,
12
12
  } from '../lib/user-data.js';
13
13
  import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
14
+ import { filterInactiveAgentWorkspaceSnapshot } from '../lib/capability-cloud-presence.js';
14
15
  import {
15
16
  listAgentWorkspacePerceptionSources,
16
17
  mergeAgentWorkspacePerceptionSources,
@@ -18,7 +19,8 @@ import {
18
19
  import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
19
20
  import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
20
21
  import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
21
- import { capabilityEntryForPath, setCapabilitySelection } from '../lib/capability-workspace.js';
22
+ import { capabilityEntryForPath, readCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
23
+ import { selectCapability } from '../lib/capability-selection.js';
22
24
 
23
25
  export interface PerceptionCommandDependencies {
24
26
  activeProfile?: () => AuthProfile | null;
@@ -56,23 +58,25 @@ Perception modules:
56
58
  const workspaceDir = getWorkspaceDir();
57
59
  const profile = activeProfile(dependencies);
58
60
  ensureAccountUserDataLayout(workspaceDir, profile);
59
- const snapshot = readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
61
+ const snapshot = filterInactiveAgentWorkspaceSnapshot(
62
+ workspaceDir,
63
+ profile,
64
+ readLocalAgentWorkspaceSnapshot(workspaceDir, profile),
65
+ );
60
66
  const hub = snapshot
61
67
  ? listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot)
62
68
  : [];
63
69
  const hubIds = new Set(hub.map(({ id }) => id));
64
70
  const local = discoverLocalCapabilities(workspaceDir, profile).perceptions
71
+ .filter(({ entry }) => !snapshot?.items.perception.some(item => item.resourceId === entry.hub?.resourceId))
65
72
  .map(({ source }) => source);
66
- if ((opts.disable && hubIds.has(opts.disable)) || (opts.enable && hubIds.has(opts.enable))) {
67
- throw new Error(`Hub Perception '${opts.disable ?? opts.enable}' enablement is controlled by the Hub loadout.`);
68
- }
73
+ const registered = (id: string) => Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
74
+ .some(entry => entry.type === 'perception' && entry.runtimeId === id);
69
75
  if (opts.disable) {
70
76
  const source = local.find(({ id }) => id === opts.disable);
71
- if (!source) throw new Error(`Unknown local Perception '${opts.disable}'.`);
72
- setCapabilitySelection(workspaceDir, profile, 'perception', opts.disable, false);
73
- const updated = updateGameplayConfig((current) => {
74
- current.disabled_perception_modules.push(opts.disable!);
75
- }, workspaceDir, profile);
77
+ if (!source && !hubIds.has(opts.disable) && !registered(opts.disable)) throw new Error(`Unknown local Perception '${opts.disable}'.`);
78
+ await selectCapability(workspaceDir, profile, 'perception', opts.disable, false);
79
+ const updated = readGameplayConfig(workspaceDir, profile);
76
80
  console.log(JSON.stringify({
77
81
  perception_module: opts.disable,
78
82
  disabled: true,
@@ -84,12 +88,9 @@ Perception modules:
84
88
  }
85
89
  if (opts.enable) {
86
90
  const source = local.find(({ id }) => id === opts.enable);
87
- if (!source) throw new Error(`Unknown local Perception '${opts.enable}'.`);
88
- setCapabilitySelection(workspaceDir, profile, 'perception', opts.enable, true);
89
- const updated = updateGameplayConfig((current) => {
90
- current.disabled_perception_modules = current.disabled_perception_modules
91
- .filter((id) => id !== opts.enable);
92
- }, workspaceDir, profile);
91
+ if (!source && !hubIds.has(opts.enable) && !registered(opts.enable)) throw new Error(`Unknown local Perception '${opts.enable}'.`);
92
+ await selectCapability(workspaceDir, profile, 'perception', opts.enable, true);
93
+ const updated = readGameplayConfig(workspaceDir, profile);
93
94
  console.log(JSON.stringify({
94
95
  perception_module: opts.enable,
95
96
  disabled: false,
@@ -15,6 +15,10 @@ import {
15
15
  import { loadPersonaSnapshot } from '../lib/load-context.js';
16
16
  import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
17
17
  import { setCapabilitySelection } from '../lib/capability-workspace.js';
18
+ import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
19
+ import { selectCapability } from '../lib/capability-selection.js';
20
+ import { HubClient } from '../lib/hub-client.js';
21
+ import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
18
22
 
19
23
  function context() {
20
24
  const profile = new AuthStore().getActive();
@@ -60,11 +64,11 @@ export function createPersonaCommand(): Command {
60
64
  persona
61
65
  .command('create <name>')
62
66
  .description('Create and select an empty account-local Persona preset')
63
- .action((name: string) => {
67
+ .action(async (name: string) => {
64
68
  const { directory, workspaceDir, profile } = context();
65
69
  const created = createPersonaPreset(name, directory);
66
70
  discoverLocalCapabilities(workspaceDir, profile);
67
- setCapabilitySelection(workspaceDir, profile, 'persona', created.id, true);
71
+ await selectCapability(workspaceDir, profile, 'persona', created.id, true);
68
72
  writePersonaSelection(workspaceDir, profile, { source: 'local', id: created.id });
69
73
  console.log(JSON.stringify({
70
74
  path: created.path,
@@ -75,16 +79,16 @@ export function createPersonaCommand(): Command {
75
79
  persona
76
80
  .command('use <preset>')
77
81
  .description('Select an account-local Persona preset')
78
- .action((presetName: string) => {
82
+ .action(async (presetName: string) => {
79
83
  const { directory, workspaceDir, profile } = context();
80
84
  const found = findPersonaPreset(presetName, directory);
81
85
  if (!found) {
82
86
  const available = listPersonaPresets(directory).map(p => p.name).join(', ') || 'none';
83
87
  throw new Error(`Persona preset "${presetName}" not found. Available: ${available}`);
84
88
  }
85
- writePersonaSelection(workspaceDir, profile, { source: 'local', id: found.id });
86
89
  discoverLocalCapabilities(workspaceDir, profile);
87
- setCapabilitySelection(workspaceDir, profile, 'persona', found.id, true);
90
+ const entry = await selectCapability(workspaceDir, profile, 'persona', found.id, true);
91
+ writePersonaSelection(workspaceDir, profile, entry.hub ? { source: 'hub' } : { source: 'local', id: found.id });
88
92
  console.log(JSON.stringify({
89
93
  path: found.path,
90
94
  preset: { id: found.id, name: found.name, source: 'local' },
@@ -97,6 +101,11 @@ export function createPersonaCommand(): Command {
97
101
  .description('Use the Persona selected by the active account Hub loadout')
98
102
  .action(() => {
99
103
  const { workspaceDir, profile } = context();
104
+ const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
105
+ for (const entry of Object.values(registry.entries)) {
106
+ if (entry.type === 'persona' && !entry.hub && entry.selection === 'equipped') entry.selection = 'unequipped';
107
+ }
108
+ writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
100
109
  writePersonaSelection(workspaceDir, profile, { source: 'hub' });
101
110
  console.log(JSON.stringify(resolveActivePersonaFile(), null, 2));
102
111
  });
@@ -104,8 +113,17 @@ export function createPersonaCommand(): Command {
104
113
  persona
105
114
  .command('clear')
106
115
  .description('Use no Persona for the active account')
107
- .action(() => {
116
+ .action(async () => {
108
117
  const { workspaceDir, profile } = context();
118
+ const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
119
+ if (Object.values(registry.entries).some(entry => entry.type === 'persona' && entry.hub)
120
+ || readLocalAgentWorkspaceSnapshot(workspaceDir, profile)?.items.persona.length) {
121
+ await HubClient.fromProfile(profile).updateWorkspaceLoadout({ personaItemIds: [] });
122
+ }
123
+ for (const entry of Object.values(registry.entries)) {
124
+ if (entry.type === 'persona') entry.selection = 'unequipped';
125
+ }
126
+ writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
109
127
  writePersonaSelection(workspaceDir, profile, { source: 'none' });
110
128
  console.log(JSON.stringify({ path: null, source: 'none' }, null, 2));
111
129
  });
@@ -17,6 +17,8 @@ export interface AgentWorkspaceRemoteItem {
17
17
  workspace_item_id: string;
18
18
  resource_id: string;
19
19
  version_id: string;
20
+ version_number?: string;
21
+ version_description?: string;
20
22
  resource_type: ResourceType;
21
23
  workspace_kind: 'owned' | 'installed';
22
24
  is_created_by_me: boolean;
@@ -44,6 +44,8 @@ export interface AgentWorkspaceBehaviorManagement {
44
44
  workspaceItemId?: string;
45
45
  resourceId?: string;
46
46
  versionId?: string;
47
+ versionNumber?: string;
48
+ versionDescription?: string;
47
49
  resolution?: LocalAgentWorkspaceSnapshot['items']['strategy'][number]['resolution'];
48
50
  ownerId?: string;
49
51
  ownerName?: string | null;
@@ -74,12 +76,14 @@ export function listAgentWorkspaceBehaviorSources(
74
76
  : []
75
77
  )),
76
78
  );
77
- const sources = listClawclawBehaviorSources(root).map((source) => {
79
+ const sources = listClawclawBehaviorSources(root)
80
+ .filter(source => itemByPath.has(realpathSync(source.sourcePath))).map((source) => {
78
81
  const item = itemByPath.get(realpathSync(source.sourcePath));
79
82
  if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
80
83
  const trusted = item.sourceFiles[0]
81
84
  && item.resolution !== 'local_modified'
82
- && item.resolution !== 'concurrent_difference';
85
+ && item.resolution !== 'concurrent_difference'
86
+ && item.resolution !== 'local_origin_unrecognized';
83
87
  return {
84
88
  ...source,
85
89
  ...(trusted ? { trustedSourceSha256: item.sourceFiles[0]!.sha256 } : {}),
@@ -90,6 +94,8 @@ export function listAgentWorkspaceBehaviorSources(
90
94
  workspaceItemId: item.workspaceItemId,
91
95
  resourceId: item.resourceId,
92
96
  versionId: item.versionId,
97
+ versionNumber: item.versionNumber,
98
+ versionDescription: item.versionDescription,
93
99
  resolution: item.resolution,
94
100
  ...(item.hub?.ownerId ? { ownerId: item.hub.ownerId } : {}),
95
101
  ...(item.hub ? { ownerName: item.hub.ownerName } : {}),
@@ -108,7 +114,10 @@ export function listAgentWorkspacePerceptionSources(
108
114
  const active = currentSnapshot(workspaceDir, profile, snapshot);
109
115
  if (!active || active.items.perception.length === 0) return [];
110
116
  const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'perceptions');
111
- const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root) : [];
117
+ const selectedPaths = new Set(active.items.perception.filter(item => item.runtimeEntryPath)
118
+ .map(item => resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath!)));
119
+ const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root)
120
+ .filter(source => selectedPaths.has(source.sourcePath)) : [];
112
121
  const ids = new Set<string>();
113
122
  for (const source of sources) {
114
123
  if (ids.has(source.id)) throw new Error(`AGENT_RESOURCE_ID_CONFLICT:perception:${source.id}`);