@myclaw163/clawclaw-cli 0.8.16 → 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.
@@ -7,12 +7,14 @@ import {
7
7
  } from 'node:fs';
8
8
  import { basename, dirname, extname, join, relative } from 'node:path';
9
9
  import { createHash } from 'node:crypto';
10
+ import { ApiError } from './http-transport.js';
10
11
  import type { AuthProfile } from './auth.js';
11
12
  import {
12
13
  capabilityWorkspacePath,
13
14
  readCapabilityWorkspaceRegistry,
14
15
  updateCapabilityHubIdentity,
15
16
  setCapabilityConflictChoice,
17
+ classifyStrategyLifecycle,
16
18
  type CapabilityWorkspaceEntry,
17
19
  type CapabilityWorkspaceType,
18
20
  } from './capability-workspace.js';
@@ -51,7 +53,7 @@ export interface CapabilityCloudSyncConflict {
51
53
  export interface CapabilityCloudSyncFailure {
52
54
  type: CapabilityWorkspaceType;
53
55
  id: string;
54
- action: 'create' | 'version' | 'fork';
56
+ action: 'create' | 'version' | 'fork' | 'equipment';
55
57
  error: string;
56
58
  }
57
59
 
@@ -62,6 +64,7 @@ export interface CapabilityCloudSyncSkip {
62
64
  }
63
65
 
64
66
  export interface CapabilityCloudSyncResult {
67
+ equipmentChanged?: boolean;
65
68
  uploaded: CapabilityCloudSyncChange[];
66
69
  conflicts: CapabilityCloudSyncConflict[];
67
70
  failed: CapabilityCloudSyncFailure[];
@@ -76,6 +79,12 @@ interface CapabilityCloudClient {
76
79
  installResource(resourceId: string): ReturnType<HubClient['installResource']>;
77
80
  getResource(type: ResourceType, id: string): ReturnType<HubClient['getResource']>;
78
81
  findWorkspaceItem(type: ResourceType, resourceId: string): ReturnType<HubClient['findWorkspaceItem']>;
82
+ updateWorkspaceEquipment(
83
+ workspaceItemId: string,
84
+ equipped: boolean,
85
+ ): ReturnType<HubClient['updateWorkspaceEquipment']>;
86
+ updateWorkspaceLoadout(input: Parameters<HubClient['updateWorkspaceLoadout']>[0]):
87
+ ReturnType<HubClient['updateWorkspaceLoadout']>;
79
88
  }
80
89
 
81
90
  export interface CapabilityCloudSyncDependencies {
@@ -83,6 +92,31 @@ export interface CapabilityCloudSyncDependencies {
83
92
  entryKeys?: readonly string[];
84
93
  }
85
94
 
95
+ async function updateCloudEquipment(
96
+ client: CapabilityCloudClient,
97
+ type: CapabilityWorkspaceType,
98
+ workspaceItemId: string,
99
+ equipped: boolean,
100
+ ): Promise<void> {
101
+ if (type === 'persona' && equipped) {
102
+ await client.updateWorkspaceLoadout({
103
+ personaItemIds: [workspaceItemId],
104
+ });
105
+ return;
106
+ }
107
+ await client.updateWorkspaceEquipment(workspaceItemId, equipped);
108
+ }
109
+
110
+ function nextPatchVersion(version: string): string {
111
+ const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
112
+ if (!match) throw new Error(`capability_cloud_version_invalid:${version}`);
113
+ return `${match[1]}.${match[2]}.${BigInt(match[3]!) + 1n}`;
114
+ }
115
+
116
+ function unavailableForkSource(error: unknown): boolean {
117
+ return error instanceof ApiError && error.status === 404;
118
+ }
119
+
86
120
  function resourceType(type: CapabilityWorkspaceType): ResourceType {
87
121
  return type === 'behavior' ? 'strategy' : type;
88
122
  }
@@ -209,9 +243,19 @@ export async function syncCapabilitiesToCloud(
209
243
  const selectedKeys = dependencies.entryKeys ? new Set(dependencies.entryKeys) : undefined;
210
244
  const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
211
245
  .filter((entry) => (
212
- entry.runtimeId !== 'clawclaw' && (!selectedKeys || selectedKeys.has(entry.key))
246
+ entry.runtimeId !== 'clawclaw'
247
+ && !entry.hub?.cloudStatus
248
+ && (!selectedKeys || selectedKeys.has(entry.key))
213
249
  ));
214
250
  for (const entry of entries) {
251
+ if (entry.hub?.pendingEquipment !== undefined) {
252
+ // An old request must never replay over a newer Hub selection. The player
253
+ // can retry equip explicitly; load always consumes the latest cloud state.
254
+ updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
255
+ ...entry.hub, pendingEquipment: undefined,
256
+ });
257
+ delete entry.hub.pendingEquipment;
258
+ }
215
259
  if (entry.hub?.pendingBackpackRestoreResourceId) {
216
260
  try {
217
261
  await client.installResource(entry.hub.pendingBackpackRestoreResourceId);
@@ -221,6 +265,9 @@ export async function syncCapabilitiesToCloud(
221
265
  });
222
266
  delete entry.hub.pendingBackpackRestoreResourceId;
223
267
  } catch (error) {
268
+ if (unavailableForkSource(error)) updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
269
+ ...entry.hub, pendingBackpackRestoreResourceId: undefined,
270
+ });
224
271
  result.failed.push({
225
272
  type: entry.type,
226
273
  id: entry.runtimeId,
@@ -290,6 +337,9 @@ export async function syncCapabilitiesToCloud(
290
337
  const action = entry.hub?.publisher === 'self' ? 'version' : entry.hub ? 'fork' : 'create';
291
338
  try {
292
339
  let baseVersionId = entry.hub?.versionId;
340
+ let versionNumber: string | undefined;
341
+ const strategyKind = entry.type === 'behavior'
342
+ ? classifyStrategyLifecycle(readFileSync(path, 'utf8')) : undefined;
293
343
  if (action === 'version' && entry.hub) {
294
344
  const latest = await client.getResource(resourceType(entry.type), entry.hub.resourceId);
295
345
  if (latest.versionId !== entry.hub.versionId && entry.conflictChoice !== 'local') {
@@ -302,6 +352,7 @@ export async function syncCapabilitiesToCloud(
302
352
  continue;
303
353
  }
304
354
  baseVersionId = latest.versionId;
355
+ versionNumber = nextPatchVersion(latest.versionNumber ?? '1.0.0');
305
356
  }
306
357
  validateUploadPayload(entry, path, payload);
307
358
  const uploadedSource = await client.uploadFiles(sourceFileType(entry.type), payload.source);
@@ -317,6 +368,8 @@ export async function syncCapabilitiesToCloud(
317
368
  ? await client.createPrivateVersion({
318
369
  resourceId: entry.hub.resourceId,
319
370
  baseVersionId,
371
+ versionNumber: versionNumber!,
372
+ strategyKind,
320
373
  title: entry.title,
321
374
  description: entry.description,
322
375
  sourceFiles: uploadedSource,
@@ -324,20 +377,21 @@ export async function syncCapabilitiesToCloud(
324
377
  })
325
378
  : await client.createPrivateResource({
326
379
  resourceType: resourceType(entry.type),
380
+ strategyKind,
327
381
  title: entry.title,
328
382
  description: entry.description,
329
383
  sourceFiles: uploadedSource,
330
384
  packageFileId,
331
385
  forkFromWorkspaceItemId: action === 'fork' ? entry.hub?.workspaceItemId : undefined,
332
386
  });
333
- const workspaceItem = mutation.workspaceItemId
334
- ? undefined
335
- : await client.findWorkspaceItem(resourceType(entry.type), mutation.resourceId);
336
- const workspaceItemId = mutation.workspaceItemId ?? workspaceItem?.workspaceItemId;
387
+ // Persist the server-confirmed resource before any further network request.
388
+ // A failed backpack lookup must not turn the next load into another create.
389
+ let workspaceItemId = mutation.workspaceItemId
390
+ ?? (action === 'version' ? entry.hub?.workspaceItemId : undefined);
337
391
  const updatedHubIdentity = {
338
392
  resourceId: mutation.resourceId,
339
393
  versionId: mutation.versionId,
340
- ...(workspaceItemId ? { workspaceItemId } : {}),
394
+ workspaceItemId,
341
395
  publisher: 'self',
342
396
  baseSha256: payload.digest,
343
397
  lastUploadedSha256: payload.digest,
@@ -356,14 +410,47 @@ export async function syncCapabilitiesToCloud(
356
410
  version_id: mutation.versionId,
357
411
  ...(workspaceItemId ? { workspace_item_id: workspaceItemId } : {}),
358
412
  });
413
+ if (!workspaceItemId) {
414
+ try {
415
+ const item = await client.findWorkspaceItem(resourceType(entry.type), mutation.resourceId);
416
+ if (!item) throw new Error('capability_cloud_workspace_item_missing');
417
+ workspaceItemId = item.workspaceItemId;
418
+ updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
419
+ ...updatedHubIdentity, workspaceItemId,
420
+ });
421
+ result.uploaded.at(-1)!.workspace_item_id = workspaceItemId;
422
+ } catch (error) {
423
+ result.failed.push({ type: entry.type, id: entry.runtimeId, action: 'equipment',
424
+ error: `resource_created_workspace_lookup_failed:${error instanceof Error ? error.message : String(error)}` });
425
+ }
426
+ }
427
+ if (action === 'create' && entry.origin === 'local' && entry.selection !== 'pending' && workspaceItemId) {
428
+ try {
429
+ await updateCloudEquipment(client, entry.type, workspaceItemId, entry.selection === 'equipped');
430
+ result.equipmentChanged = true;
431
+ } catch (error) {
432
+ result.failed.push({
433
+ type: entry.type,
434
+ id: entry.runtimeId,
435
+ action: 'equipment',
436
+ error: `capability_cloud_equipment_sync_failed:${
437
+ error instanceof Error ? error.message : String(error)
438
+ }`,
439
+ });
440
+ }
441
+ }
359
442
  if (action === 'fork' && entry.hub) {
360
443
  try {
361
444
  await client.installResource(entry.hub.resourceId);
362
445
  updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
363
446
  ...updatedHubIdentity,
447
+ workspaceItemId,
364
448
  pendingBackpackRestoreResourceId: undefined,
365
449
  });
366
450
  } catch (error) {
451
+ if (unavailableForkSource(error)) updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
452
+ ...updatedHubIdentity, workspaceItemId, pendingBackpackRestoreResourceId: undefined,
453
+ });
367
454
  result.failed.push({
368
455
  type: entry.type,
369
456
  id: entry.runtimeId,
@@ -0,0 +1,62 @@
1
+ import type { AuthProfile } from './auth.js';
2
+ import { HubClient } from './hub-client.js';
3
+ import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry,
4
+ type CapabilityWorkspaceType } from './capability-workspace.js';
5
+ import { updateGameplayConfig } from './gameplay-config.js';
6
+
7
+ export type EquipmentClient = Pick<HubClient,
8
+ 'updateWorkspaceEquipment' | 'updateWorkspaceLoadout' | 'findWorkspaceItem'>;
9
+
10
+ /** One selection path for all currently exposed Agent commands. Cloud failures
11
+ * leave local selection untouched; a confirmed cloud choice is not rolled back
12
+ * using a possibly stale local snapshot. */
13
+ export async function selectCapability(
14
+ workspaceDir: string,
15
+ profile: Pick<AuthProfile, 'apiKey' | 'serverUrl'>,
16
+ type: CapabilityWorkspaceType,
17
+ id: string,
18
+ equipped: boolean,
19
+ providedClient?: EquipmentClient,
20
+ ) {
21
+ const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
22
+ const matches = Object.values(registry.entries).filter(entry => entry.type === type && entry.runtimeId === id);
23
+ const local = matches.filter(entry => entry.origin === 'local');
24
+ const candidates = local.length ? local : matches;
25
+ if (candidates.length !== 1) throw new Error(`capability_selection_${candidates.length ? 'ambiguous' : 'not_found'}:${type}:${id}`);
26
+ const entry = candidates[0]!;
27
+ if (entry.hub) {
28
+ const client = providedClient ?? HubClient.fromProfile(profile);
29
+ if (entry.hub.cloudStatus) throw new Error(`capability_workspace_removed:${type}/${id}`);
30
+ let itemId = entry.hub.workspaceItemId;
31
+ if (!itemId) {
32
+ const item = await client.findWorkspaceItem(type === 'behavior' ? 'strategy' : type, entry.hub.resourceId);
33
+ if (!item) throw new Error(`capability_cloud_workspace_item_missing:${type}/${id}`);
34
+ itemId = item.workspaceItemId;
35
+ }
36
+ if (type === 'persona' && equipped) {
37
+ await client.updateWorkspaceLoadout({ personaItemIds: [itemId] });
38
+ } else {
39
+ await client.updateWorkspaceEquipment(itemId, equipped);
40
+ }
41
+ entry.hub.workspaceItemId = itemId;
42
+ delete entry.hub.pendingEquipment;
43
+ }
44
+ if (type === 'persona' && equipped) {
45
+ for (const other of Object.values(registry.entries)) {
46
+ if (other.type === 'persona' && other.key !== entry.key && other.selection === 'equipped') {
47
+ other.selection = 'unequipped';
48
+ }
49
+ }
50
+ }
51
+ entry.selection = equipped ? 'equipped' : 'unequipped';
52
+ entry.updatedAt = new Date().toISOString();
53
+ writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
54
+ if (type === 'behavior' || type === 'perception') {
55
+ updateGameplayConfig(config => {
56
+ const field = type === 'behavior' ? 'disabled_behaviors' : 'disabled_perception_modules';
57
+ config[field] = config[field].filter(value => value !== id);
58
+ if (!equipped && !entry.hub) config[field].push(id);
59
+ }, workspaceDir, profile);
60
+ }
61
+ return entry;
62
+ }
@@ -28,9 +28,13 @@ export interface CapabilityHubIdentity {
28
28
  baseSha256?: string;
29
29
  lastUploadedSha256?: string;
30
30
  pendingBackpackRestoreResourceId?: string;
31
+ /** Retry a local equipment choice after the cloud resource itself was created successfully. */
32
+ pendingEquipment?: boolean;
31
33
  observedCloudVersionId?: string;
32
34
  /** The working copy existed before CCL had a trustworthy Hub baseline. */
33
35
  localOriginUnrecognized?: boolean;
36
+ /** Cloud association is retained locally but automatic cloud I/O is suspended. */
37
+ cloudStatus?: 'workspace_missing';
34
38
  }
35
39
 
36
40
  export interface CapabilityWorkspaceEntry {
@@ -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 {
@@ -93,6 +93,7 @@ import {
93
93
  readLocalAgentWorkspaceSnapshot,
94
94
  resolveLocalAgentWorkspaceSnapshot,
95
95
  } from '../../lib/agent-workspace-sync.js';
96
+ import { filterInactiveAgentWorkspaceSnapshot } from '../../lib/capability-cloud-presence.js';
96
97
  import {
97
98
  listAgentWorkspaceBehaviorSources,
98
99
  listAgentWorkspacePerceptionSources,
@@ -725,9 +726,13 @@ export async function runClawclawOwner(
725
726
  const perceptionConfig = readWorkspacePerceptionConfig();
726
727
  const gameplayConfig = readGameplayConfig(workspaceDir, options.profile);
727
728
  const storedAgentWorkspace = readLocalAgentWorkspaceSnapshot(workspaceDir, options.profile);
728
- const agentWorkspace = storedAgentWorkspace
729
- ? resolveLocalAgentWorkspaceSnapshot(workspaceDir, options.profile, storedAgentWorkspace)
730
- : undefined;
729
+ const agentWorkspace = filterInactiveAgentWorkspaceSnapshot(
730
+ workspaceDir,
731
+ options.profile,
732
+ storedAgentWorkspace
733
+ ? resolveLocalAgentWorkspaceSnapshot(workspaceDir, options.profile, storedAgentWorkspace)
734
+ : undefined,
735
+ );
731
736
  const configurationWarning: ConfigurationWarning = (code, details) => {
732
737
  telemetry?.log('warn', `runtime.configuration.${code}`, details, {
733
738
  component: 'runtime.behavior',
@@ -742,6 +747,7 @@ export async function runClawclawOwner(
742
747
  discoveredLocalCapabilities.behaviors
743
748
  .filter(({ source, entry }) => (
744
749
  entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
750
+ && !agentWorkspace?.items.strategy.some(item => item.resourceId === entry.hub?.resourceId)
745
751
  ))
746
752
  .map(({ source }) => source),
747
753
  agentBehaviorSources,
@@ -774,6 +780,7 @@ export async function runClawclawOwner(
774
780
  const localPerceptionSources = discoveredLocalCapabilities.perceptions
775
781
  .filter(({ source, entry }) => (
776
782
  entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
783
+ && !agentWorkspace?.items.perception.some(item => item.resourceId === entry.hub?.resourceId)
777
784
  ))
778
785
  .map(({ source }) => source);
779
786
  const perceptionSources = mergeAgentWorkspacePerceptionSources(
@@ -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,