@myclaw163/clawclaw-cli 0.10.18 → 0.10.19

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.
@@ -297,19 +297,19 @@ function createPrepareCommand(dependencies = {}) {
297
297
  });
298
298
  }
299
299
  if (activeWorkspace) {
300
- const discoveredPaths = new Set(hubBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
300
+ const discoveredResources = new Set(hubBehaviors.map((source) => source.management.resourceId));
301
301
  for (const item of activeWorkspace.items.strategy) {
302
302
  if (!item.runtimeEntryPath) {
303
303
  capabilityWarnings.push(missingProjectionWarning("behavior", item));
304
304
  continue;
305
305
  }
306
+ if (discoveredResources.has(item.resourceId)) continue;
306
307
  const path = resolveLocalAgentWorkspacePath(
307
308
  workspaceDir,
308
309
  profile,
309
310
  activeWorkspace,
310
311
  item.runtimeEntryPath
311
312
  );
312
- if (discoveredPaths.has(resolve(path))) continue;
313
313
  capabilityWarnings.push(warningFromStaticDiagnostic(
314
314
  "behavior",
315
315
  "hub",
@@ -407,12 +407,7 @@ function createPrepareCommand(dependencies = {}) {
407
407
  const hubPerceptions = activeWorkspace ? listAgentWorkspacePerceptionSources(workspaceDir, profile, activeWorkspace) : [];
408
408
  if (activeWorkspace) {
409
409
  for (const source of hubPerceptions) {
410
- const item = activeWorkspace.items.perception.find((candidate) => !!candidate.runtimeEntryPath && resolveLocalAgentWorkspacePath(
411
- workspaceDir,
412
- profile,
413
- activeWorkspace,
414
- candidate.runtimeEntryPath
415
- ) === source.sourcePath);
410
+ const item = activeWorkspace.items.perception.find((candidate) => candidate.resourceId === source.resourceId);
416
411
  const workingPath = item ? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item) : void 0;
417
412
  if (!item || !workingPath) continue;
418
413
  registerDiscoveredCapability(workspaceDir, profile, {
@@ -453,19 +448,19 @@ function createPrepareCommand(dependencies = {}) {
453
448
  });
454
449
  }
455
450
  if (activeWorkspace) {
456
- const discoveredPaths = new Set(hubPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
451
+ const discoveredResources = new Set(hubPerceptions.map((source) => source.resourceId));
457
452
  for (const item of activeWorkspace.items.perception) {
458
453
  if (!item.runtimeEntryPath) {
459
454
  capabilityWarnings.push(missingProjectionWarning("perception", item));
460
455
  continue;
461
456
  }
457
+ if (discoveredResources.has(item.resourceId)) continue;
462
458
  const path = resolveLocalAgentWorkspacePath(
463
459
  workspaceDir,
464
460
  profile,
465
461
  activeWorkspace,
466
462
  item.runtimeEntryPath
467
463
  );
468
- if (discoveredPaths.has(resolve(path))) continue;
469
464
  capabilityWarnings.push(warningFromStaticDiagnostic(
470
465
  "perception",
471
466
  "hub",
@@ -18,6 +18,27 @@ import {
18
18
  function currentSnapshot(workspaceDir, profile, snapshot) {
19
19
  return snapshot ?? readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
20
20
  }
21
+ function existingFilePath(path) {
22
+ try {
23
+ return realpathSync.native(path);
24
+ } catch {
25
+ return void 0;
26
+ }
27
+ }
28
+ function matchHubProjections(workspaceDir, profile, snapshot, items, sources) {
29
+ const itemsByPath = /* @__PURE__ */ new Map();
30
+ for (const item of items) {
31
+ if (!item.runtimeEntryPath) continue;
32
+ const projection = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.runtimeEntryPath);
33
+ const path = existingFilePath(projection);
34
+ if (path !== void 0) itemsByPath.set(path, item);
35
+ }
36
+ return sources.flatMap((source) => {
37
+ const path = existingFilePath(source.sourcePath);
38
+ const item = path === void 0 ? void 0 : itemsByPath.get(path);
39
+ return item ? [{ source, item }] : [];
40
+ });
41
+ }
21
42
  function assertUniqueBehaviorIds(sources, origin) {
22
43
  const ids = /* @__PURE__ */ new Set();
23
44
  for (const source of sources) {
@@ -32,17 +53,14 @@ function listAgentWorkspaceBehaviorSources(workspaceDir, profile, snapshot) {
32
53
  if (!active || active.items.strategy.length === 0) return [];
33
54
  const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), "runtime", "behaviors");
34
55
  if (!existsSync(root)) return [];
35
- const itemByPath = new Map(
36
- active.items.strategy.flatMap((item) => item.runtimeEntryPath ? [[realpathSync(resolveLocalAgentWorkspacePath(
37
- workspaceDir,
38
- profile,
39
- active,
40
- item.runtimeEntryPath
41
- )), item]] : [])
56
+ const projections = matchHubProjections(
57
+ workspaceDir,
58
+ profile,
59
+ active,
60
+ active.items.strategy,
61
+ listClawclawBehaviorSources(root)
42
62
  );
43
- const sources = listClawclawBehaviorSources(root).filter((source) => itemByPath.has(realpathSync(source.sourcePath))).map((source) => {
44
- const item = itemByPath.get(realpathSync(source.sourcePath));
45
- if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
63
+ const sources = projections.map(({ source, item }) => {
46
64
  const trusted = item.sourceFiles[0] && item.resolution !== "local_modified" && item.resolution !== "concurrent_difference" && item.resolution !== "local_origin_unrecognized";
47
65
  const managed = {
48
66
  ...source,
@@ -98,10 +116,14 @@ function listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot) {
98
116
  const active = currentSnapshot(workspaceDir, profile, snapshot);
99
117
  if (!active || active.items.perception.length === 0) return [];
100
118
  const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), "runtime", "perceptions");
101
- const selectedPaths = new Set(active.items.perception.filter((item) => item.runtimeEntryPath).map((item) => resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath)));
102
- const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root).filter((source) => selectedPaths.has(source.sourcePath)) : [];
103
- const namedSources = sources.map((source) => {
104
- const item = active.items.perception.find((item2) => item2.runtimeEntryPath && resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item2.runtimeEntryPath) === source.sourcePath);
119
+ const projections = matchHubProjections(
120
+ workspaceDir,
121
+ profile,
122
+ active,
123
+ active.items.perception,
124
+ listClawclawPerceptionSourcesInDirectory(root)
125
+ );
126
+ const namedSources = projections.map(({ source, item }) => {
105
127
  const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item) ?? join(
106
128
  getUserDataAccountCapabilitiesDir(workspaceDir, profile),
107
129
  "perceptions",
@@ -128,7 +150,7 @@ function listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot) {
128
150
  baseSha256: item.sourceFiles[0]?.sha256
129
151
  }
130
152
  });
131
- return perceptionOperationName({ ...source, workingCopyPath }, entry);
153
+ return perceptionOperationName({ ...source, workingCopyPath, resourceId: item.resourceId }, entry);
132
154
  });
133
155
  const ids = /* @__PURE__ */ new Set();
134
156
  for (const source of namedSources) {
@@ -4,6 +4,7 @@ import {
4
4
  existsSync,
5
5
  mkdirSync,
6
6
  readFileSync,
7
+ realpathSync,
7
8
  writeFileSync
8
9
  } from "fs";
9
10
  import { createHash } from "crypto";
@@ -43,7 +44,8 @@ function getUserDataMemoryFile(workspaceDir, profile) {
43
44
  return join(getUserDataAccountDir(workspaceDir, profile), "memory.md");
44
45
  }
45
46
  function getUserDataAgentWorkspaceDir(workspaceDir, profile) {
46
- return join(getUserDataAccountDir(workspaceDir, profile), "hub-loadout");
47
+ const directory = join(getUserDataAccountDir(workspaceDir, profile), "hub-loadout");
48
+ return existsSync(directory) ? realpathSync(directory) : directory;
47
49
  }
48
50
  function getUserDataAgentWorkspaceCurrentFile(workspaceDir, profile) {
49
51
  return join(getUserDataAgentWorkspaceDir(workspaceDir, profile), "current.json");
@@ -216,6 +216,7 @@ import {
216
216
  existsSync,
217
217
  mkdirSync,
218
218
  readFileSync,
219
+ realpathSync,
219
220
  writeFileSync
220
221
  } from "fs";
221
222
  import { createHash as createHash2 } from "crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.10.18",
3
+ "version": "0.10.19",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: clawclaw
3
3
  description: ClawClaw/龙虾杀的完整玩法 Skill,仅在游戏事件流接通后读取。开局或恢复连接之前不要读取本 Skill,此阶段只读取 clawclaw-start。start/join 成功接流后立即调用本 Skill,不必等待匹配完成或身份分配。用于处理实时游戏事件、角色行动、策略、会议发言与投票、结算和复盘。资源创作使用 clawclaw-creator。
4
- version: 4.8.135
4
+ version: 4.8.136
5
5
  ---
6
6
 
7
7
  # 龙虾杀完整玩法(接流后调用)
@@ -406,19 +406,19 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
406
406
  ...(operationName ? { id: operationName } : {}) });
407
407
  }
408
408
  if (activeWorkspace) {
409
- const discoveredPaths = new Set(hubBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
409
+ const discoveredResources = new Set(hubBehaviors.map(source => source.management.resourceId));
410
410
  for (const item of activeWorkspace.items.strategy) {
411
411
  if (!item.runtimeEntryPath) {
412
412
  capabilityWarnings.push(missingProjectionWarning('behavior', item));
413
413
  continue;
414
414
  }
415
+ if (discoveredResources.has(item.resourceId)) continue;
415
416
  const path = resolveLocalAgentWorkspacePath(
416
417
  workspaceDir,
417
418
  profile,
418
419
  activeWorkspace,
419
420
  item.runtimeEntryPath,
420
421
  );
421
- if (discoveredPaths.has(resolve(path))) continue;
422
422
  capabilityWarnings.push(warningFromStaticDiagnostic(
423
423
  'behavior',
424
424
  'hub',
@@ -521,15 +521,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
521
521
  : [];
522
522
  if (activeWorkspace) {
523
523
  for (const source of hubPerceptions) {
524
- const item = activeWorkspace.items.perception.find((candidate) => (
525
- !!candidate.runtimeEntryPath
526
- && resolveLocalAgentWorkspacePath(
527
- workspaceDir,
528
- profile,
529
- activeWorkspace!,
530
- candidate.runtimeEntryPath,
531
- ) === source.sourcePath
532
- ));
524
+ const item = activeWorkspace.items.perception.find(candidate => candidate.resourceId === source.resourceId);
533
525
  const workingPath = item
534
526
  ? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
535
527
  : undefined;
@@ -577,19 +569,19 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
577
569
  ...(operationName ? { id: operationName } : {}) });
578
570
  }
579
571
  if (activeWorkspace) {
580
- const discoveredPaths = new Set(hubPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
572
+ const discoveredResources = new Set(hubPerceptions.map(source => source.resourceId));
581
573
  for (const item of activeWorkspace.items.perception) {
582
574
  if (!item.runtimeEntryPath) {
583
575
  capabilityWarnings.push(missingProjectionWarning('perception', item));
584
576
  continue;
585
577
  }
578
+ if (discoveredResources.has(item.resourceId)) continue;
586
579
  const path = resolveLocalAgentWorkspacePath(
587
580
  workspaceDir,
588
581
  profile,
589
582
  activeWorkspace,
590
583
  item.runtimeEntryPath,
591
584
  );
592
- if (discoveredPaths.has(resolve(path))) continue;
593
585
  capabilityWarnings.push(warningFromStaticDiagnostic(
594
586
  'perception',
595
587
  'hub',
@@ -1,11 +1,12 @@
1
1
  import { existsSync, realpathSync } from 'node:fs';
2
- import { join, resolve, basename } from 'node:path';
2
+ import { join, basename } from 'node:path';
3
3
  import type { AuthProfile } from './auth.js';
4
4
  import {
5
5
  localAgentWorkspaceSnapshotRoot,
6
6
  readLocalAgentWorkspaceSnapshot,
7
7
  resolveLocalAgentWorkspacePath,
8
8
  resolveLocalAgentWorkspaceWorkingCopyPath,
9
+ type LocalAgentWorkspaceItem,
9
10
  type LocalAgentWorkspaceSnapshot,
10
11
  } from './agent-workspace-sync.js';
11
12
  import { registerDiscoveredCapability } from './capability-workspace.js';
@@ -28,6 +29,36 @@ function currentSnapshot(
28
29
  return snapshot ?? readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
29
30
  }
30
31
 
32
+ function existingFilePath(path: string): string | undefined {
33
+ try {
34
+ return realpathSync.native(path);
35
+ } catch {
36
+ // An unavailable projection stays undiscovered so prepare can report its diagnostic.
37
+ return undefined;
38
+ }
39
+ }
40
+
41
+ function matchHubProjections<T extends { readonly sourcePath: string }>(
42
+ workspaceDir: string,
43
+ profile: Pick<AuthProfile, 'apiKey'>,
44
+ snapshot: LocalAgentWorkspaceSnapshot,
45
+ items: readonly LocalAgentWorkspaceItem[],
46
+ sources: readonly T[],
47
+ ): { source: T; item: LocalAgentWorkspaceItem }[] {
48
+ const itemsByPath = new Map<string, LocalAgentWorkspaceItem>();
49
+ for (const item of items) {
50
+ if (!item.runtimeEntryPath) continue;
51
+ const projection = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.runtimeEntryPath);
52
+ const path = existingFilePath(projection);
53
+ if (path !== undefined) itemsByPath.set(path, item);
54
+ }
55
+ return sources.flatMap(source => {
56
+ const path = existingFilePath(source.sourcePath);
57
+ const item = path === undefined ? undefined : itemsByPath.get(path);
58
+ return item ? [{ source, item }] : [];
59
+ });
60
+ }
61
+
31
62
  function assertUniqueBehaviorIds(
32
63
  sources: readonly ResolvedClawclawBehaviorSource[],
33
64
  origin: 'local' | 'hub',
@@ -69,22 +100,10 @@ export function listAgentWorkspaceBehaviorSources(
69
100
  if (!active || active.items.strategy.length === 0) return [];
70
101
  const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'behaviors');
71
102
  if (!existsSync(root)) return [];
72
- const itemByPath = new Map(
73
- active.items.strategy.flatMap((item) => (
74
- item.runtimeEntryPath
75
- ? [[realpathSync(resolveLocalAgentWorkspacePath(
76
- workspaceDir,
77
- profile,
78
- active,
79
- item.runtimeEntryPath,
80
- )), item] as const]
81
- : []
82
- )),
103
+ const projections = matchHubProjections(
104
+ workspaceDir, profile, active, active.items.strategy, listClawclawBehaviorSources(root),
83
105
  );
84
- const sources = listClawclawBehaviorSources(root)
85
- .filter(source => itemByPath.has(realpathSync(source.sourcePath))).map((source) => {
86
- const item = itemByPath.get(realpathSync(source.sourcePath));
87
- if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
106
+ const sources = projections.map(({ source, item }) => {
88
107
  const trusted = item.sourceFiles[0]
89
108
  && item.resolution !== 'local_modified'
90
109
  && item.resolution !== 'concurrent_difference'
@@ -132,17 +151,14 @@ export function listAgentWorkspacePerceptionSources(
132
151
  workspaceDir: string,
133
152
  profile: Pick<AuthProfile, 'apiKey'>,
134
153
  snapshot?: LocalAgentWorkspaceSnapshot,
135
- ): readonly ResolvedClawclawPerceptionSource[] {
154
+ ): readonly (ResolvedClawclawPerceptionSource & { readonly resourceId: string })[] {
136
155
  const active = currentSnapshot(workspaceDir, profile, snapshot);
137
156
  if (!active || active.items.perception.length === 0) return [];
138
157
  const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'perceptions');
139
- const selectedPaths = new Set(active.items.perception.filter(item => item.runtimeEntryPath)
140
- .map(item => resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath!)));
141
- const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root)
142
- .filter(source => selectedPaths.has(source.sourcePath)) : [];
143
- const namedSources = sources.map(source => {
144
- const item = active.items.perception.find(item => item.runtimeEntryPath
145
- && resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath) === source.sourcePath)!;
158
+ const projections = matchHubProjections(
159
+ workspaceDir, profile, active, active.items.perception, listClawclawPerceptionSourcesInDirectory(root),
160
+ );
161
+ const namedSources = projections.map(({ source, item }) => {
146
162
  const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
147
163
  ?? join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'perceptions', item.resourceId,
148
164
  item.sourceFiles[0]?.relativePath ?? basename(source.sourcePath));
@@ -156,7 +172,7 @@ export function listAgentWorkspacePerceptionSources(
156
172
  ...(item.forkReconciliation?.status === 'unresolved' ? { forkRelationshipUnresolved: true } : {}),
157
173
  publisher: item.hub?.publisher ?? 'community', baseSha256: item.sourceFiles[0]?.sha256 },
158
174
  });
159
- return perceptionOperationName({ ...source, workingCopyPath }, entry);
175
+ return perceptionOperationName({ ...source, workingCopyPath, resourceId: item.resourceId }, entry);
160
176
  });
161
177
  const ids = new Set<string>();
162
178
  for (const source of namedSources) {
@@ -5,6 +5,7 @@ import {
5
5
  mkdirSync,
6
6
  readdirSync,
7
7
  readFileSync,
8
+ realpathSync,
8
9
  writeFileSync,
9
10
  } from 'fs';
10
11
  import { createHash } from 'crypto';
@@ -75,7 +76,9 @@ export function getUserDataAgentWorkspaceDir(
75
76
  workspaceDir: string,
76
77
  profile: Pick<AuthProfile, 'apiKey'>,
77
78
  ): string {
78
- return join(getUserDataAccountDir(workspaceDir, profile), 'hub-loadout');
79
+ const directory = join(getUserDataAccountDir(workspaceDir, profile), 'hub-loadout');
80
+ // Staging and validating an update must use the same directory the module scanner sees.
81
+ return existsSync(directory) ? realpathSync(directory) : directory;
79
82
  }
80
83
 
81
84
  export function getUserDataAgentWorkspaceCurrentFile(