@myclaw163/clawclaw-cli 0.7.6 → 0.7.7

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 (46) hide show
  1. package/docs/desktop-event-push.md +37 -3
  2. package/docs/runtime/README.md +1 -0
  3. package/docs/runtime/official-perception-modules.md +346 -0
  4. package/package.json +1 -1
  5. package/src/commands/game/index.ts +1 -1
  6. package/src/lib/service-status.test.ts +56 -0
  7. package/src/lib/service-status.ts +111 -0
  8. package/src/pipeline/event-format.test.ts +13 -0
  9. package/src/pipeline/event-format.ts +11 -0
  10. package/src/pipeline/event-hints.test.ts +18 -3
  11. package/src/pipeline/event-hints.ts +11 -0
  12. package/src/runtime/clawclaw/agent-event-policy.test.ts +4 -0
  13. package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
  14. package/src/runtime/clawclaw/owner.ts +6 -0
  15. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +24 -0
  16. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +29 -0
  17. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +39 -0
  18. package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -0
  19. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +6 -0
  20. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +6 -0
  21. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +6 -0
  22. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +6 -0
  23. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +6 -0
  24. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +6 -0
  25. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +6 -0
  26. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +11 -0
  27. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +8 -0
  28. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +12 -0
  29. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +37 -1
  30. package/src/runtime/clawclaw/plugins/source/room-transport.ts +2 -1
  31. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +149 -1
  32. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +109 -21
  33. package/src/runtime/clawclaw/plugins/source/types.ts +1 -0
  34. package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +6 -0
  35. package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +4 -0
  36. package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +4 -0
  37. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +36 -0
  38. package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +13 -0
  39. package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +22 -0
  40. package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +46 -16
  41. package/src/runtime/clawclaw-event-catalog.test.ts +2 -0
  42. package/src/runtime/clawclaw-event-catalog.ts +1 -0
  43. package/src/sdk/perception-plugin/index.ts +14 -0
  44. package/src/sdk/resource-metadata.test.ts +40 -0
  45. package/src/sdk/resource-metadata.ts +63 -0
  46. package/src/sdk/strategy-plugin/index.ts +14 -0
@@ -23,7 +23,10 @@ import {
23
23
  getUserDataStrategiesDir,
24
24
  } from '../../../../lib/user-data.js';
25
25
  import type { StrategySource } from './strategy-executor-types.js';
26
- import type { StrategyControlSpec } from '../../../../sdk/strategy-plugin/index.js';
26
+ import type {
27
+ ClawclawResourceLocalizations,
28
+ StrategyControlSpec,
29
+ } from '../../../../sdk/strategy-plugin/index.js';
27
30
 
28
31
  export const CLAWCLAW_TASK_ONLY_DEMO_STRATEGY_ID = 'runtime-task-demo';
29
32
 
@@ -49,20 +52,9 @@ export interface ResolvedClawclawStrategySource extends StrategySource {
49
52
  }
50
53
 
51
54
  function demoSource(): ResolvedClawclawStrategySource {
52
- return {
53
- id: CLAWCLAW_TASK_ONLY_DEMO_STRATEGY_ID,
54
- name: 'Runtime task demo',
55
- description: 'Greets newly visible players and completes the nearest task by local A* path distance.',
56
- execution: 'parallel_compute',
57
- controls: [{
58
- id: 'greeting',
59
- type: 'string',
60
- description: 'Speech template used for newly visible players; {player} is replaced with the player name.',
61
- default: '你好,{player}',
62
- }],
63
- sourcePath: DEMO_SOURCE,
64
- sourceRoot: dirname(DEMO_SOURCE),
65
- };
55
+ const source = parseClassStrategy(DEMO_SOURCE, dirname(DEMO_SOURCE));
56
+ if (!source) throw new Error('Bundled Runtime task demo strategy manifest is invalid.');
57
+ return source;
66
58
  }
67
59
 
68
60
  function isPathInside(root: string, candidate: string): boolean {
@@ -258,6 +250,36 @@ function parseControlSpecs(classBody: string): StrategyControlSpec[] | undefined
258
250
  return controls;
259
251
  }
260
252
 
253
+ function literalLocalizations(
254
+ source: string,
255
+ ): ClawclawResourceLocalizations | null | undefined {
256
+ const property = /\blocalizations\s*:\s*\{/m.exec(source);
257
+ if (!property) return undefined;
258
+ const open = property.index + property[0].lastIndexOf('{');
259
+ const block = balancedBlock(source, open);
260
+ if (!block) return null;
261
+ const values: Record<string, { name: string; description: string }> = {};
262
+ const entry = /(["'\x60])((?:\\.|(?!\1)[\s\S])*)\1\s*:\s*\{/g;
263
+ let cursor = 1;
264
+ let match: RegExpExecArray | null;
265
+ while ((match = entry.exec(block)) !== null) {
266
+ if (block.slice(cursor, match.index).replace(/[\s,]/g, '')) return null;
267
+ if (match[1] === '`' && match[2].includes('${')) return null;
268
+ const locale = decodeEscapedString(match[2])?.trim();
269
+ const entryOpen = match.index + match[0].lastIndexOf('{');
270
+ const entryBlock = balancedBlock(block, entryOpen);
271
+ if (!locale || !entryBlock || values[locale]) return null;
272
+ const name = literalProperty(entryBlock, 'name')?.trim();
273
+ const description = literalProperty(entryBlock, 'description')?.trim();
274
+ if (!name || !description) return null;
275
+ values[locale] = { name, description };
276
+ cursor = entryOpen + entryBlock.length;
277
+ entry.lastIndex = cursor;
278
+ }
279
+ if (block.slice(cursor, -1).replace(/[\s,]/g, '')) return null;
280
+ return values;
281
+ }
282
+
261
283
  function parseClassStrategy(
262
284
  sourcePath: string,
263
285
  strategiesRoot: string,
@@ -285,7 +307,14 @@ function parseClassStrategy(
285
307
  const id = literalProperty(manifest, 'id')?.trim();
286
308
  const name = literalProperty(manifest, 'name')?.trim();
287
309
  const description = literalProperty(manifest, 'description')?.trim();
288
- if (!id || !name || !description || !/^[a-z0-9][a-z0-9._-]*$/.test(id)) return null;
310
+ const localizations = literalLocalizations(manifest);
311
+ if (
312
+ !id
313
+ || !name
314
+ || !description
315
+ || localizations === null
316
+ || !/^[a-z0-9][a-z0-9._-]*$/.test(id)
317
+ ) return null;
289
318
  const execution = literalProperty(manifest, 'execution')?.trim() ?? null;
290
319
  const computeClass = classMatch[1] === 'ClawclawComputeStrategy';
291
320
  const directHybridClass = classMatch[1] === 'ClawclawHybridStrategy';
@@ -320,6 +349,7 @@ function parseClassStrategy(
320
349
  id,
321
350
  name,
322
351
  description,
352
+ ...(localizations === undefined ? {} : { localizations }),
323
353
  ...(execution === null ? {} : { execution: execution as 'parallel_compute' | 'parallel_analyze' }),
324
354
  ...(controls === undefined ? {} : { controls }),
325
355
  sourcePath,
@@ -11,6 +11,7 @@ describe('ClawClaw Event Catalog', () => {
11
11
  it('uses the two explicit Agent registries and keeps events-only empty', () => {
12
12
  expect(CLAWCLAW_EVENTS_ONLY_EVENT_TYPES.size).toBe(0);
13
13
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('speech_your_turn');
14
+ expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('service_status');
14
15
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room_attached');
15
16
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('quit_requested');
16
17
  expect(CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES).toContain('room_created');
@@ -26,6 +27,7 @@ describe('ClawClaw Event Catalog', () => {
26
27
  it('enforces a single producer for known semantics', () => {
27
28
  const catalog = createClawclawEventCatalog();
28
29
  expect(catalog.resolve('game_over', 'backend_push').deliveryClass).toBe('monitor_and_events');
30
+ expect(catalog.resolve('service_status', 'backend_push').deliveryClass).toBe('monitor_and_events');
29
31
  expect(() => catalog.resolve('game_over', 'local_synth')).toThrow(/must be produced by backend_push/);
30
32
  expect(catalog.resolve('future_backend_event', 'backend_push').deliveryClass).toBe('internal_only');
31
33
  });
@@ -90,6 +90,7 @@ export const CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [
90
90
 
91
91
  /** Backend facts that wake Monitor and remain available through ccl events. */
92
92
  export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
93
+ 'service_status',
93
94
  'move_interrupted',
94
95
  'kill',
95
96
  'killed',
@@ -1,5 +1,18 @@
1
1
  export const PERCEPTION_PLUGIN_API_VERSION = 1 as const;
2
2
 
3
+ export {
4
+ hasValidClawclawResourceLocalizations,
5
+ resolveClawclawResourceMetadata,
6
+ } from '../resource-metadata.js';
7
+ export type {
8
+ ClawclawLocalizedResourceText,
9
+ ClawclawResolvedResourceMetadata,
10
+ ClawclawResourceLocalizations,
11
+ ClawclawResourceMetadata,
12
+ } from '../resource-metadata.js';
13
+
14
+ import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
15
+
3
16
  export type PerceptionSubjectScope =
4
17
  | 'others'
5
18
  | 'self_and_others'
@@ -188,6 +201,7 @@ export interface ClawclawPerceptionManifest {
188
201
  readonly id: string;
189
202
  readonly name: string;
190
203
  readonly description: string;
204
+ readonly localizations?: ClawclawResourceLocalizations;
191
205
  /** Describes Event subjects; every module still receives self as a spatial reference. */
192
206
  readonly subjectScope: PerceptionSubjectScope;
193
207
  readonly produces: readonly string[];
@@ -0,0 +1,40 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ hasValidClawclawResourceLocalizations,
4
+ resolveClawclawResourceMetadata,
5
+ } from './resource-metadata.js';
6
+
7
+ const metadata = {
8
+ id: 'visual.motion',
9
+ name: 'Player movement',
10
+ description: 'Reports movement.',
11
+ localizations: {
12
+ 'zh-CN': {
13
+ name: '玩家移动',
14
+ description: '感知玩家移动。',
15
+ },
16
+ en: {
17
+ name: 'Movement',
18
+ description: 'Perceives movement.',
19
+ },
20
+ },
21
+ } as const;
22
+
23
+ describe('resource metadata localization', () => {
24
+ it('resolves an exact locale, then language and manifest fallbacks', () => {
25
+ expect(resolveClawclawResourceMetadata(metadata, 'zh_CN')).toEqual({
26
+ id: 'visual.motion',
27
+ name: '玩家移动',
28
+ description: '感知玩家移动。',
29
+ });
30
+ expect(resolveClawclawResourceMetadata(metadata, 'en-US').name).toBe('Movement');
31
+ expect(resolveClawclawResourceMetadata(metadata, 'ja-JP').name).toBe('Player movement');
32
+ });
33
+
34
+ it('rejects incomplete localized display text', () => {
35
+ expect(hasValidClawclawResourceLocalizations(metadata.localizations)).toBe(true);
36
+ expect(hasValidClawclawResourceLocalizations({
37
+ 'zh-CN': { name: '玩家移动', description: ' ' },
38
+ })).toBe(false);
39
+ });
40
+ });
@@ -0,0 +1,63 @@
1
+ export interface ClawclawLocalizedResourceText {
2
+ readonly name: string;
3
+ readonly description: string;
4
+ }
5
+
6
+ export type ClawclawResourceLocalizations = Readonly<
7
+ Record<string, ClawclawLocalizedResourceText>
8
+ >;
9
+
10
+ export interface ClawclawResourceMetadata {
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly description: string;
14
+ readonly localizations?: ClawclawResourceLocalizations;
15
+ }
16
+
17
+ export interface ClawclawResolvedResourceMetadata {
18
+ readonly id: string;
19
+ readonly name: string;
20
+ readonly description: string;
21
+ }
22
+
23
+ function normalizedLocale(value: string): string {
24
+ return value.trim().replaceAll('_', '-').toLowerCase();
25
+ }
26
+
27
+ export function hasValidClawclawResourceLocalizations(
28
+ localizations: ClawclawResourceLocalizations | undefined,
29
+ ): boolean {
30
+ if (localizations === undefined) return true;
31
+ if (!localizations || typeof localizations !== 'object' || Array.isArray(localizations)) return false;
32
+ return Object.entries(localizations).every(([locale, text]) => (
33
+ normalizedLocale(locale).length > 0
34
+ && !!text
35
+ && typeof text === 'object'
36
+ && !Array.isArray(text)
37
+ && typeof text.name === 'string'
38
+ && text.name.trim().length > 0
39
+ && typeof text.description === 'string'
40
+ && text.description.trim().length > 0
41
+ ));
42
+ }
43
+
44
+ /** Resolves localized display text while preserving manifest text as the fallback. */
45
+ export function resolveClawclawResourceMetadata(
46
+ metadata: ClawclawResourceMetadata,
47
+ locale: string,
48
+ ): ClawclawResolvedResourceMetadata {
49
+ const requested = normalizedLocale(locale);
50
+ const entries = Object.entries(metadata.localizations ?? {});
51
+ const exact = entries.find(([key]) => normalizedLocale(key) === requested)?.[1];
52
+ const language = requested.split('-')[0];
53
+ const languageMatch = entries.find(([key]) => normalizedLocale(key) === language)?.[1];
54
+ const regionalMatch = entries.find(([key]) => (
55
+ normalizedLocale(key).startsWith(`${language}-`)
56
+ ))?.[1];
57
+ const localized = exact ?? languageMatch ?? regionalMatch;
58
+ return {
59
+ id: metadata.id,
60
+ name: localized?.name ?? metadata.name,
61
+ description: localized?.description ?? metadata.description,
62
+ };
63
+ }
@@ -22,6 +22,19 @@ import type {
22
22
 
23
23
  export const STRATEGY_PLUGIN_API_VERSION = 1 as const;
24
24
 
25
+ export {
26
+ hasValidClawclawResourceLocalizations,
27
+ resolveClawclawResourceMetadata,
28
+ } from '../resource-metadata.js';
29
+ export type {
30
+ ClawclawLocalizedResourceText,
31
+ ClawclawResolvedResourceMetadata,
32
+ ClawclawResourceLocalizations,
33
+ ClawclawResourceMetadata,
34
+ } from '../resource-metadata.js';
35
+
36
+ import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
37
+
25
38
  export interface StrategyScope {
26
39
  readonly sessionId: string;
27
40
  readonly segmentId: string;
@@ -292,6 +305,7 @@ export interface ClawclawStrategyManifest {
292
305
  readonly id: string;
293
306
  readonly name: string;
294
307
  readonly description: string;
308
+ readonly localizations?: ClawclawResourceLocalizations;
295
309
  readonly controls?: readonly StrategyControlSpec[];
296
310
  /** Omitted means the stateful, serial update() compatibility contract. */
297
311
  readonly execution?: 'parallel_compute' | 'parallel_analyze';