@myclaw163/clawclaw-cli 0.8.14 → 0.8.16
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.
- package/docs/custom-modules/perception.md +4 -4
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/behavior-runtime.md +1 -1
- package/docs/runtime/official-perception-modules.md +23 -30
- package/docs/runtime/perception-replay.md +1 -1
- package/package.json +1 -1
- package/scripts/sync-bundled-skill.mjs +28 -57
- package/skills/clawclaw/SKILL.md +6 -2
- package/skills/clawclaw/references/BEHAVIORS.md +16 -1
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +310 -0
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +684 -0
- package/skills/clawclaw/references/CUSTOM-MODULES.md +125 -0
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +331 -0
- package/skills/clawclaw/references/HUB.md +2 -1
- package/src/commands/account.ts +36 -0
- package/src/commands/capability.ts +6 -1
- package/src/commands/load.ts +11 -0
- package/src/lib/agent-workspace-runtime.ts +2 -1
- package/src/lib/agent-workspace-skills.ts +235 -23
- package/src/lib/agent-workspace-sync.ts +17 -5
- package/src/lib/capability-cloud-refresh.ts +10 -1
- package/src/lib/capability-cloud-sync.ts +71 -1
- package/src/lib/capability-workspace.ts +2 -0
- package/src/lib/game-client.ts +10 -0
- package/src/runtime/clawclaw/behavior-decision.ts +4 -1
- package/src/runtime/clawclaw/owner.ts +79 -2
- package/src/runtime/clawclaw/plugins/assembly.ts +4 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +35 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +11 -7
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +46 -50
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +39 -9
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +167 -7
- package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +107 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +86 -89
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +157 -41
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +28 -4
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +3 -1
- package/src/runtime/clawclaw/plugins/perception/perception-module-output.ts +30 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +126 -17
- package/src/runtime/clawclaw/plugins/perception/perception-reducer-thread-pool.ts +660 -0
- package/src/runtime/clawclaw/plugins/perception/perception-reducer-thread-worker.ts +262 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +41 -12
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +252 -20
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +496 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +164 -0
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
- package/src/runtime/framework/events/memory-event-repository.ts +12 -0
- package/src/runtime/framework/modules/runtime-module-output.ts +24 -0
- package/src/runtime/framework/persistence/memory-first-persistence.ts +3 -0
- package/src/runtime/framework/plugins/contracts.ts +3 -0
- package/src/runtime/framework/plugins/runtime-input-journal.ts +12 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +150 -23
- package/src/runtime/framework/runtime.ts +18 -0
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +10 -0
- package/src/runtime/game-sync-protocol.ts +47 -0
- package/src/runtime/observability/redaction.ts +28 -1
- package/src/runtime/ws-client.ts +7 -0
- package/src/sdk/perception-plugin/index.ts +13 -8
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
PerceptionModuleLoader,
|
|
45
45
|
type PerceptionThreadModuleSpec,
|
|
46
46
|
} from './perception-module-loader.js';
|
|
47
|
+
import { PerceptionReducerThreadPool } from './perception-reducer-thread-pool.js';
|
|
47
48
|
import {
|
|
48
49
|
CLAWCLAW_PERCEPTION_SPATIAL_API,
|
|
49
50
|
CLAWCLAW_PERCEPTION_SPATIAL_FACTS,
|
|
@@ -66,6 +67,8 @@ export interface ClawclawPerceptionConfig {
|
|
|
66
67
|
moduleSources?: readonly ResolvedClawclawPerceptionSource[];
|
|
67
68
|
/** Maximum visual frames replayed into modules during one live Runtime invocation. */
|
|
68
69
|
maxBackfillVisualFrames?: number;
|
|
70
|
+
/** Samples Worker heaps only for explicit full diagnostics. */
|
|
71
|
+
diagnosticsEnabled?: boolean;
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
export interface PerceptionModuleDescriptor extends ClawclawPerceptionManifest {
|
|
@@ -310,26 +313,43 @@ export function validatePerceptionManifest(
|
|
|
310
313
|
function createModuleSlots(
|
|
311
314
|
config: ClawclawPerceptionConfig,
|
|
312
315
|
loader: PerceptionModuleLoader,
|
|
313
|
-
):
|
|
316
|
+
): Readonly<{
|
|
317
|
+
modules: PerceptionModuleSlot[];
|
|
318
|
+
reducerPool?: PerceptionReducerThreadPool;
|
|
319
|
+
}> {
|
|
314
320
|
const ids = [...new Set(config.modules ?? DEFAULT_PERCEPTION_MODULES)].sort();
|
|
315
321
|
const sources = new Map(
|
|
316
322
|
(config.moduleSources ?? listClawclawPerceptionSources(config.workspaceDir))
|
|
317
323
|
.map((source) => [source.id, source]),
|
|
318
324
|
);
|
|
319
|
-
|
|
325
|
+
const selected = ids.map((id) => {
|
|
320
326
|
const source = sources.get(id);
|
|
321
327
|
if (!source) throw new Error(`Unknown perception module '${id}'.`);
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
manifest: validatePerceptionManifest(runner.manifest),
|
|
325
|
-
runner,
|
|
326
|
-
source,
|
|
327
|
-
analysisGeneration: 0,
|
|
328
|
-
analysisHistoryFloorFrameSeq: 0,
|
|
329
|
-
analysisBaselinePending: false,
|
|
330
|
-
reducerReplayFromFrameSeq: undefined,
|
|
331
|
-
};
|
|
328
|
+
return source;
|
|
332
329
|
});
|
|
330
|
+
const reducerPool = selected.length > 0
|
|
331
|
+
? new PerceptionReducerThreadPool({
|
|
332
|
+
modules: selected.map((source) => loader.threadSpec(source)),
|
|
333
|
+
loader: loader.threadConfig(),
|
|
334
|
+
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
335
|
+
diagnosticsEnabled: config.diagnosticsEnabled === true,
|
|
336
|
+
})
|
|
337
|
+
: undefined;
|
|
338
|
+
return {
|
|
339
|
+
reducerPool,
|
|
340
|
+
modules: selected.map((source) => {
|
|
341
|
+
const runner = new ImportedLocalPerceptionModuleRunner(source, loader, reducerPool);
|
|
342
|
+
return {
|
|
343
|
+
manifest: validatePerceptionManifest(runner.manifest),
|
|
344
|
+
runner,
|
|
345
|
+
source,
|
|
346
|
+
analysisGeneration: 0,
|
|
347
|
+
analysisHistoryFloorFrameSeq: 0,
|
|
348
|
+
analysisBaselinePending: false,
|
|
349
|
+
reducerReplayFromFrameSeq: undefined,
|
|
350
|
+
};
|
|
351
|
+
}),
|
|
352
|
+
};
|
|
333
353
|
}
|
|
334
354
|
|
|
335
355
|
function proposals(value: readonly PerceptionEventProposal[] | void): RuntimeEventProposal[] {
|
|
@@ -351,13 +371,16 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
351
371
|
: 'every_epoch';
|
|
352
372
|
}
|
|
353
373
|
readonly maxInFlight: number;
|
|
374
|
+
readonly maxPendingEpochs = 10;
|
|
354
375
|
readonly recoveryTimeoutMs = DEFAULT_PERCEPTION_RECOVERY_TIMEOUT_MS;
|
|
355
376
|
readonly produces: { readonly events: readonly string[] };
|
|
356
377
|
|
|
357
378
|
private readonly configuredModules: readonly PerceptionModuleSlot[];
|
|
379
|
+
private readonly reducerPool?: PerceptionReducerThreadPool;
|
|
358
380
|
/** Modules that completed every startup stage for the current lifecycle. */
|
|
359
381
|
private modules: readonly PerceptionModuleSlot[];
|
|
360
382
|
private readonly maxBackfillVisualFrames: number;
|
|
383
|
+
private readonly diagnosticsEnabled: boolean;
|
|
361
384
|
private readonly moduleLoader = new PerceptionModuleLoader();
|
|
362
385
|
private analysisPool?: PerceptionAnalysisThreadPool;
|
|
363
386
|
private readonly projector = new ObservationFrameProjector();
|
|
@@ -379,6 +402,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
379
402
|
failureCount: number;
|
|
380
403
|
suppressedCount: number;
|
|
381
404
|
}>();
|
|
405
|
+
private readonly disabledModuleIds = new Set<string>();
|
|
382
406
|
private readonly moduleTimingWindows = new Map<string, PerceptionModuleTimingWindow>();
|
|
383
407
|
private moduleTimingWindowStartedAt = performance.now();
|
|
384
408
|
private frameTimingWindow: PerceptionFrameTimingWindow = this.newFrameTimingWindow();
|
|
@@ -399,7 +423,10 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
399
423
|
throw new TypeError('maxBackfillVisualFrames must be an integer between 1 and 10.');
|
|
400
424
|
}
|
|
401
425
|
this.maxBackfillVisualFrames = maxBackfillVisualFrames;
|
|
402
|
-
this.
|
|
426
|
+
this.diagnosticsEnabled = config.diagnosticsEnabled === true;
|
|
427
|
+
const configured = createModuleSlots(config, this.moduleLoader);
|
|
428
|
+
this.configuredModules = configured.modules;
|
|
429
|
+
this.reducerPool = configured.reducerPool;
|
|
403
430
|
// Keep configured descriptors available before the first Runtime start.
|
|
404
431
|
// Once startup settles, this is narrowed to only successfully active modules.
|
|
405
432
|
this.modules = this.configuredModules;
|
|
@@ -649,7 +676,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
649
676
|
// Close every module's old slice before it receives the new phase/gap frame.
|
|
650
677
|
if (gap || phaseChanged) {
|
|
651
678
|
const kind: PerceptionBoundaryKind = gap ? 'trajectory_gap' : 'phase_changed';
|
|
652
|
-
emitted.push(...await this.flushModules(kind, 'close', signal, diagnostic));
|
|
679
|
+
emitted.push(...await this.flushModules(kind, 'close', signal, diagnostic, projected));
|
|
653
680
|
await this.resetModules(
|
|
654
681
|
kind,
|
|
655
682
|
signal,
|
|
@@ -717,12 +744,14 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
717
744
|
const analysisPool = this.analysisPool;
|
|
718
745
|
this.analysisPool = undefined;
|
|
719
746
|
await analysisPool?.stop();
|
|
720
|
-
// This includes
|
|
721
|
-
// generation fence prevents a late
|
|
747
|
+
// This includes reducer Workers that are still starting; their own
|
|
748
|
+
// generation fence prevents a late ready result from resurrecting them.
|
|
722
749
|
await Promise.allSettled(this.configuredModules.map(({ runner }) => runner.stop(reason)));
|
|
750
|
+
await this.reducerPool?.stop();
|
|
723
751
|
await this.moduleLoader.stop();
|
|
724
752
|
this.modules = [];
|
|
725
753
|
this.moduleFailureReports.clear();
|
|
754
|
+
this.disabledModuleIds.clear();
|
|
726
755
|
this.moduleTimingWindows.clear();
|
|
727
756
|
this.moduleTimingWindowStartedAt = performance.now();
|
|
728
757
|
this.frameTimingWindow = this.newFrameTimingWindow();
|
|
@@ -746,10 +775,64 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
746
775
|
}));
|
|
747
776
|
}
|
|
748
777
|
|
|
778
|
+
diagnosticSnapshot(): Readonly<Record<string, unknown>> {
|
|
779
|
+
const pool = this.analysisPool?.snapshot();
|
|
780
|
+
const reducerPool = this.reducerPool?.snapshot();
|
|
781
|
+
return Object.freeze({
|
|
782
|
+
configured_module_count: this.configuredModules.length,
|
|
783
|
+
active_module_count: this.modules.length,
|
|
784
|
+
active_module_ids: this.modules.map(({ manifest }) => manifest.id),
|
|
785
|
+
analysis_pool: pool
|
|
786
|
+
? {
|
|
787
|
+
state: pool.state,
|
|
788
|
+
min_worker_count: pool.minWorkers,
|
|
789
|
+
max_worker_count: pool.maxWorkers,
|
|
790
|
+
worker_count: pool.workerCount,
|
|
791
|
+
idle_worker_count: pool.idleWorkerCount,
|
|
792
|
+
busy_worker_count: pool.busyWorkerCount,
|
|
793
|
+
queued_batch_count: pool.queuedBatchCount,
|
|
794
|
+
queued_job_count: pool.queuedJobCount,
|
|
795
|
+
in_flight_batch_count: pool.inFlightBatchCount,
|
|
796
|
+
started_worker_count: pool.startedWorkerCount,
|
|
797
|
+
retired_worker_count: pool.retiredWorkerCount,
|
|
798
|
+
worker_heap_used_bytes: pool.workerHeapUsedBytes,
|
|
799
|
+
peak_worker_heap_used_bytes: pool.peakWorkerHeapUsedBytes,
|
|
800
|
+
}
|
|
801
|
+
: null,
|
|
802
|
+
reducer_pool: reducerPool
|
|
803
|
+
? {
|
|
804
|
+
state: reducerPool.state,
|
|
805
|
+
max_worker_count: reducerPool.maxWorkerCount,
|
|
806
|
+
worker_count: reducerPool.workerCount,
|
|
807
|
+
busy_worker_count: reducerPool.busyWorkerCount,
|
|
808
|
+
queued_request_count: reducerPool.queuedRequestCount,
|
|
809
|
+
in_flight_request_count: reducerPool.inFlightRequestCount,
|
|
810
|
+
active_module_count: reducerPool.activeModuleCount,
|
|
811
|
+
unavailable_module_ids: reducerPool.unavailableModuleIds,
|
|
812
|
+
restarted_worker_count: reducerPool.restartedWorkerCount,
|
|
813
|
+
worker_heap_used_bytes: reducerPool.workerHeapUsedBytes,
|
|
814
|
+
peak_worker_heap_used_bytes: reducerPool.peakWorkerHeapUsedBytes,
|
|
815
|
+
}
|
|
816
|
+
: null,
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
|
|
749
820
|
localizedModuleDescriptors(locale: string): ClawclawResolvedResourceMetadata[] {
|
|
750
821
|
return this.modules.map(({ manifest }) => resolveClawclawResourceMetadata(manifest, locale));
|
|
751
822
|
}
|
|
752
823
|
|
|
824
|
+
localizedModuleDescriptorForEvent(
|
|
825
|
+
type: string,
|
|
826
|
+
locale: string,
|
|
827
|
+
): (ClawclawResolvedResourceMetadata & { perceptionId: string }) | undefined {
|
|
828
|
+
const module = this.modules.find(({ manifest }) => manifest.produces.includes(type));
|
|
829
|
+
if (!module) return undefined;
|
|
830
|
+
return {
|
|
831
|
+
...resolveClawclawResourceMetadata(module.manifest, locale),
|
|
832
|
+
perceptionId: module.manifest.id,
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
753
836
|
localizedEventDescriptors(locale: string): LocalizedPerceptionEventDescriptor[] {
|
|
754
837
|
return this.modules.flatMap(({ manifest }) => manifest.produces.flatMap((type) => {
|
|
755
838
|
const metadata = manifest.eventMetadata?.[type];
|
|
@@ -838,6 +921,18 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
838
921
|
return [];
|
|
839
922
|
}
|
|
840
923
|
if (!analysis || analysis.outcome === 'rejected') {
|
|
924
|
+
const failure = analysis?.outcome === 'rejected' ? analysis.failure : undefined;
|
|
925
|
+
if (
|
|
926
|
+
failure
|
|
927
|
+
&& this.analysisFailureDisablesModule(failure.errorCode)
|
|
928
|
+
&& !this.disabledModuleIds.has(manifest.id)
|
|
929
|
+
) {
|
|
930
|
+
this.disabledModuleIds.add(manifest.id);
|
|
931
|
+
diagnostic?.('perception.module.disabled', {
|
|
932
|
+
module_id: manifest.id,
|
|
933
|
+
reason: failure.errorCode,
|
|
934
|
+
}, 'error');
|
|
935
|
+
}
|
|
841
936
|
await this.invalidateParallelModule(
|
|
842
937
|
module,
|
|
843
938
|
frame.frameSeq + 1,
|
|
@@ -1041,7 +1136,14 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1041
1136
|
module: PerceptionModuleSlot,
|
|
1042
1137
|
frameSeq: number,
|
|
1043
1138
|
): boolean {
|
|
1044
|
-
return
|
|
1139
|
+
return !this.disabledModuleIds.has(module.manifest.id)
|
|
1140
|
+
&& frameSeq >= module.analysisHistoryFloorFrameSeq;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
private analysisFailureDisablesModule(errorCode: string): boolean {
|
|
1144
|
+
return errorCode === 'perception_analysis_worker_exited'
|
|
1145
|
+
|| errorCode === 'perception_analysis_worker_memory_invalid'
|
|
1146
|
+
|| errorCode === 'perception_analysis_output_too_large';
|
|
1045
1147
|
}
|
|
1046
1148
|
|
|
1047
1149
|
private analysisInputFromHistory(
|
|
@@ -1210,11 +1312,13 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1210
1312
|
mode: PerceptionBoundary['mode'],
|
|
1211
1313
|
signal: AbortSignal,
|
|
1212
1314
|
diagnostic?: PerceptionDiagnostic,
|
|
1315
|
+
next?: Readonly<PerceptionFrame> | null,
|
|
1213
1316
|
): Promise<RuntimeEventProposal[]> {
|
|
1214
1317
|
const boundary: PerceptionBoundary = Object.freeze({
|
|
1215
1318
|
kind,
|
|
1216
1319
|
mode,
|
|
1217
1320
|
through: this.lastVisualFrame,
|
|
1321
|
+
...(next === undefined ? {} : { next }),
|
|
1218
1322
|
});
|
|
1219
1323
|
const output = await this.collectModuleEvents(
|
|
1220
1324
|
`flush:${kind}`,
|
|
@@ -1543,6 +1647,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1543
1647
|
let analysisPool: PerceptionAnalysisThreadPool | undefined;
|
|
1544
1648
|
try {
|
|
1545
1649
|
const candidates = this.configuredModules;
|
|
1650
|
+
this.disabledModuleIds.clear();
|
|
1546
1651
|
for (const module of candidates) {
|
|
1547
1652
|
module.analysisGeneration = 0;
|
|
1548
1653
|
module.analysisHistoryFloorFrameSeq = 0;
|
|
@@ -1553,6 +1658,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1553
1658
|
CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1554
1659
|
this.api,
|
|
1555
1660
|
signal,
|
|
1661
|
+
diagnostic,
|
|
1556
1662
|
)));
|
|
1557
1663
|
this.assertRunnerLifecycle(generation, signal);
|
|
1558
1664
|
|
|
@@ -1607,6 +1713,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1607
1713
|
loader: this.moduleLoader.threadConfig(),
|
|
1608
1714
|
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1609
1715
|
maxWorkers: this.maxInFlight,
|
|
1716
|
+
diagnosticsEnabled: this.diagnosticsEnabled,
|
|
1610
1717
|
diagnostic,
|
|
1611
1718
|
});
|
|
1612
1719
|
analysisPool = currentPool;
|
|
@@ -1686,6 +1793,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1686
1793
|
await analysisPool?.stop();
|
|
1687
1794
|
if (this.analysisPool === analysisPool) this.analysisPool = undefined;
|
|
1688
1795
|
await Promise.allSettled(this.configuredModules.map(({ runner }) => runner.stop('shutdown')));
|
|
1796
|
+
await this.reducerPool?.stop();
|
|
1689
1797
|
if (generation === this.runnerLifecycleGeneration) {
|
|
1690
1798
|
await this.moduleLoader.stop();
|
|
1691
1799
|
this.modules = [];
|
|
@@ -1709,6 +1817,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1709
1817
|
loader: this.moduleLoader.threadConfig(),
|
|
1710
1818
|
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1711
1819
|
maxWorkers: 1,
|
|
1820
|
+
diagnosticsEnabled: this.diagnosticsEnabled,
|
|
1712
1821
|
});
|
|
1713
1822
|
this.analysisPool = pool;
|
|
1714
1823
|
let failure: unknown;
|