@myclaw163/clawclaw-cli 0.8.14 → 0.8.15
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/skills/clawclaw/SKILL.md +5 -1
- package/skills/clawclaw/references/BEHAVIORS.md +16 -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/src/runtime/clawclaw/behavior-decision.ts +4 -1
- package/src/runtime/clawclaw/owner.ts +64 -1
- 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/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 +114 -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/observability/redaction.ts +28 -1
- 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,6 +775,48 @@ 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
|
}
|
|
@@ -838,6 +909,18 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
838
909
|
return [];
|
|
839
910
|
}
|
|
840
911
|
if (!analysis || analysis.outcome === 'rejected') {
|
|
912
|
+
const failure = analysis?.outcome === 'rejected' ? analysis.failure : undefined;
|
|
913
|
+
if (
|
|
914
|
+
failure
|
|
915
|
+
&& this.analysisFailureDisablesModule(failure.errorCode)
|
|
916
|
+
&& !this.disabledModuleIds.has(manifest.id)
|
|
917
|
+
) {
|
|
918
|
+
this.disabledModuleIds.add(manifest.id);
|
|
919
|
+
diagnostic?.('perception.module.disabled', {
|
|
920
|
+
module_id: manifest.id,
|
|
921
|
+
reason: failure.errorCode,
|
|
922
|
+
}, 'error');
|
|
923
|
+
}
|
|
841
924
|
await this.invalidateParallelModule(
|
|
842
925
|
module,
|
|
843
926
|
frame.frameSeq + 1,
|
|
@@ -1041,7 +1124,14 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1041
1124
|
module: PerceptionModuleSlot,
|
|
1042
1125
|
frameSeq: number,
|
|
1043
1126
|
): boolean {
|
|
1044
|
-
return
|
|
1127
|
+
return !this.disabledModuleIds.has(module.manifest.id)
|
|
1128
|
+
&& frameSeq >= module.analysisHistoryFloorFrameSeq;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
private analysisFailureDisablesModule(errorCode: string): boolean {
|
|
1132
|
+
return errorCode === 'perception_analysis_worker_exited'
|
|
1133
|
+
|| errorCode === 'perception_analysis_worker_memory_invalid'
|
|
1134
|
+
|| errorCode === 'perception_analysis_output_too_large';
|
|
1045
1135
|
}
|
|
1046
1136
|
|
|
1047
1137
|
private analysisInputFromHistory(
|
|
@@ -1210,11 +1300,13 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1210
1300
|
mode: PerceptionBoundary['mode'],
|
|
1211
1301
|
signal: AbortSignal,
|
|
1212
1302
|
diagnostic?: PerceptionDiagnostic,
|
|
1303
|
+
next?: Readonly<PerceptionFrame> | null,
|
|
1213
1304
|
): Promise<RuntimeEventProposal[]> {
|
|
1214
1305
|
const boundary: PerceptionBoundary = Object.freeze({
|
|
1215
1306
|
kind,
|
|
1216
1307
|
mode,
|
|
1217
1308
|
through: this.lastVisualFrame,
|
|
1309
|
+
...(next === undefined ? {} : { next }),
|
|
1218
1310
|
});
|
|
1219
1311
|
const output = await this.collectModuleEvents(
|
|
1220
1312
|
`flush:${kind}`,
|
|
@@ -1543,6 +1635,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1543
1635
|
let analysisPool: PerceptionAnalysisThreadPool | undefined;
|
|
1544
1636
|
try {
|
|
1545
1637
|
const candidates = this.configuredModules;
|
|
1638
|
+
this.disabledModuleIds.clear();
|
|
1546
1639
|
for (const module of candidates) {
|
|
1547
1640
|
module.analysisGeneration = 0;
|
|
1548
1641
|
module.analysisHistoryFloorFrameSeq = 0;
|
|
@@ -1553,6 +1646,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1553
1646
|
CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1554
1647
|
this.api,
|
|
1555
1648
|
signal,
|
|
1649
|
+
diagnostic,
|
|
1556
1650
|
)));
|
|
1557
1651
|
this.assertRunnerLifecycle(generation, signal);
|
|
1558
1652
|
|
|
@@ -1607,6 +1701,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1607
1701
|
loader: this.moduleLoader.threadConfig(),
|
|
1608
1702
|
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1609
1703
|
maxWorkers: this.maxInFlight,
|
|
1704
|
+
diagnosticsEnabled: this.diagnosticsEnabled,
|
|
1610
1705
|
diagnostic,
|
|
1611
1706
|
});
|
|
1612
1707
|
analysisPool = currentPool;
|
|
@@ -1686,6 +1781,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1686
1781
|
await analysisPool?.stop();
|
|
1687
1782
|
if (this.analysisPool === analysisPool) this.analysisPool = undefined;
|
|
1688
1783
|
await Promise.allSettled(this.configuredModules.map(({ runner }) => runner.stop('shutdown')));
|
|
1784
|
+
await this.reducerPool?.stop();
|
|
1689
1785
|
if (generation === this.runnerLifecycleGeneration) {
|
|
1690
1786
|
await this.moduleLoader.stop();
|
|
1691
1787
|
this.modules = [];
|
|
@@ -1709,6 +1805,7 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
|
|
|
1709
1805
|
loader: this.moduleLoader.threadConfig(),
|
|
1710
1806
|
spatialFacts: CLAWCLAW_PERCEPTION_SPATIAL_FACTS satisfies PerceptionSpatialFacts,
|
|
1711
1807
|
maxWorkers: 1,
|
|
1808
|
+
diagnosticsEnabled: this.diagnosticsEnabled,
|
|
1712
1809
|
});
|
|
1713
1810
|
this.analysisPool = pool;
|
|
1714
1811
|
let failure: unknown;
|