@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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PERCEPTION_PLUGIN_API_VERSION } from './contracts.js';
|
|
2
1
|
import type {
|
|
3
2
|
ClawclawPerception,
|
|
4
3
|
ClawclawPerceptionManifest,
|
|
@@ -11,6 +10,13 @@ import type {
|
|
|
11
10
|
} from './contracts.js';
|
|
12
11
|
import type { PerceptionModuleLoader } from './perception-module-loader.js';
|
|
13
12
|
import type { ResolvedClawclawPerceptionSource } from './perception-source.js';
|
|
13
|
+
import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
|
|
14
|
+
import { normalizePerceptionEvents } from './perception-module-output.js';
|
|
15
|
+
import type { RuntimeDiagnosticSeverity } from '../../../framework/plugins/index.js';
|
|
16
|
+
import {
|
|
17
|
+
PerceptionReducerThreadPool,
|
|
18
|
+
type PerceptionReducerThreadPoolSnapshot,
|
|
19
|
+
} from './perception-reducer-thread-pool.js';
|
|
14
20
|
|
|
15
21
|
function deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {
|
|
16
22
|
if (!value || typeof value !== 'object') return value;
|
|
@@ -25,28 +31,6 @@ function isolatedClone<T>(value: T): T {
|
|
|
25
31
|
return deepFreeze(structuredClone(value));
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
function isolatedEvents(
|
|
29
|
-
value: readonly PerceptionEventProposal[] | void,
|
|
30
|
-
manifest: ClawclawPerceptionManifest,
|
|
31
|
-
): readonly PerceptionEventProposal[] {
|
|
32
|
-
if (value === undefined) return [];
|
|
33
|
-
if (!Array.isArray(value)) throw new Error('perception_result_must_be_array');
|
|
34
|
-
const declared = new Set(manifest.produces);
|
|
35
|
-
return value.map((event, index) => {
|
|
36
|
-
if (
|
|
37
|
-
!event
|
|
38
|
-
|| typeof event !== 'object'
|
|
39
|
-
|| !declared.has(event.type)
|
|
40
|
-
|| typeof event.dedupeKey !== 'string'
|
|
41
|
-
|| !event.dedupeKey
|
|
42
|
-
|| !event.payload
|
|
43
|
-
|| typeof event.payload !== 'object'
|
|
44
|
-
|| Array.isArray(event.payload)
|
|
45
|
-
) throw new Error(`perception_event_invalid:${index}`);
|
|
46
|
-
return structuredClone(event);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
34
|
export interface PerceptionModuleRunner {
|
|
51
35
|
readonly manifest: ClawclawPerceptionManifest;
|
|
52
36
|
readonly execution: 'ordered_update' | 'parallel_analysis';
|
|
@@ -54,6 +38,11 @@ export interface PerceptionModuleRunner {
|
|
|
54
38
|
spatialFacts: PerceptionSpatialFacts,
|
|
55
39
|
api: PerceptionApi,
|
|
56
40
|
signal: AbortSignal,
|
|
41
|
+
diagnostic?: (
|
|
42
|
+
name: string,
|
|
43
|
+
attributes?: Readonly<Record<string, unknown>>,
|
|
44
|
+
severity?: RuntimeDiagnosticSeverity,
|
|
45
|
+
) => void,
|
|
57
46
|
): void | Promise<void>;
|
|
58
47
|
update(
|
|
59
48
|
frame: Readonly<PerceptionFrame>,
|
|
@@ -82,6 +71,7 @@ export interface PerceptionModuleRunner {
|
|
|
82
71
|
): void | Promise<void>;
|
|
83
72
|
stop(reason: 'segment_ending' | 'shutdown'): void | Promise<void>;
|
|
84
73
|
debugSnapshot(): unknown;
|
|
74
|
+
reducerDiagnosticSnapshot?(): PerceptionReducerThreadPoolSnapshot | null;
|
|
85
75
|
}
|
|
86
76
|
|
|
87
77
|
export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
@@ -96,8 +86,8 @@ export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
|
96
86
|
|
|
97
87
|
start(): void {}
|
|
98
88
|
|
|
99
|
-
update(frame: Readonly<PerceptionFrame>, api: PerceptionApi) {
|
|
100
|
-
return this.module.update(frame, api);
|
|
89
|
+
async update(frame: Readonly<PerceptionFrame>, api: PerceptionApi) {
|
|
90
|
+
return normalizePerceptionEvents(await this.module.update(frame, api), this.manifest);
|
|
101
91
|
}
|
|
102
92
|
|
|
103
93
|
async analyze(input: Readonly<PerceptionAnalysisInput>, api: PerceptionApi): Promise<unknown> {
|
|
@@ -110,7 +100,9 @@ export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
|
110
100
|
) => unknown | Promise<unknown>;
|
|
111
101
|
};
|
|
112
102
|
if (typeof analyzer.analyze !== 'function') throw new Error('parallel_perception_analyze_missing');
|
|
113
|
-
|
|
103
|
+
const analysis = structuredClone(await analyzer.analyze(input, api));
|
|
104
|
+
assertRuntimeModuleOutputSize(analysis, 'perception_analysis_output');
|
|
105
|
+
return analysis;
|
|
114
106
|
}
|
|
115
107
|
|
|
116
108
|
async commit(frame: Readonly<PerceptionFrame>, analysis: unknown, api: PerceptionApi) {
|
|
@@ -126,7 +118,10 @@ export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
|
126
118
|
};
|
|
127
119
|
if (typeof reducer.commit !== 'function') throw new Error('parallel_perception_commit_missing');
|
|
128
120
|
try {
|
|
129
|
-
return
|
|
121
|
+
return normalizePerceptionEvents(
|
|
122
|
+
await reducer.commit(frame, structuredClone(analysis), api),
|
|
123
|
+
this.manifest,
|
|
124
|
+
);
|
|
130
125
|
} catch (error) {
|
|
131
126
|
// commit() is allowed to mutate its private reducer before it throws.
|
|
132
127
|
// Never reuse that unknowable state on the next ordered frame.
|
|
@@ -136,8 +131,8 @@ export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
133
|
|
|
139
|
-
flush(boundary: Readonly<PerceptionBoundary>, api: PerceptionApi) {
|
|
140
|
-
return this.module.flush?.(boundary, api);
|
|
134
|
+
async flush(boundary: Readonly<PerceptionBoundary>, api: PerceptionApi) {
|
|
135
|
+
return normalizePerceptionEvents(await this.module.flush?.(boundary, api), this.manifest);
|
|
141
136
|
}
|
|
142
137
|
|
|
143
138
|
async reset(reason: Parameters<NonNullable<ClawclawPerception['reset']>>[0]): Promise<void> {
|
|
@@ -159,32 +154,39 @@ export class LocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
|
159
154
|
}
|
|
160
155
|
}
|
|
161
156
|
|
|
162
|
-
/**
|
|
157
|
+
/** Proxies one installed module to a persistent, memory-bounded reducer Worker lane. */
|
|
163
158
|
export class ImportedLocalPerceptionModuleRunner implements PerceptionModuleRunner {
|
|
164
159
|
readonly manifest: ClawclawPerceptionManifest;
|
|
165
160
|
readonly execution: 'ordered_update' | 'parallel_analysis';
|
|
166
|
-
private
|
|
161
|
+
private reducerPool?: PerceptionReducerThreadPool;
|
|
167
162
|
private startTask?: Promise<void>;
|
|
168
163
|
private lifecycleGeneration = 0;
|
|
164
|
+
private started = false;
|
|
169
165
|
|
|
170
166
|
constructor(
|
|
171
167
|
private readonly source: ResolvedClawclawPerceptionSource,
|
|
172
168
|
private readonly loader: PerceptionModuleLoader,
|
|
169
|
+
reducerPool?: PerceptionReducerThreadPool,
|
|
173
170
|
) {
|
|
174
171
|
this.manifest = source.manifest;
|
|
175
172
|
this.execution = source.manifest.execution ?? 'ordered_update';
|
|
173
|
+
this.reducerPool = reducerPool;
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
start(
|
|
179
177
|
spatialFacts: PerceptionSpatialFacts,
|
|
180
|
-
|
|
178
|
+
_api: PerceptionApi,
|
|
181
179
|
signal: AbortSignal,
|
|
180
|
+
diagnostic?: (
|
|
181
|
+
name: string,
|
|
182
|
+
attributes?: Readonly<Record<string, unknown>>,
|
|
183
|
+
severity?: RuntimeDiagnosticSeverity,
|
|
184
|
+
) => void,
|
|
182
185
|
): Promise<void> {
|
|
183
|
-
if (this.delegate) return Promise.resolve();
|
|
184
186
|
if (this.startTask) return this.startTask;
|
|
185
187
|
const generation = ++this.lifecycleGeneration;
|
|
186
188
|
let task!: Promise<void>;
|
|
187
|
-
task = this.startInternal(spatialFacts,
|
|
189
|
+
task = this.startInternal(spatialFacts, signal, diagnostic, generation).finally(() => {
|
|
188
190
|
if (this.startTask === task) this.startTask = undefined;
|
|
189
191
|
});
|
|
190
192
|
this.startTask = task;
|
|
@@ -192,101 +194,96 @@ export class ImportedLocalPerceptionModuleRunner implements PerceptionModuleRunn
|
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
private async startInternal(
|
|
195
|
-
|
|
196
|
-
_api: PerceptionApi,
|
|
197
|
+
spatialFacts: PerceptionSpatialFacts,
|
|
197
198
|
signal: AbortSignal,
|
|
199
|
+
diagnostic: ((
|
|
200
|
+
name: string,
|
|
201
|
+
attributes?: Readonly<Record<string, unknown>>,
|
|
202
|
+
severity?: RuntimeDiagnosticSeverity,
|
|
203
|
+
) => void) | undefined,
|
|
198
204
|
generation: number,
|
|
199
205
|
): Promise<void> {
|
|
200
206
|
signal.throwIfAborted();
|
|
201
|
-
const
|
|
207
|
+
const pool = this.reducerPool ?? new PerceptionReducerThreadPool({
|
|
208
|
+
modules: [this.loader.threadSpec(this.source)],
|
|
209
|
+
loader: this.loader.threadConfig(),
|
|
210
|
+
spatialFacts,
|
|
211
|
+
diagnostic,
|
|
212
|
+
});
|
|
213
|
+
this.reducerPool = pool;
|
|
214
|
+
pool.setDiagnostic(diagnostic);
|
|
215
|
+
await pool.start();
|
|
202
216
|
signal.throwIfAborted();
|
|
203
217
|
if (generation !== this.lifecycleGeneration) {
|
|
204
218
|
throw new Error('perception_module_start_cancelled');
|
|
205
219
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
!manifest
|
|
209
|
-
|| manifest.apiVersion !== PERCEPTION_PLUGIN_API_VERSION
|
|
210
|
-
|| manifest.id !== this.manifest.id
|
|
211
|
-
|| (manifest.execution ?? 'ordered_update') !== this.execution
|
|
212
|
-
|| JSON.stringify(manifest.produces) !== JSON.stringify(this.manifest.produces)
|
|
213
|
-
) throw new Error(`Perception module '${this.source.id}' changed after discovery.`);
|
|
214
|
-
const instance = new ModuleClass();
|
|
215
|
-
if (
|
|
216
|
-
!instance
|
|
217
|
-
|| typeof instance !== 'object'
|
|
218
|
-
|| (this.execution === 'ordered_update' && typeof instance.update !== 'function')
|
|
219
|
-
|| (this.execution === 'parallel_analysis' && (
|
|
220
|
-
typeof (instance as any).analyze !== 'function'
|
|
221
|
-
|| typeof (instance as any).commit !== 'function'
|
|
222
|
-
))
|
|
223
|
-
) throw new Error(`Perception module '${this.source.id}' does not implement its execution contract.`);
|
|
224
|
-
const delegate = new LocalPerceptionModuleRunner(instance, manifest);
|
|
225
|
-
await delegate.start();
|
|
226
|
-
try {
|
|
227
|
-
signal.throwIfAborted();
|
|
228
|
-
if (generation !== this.lifecycleGeneration) {
|
|
229
|
-
throw new Error('perception_module_start_cancelled');
|
|
230
|
-
}
|
|
231
|
-
} catch (error) {
|
|
232
|
-
await delegate.stop('shutdown').catch(() => {});
|
|
233
|
-
throw error;
|
|
234
|
-
}
|
|
235
|
-
this.delegate = delegate;
|
|
220
|
+
pool.assertAvailable(this.manifest.id);
|
|
221
|
+
this.started = true;
|
|
236
222
|
}
|
|
237
223
|
|
|
238
224
|
async update(frame: Readonly<PerceptionFrame>, api: PerceptionApi, signal: AbortSignal) {
|
|
239
225
|
signal.throwIfAborted();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
this.manifest,
|
|
226
|
+
void api;
|
|
227
|
+
return this.required().operate(
|
|
228
|
+
this.manifest.id,
|
|
229
|
+
'update',
|
|
230
|
+
{ frame: isolatedClone(frame) },
|
|
231
|
+
signal,
|
|
243
232
|
);
|
|
244
233
|
}
|
|
245
234
|
|
|
246
235
|
async analyze(input: Readonly<PerceptionAnalysisInput>, api: PerceptionApi, signal: AbortSignal) {
|
|
247
236
|
signal.throwIfAborted();
|
|
248
|
-
|
|
237
|
+
void input;
|
|
238
|
+
void api;
|
|
239
|
+
throw new Error('perception_parallel_analysis_uses_analysis_pool');
|
|
249
240
|
}
|
|
250
241
|
|
|
251
242
|
async commit(frame: Readonly<PerceptionFrame>, analysis: unknown, api: PerceptionApi, signal: AbortSignal) {
|
|
252
243
|
signal.throwIfAborted();
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
this.manifest,
|
|
244
|
+
void api;
|
|
245
|
+
return this.required().operate(
|
|
246
|
+
this.manifest.id,
|
|
247
|
+
'commit',
|
|
248
|
+
{ frame: isolatedClone(frame), analysis: isolatedClone(analysis) },
|
|
249
|
+
signal,
|
|
260
250
|
);
|
|
261
251
|
}
|
|
262
252
|
|
|
263
253
|
async flush(boundary: Readonly<PerceptionBoundary>, api: PerceptionApi, signal: AbortSignal) {
|
|
264
254
|
signal.throwIfAborted();
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.manifest,
|
|
255
|
+
void api;
|
|
256
|
+
return this.required().operate(
|
|
257
|
+
this.manifest.id,
|
|
258
|
+
'flush',
|
|
259
|
+
{ boundary: isolatedClone(boundary) },
|
|
260
|
+
signal,
|
|
268
261
|
);
|
|
269
262
|
}
|
|
270
263
|
|
|
271
264
|
reset(reason: Parameters<NonNullable<ClawclawPerception['reset']>>[0], signal: AbortSignal) {
|
|
272
265
|
signal.throwIfAborted();
|
|
273
|
-
return this.required().reset
|
|
266
|
+
return this.required().operate(this.manifest.id, 'reset', { reason }, signal).then(() => {});
|
|
274
267
|
}
|
|
275
268
|
|
|
276
269
|
async stop(reason: 'segment_ending' | 'shutdown'): Promise<void> {
|
|
277
270
|
this.lifecycleGeneration += 1;
|
|
278
271
|
this.startTask = undefined;
|
|
279
|
-
|
|
280
|
-
this.
|
|
281
|
-
if (delegate) await delegate.stop(reason);
|
|
272
|
+
this.started = false;
|
|
273
|
+
await this.reducerPool?.releaseModule(this.manifest.id, reason);
|
|
282
274
|
}
|
|
283
275
|
|
|
284
276
|
debugSnapshot(): unknown {
|
|
285
|
-
return this.
|
|
277
|
+
return this.started ? this.reducerPool?.debugSnapshot(this.manifest.id) ?? null : null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
reducerDiagnosticSnapshot(): PerceptionReducerThreadPoolSnapshot | null {
|
|
281
|
+
return this.reducerPool?.snapshot() ?? null;
|
|
286
282
|
}
|
|
287
283
|
|
|
288
|
-
private required():
|
|
289
|
-
if (!this.
|
|
290
|
-
|
|
284
|
+
private required(): PerceptionReducerThreadPool {
|
|
285
|
+
if (!this.reducerPool || !this.started) throw new Error('perception_module_not_started');
|
|
286
|
+
this.reducerPool.assertAvailable(this.manifest.id);
|
|
287
|
+
return this.reducerPool;
|
|
291
288
|
}
|
|
292
289
|
}
|