@myclaw163/clawclaw-cli 0.8.12 → 0.8.14

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 (68) hide show
  1. package/docs/configuration.md +11 -12
  2. package/docs/custom-modules/README.md +3 -3
  3. package/docs/custom-modules/behavior.md +1 -1
  4. package/docs/custom-modules/perception.md +1 -1
  5. package/docs/custom-modules/trigger.md +1 -1
  6. package/docs/runtime/official-perception-modules.md +1 -1
  7. package/package.json +1 -1
  8. package/scripts/check-skill-command-surface.mjs +1 -0
  9. package/scripts/sync-bundled-skill.mjs +89 -52
  10. package/skills/clawclaw/SKILL.md +10 -6
  11. package/skills/clawclaw/references/BEHAVIORS.md +2 -0
  12. package/skills/clawclaw/references/CHANNELS.md +1 -1
  13. package/skills/clawclaw/references/COMMANDS.md +11 -4
  14. package/skills/clawclaw/references/HUB.md +4 -2
  15. package/skills/clawclaw/references/STREAM.md +4 -2
  16. package/src/cli.ts +2 -0
  17. package/src/commands/behavior.ts +49 -8
  18. package/src/commands/capability.ts +345 -0
  19. package/src/commands/load.ts +195 -8
  20. package/src/commands/perception.ts +21 -7
  21. package/src/commands/persona.ts +6 -0
  22. package/src/commands/trigger.ts +8 -5
  23. package/src/lib/agent-workspace-skills.ts +167 -68
  24. package/src/lib/agent-workspace-sync.ts +20 -31
  25. package/src/lib/capability-cloud-refresh.ts +313 -0
  26. package/src/lib/capability-cloud-sync.ts +315 -0
  27. package/src/lib/capability-discovery.ts +94 -0
  28. package/src/lib/capability-workspace.ts +291 -0
  29. package/src/lib/game-client.ts +12 -4
  30. package/src/lib/hub-client.ts +131 -4
  31. package/src/lib/persona.ts +1 -24
  32. package/src/lib/skill-host.ts +63 -0
  33. package/src/lib/user-data.ts +47 -59
  34. package/src/lib/zip-store.ts +92 -0
  35. package/src/pipeline/event-format.ts +5 -0
  36. package/src/pipeline/event-hints.ts +10 -0
  37. package/src/runtime/clawclaw/agent-event-policy.ts +2 -0
  38. package/src/runtime/clawclaw/behavior-input.ts +5 -0
  39. package/src/runtime/clawclaw/owner.ts +12 -12
  40. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +150 -18
  41. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +8 -0
  42. package/src/runtime/clawclaw/plugins/behavior/behavior-decision-history.ts +88 -0
  43. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +173 -11
  44. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +6 -0
  45. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +3 -1
  46. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +5 -1
  47. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +5 -5
  48. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +213 -6
  49. package/src/runtime/clawclaw/plugins/source/game-transport.ts +29 -4
  50. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +153 -0
  51. package/src/runtime/clawclaw/plugins/source/types.ts +1 -0
  52. package/src/runtime/clawclaw/runtime.ts +31 -3
  53. package/src/runtime/clawclaw-event-catalog.ts +2 -0
  54. package/src/runtime/framework/events/event-repository.ts +1 -1
  55. package/src/runtime/framework/events/memory-event-repository.ts +59 -1
  56. package/src/runtime/framework/events/sqlite-event-repository.ts +23 -1
  57. package/src/runtime/framework/mailbox/types.ts +2 -0
  58. package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +58 -0
  59. package/src/runtime/framework/persistence/memory-first-persistence.ts +380 -0
  60. package/src/runtime/framework/plugins/contracts.ts +2 -2
  61. package/src/runtime/framework/plugins/runtime-input-journal.ts +173 -17
  62. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +23 -11
  63. package/src/runtime/framework/runtime.ts +57 -4
  64. package/src/runtime/framework/state/history/contracts.ts +9 -1
  65. package/src/runtime/framework/state/history/memory-state-history-repository.ts +49 -7
  66. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +16 -0
  67. package/src/sdk/behavior-plugin/index.ts +5 -24
  68. package/src/sdk/module-input/index.ts +47 -0
@@ -2,17 +2,22 @@ import { spawnSync } from 'node:child_process';
2
2
  import {
3
3
  cpSync,
4
4
  existsSync,
5
+ lstatSync,
5
6
  mkdirSync,
6
7
  readFileSync,
8
+ realpathSync,
7
9
  readdirSync,
8
10
  renameSync,
9
11
  rmSync,
10
12
  statSync,
13
+ symlinkSync,
14
+ unlinkSync,
11
15
  } from 'node:fs';
12
16
  import { createHash, randomUUID } from 'node:crypto';
13
17
  import { homedir } from 'node:os';
14
18
  import { dirname, join, resolve } from 'node:path';
15
19
  import { createRequire } from 'node:module';
20
+ import { fileURLToPath } from 'node:url';
16
21
 
17
22
  const require = createRequire(import.meta.url);
18
23
 
@@ -106,6 +111,13 @@ export function agentSkillTargets(name: string): string[] {
106
111
  ];
107
112
  }
108
113
 
114
+ export function resolveBundledClawclawSkill(): string {
115
+ const dev = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'skills', 'clawclaw');
116
+ if (existsSync(join(dev, 'SKILL.md'))) return dev;
117
+ const packageRoot = dirname(require.resolve('@myclaw163/clawclaw-cli/package.json'));
118
+ return join(packageRoot, 'skills', 'clawclaw');
119
+ }
120
+
109
121
  export function hashAgentSkillDirectory(path: string): string | undefined {
110
122
  if (!existsSync(path) || !statSync(path).isDirectory()) return undefined;
111
123
  const root = resolve(path);
@@ -155,6 +167,57 @@ export function overwriteAgentSkillTarget(sourcePath: string, targetPath: string
155
167
  }
156
168
  }
157
169
 
170
+ /** Point one host at the account's canonical Skill without consuming legacy real directories. */
171
+ export function linkAgentSkillTarget(sourcePath: string, targetPath: string): SkillHostMutationResult {
172
+ const source = resolve(findSkillRoot(sourcePath));
173
+ const target = resolve(targetPath);
174
+ const stage = `${target}.ccl-link-${randomUUID()}`;
175
+ const displaced = `${target}.ccl-old-link-${randomUUID()}`;
176
+ let moved = false;
177
+ try {
178
+ if (!existsSync(join(source, 'SKILL.md'))) return { ok: false, error: 'canonical skill is invalid' };
179
+ mkdirSync(dirname(target), { recursive: true });
180
+ if (existsSync(target)) {
181
+ if (!lstatSync(target).isSymbolicLink()) {
182
+ return { ok: false, error: 'legacy real skill directory is unsupported and was preserved' };
183
+ }
184
+ try {
185
+ if (resolve(realpathSync(target)) === source) {
186
+ return { ok: true };
187
+ }
188
+ } catch {}
189
+ }
190
+ symlinkSync(source, stage, process.platform === 'win32' ? 'junction' : 'dir');
191
+ if (existsSync(target)) {
192
+ renameSync(target, displaced);
193
+ moved = true;
194
+ }
195
+ renameSync(stage, target);
196
+ if (moved) unlinkSync(displaced);
197
+ return { ok: true };
198
+ } catch (error) {
199
+ if (existsSync(stage)) unlinkSync(stage);
200
+ if (moved && !existsSync(target) && existsSync(displaced)) {
201
+ try { renameSync(displaced, target); } catch {}
202
+ }
203
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
204
+ }
205
+ }
206
+
207
+ export function unlinkAgentSkillTarget(targetPath: string): SkillHostMutationResult {
208
+ const target = resolve(targetPath);
209
+ try {
210
+ if (!existsSync(target)) return { ok: true };
211
+ if (!lstatSync(target).isSymbolicLink()) {
212
+ return { ok: false, error: 'legacy real skill directory is unsupported and was preserved' };
213
+ }
214
+ unlinkSync(target);
215
+ return { ok: true };
216
+ } catch (error) {
217
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
218
+ }
219
+ }
220
+
158
221
  export function unregisterAgentSkill(name: string): SkillHostMutationResult {
159
222
  return runSkillsCli(['remove', name, '-g', '-y']);
160
223
  }
@@ -1,11 +1,9 @@
1
1
  import {
2
- cpSync,
3
2
  copyFileSync,
4
3
  existsSync,
5
4
  mkdirSync,
6
5
  readdirSync,
7
6
  readFileSync,
8
- statSync,
9
7
  writeFileSync,
10
8
  } from 'fs';
11
9
  import { createHash } from 'crypto';
@@ -100,67 +98,88 @@ export function getUserDataAccountLocalDir(
100
98
  return join(getUserDataAccountDir(workspaceDir, profile), 'local');
101
99
  }
102
100
 
101
+ export function getUserDataAccountCapabilitiesDir(
102
+ workspaceDir: string,
103
+ profile: Pick<AuthProfile, 'apiKey'>,
104
+ ): string {
105
+ return join(getUserDataAccountDir(workspaceDir, profile), 'capabilities');
106
+ }
107
+
108
+ export function getUserDataAccountDraftsDir(
109
+ workspaceDir: string,
110
+ profile: Pick<AuthProfile, 'apiKey'>,
111
+ ): string {
112
+ return join(getUserDataAccountDir(workspaceDir, profile), 'drafts');
113
+ }
114
+
115
+ export function getUserDataAccountCapabilityRegistryFile(
116
+ workspaceDir: string,
117
+ profile: Pick<AuthProfile, 'apiKey'>,
118
+ ): string {
119
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'registry.json');
120
+ }
121
+
103
122
  export function getUserDataAccountBehaviorsRoot(
104
123
  workspaceDir: string,
105
124
  profile: Pick<AuthProfile, 'apiKey'>,
106
125
  ): string {
107
- return join(getUserDataAccountDir(workspaceDir, profile), 'behaviors');
126
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'behaviors');
108
127
  }
109
128
 
110
129
  export function getUserDataAccountBehaviorsDir(
111
130
  workspaceDir: string,
112
131
  profile: Pick<AuthProfile, 'apiKey'>,
113
132
  ): string {
114
- return join(getUserDataAccountBehaviorsRoot(workspaceDir, profile), 'local');
133
+ return getUserDataAccountBehaviorsRoot(workspaceDir, profile);
115
134
  }
116
135
 
117
136
  export function getUserDataAccountHubBehaviorsDir(
118
137
  workspaceDir: string,
119
138
  profile: Pick<AuthProfile, 'apiKey'>,
120
139
  ): string {
121
- return join(getUserDataAccountBehaviorsRoot(workspaceDir, profile), 'hub');
140
+ return getUserDataAccountBehaviorsRoot(workspaceDir, profile);
122
141
  }
123
142
 
124
143
  export function getUserDataAccountPerceptionsRoot(
125
144
  workspaceDir: string,
126
145
  profile: Pick<AuthProfile, 'apiKey'>,
127
146
  ): string {
128
- return join(getUserDataAccountDir(workspaceDir, profile), 'perceptions');
147
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'perceptions');
129
148
  }
130
149
 
131
150
  export function getUserDataAccountPerceptionsDir(
132
151
  workspaceDir: string,
133
152
  profile: Pick<AuthProfile, 'apiKey'>,
134
153
  ): string {
135
- return join(getUserDataAccountPerceptionsRoot(workspaceDir, profile), 'local');
154
+ return getUserDataAccountPerceptionsRoot(workspaceDir, profile);
136
155
  }
137
156
 
138
157
  export function getUserDataAccountHubPerceptionsDir(
139
158
  workspaceDir: string,
140
159
  profile: Pick<AuthProfile, 'apiKey'>,
141
160
  ): string {
142
- return join(getUserDataAccountPerceptionsRoot(workspaceDir, profile), 'hub');
161
+ return getUserDataAccountPerceptionsRoot(workspaceDir, profile);
143
162
  }
144
163
 
145
164
  export function getUserDataAccountPersonasRoot(
146
165
  workspaceDir: string,
147
166
  profile: Pick<AuthProfile, 'apiKey'>,
148
167
  ): string {
149
- return join(getUserDataAccountDir(workspaceDir, profile), 'personas');
168
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'personas');
150
169
  }
151
170
 
152
171
  export function getUserDataAccountPersonasDir(
153
172
  workspaceDir: string,
154
173
  profile: Pick<AuthProfile, 'apiKey'>,
155
174
  ): string {
156
- return join(getUserDataAccountPersonasRoot(workspaceDir, profile), 'local');
175
+ return getUserDataAccountPersonasRoot(workspaceDir, profile);
157
176
  }
158
177
 
159
178
  export function getUserDataAccountHubPersonasDir(
160
179
  workspaceDir: string,
161
180
  profile: Pick<AuthProfile, 'apiKey'>,
162
181
  ): string {
163
- return join(getUserDataAccountPersonasRoot(workspaceDir, profile), 'hub');
182
+ return getUserDataAccountPersonasRoot(workspaceDir, profile);
164
183
  }
165
184
 
166
185
  export function getUserDataAccountPersonaSelectionFile(
@@ -174,14 +193,21 @@ export function getUserDataAccountTriggersRoot(
174
193
  workspaceDir: string,
175
194
  profile: Pick<AuthProfile, 'apiKey'>,
176
195
  ): string {
177
- return join(getUserDataAccountDir(workspaceDir, profile), 'triggers');
196
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'triggers');
178
197
  }
179
198
 
180
199
  export function getUserDataAccountTriggersDir(
181
200
  workspaceDir: string,
182
201
  profile: Pick<AuthProfile, 'apiKey'>,
183
202
  ): string {
184
- return join(getUserDataAccountTriggersRoot(workspaceDir, profile), 'local');
203
+ return getUserDataAccountTriggersRoot(workspaceDir, profile);
204
+ }
205
+
206
+ export function getUserDataAccountSkillsDir(
207
+ workspaceDir: string,
208
+ profile: Pick<AuthProfile, 'apiKey'>,
209
+ ): string {
210
+ return join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'skills');
185
211
  }
186
212
 
187
213
  export function getUserDataAccountGameplayConfigFile(
@@ -245,30 +271,6 @@ function writeJson(path: string, data: unknown): void {
245
271
  writeFileSync(path, JSON.stringify(data, null, 2) + '\n', 'utf8');
246
272
  }
247
273
 
248
- function contentHash(path: string): string {
249
- return createHash('sha256').update(readFileSync(path)).digest('hex').slice(0, 16);
250
- }
251
-
252
- function copyLegacyLocalModules(from: string, to: string): void {
253
- if (!existsSync(from)) return;
254
- const manifest = readJson<Record<string, { installedHash?: string }>>(
255
- join(from, '.official-manifest.json'),
256
- ) ?? {};
257
- for (const entry of readdirSync(from)) {
258
- if (entry === '.official-manifest.json') continue;
259
- const source = join(from, entry);
260
- const target = join(to, entry);
261
- if (statSync(source).isDirectory()) {
262
- cpSync(source, target, { recursive: true, force: false, errorOnExist: false });
263
- continue;
264
- }
265
- const id = entry.replace(/\.(?:ts|js)$/, '');
266
- const tracked = manifest[id];
267
- if (tracked?.installedHash && tracked.installedHash === contentHash(source)) continue;
268
- if (!existsSync(target)) copyFileSync(source, target);
269
- }
270
- }
271
-
272
274
  export function splitAuthData(data: AuthData): {
273
275
  auth: AuthData;
274
276
  runtime: RuntimeAuthState;
@@ -409,9 +411,8 @@ export function ensureUserDataLayout(workspaceDir: string): UserDataMigrationRes
409
411
  }
410
412
 
411
413
  /**
412
- * Materialize the account-scoped type/local + type/hub authoring layout without
413
- * deleting either legacy workspace-scoped or account/local source. The copy is
414
- * intentionally one-shot per account: after migration, accounts evolve independently.
414
+ * Materialize the account-scoped canonical capability workspace. Legacy local/hub
415
+ * trees are deliberately not migrated: the v3 product model has one editable source.
415
416
  */
416
417
  export function ensureAccountUserDataLayout(
417
418
  workspaceDir: string,
@@ -420,7 +421,7 @@ export function ensureAccountUserDataLayout(
420
421
  ensureUserDataLayout(workspaceDir);
421
422
  const result = EMPTY_RESULT();
422
423
  const accountDir = getUserDataAccountDir(workspaceDir, profile);
423
- const marker = join(accountDir, '.capability-layout-v2.json');
424
+ const marker = join(accountDir, '.capability-layout-v3.json');
424
425
  ensureDir(accountDir);
425
426
  ensureDir(getUserDataAccountBehaviorsDir(workspaceDir, profile));
426
427
  ensureDir(getUserDataAccountHubBehaviorsDir(workspaceDir, profile));
@@ -429,26 +430,13 @@ export function ensureAccountUserDataLayout(
429
430
  ensureDir(getUserDataAccountPersonasDir(workspaceDir, profile));
430
431
  ensureDir(getUserDataAccountHubPersonasDir(workspaceDir, profile));
431
432
  ensureDir(getUserDataAccountTriggersDir(workspaceDir, profile));
433
+ ensureDir(getUserDataAccountSkillsDir(workspaceDir, profile));
434
+ ensureDir(getUserDataAccountDraftsDir(workspaceDir, profile));
432
435
  if (existsSync(marker)) return result;
433
-
434
- const copies: Array<[string, string, string]> = [
435
- [join(getUserDataAccountLocalDir(workspaceDir, profile), 'behaviors'), getUserDataAccountBehaviorsDir(workspaceDir, profile), 'account-local/behaviors'],
436
- [join(getUserDataAccountLocalDir(workspaceDir, profile), 'perceptions'), getUserDataAccountPerceptionsDir(workspaceDir, profile), 'account-local/perceptions'],
437
- [join(getUserDataAccountLocalDir(workspaceDir, profile), 'personas'), getUserDataAccountPersonasDir(workspaceDir, profile), 'account-local/personas'],
438
- [join(getUserDataAccountLocalDir(workspaceDir, profile), 'triggers'), getUserDataAccountTriggersDir(workspaceDir, profile), 'account-local/triggers'],
439
- [getUserDataBehaviorsDir(workspaceDir), getUserDataAccountBehaviorsDir(workspaceDir, profile), 'behaviors'],
440
- [getUserDataPerceptionsDir(workspaceDir), getUserDataAccountPerceptionsDir(workspaceDir, profile), 'perceptions'],
441
- [getUserDataTriggersDir(workspaceDir), getUserDataAccountTriggersDir(workspaceDir, profile), 'triggers'],
442
- ];
443
- for (const [from, to, label] of copies) {
444
- if (!existsSync(from)) continue;
445
- copyLegacyLocalModules(from, to);
446
- result.copied.push(`user-data/${label} -> user-data/accounts/<account-hash>/<type>/local`);
447
- }
448
436
  writeJson(marker, {
449
- format: 2,
450
- migrated_at: new Date().toISOString(),
451
- copied: result.copied,
437
+ format: 3,
438
+ created_at: new Date().toISOString(),
439
+ migrated: false,
452
440
  });
453
441
  return result;
454
442
  }
@@ -0,0 +1,92 @@
1
+ import { createHash } from 'node:crypto';
2
+
3
+ export interface ZipStoreEntry {
4
+ path: string;
5
+ content: Buffer;
6
+ }
7
+
8
+ const CRC_TABLE = (() => {
9
+ const table = new Uint32Array(256);
10
+ for (let index = 0; index < 256; index += 1) {
11
+ let value = index;
12
+ for (let bit = 0; bit < 8; bit += 1) {
13
+ value = (value & 1) !== 0 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
14
+ }
15
+ table[index] = value >>> 0;
16
+ }
17
+ return table;
18
+ })();
19
+
20
+ function crc32(buffer: Buffer): number {
21
+ let crc = 0xffffffff;
22
+ for (const byte of buffer) crc = CRC_TABLE[(crc ^ byte) & 0xff]! ^ (crc >>> 8);
23
+ return (crc ^ 0xffffffff) >>> 0;
24
+ }
25
+
26
+ function normalizedPath(path: string): string {
27
+ const value = path.replaceAll('\\', '/');
28
+ if (
29
+ !value
30
+ || value.startsWith('/')
31
+ || value.split('/').some((segment) => !segment || segment === '.' || segment === '..')
32
+ ) throw new Error('zip_store_path_invalid');
33
+ return value;
34
+ }
35
+
36
+ /** Deterministic uncompressed ZIP, sufficient for Hub Skill packages. */
37
+ export function createStoredZip(entries: readonly ZipStoreEntry[]): Buffer {
38
+ const sorted = [...entries]
39
+ .map((entry) => ({ path: normalizedPath(entry.path), content: Buffer.from(entry.content) }))
40
+ .sort((left, right) => left.path.localeCompare(right.path));
41
+ if (sorted.length === 0 || sorted.length > 0xffff) throw new Error('zip_store_entry_count_invalid');
42
+ const localParts: Buffer[] = [];
43
+ const centralParts: Buffer[] = [];
44
+ let offset = 0;
45
+ for (const entry of sorted) {
46
+ const name = Buffer.from(entry.path, 'utf8');
47
+ const checksum = crc32(entry.content);
48
+ const local = Buffer.alloc(30);
49
+ local.writeUInt32LE(0x04034b50, 0);
50
+ local.writeUInt16LE(20, 4);
51
+ local.writeUInt16LE(0x0800, 6);
52
+ local.writeUInt16LE(0, 8);
53
+ local.writeUInt32LE(checksum, 14);
54
+ local.writeUInt32LE(entry.content.length, 18);
55
+ local.writeUInt32LE(entry.content.length, 22);
56
+ local.writeUInt16LE(name.length, 26);
57
+ localParts.push(local, name, entry.content);
58
+
59
+ const central = Buffer.alloc(46);
60
+ central.writeUInt32LE(0x02014b50, 0);
61
+ central.writeUInt16LE(20, 4);
62
+ central.writeUInt16LE(20, 6);
63
+ central.writeUInt16LE(0x0800, 8);
64
+ central.writeUInt16LE(0, 10);
65
+ central.writeUInt32LE(checksum, 16);
66
+ central.writeUInt32LE(entry.content.length, 20);
67
+ central.writeUInt32LE(entry.content.length, 24);
68
+ central.writeUInt16LE(name.length, 28);
69
+ central.writeUInt32LE(offset, 42);
70
+ centralParts.push(central, name);
71
+ offset += local.length + name.length + entry.content.length;
72
+ }
73
+ const centralDirectory = Buffer.concat(centralParts);
74
+ const end = Buffer.alloc(22);
75
+ end.writeUInt32LE(0x06054b50, 0);
76
+ end.writeUInt16LE(sorted.length, 8);
77
+ end.writeUInt16LE(sorted.length, 10);
78
+ end.writeUInt32LE(centralDirectory.length, 12);
79
+ end.writeUInt32LE(offset, 16);
80
+ return Buffer.concat([...localParts, centralDirectory, end]);
81
+ }
82
+
83
+ export function zipContentDigest(entries: readonly ZipStoreEntry[]): string {
84
+ const hash = createHash('sha256');
85
+ for (const entry of [...entries].sort((left, right) => left.path.localeCompare(right.path))) {
86
+ hash.update(normalizedPath(entry.path));
87
+ hash.update('\0');
88
+ hash.update(entry.content);
89
+ hash.update('\0');
90
+ }
91
+ return hash.digest('hex');
92
+ }
@@ -503,6 +503,11 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
503
503
  case 'game_over':
504
504
  if (isRoomGameEvent(event, ctx)) return '本轮房间对局结束。';
505
505
  return `游戏结束:${firstString(event, ['winner_name'], '未知玩家')}获胜(${firstString(event, ['winner'])}),原因 ${firstString(event, ['reason'])}。`;
506
+ case 'game_over_recovered':
507
+ if (isRoomGameEvent(event, ctx)) return 'GameSync终局帧缺失,但后端结算已确认本轮房间对局结束。';
508
+ return `GameSync终局帧缺失,但后端结算已确认游戏结束:${firstString(event, ['winner', 'winning_faction'])}阵营获胜,原因 ${firstString(event, ['reason', 'win_reason'])}。`;
509
+ case 'game_terminal_missing':
510
+ return '当前对局已从后端参与状态中消失,但未收到终局帧,也没有查到匹配的结算;本局结果未知。';
506
511
  case 'octopus_time_win':
507
512
  return `${playerLabel(event.winner_name ?? event.actor_name, firstNumber(event, ['winner_seat', 'actor_seat']), ctx)}作为章鱼存活满60秒并获胜。`;
508
513
  case 'win_blocked_by_octopus':
@@ -318,6 +318,16 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
318
318
  }
319
319
  return 'The GameServer did not provide its first State in time. The Owner is reconciling automatically; stay attached and do not start a duplicate runtime.';
320
320
  },
321
+ game_over_recovered: (event, ctx) => (
322
+ isRoomGameEvent(event, ctx)
323
+ ? ROOM_GAME_OVER_HINT
324
+ : 'The terminal GameSync frame was missed, but the matching Lobby settlement confirms game over. Stop game actions, review the result with the user, and start another match only if the user asks.'
325
+ ),
326
+ game_terminal_missing: (event, ctx) => (
327
+ isRoomGameEvent(event, ctx)
328
+ ? 'The room round disappeared from backend participation without a terminal frame or matching settlement. The result is unknown; tell the user and stay attached while the runtime returns to the room Lobby.'
329
+ : 'The game disappeared from backend participation without a terminal frame or matching settlement. The result is unknown; tell the user and do not claim a winner.'
330
+ ),
321
331
  game_stream_disconnected: () => (
322
332
  'The game stream disconnected and the Owner is reconnecting. Stay attached and do not start a duplicate runtime.'
323
333
  ),
@@ -2,6 +2,8 @@ const DEFAULT_MONITOR_PRIORITY = 50;
2
2
 
3
3
  export const CLAWCLAW_MONITOR_EVENT_PRIORITY: Readonly<Record<string, number>> = Object.freeze({
4
4
  service_status: 95,
5
+ game_stream_disconnected: 80,
6
+ game_terminal_missing: 95,
5
7
  kill: 99,
6
8
  killed: 99,
7
9
  murder_witnessed: 95,
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  BehaviorContinuation,
3
+ BehaviorDecisionFrame,
3
4
  BehaviorInput,
4
5
  GameEvent,
5
6
  GameState,
@@ -49,6 +50,7 @@ export function createBehaviorInput<
49
50
  input: RuntimeEpochPluginInput<Record<string, any>>,
50
51
  behaviorInput: TInput,
51
52
  continuation?: Readonly<BehaviorContinuation>,
53
+ decisionHistory: readonly Readonly<BehaviorDecisionFrame>[] = [],
52
54
  ): BehaviorInput<TInput> | null {
53
55
  const runtimeState = input.epoch.state;
54
56
  if (!isClawclawRuntimeState(runtimeState) || runtimeState.game_snapshot.status !== 'fresh') {
@@ -68,6 +70,9 @@ export function createBehaviorInput<
68
70
  gameState,
69
71
  events: behaviorEvents(input),
70
72
  input: structuredClone(behaviorInput),
73
+ // The Owner ring exposes one recursively immutable snapshot. Serial modules
74
+ // can share it directly; Worker postMessage performs the one required clone.
75
+ decisionHistory,
71
76
  ...(continuation === undefined ? {} : { continuation: structuredClone(continuation) }),
72
77
  });
73
78
  }
@@ -87,9 +87,6 @@ import {
87
87
  } from './plugins/mailbox/index.js';
88
88
  import { BEHAVIOR_PLUGIN_API_VERSION, resolveClawclawResourceMetadata } from '../../sdk/behavior-plugin/index.js';
89
89
  import { TRIGGER_PLUGIN_API_VERSION } from '../../sdk/trigger-plugin/index.js';
90
- import {
91
- listClawclawBehaviorSources,
92
- } from './plugins/behavior/behavior-source.js';
93
90
  import {
94
91
  readLocalAgentWorkspaceSnapshot,
95
92
  resolveLocalAgentWorkspaceSnapshot,
@@ -115,11 +112,9 @@ import {
115
112
  import {
116
113
  type ClawclawOwnerNotificationHost,
117
114
  } from './notifications.js';
118
- import { listClawclawPerceptionSourcesInDirectory } from './plugins/perception/perception-source.js';
115
+ import { discoverLocalCapabilities } from '../../lib/capability-discovery.js';
119
116
  import {
120
117
  ensureAccountUserDataLayout,
121
- getUserDataAccountBehaviorsDir,
122
- getUserDataAccountPerceptionsDir,
123
118
  getUserDataAccountTriggersDir,
124
119
  } from '../../lib/user-data.js';
125
120
 
@@ -733,13 +728,16 @@ export async function runClawclawOwner(
733
728
  });
734
729
  };
735
730
  const disabledBehaviors = new Set(gameplayConfig.disabled_behaviors);
731
+ const discoveredLocalCapabilities = discoverLocalCapabilities(workspaceDir, options.profile);
736
732
  const agentBehaviorSources = agentWorkspace
737
733
  ? listAgentWorkspaceBehaviorSources(workspaceDir, options.profile, agentWorkspace)
738
734
  : [];
739
735
  const behaviorSources = mergeAgentWorkspaceBehaviorSources(
740
- listClawclawBehaviorSources(
741
- getUserDataAccountBehaviorsDir(workspaceDir, options.profile),
742
- ).filter((source) => !disabledBehaviors.has(source.id)),
736
+ discoveredLocalCapabilities.behaviors
737
+ .filter(({ source, entry }) => (
738
+ entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
739
+ ))
740
+ .map(({ source }) => source),
743
741
  agentBehaviorSources,
744
742
  );
745
743
  const behaviorSourceById = new Map(behaviorSources.map((source) => [source.id, source]));
@@ -767,9 +765,11 @@ export async function runClawclawOwner(
767
765
  const agentPerceptionSources = agentWorkspace
768
766
  ? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace)
769
767
  : [];
770
- const localPerceptionSources = listClawclawPerceptionSourcesInDirectory(
771
- getUserDataAccountPerceptionsDir(workspaceDir, options.profile),
772
- ).filter((source) => !disabledPerceptions.has(source.id));
768
+ const localPerceptionSources = discoveredLocalCapabilities.perceptions
769
+ .filter(({ source, entry }) => (
770
+ entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
771
+ ))
772
+ .map(({ source }) => source);
773
773
  const perceptionSources = mergeAgentWorkspacePerceptionSources(
774
774
  localPerceptionSources,
775
775
  agentPerceptionSources,