@myclaw163/clawclaw-cli 0.9.1 → 0.10.1
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/QUICKSTART_OTHER.md +5 -5
- package/README.md +7 -8
- package/bin/clawclaw-channel.mjs +2 -2
- package/bin/clawclaw-cli.mjs +2 -2
- package/docs/configuration.md +25 -99
- package/docs/custom-modules/README.md +27 -40
- package/docs/custom-modules/api-reference.md +132 -273
- package/docs/custom-modules/behavior.md +185 -75
- package/docs/custom-modules/examples/auto-escape.ts +41 -0
- package/docs/custom-modules/examples/go-to-point.ts +11 -11
- package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
- package/docs/custom-modules/examples/task-reminder.ts +4 -5
- package/docs/custom-modules/perception.md +46 -806
- package/docs/custom-modules/skill.md +1 -1
- package/docs/desktop-event-push.md +3 -3
- package/docs/runtime/README.md +18 -19
- package/docs/runtime/agent-notifications.md +31 -12
- package/docs/runtime/behavior-runtime.md +54 -48
- package/docs/runtime/components-and-boundaries.md +87 -137
- package/docs/runtime/events-and-state.md +52 -17
- package/docs/runtime/framework-package.md +73 -0
- package/docs/runtime/official-perception-modules.md +5 -5
- package/docs/runtime/owner-lifecycle-and-observability.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +8 -9
- package/docs/user-guide/README.md +12 -9
- package/docs/user-guide/api-reference.md +132 -180
- package/docs/user-guide/behavior.md +175 -65
- package/docs/user-guide/installation.md +7 -7
- package/docs/user-guide/perception.md +46 -789
- package/docs/user-guide/skill.md +1 -1
- package/package.json +24 -9
- package/scripts/check-framework-boundaries.mjs +27 -0
- package/scripts/check-skill-command-surface.mjs +9 -14
- package/scripts/install-local-runtime.mjs +35 -0
- package/scripts/qa-install.mjs +105 -0
- package/skills/clawclaw/SKILL.md +50 -48
- package/skills/clawclaw/references/BEHAVIORS.md +45 -65
- package/skills/clawclaw/references/CHANNELS.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +65 -87
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +185 -75
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +145 -198
- package/skills/clawclaw/references/CUSTOM-MODULES.md +28 -29
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +46 -811
- package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
- package/skills/clawclaw/references/HUB.md +1 -1
- package/skills/clawclaw/references/STREAM.md +8 -8
- package/skills/clawclaw/references/TACTICS.md +1 -1
- package/src/channel/claude-channel-ipc-server.ts +1 -0
- package/src/cli.ts +4 -2
- package/src/commands/behavior.ts +49 -104
- package/src/commands/capability.ts +3 -3
- package/src/commands/load.ts +18 -25
- package/src/commands/module-runtime-control.ts +113 -0
- package/src/commands/perception.ts +23 -4
- package/src/commands/strategy.ts +2 -0
- package/src/commands/trigger.ts +1 -1
- package/src/lib/capability-load-diagnostics.ts +3 -3
- package/src/lib/perception-config.ts +18 -6
- package/src/lib/runtime-cadence-config.ts +16 -0
- package/src/lib/workspace-runtime-lock.ts +3 -46
- package/src/pipeline/canonical-event-presentation.ts +23 -124
- package/src/pipeline/event-format.ts +12 -21
- package/src/pipeline/event-hints.ts +6 -6
- package/src/pipeline/game-sync-event-normalization.ts +57 -63
- package/src/runtime/clawclaw/behavior-decision.ts +7 -3
- package/src/runtime/clawclaw/behavior-input.ts +8 -4
- package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
- package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
- package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
- package/src/runtime/clawclaw/notification-policy.ts +42 -0
- package/src/runtime/clawclaw/notification-turn.ts +19 -0
- package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
- package/src/runtime/clawclaw/owner.ts +67 -8
- package/src/runtime/clawclaw/perception-module-manifest.ts +22 -8
- package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
- package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
- package/src/runtime/clawclaw/plugins/assembly.ts +29 -41
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -482
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -186
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1707
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -271
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -960
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +9 -107
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +5 -4
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +27 -17
- package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
- package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
- package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +136 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +13 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +13 -24
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +19 -8
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +23 -15
- package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +8 -103
- package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +3 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +5 -2
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +69 -13
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +13 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +4 -0
- package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
- package/src/runtime/clawclaw/reaction-manifest.ts +18 -12
- package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
- package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
- package/src/runtime/clawclaw/runtime-state.ts +12 -1
- package/src/runtime/clawclaw/runtime.ts +11 -3
- package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -0
- package/src/runtime/clawclaw/strategy-memory.ts +1 -0
- package/src/runtime/clawclaw-event-catalog.ts +17 -17
- package/src/runtime/framework/action-diagnostics.ts +3 -83
- package/src/runtime/framework/capability-registry.ts +2 -395
- package/src/runtime/framework/contracts.ts +2 -144
- package/src/runtime/framework/control/control-scheduler.ts +2 -1268
- package/src/runtime/framework/control/domain-set.ts +2 -81
- package/src/runtime/framework/control/index.ts +1 -3
- package/src/runtime/framework/control/types.ts +2 -191
- package/src/runtime/framework/control-coordinator.ts +2 -11
- package/src/runtime/framework/events/event-catalog.ts +2 -74
- package/src/runtime/framework/events/event-delivery-service.ts +2 -200
- package/src/runtime/framework/events/event-ingress.ts +2 -99
- package/src/runtime/framework/events/event-repository.ts +2 -82
- package/src/runtime/framework/events/index.ts +2 -7
- package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
- package/src/runtime/framework/events/runtime-resume.ts +2 -20
- package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
- package/src/runtime/framework/events/test-helpers.ts +1 -1
- package/src/runtime/framework/events/types.ts +2 -312
- package/src/runtime/framework/index.ts +3 -7
- package/src/runtime/framework/load-node-sqlite.ts +2 -17
- package/src/runtime/framework/mailbox/coalescer.ts +2 -83
- package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
- package/src/runtime/framework/mailbox/identity.ts +2 -38
- package/src/runtime/framework/mailbox/index.ts +1 -7
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
- package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
- package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
- package/src/runtime/framework/mailbox/types.ts +2 -145
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
- package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
- package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
- package/src/runtime/framework/participation-manager.ts +2 -253
- package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
- package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
- package/src/runtime/framework/plugins/contracts.ts +2 -388
- package/src/runtime/framework/plugins/index.ts +1 -4
- package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
- package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2060
- package/src/runtime/framework/runtime.ts +5 -1843
- package/src/runtime/framework/serial-task-queue.ts +2 -14
- package/src/runtime/framework/state/contracts.ts +2 -49
- package/src/runtime/framework/state/current-state-store.ts +2 -184
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
- package/src/runtime/framework/state/freshness.ts +2 -72
- package/src/runtime/framework/state/history/contracts.ts +2 -158
- package/src/runtime/framework/state/history/history-writer.ts +2 -194
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
- package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
- package/src/runtime/framework/state/index.ts +1 -13
- package/src/runtime/framework/state/state-ingress.ts +2 -95
- package/src/runtime/framework/state/state-provider.ts +2 -62
- package/src/runtime/framework/state/types.ts +2 -155
- package/src/runtime/host-monitor-rate-gate.ts +1 -123
- package/src/runtime/mailbox-host-relay.ts +1 -326
- package/src/runtime/observability/detail-capture.ts +4 -108
- package/src/runtime/observability/process-timing.ts +2 -59
- package/src/runtime/observability/recorder.ts +2 -238
- package/src/runtime/observability/redaction.ts +2 -181
- package/src/runtime/observability/reporter.ts +2 -154
- package/src/runtime/observability/sinks.ts +2 -135
- package/src/runtime/observability/types.ts +2 -92
- package/src/runtime/owner-control.ts +45 -315
- package/src/runtime/parent-process-watch.ts +1 -51
- package/src/runtime/process-identity.ts +1 -72
- package/src/sdk/behavior-plugin/index.ts +13 -4
- package/src/sdk/index.ts +44 -3
- package/src/sdk/module-input/index.ts +5 -0
- package/src/sdk/perception-plugin/index.ts +9 -5
- package/src/sdk/perception-plugin/module.ts +25 -6
- package/src/sdk/perception-plugin/reaction.ts +1 -1
- package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
- package/src/sdk/perception-plugin/reminder.ts +2 -1
- package/src/{runtime/clawclaw/plugins/source → sdk/perception-plugin}/task-change-tracker.ts +1 -2
- package/src/sdk/strategy-memory.ts +1 -0
- package/src/sdk/strategy-plugin/index.ts +36 -0
- package/src/sdk/trigger-plugin/index.ts +4 -3
- package/docs/custom-modules/examples/nearby-escape.ts +0 -56
- package/docs/custom-modules/examples/nearby-notice.ts +0 -36
- package/docs/custom-modules/trigger.md +0 -295
- package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
- package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +0 -233
- package/src/runtime/clawclaw/plugins/perception/reaction-runner.ts +0 -49
- package/src/runtime/clawclaw/plugins/perception/reaction-worker.ts +0 -26
- /package/src/runtime/clawclaw/plugins/{source → derived-event}/player-change-tracker.ts +0 -0
|
@@ -71,6 +71,7 @@ export class ClawclawBehaviorObservationMemory {
|
|
|
71
71
|
}
|
|
72
72
|
const existing = this.snapshots.get(input.epochId);
|
|
73
73
|
if (existing) return existing;
|
|
74
|
+
const observedAtMs = input.cycle?.stateReceivedAtMs ?? input.nowMs;
|
|
74
75
|
|
|
75
76
|
for (const visible of input.gameState.visible_players ?? []) {
|
|
76
77
|
const ref = playerRef(visible);
|
|
@@ -88,7 +89,7 @@ export class ClawclawBehaviorObservationMemory {
|
|
|
88
89
|
...(knownAlive(input, ref) === undefined
|
|
89
90
|
? {}
|
|
90
91
|
: { isAlive: knownAlive(input, ref) }),
|
|
91
|
-
observedAtMs
|
|
92
|
+
observedAtMs,
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
for (const visible of input.gameState.visible_corpses ?? []) {
|
|
@@ -103,7 +104,7 @@ export class ClawclawBehaviorObservationMemory {
|
|
|
103
104
|
y: visible.y,
|
|
104
105
|
room: visible.room,
|
|
105
106
|
...(visible.distance === undefined ? {} : { distance: visible.distance }),
|
|
106
|
-
observedAtMs
|
|
107
|
+
observedAtMs,
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
} from './navigation/astar-path.js';
|
|
13
13
|
import { CLAWCLAW_PERCEPTION_SPATIAL_API } from './plugins/perception/spatial-facts.js';
|
|
14
14
|
import type { ClawclawBehaviorObservationSnapshot } from './behavior-observation-memory.js';
|
|
15
|
+
import type { StrategyMemory } from '../../sdk/strategy-memory.js';
|
|
16
|
+
import { unavailableStrategyMemory } from './strategy-memory-rpc.js';
|
|
15
17
|
|
|
16
18
|
export interface BehaviorObservationApi {
|
|
17
19
|
lastSeenPlayer(targetSeat: number, maxAgeMs?: number): Readonly<ObservedPlayer> | undefined;
|
|
@@ -19,6 +21,7 @@ export interface BehaviorObservationApi {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export interface CreateBehaviorReadApiOptions {
|
|
24
|
+
readonly memory?: StrategyMemory;
|
|
22
25
|
readonly isActive?: () => boolean;
|
|
23
26
|
readonly onQuery?: (kind: 'path_distance' | 'observation') => void;
|
|
24
27
|
readonly observation?: Readonly<BehaviorObservationApi>;
|
|
@@ -127,6 +130,7 @@ export function createBehaviorReadApi(
|
|
|
127
130
|
return getLocalPathDistances(queries);
|
|
128
131
|
};
|
|
129
132
|
return Object.freeze({
|
|
133
|
+
memory: options.memory ?? unavailableStrategyMemory,
|
|
130
134
|
spatial: CLAWCLAW_PERCEPTION_SPATIAL_API,
|
|
131
135
|
navigation: Object.freeze({
|
|
132
136
|
pathDistance: async (from: Readonly<Position>, to: Readonly<Position>) => {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { normalizeBehaviorInput } from './behavior-input-fields.js';
|
|
2
|
+
import type { ClawclawBehaviorCatalog } from './plugins/behavior/behavior-catalog.js';
|
|
3
|
+
import type { ClawclawBehaviorPlugin } from './plugins/behavior/behavior-plugin.js';
|
|
4
|
+
import type { ClawclawPerceptionModulePlugin } from './plugins/perception/perception-module-plugin.js';
|
|
5
|
+
|
|
6
|
+
type Scope = Readonly<{ sessionId: string; segmentId: string }>;
|
|
7
|
+
const same = (a: Scope, b: Scope) => a.sessionId === b.sessionId && a.segmentId === b.segmentId;
|
|
8
|
+
|
|
9
|
+
/** Strategy defaults and automatic activation gates are independent of perception execution. */
|
|
10
|
+
export class BehaviorReflexControl {
|
|
11
|
+
private parameters = new Map<string, Readonly<Record<string, unknown>>>();
|
|
12
|
+
private currentScope?: Scope;
|
|
13
|
+
private tail: Promise<unknown> = Promise.resolve();
|
|
14
|
+
constructor(private readonly modules: ClawclawPerceptionModulePlugin | undefined,
|
|
15
|
+
private readonly behavior: Pick<ClawclawBehaviorPlugin, 'status' | 'updateReflex' | 'configureInput'>,
|
|
16
|
+
private readonly catalog: Pick<ClawclawBehaviorCatalog, 'list'>,
|
|
17
|
+
private readonly scope: () => Scope) {}
|
|
18
|
+
status(id?: string) {
|
|
19
|
+
this.refreshScope();
|
|
20
|
+
const active = this.behavior.status().stack.reflex;
|
|
21
|
+
return (this.modules?.bindings(id) ?? []).map(binding => ({ ...binding,
|
|
22
|
+
active: active?.triggerId === binding.trigger_id,
|
|
23
|
+
...(active?.triggerId === binding.trigger_id ? { activation_id: active.activationId,
|
|
24
|
+
instance_generation: active.instanceGeneration } : {}), scope: this.currentScope }));
|
|
25
|
+
}
|
|
26
|
+
view(id?: string) {
|
|
27
|
+
const watches = this.status(id), status = this.behavior.status();
|
|
28
|
+
const parameters = [...this.parameters].filter(([key]) => id === undefined || key === id)
|
|
29
|
+
.map(([key,input]) => ({ id: key, input }));
|
|
30
|
+
if (id === undefined) return { ...status, parameters, watches };
|
|
31
|
+
const { current, ...rest } = status, stack = { ...status.stack };
|
|
32
|
+
for (const layer of ['long', 'short', 'reflex'] as const) if (stack[layer]?.behaviorId !== id) delete stack[layer];
|
|
33
|
+
if (stack.fallback?.behaviorId !== id) delete stack.fallback;
|
|
34
|
+
const selected = current?.behaviorId === id ? current : undefined;
|
|
35
|
+
return { ...rest, running: !!selected, stack, ...(selected ? { current: selected } : {}), parameters, watches };
|
|
36
|
+
}
|
|
37
|
+
apply(operation: 'enable' | 'update' | 'disable', id: string,
|
|
38
|
+
patch: Readonly<Record<string, unknown>>, expected: Scope): Promise<unknown> {
|
|
39
|
+
const task = this.tail.then(async () => {
|
|
40
|
+
this.refreshScope();
|
|
41
|
+
const guard = () => same(this.scope(),expected);
|
|
42
|
+
if (!guard()) throw Error('stale_runtime_scope');
|
|
43
|
+
const entry = this.catalog.list().find(entry => entry.id === id);
|
|
44
|
+
if (!entry) throw Error('behavior_not_found');
|
|
45
|
+
if (operation !== 'update') {
|
|
46
|
+
const bindings = this.modules?.bindings(id) ?? [];
|
|
47
|
+
if (!bindings.length || operation === 'enable' && !bindings.some(binding => binding.available)) {
|
|
48
|
+
throw Error('perception_binding_unavailable');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let input = this.parameters.get(id) ?? {}, updated = 0;
|
|
52
|
+
// A detector may inject required targets later; enabling alone does not prepare a Behavior.
|
|
53
|
+
if (operation === 'update' || Object.keys(patch).length) {
|
|
54
|
+
input = normalizeBehaviorInput({ ...input, ...patch },entry.inputs);
|
|
55
|
+
updated = await this.behavior.configureInput(id,input,patch,guard,
|
|
56
|
+
() => { this.parameters.set(id,input); this.modules?.behaviorInputChanged(id); });
|
|
57
|
+
}
|
|
58
|
+
if (operation !== 'update') {
|
|
59
|
+
const triggerIds = this.modules?.setWatch(id,operation === 'enable',guard);
|
|
60
|
+
if (!triggerIds) throw Error('perception_binding_unavailable');
|
|
61
|
+
if (operation === 'disable') for (const triggerId of triggerIds) {
|
|
62
|
+
updated += Number(await this.behavior.updateReflex(triggerId,undefined,guard));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { operation, applied: true, updated_active: updated > 0, updated_activations: updated,
|
|
66
|
+
input, watches: this.status(id) };
|
|
67
|
+
});
|
|
68
|
+
this.tail = task.catch(() => {}); return task;
|
|
69
|
+
}
|
|
70
|
+
private refreshScope(): void {
|
|
71
|
+
const scope = this.scope();
|
|
72
|
+
if (!this.currentScope || !same(this.currentScope,scope)) { this.currentScope = { ...scope }; this.parameters.clear(); }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { prepareNotificationContent } from './plugins/perception/notification-content.js';
|
|
2
|
+
import type { CanonicalEvent } from '../framework/events/index.js';
|
|
3
|
+
import type { EventIngressOptions } from '../framework/events/event-ingress.js';
|
|
4
|
+
import type { RuntimeEpochPlugin } from '../framework/plugins/index.js';
|
|
5
|
+
import { createClawclawEventCatalog } from '../clawclaw-event-catalog.js';
|
|
6
|
+
|
|
7
|
+
/** Fixed host lifecycle exception. Game facts and Behavior outputs are not in this list. */
|
|
8
|
+
export const CLAWCLAW_SYSTEM_CONTROL_EVENTS = new Set([
|
|
9
|
+
'service_status', 'joined', 'room_created', 'room_joined', 'session_resumed', 'session_recovered',
|
|
10
|
+
'not_in_queue', 'poll_error', 'error', 'game_start_failed', 'game_terminal_missing',
|
|
11
|
+
'game_stream_disconnected', 'game_stream_reconnected', 'stop_requested', 'quit_requested',
|
|
12
|
+
'match_start', 'match_waiting', 'match_timeout', 'user_left_game', 'session_left', 'quit_failed',
|
|
13
|
+
'room_attached', 'room_lobby_reconnect_failed', 'room_lobby_missing', 'room_returning_to_lobby',
|
|
14
|
+
'room_ping_timeout', 'room_destroyed', 'room.self_left', 'room.game_start_failed',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
export const BUILTIN_PERCEPTION_PREFIX = 'clawclaw.perception.system.';
|
|
18
|
+
|
|
19
|
+
export function createClawclawNotificationPolicy(
|
|
20
|
+
plugins: readonly RuntimeEpochPlugin<Record<string, any>>[],
|
|
21
|
+
): NonNullable<EventIngressOptions['notificationPolicy']> {
|
|
22
|
+
const producers = new Set(plugins.filter(plugin => plugin.agentNotificationProducer).map(plugin => plugin.id));
|
|
23
|
+
const systemCatalog = createClawclawEventCatalog();
|
|
24
|
+
return input => {
|
|
25
|
+
if (input.producerPluginId && producers.has(input.producerPluginId)) {
|
|
26
|
+
// Mandatory builtin notifications are not controlled by user visual delivery preferences.
|
|
27
|
+
const fixed = input.producerPluginId.startsWith(BUILTIN_PERCEPTION_PREFIX)
|
|
28
|
+
? systemCatalog.get(input.type) : undefined;
|
|
29
|
+
return { source: 'perception', ...(fixed
|
|
30
|
+
? { deliveryClass: fixed.deliveryClass, wakeAgent: input.wakeAgent ?? true } : {}) };
|
|
31
|
+
}
|
|
32
|
+
if (input.producerPluginId === undefined && CLAWCLAW_SYSTEM_CONTROL_EVENTS.has(input.type)) {
|
|
33
|
+
return { source: 'system', content: prepareNotificationContent(input.type, input.payload ?? {}, null, 'system', input) };
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isClawclawAgentNotification(event: CanonicalEvent): boolean {
|
|
40
|
+
return event.deliveryClass !== 'internal_only'
|
|
41
|
+
&& (event.notificationSource === 'perception' || event.notificationSource === 'system');
|
|
42
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RuntimeOptions } from '../framework/runtime.js';
|
|
2
|
+
import { isClawclawRuntimeState } from './runtime-state.js';
|
|
3
|
+
|
|
4
|
+
export function isNotificationTurn(state: Record<string, any>): boolean {
|
|
5
|
+
return isClawclawRuntimeState(state) && state.cause === 'control' && state.control?.type === 'perception_notifications';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** A notification round has no fresh snapshot, backend tick, or new game action. */
|
|
9
|
+
export const clawclawNotificationFollowUp: NonNullable<RuntimeOptions['followUpInput']> = (epoch, latest, events) => {
|
|
10
|
+
if (!events.some(event => event.producerPluginId === 'clawclaw.behavior' && !event.notificationOf)) return;
|
|
11
|
+
if (!isClawclawRuntimeState(latest.state)) return;
|
|
12
|
+
return {
|
|
13
|
+
scope: epoch.scope, sourceId: 'clawclaw.notification-turn', connectionId: latest.connectionId,
|
|
14
|
+
sourceKey: `notification-after:${epoch.epochSeq}`,
|
|
15
|
+
state: { ...latest.state, cause: 'control', control: { type: 'perception_notifications', after_epoch: epoch.epochSeq },
|
|
16
|
+
game_snapshot: { status: 'not_updated' } },
|
|
17
|
+
events: [], completeness: 'complete', coalescing: 'forbidden', receivedAt: new Date().toISOString(),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
import type { StoredStateFrame } from '../framework/state/history/contracts.js';
|
|
9
9
|
import { createCanonicalGameState } from './behavior-input.js';
|
|
10
10
|
import { resolveRoom } from './plugins/perception/spatial-facts.js';
|
|
11
|
-
import {
|
|
11
|
+
import { clawclawComputationGameState } from './runtime-state.js';
|
|
12
12
|
|
|
13
13
|
function finite(value: unknown): value is number {
|
|
14
14
|
return typeof value === 'number' && Number.isFinite(value);
|
|
@@ -42,7 +42,7 @@ export class ObservationFrameProjector {
|
|
|
42
42
|
reset(): void {}
|
|
43
43
|
|
|
44
44
|
project(frame: StoredStateFrame<Record<string, any>>): ObservationFrame | null {
|
|
45
|
-
const freshState =
|
|
45
|
+
const freshState = clawclawComputationGameState(frame.state);
|
|
46
46
|
if (!freshState) return null;
|
|
47
47
|
const gameState = createCanonicalGameState(freshState, frame.backendTick);
|
|
48
48
|
const players: VisualPlayer[] = [];
|
|
@@ -71,7 +71,7 @@ export class ObservationFrameProjector {
|
|
|
71
71
|
frameKey: frame.sourceKey,
|
|
72
72
|
frameSeq: frame.frameSeq,
|
|
73
73
|
tick,
|
|
74
|
-
timeMs: frame.observedAtMs ?? frame.receivedAtMs,
|
|
74
|
+
timeMs: frame.state.cycle?.stateReceivedAtMs ?? frame.observedAtMs ?? frame.receivedAtMs,
|
|
75
75
|
tickDelta: null,
|
|
76
76
|
continuousFromPrevious: false,
|
|
77
77
|
gameState,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { BUILTIN_PERCEPTION_NAMES } from './plugins/system-perception/system-perceptions.js';
|
|
2
|
+
import { BUILTIN_PERCEPTION_PREFIX } from './notification-policy.js';
|
|
3
|
+
import { isClawclawAgentNotification } from './notification-policy.js';
|
|
4
|
+
import { createClawclawProcessingCadence } from './runtime-cadence.js';
|
|
5
|
+
import { readRuntimeCycleIntervalMs } from '../../lib/runtime-cadence-config.js';
|
|
1
6
|
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { BehaviorReflexControl } from './behavior-reflex-control.js';
|
|
2
8
|
import { acquireOwnerLock, type OwnerLock } from './owner-lock.js';
|
|
3
9
|
import { createStartingOwnerControl } from './starting-owner-control.js';
|
|
4
10
|
export { acquireOwnerLock, type OwnerLock, type OwnerLockOperations } from './owner-lock.js';
|
|
@@ -585,7 +591,7 @@ export async function runClawclawOwner(
|
|
|
585
591
|
agentBehaviorSources,
|
|
586
592
|
disabledBehaviors,
|
|
587
593
|
);
|
|
588
|
-
const behaviorSourceById = new Map(behaviorSources.map(
|
|
594
|
+
const behaviorSourceById = new Map(behaviorSources.map(source => [source.id,source]));
|
|
589
595
|
const behaviorCatalog = new ClawclawBehaviorCatalog(behaviorSources);
|
|
590
596
|
const behaviorEventTypes = [...new Set(
|
|
591
597
|
behaviorCatalog.list()
|
|
@@ -600,12 +606,13 @@ export async function runClawclawOwner(
|
|
|
600
606
|
const triggerSources = listClawclawTriggerSources(
|
|
601
607
|
getUserDataAccountTriggersDir(workspaceDir, options.profile),
|
|
602
608
|
);
|
|
603
|
-
const
|
|
609
|
+
const legacyTriggers = triggerRegistrations(
|
|
604
610
|
triggerSources,
|
|
605
611
|
gameplayConfig,
|
|
606
612
|
behaviorCatalog,
|
|
607
613
|
configurationWarning,
|
|
608
614
|
);
|
|
615
|
+
const triggers = legacyTriggers;
|
|
609
616
|
const disabledPerceptions = new Set(gameplayConfig.disabled_perception_modules);
|
|
610
617
|
const agentPerceptionSources = agentWorkspace
|
|
611
618
|
? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace)
|
|
@@ -647,7 +654,10 @@ export async function runClawclawOwner(
|
|
|
647
654
|
await client.getQueueStatus('clawclaw'),
|
|
648
655
|
options.intent,
|
|
649
656
|
);
|
|
657
|
+
const reflexControl = new BehaviorReflexControl(assembly.modules,
|
|
658
|
+
assembly.behavior, behaviorCatalog, () => runtime!.publicScope());
|
|
650
659
|
runtime = createClawclawRuntime(options.profile, {
|
|
660
|
+
processingCadence: createClawclawProcessingCadence(readRuntimeCycleIntervalMs()),
|
|
651
661
|
initialSegment: runtimeStart.initialSegment,
|
|
652
662
|
mode: runtimeStart.mode,
|
|
653
663
|
resume: runtimeStart.resume,
|
|
@@ -657,7 +667,7 @@ export async function runClawclawOwner(
|
|
|
657
667
|
visualEventDelivery: perceptionConfig.events.delivery,
|
|
658
668
|
visualEventTypes: assembly.perception.produces.events,
|
|
659
669
|
behaviorEventTypes: assembly.behavior.produces?.events ?? [],
|
|
660
|
-
|
|
670
|
+
perceptionEventTypes: assembly.modules?.produces.events,
|
|
661
671
|
});
|
|
662
672
|
if (fullDiagnosticsEnabled) {
|
|
663
673
|
processTimingSampler = new RuntimeProcessTimingSampler();
|
|
@@ -740,6 +750,7 @@ export async function runClawclawOwner(
|
|
|
740
750
|
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
741
751
|
presentEvent: ownerAgentEventPresenter('ccl_events', !!options.desktopEvents),
|
|
742
752
|
compactState: compactStateForEvents,
|
|
753
|
+
admitEvent: isClawclawAgentNotification,
|
|
743
754
|
eventFilter: clawclawEventRequiresDetails,
|
|
744
755
|
delegatedMonitorConsumerId: MONITOR_MAILBOX_CONSUMER_ID,
|
|
745
756
|
consumerId: CCL_EVENTS_MAILBOX_CONSUMER_ID,
|
|
@@ -751,6 +762,7 @@ export async function runClawclawOwner(
|
|
|
751
762
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
752
763
|
});
|
|
753
764
|
mailboxService = new ClawclawMailboxService({
|
|
765
|
+
notificationOnly: true,
|
|
754
766
|
repository: mailboxRepository,
|
|
755
767
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
756
768
|
agentMailbox: cclEventsMailbox,
|
|
@@ -765,11 +777,12 @@ export async function runClawclawOwner(
|
|
|
765
777
|
];
|
|
766
778
|
if (options.desktopEvents) {
|
|
767
779
|
desktopMailbox = new AgentMailboxCoordinator({
|
|
780
|
+
admitEvent: isClawclawAgentNotification,
|
|
768
781
|
repository: mailboxRepository,
|
|
769
782
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
770
783
|
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
771
784
|
presentEvent: ownerAgentEventPresenter('desktop_ipc', true),
|
|
772
|
-
compactState:
|
|
785
|
+
compactState: () => null,
|
|
773
786
|
consumerId: DESKTOP_IPC_MAILBOX_CONSUMER_ID,
|
|
774
787
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
775
788
|
});
|
|
@@ -787,7 +800,6 @@ export async function runClawclawOwner(
|
|
|
787
800
|
})(),
|
|
788
801
|
perceptions: [...assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
789
802
|
...assembly.reminders.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
790
|
-
...(assembly.reactions?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? []),
|
|
791
803
|
...(assembly.modules?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? [])],
|
|
792
804
|
}),
|
|
793
805
|
eventDescriptors: () => assembly.perception
|
|
@@ -813,7 +825,7 @@ export async function runClawclawOwner(
|
|
|
813
825
|
ownerIdPrefix: 'desktop_ipc',
|
|
814
826
|
}),
|
|
815
827
|
renew: (deliveryToken) => desktopMailbox!.renew(deliveryToken),
|
|
816
|
-
ack: (deliveryToken) => desktopMailbox!.ack(deliveryToken),
|
|
828
|
+
ack: (deliveryToken, level) => desktopMailbox!.ack(deliveryToken, level),
|
|
817
829
|
release: (deliveryToken) => desktopMailbox!.release(deliveryToken),
|
|
818
830
|
},
|
|
819
831
|
sink: desktopSink,
|
|
@@ -825,6 +837,7 @@ export async function runClawclawOwner(
|
|
|
825
837
|
assembly.behavior.attachDriver(createClawclawBehaviorControlDriver(runtime));
|
|
826
838
|
if (channelPolicy.enabled) {
|
|
827
839
|
channelAdapter = new ClaudeChannelMailboxAdapter({
|
|
840
|
+
notificationOnly: true,
|
|
828
841
|
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
829
842
|
repository: mailboxRepository,
|
|
830
843
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
@@ -838,7 +851,7 @@ export async function runClawclawOwner(
|
|
|
838
851
|
source: {
|
|
839
852
|
prepare: () => channelAdapter!.prepare(),
|
|
840
853
|
renew: (deliveryToken) => channelAdapter!.renew(deliveryToken),
|
|
841
|
-
ack: (deliveryToken) => channelAdapter!.ack(deliveryToken),
|
|
854
|
+
ack: (deliveryToken, level) => channelAdapter!.ack(deliveryToken, level),
|
|
842
855
|
release: (deliveryToken) => channelAdapter!.release(deliveryToken),
|
|
843
856
|
},
|
|
844
857
|
sink: channelSink,
|
|
@@ -1122,6 +1135,52 @@ export async function runClawclawOwner(
|
|
|
1122
1135
|
);
|
|
1123
1136
|
return { ok: true, type: 'action', result };
|
|
1124
1137
|
}
|
|
1138
|
+
if (request.type === 'perception_status') {
|
|
1139
|
+
return { ok: true, type: request.type, status: [...Object.entries(BUILTIN_PERCEPTION_NAMES).map(([id, name]) => ({
|
|
1140
|
+
id: `${BUILTIN_PERCEPTION_PREFIX}${id}`, name, mandatory: true, configurable: false,
|
|
1141
|
+
outcome: runtime!.readReadyView().pluginOutcomes[`${BUILTIN_PERCEPTION_PREFIX}${id}`]?.outcome,
|
|
1142
|
+
})).filter(item => !request.perception || item.id === request.perception), ...(assembly.modules?.status(request.perception) ?? [])] };
|
|
1143
|
+
}
|
|
1144
|
+
if (request.type === 'perception_update') {
|
|
1145
|
+
const expected = ownerExpectedScope(request.expected_scope);
|
|
1146
|
+
if (!expected || !request.input || typeof request.input !== 'object' || Array.isArray(request.input)
|
|
1147
|
+
|| typeof request.perception !== 'string') return { ok: false, type: request.type, error: 'invalid_perception_control_request' };
|
|
1148
|
+
if (runtime!.currentSegment().kind !== 'game') return { ok: false, type: request.type, error: 'no_active_game' };
|
|
1149
|
+
if (!ownerScopeIsCurrent(runtime!,expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
|
|
1150
|
+
try {
|
|
1151
|
+
if (request.perception.startsWith(BUILTIN_PERCEPTION_PREFIX)) throw Error('builtin_perception_readonly');
|
|
1152
|
+
if (!assembly.modules) throw Error('perception_not_found');
|
|
1153
|
+
const result = assembly.modules.configure(request.perception,request.input,() => ownerScopeIsCurrent(runtime!,expected));
|
|
1154
|
+
return { ok: true, type: request.type, result };
|
|
1155
|
+
} catch (error) { return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'perception_control_failed' }; }
|
|
1156
|
+
}
|
|
1157
|
+
if (request.type === 'behavior_watch' || request.type === 'behavior_unwatch' || request.type === 'behavior_update') {
|
|
1158
|
+
if (runtime!.currentSegment().kind !== 'game') {
|
|
1159
|
+
return { ok: false, type: request.type, error: 'no_active_game' };
|
|
1160
|
+
}
|
|
1161
|
+
const expected = ownerExpectedScope(request.expected_scope);
|
|
1162
|
+
const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
|
|
1163
|
+
const activationId = typeof request.activation_id === 'string' ? request.activation_id.trim() : '';
|
|
1164
|
+
const patch = request.type === 'behavior_unwatch' ? {} : request.input;
|
|
1165
|
+
if (!expected || !patch || typeof patch !== 'object' || Array.isArray(patch)
|
|
1166
|
+
|| (request.type === 'behavior_update' ? (Boolean(behavior) === Boolean(activationId)) : (!behavior || !!activationId))) {
|
|
1167
|
+
return { ok: false, type: request.type, error: 'invalid_behavior_control_request' };
|
|
1168
|
+
}
|
|
1169
|
+
if (!ownerScopeIsCurrent(runtime!, expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
|
|
1170
|
+
try {
|
|
1171
|
+
if (activationId) {
|
|
1172
|
+
const activation = await assembly.behavior.updateInput(activationId, patch,
|
|
1173
|
+
() => ownerScopeIsCurrent(runtime!, expected));
|
|
1174
|
+
return { ok: true, type: request.type, updated: true, activation };
|
|
1175
|
+
}
|
|
1176
|
+
const operation = request.type === 'behavior_watch' ? 'enable'
|
|
1177
|
+
: request.type === 'behavior_unwatch' ? 'disable' : 'update';
|
|
1178
|
+
const result = await reflexControl.apply(operation, behavior, patch, expected);
|
|
1179
|
+
return { ok: true, type: request.type, result };
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'behavior_control_failed' };
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1125
1184
|
if (request.type === 'behavior_start') {
|
|
1126
1185
|
const expected = ownerExpectedScope(request.expected_scope);
|
|
1127
1186
|
const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
|
|
@@ -1164,7 +1223,7 @@ export async function runClawclawOwner(
|
|
|
1164
1223
|
}
|
|
1165
1224
|
}
|
|
1166
1225
|
if (request.type === 'behavior_status') {
|
|
1167
|
-
return { ok: true, type: 'behavior_status', status:
|
|
1226
|
+
return { ok: true, type: 'behavior_status', status: reflexControl.view(typeof request.behavior === 'string' ? request.behavior : undefined) };
|
|
1168
1227
|
}
|
|
1169
1228
|
if (request.type === 'behavior_cancel') {
|
|
1170
1229
|
const expected = ownerExpectedScope(request.expected_scope);
|
|
@@ -1,27 +1,41 @@
|
|
|
1
|
+
import { normalizePerceptionBehaviorBindings } from './reaction-manifest.js';
|
|
1
2
|
import type { PerceptionModuleManifest } from '../../sdk/perception-plugin/module.js';
|
|
2
|
-
import {
|
|
3
|
+
import { hasValidClawclawResourceLocalizations } from '../../sdk/resource-metadata.js';
|
|
4
|
+
import { normalizeBehaviorInputFields, normalizeBehaviorInput } from './behavior-input-fields.js';
|
|
3
5
|
import { isClawclawFixedEventType, CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES,
|
|
4
6
|
CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, CLAWCLAW_LOCAL_AGENT_EVENT_TYPES, CLAWCLAW_VISUAL_EVENT_TYPES } from '../clawclaw-event-catalog.js';
|
|
5
7
|
|
|
8
|
+
export const REMOVED_PERCEPTION_INPUT_TYPES = new Set(['players_changed', 'tasks_changed', 'meeting_state', 'ability.ready',
|
|
9
|
+
'ability.remaining_uses_changed', 'ability.exhausted', 'emergency_countdown_warning', 'room_ready_to_start']);
|
|
6
10
|
const INPUT_TYPES = new Set<string>([...CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES, ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES,
|
|
7
11
|
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter(type => !/^(behavior|reminder|perception)\./.test(type)),
|
|
8
12
|
'tasks_changed', 'meeting_state']);
|
|
9
13
|
const PERCEPTION_OWNED_TYPES = new Set<string>([...CLAWCLAW_VISUAL_EVENT_TYPES, 'reminder.task', 'reminder.speech']);
|
|
10
14
|
|
|
11
15
|
const record = (value: unknown): value is Record<string, any> => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
12
|
-
export function normalizePerceptionModuleManifest(value: unknown, current = true): PerceptionModuleManifest {
|
|
16
|
+
export function normalizePerceptionModuleManifest(value: unknown, current = true, discoverRemovedInputs = false): PerceptionModuleManifest {
|
|
13
17
|
if (!record(value) || !Number.isInteger(value.apiVersion) || current && value.apiVersion !== 3
|
|
14
18
|
|| Object.keys(value).some(key => !['apiVersion', 'id', 'name', 'description', 'localizations', 'consumes',
|
|
15
|
-
'produces', '
|
|
19
|
+
'produces', 'inputs', 'config', 'behaviors', 'strategies'].includes(key))
|
|
20
|
+
|| typeof value.id !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/.test(value.id)
|
|
21
|
+
|| typeof value.description !== 'string' || !value.description.trim()
|
|
22
|
+
|| value.name !== undefined && (typeof value.name !== 'string' || !value.name.trim())
|
|
23
|
+
|| !hasValidClawclawResourceLocalizations(value.localizations)
|
|
24
|
+
|| value.config !== undefined && !record(value.config)) throw new Error('perception_module_manifest_invalid');
|
|
16
25
|
const consumes = value.consumes ?? [], produces = value.produces ?? [];
|
|
26
|
+
if (value.strategies !== undefined && value.behaviors !== undefined) throw new Error('perception_strategy_bindings_conflict');
|
|
27
|
+
const bindings = value.strategies ?? value.behaviors;
|
|
17
28
|
if (!Array.isArray(produces) || produces.some(type => typeof type !== 'string'
|
|
18
29
|
|| !/^[a-z0-9][a-z0-9._-]*$/.test(type)
|
|
19
30
|
|| isClawclawFixedEventType(type) && !PERCEPTION_OWNED_TYPES.has(type))
|
|
20
31
|
|| !Array.isArray(consumes) || consumes.some(type => typeof type !== 'string' || !INPUT_TYPES.has(type)
|
|
21
32
|
|| /^(visual|reminder|reaction|perception|behavior|decision)\./.test(type))) throw new Error('perception_module_event_contract_invalid');
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
if (!discoverRemovedInputs && consumes.some(type => REMOVED_PERCEPTION_INPUT_TYPES.has(type))) throw new Error('perception_input_removed: use gameState, frame or module-local taskChanges; perceptions cannot subscribe to other perceptions');
|
|
34
|
+
const inputs = value.inputs ? normalizeBehaviorInputFields(value.inputs) : undefined;
|
|
35
|
+
const config = inputs ? normalizeBehaviorInput(value.config ?? {}, inputs) : structuredClone(value.config ?? {});
|
|
36
|
+
return { apiVersion: value.apiVersion, id: value.id, description: value.description,
|
|
37
|
+
...(value.name === undefined ? {} : { name: value.name }),
|
|
38
|
+
...(value.localizations === undefined ? {} : { localizations: structuredClone(value.localizations) }),
|
|
39
|
+
...(bindings === undefined ? {} : { behaviors: normalizePerceptionBehaviorBindings(bindings) }),
|
|
40
|
+
consumes: [...new Set(consumes)], produces: [...new Set(produces)], ...(inputs ? { inputs } : {}), config };
|
|
27
41
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PerceptionModuleResult } from '../../sdk/perception-plugin/module.js';
|
|
2
|
+
import type { ReactionActivation } from '../../sdk/perception-plugin/reaction.js';
|
|
3
|
+
|
|
4
|
+
export type NormalizedPerceptionModuleResult = Omit<PerceptionModuleResult, 'activations'> & {
|
|
5
|
+
readonly activations?: readonly ReactionActivation[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** Resolve public names once before the existing admission/arbitration path. */
|
|
9
|
+
export function normalizePerceptionStrategyNames(value: PerceptionModuleResult): NormalizedPerceptionModuleResult {
|
|
10
|
+
if (!value || typeof value !== 'object' || !Array.isArray(value.activations)) return value as NormalizedPerceptionModuleResult;
|
|
11
|
+
return { ...value, activations: value.activations.map(activation => {
|
|
12
|
+
if (!activation || typeof activation !== 'object' || !Object.hasOwn(activation, 'strategy')) return activation as ReactionActivation;
|
|
13
|
+
if (Object.hasOwn(activation, 'behavior')) throw new Error('perception_strategy_activation_conflict');
|
|
14
|
+
const { strategy, ...rest } = activation as Record<string, unknown>;
|
|
15
|
+
return { ...rest, behavior: strategy } as unknown as ReactionActivation;
|
|
16
|
+
}) };
|
|
17
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EventStoreCompatibility } from '@myclaw163/game-agent-runtime/framework/events/store-compatibility.js';
|
|
2
|
+
export const CLAWCLAW_STORE_COMPATIBILITY: EventStoreCompatibility = {
|
|
3
|
+
"legacyConsumer": "local-agent",
|
|
4
|
+
"monitorConsumer": "local-agent:monitor",
|
|
5
|
+
"detailsConsumer": "local-agent:ccl-events",
|
|
6
|
+
"desktopConsumer": "local-agent:desktop",
|
|
7
|
+
"channelConsumer": "local-agent:claude-channel",
|
|
8
|
+
"detailEvidence": [
|
|
9
|
+
"ccl_events",
|
|
10
|
+
"ccl_events_backlog",
|
|
11
|
+
"stdout_full"
|
|
12
|
+
],
|
|
13
|
+
"desktopEvidence": [
|
|
14
|
+
"mailbox_full",
|
|
15
|
+
"desktop_ipc"
|
|
16
|
+
],
|
|
17
|
+
"channelEvidence": [
|
|
18
|
+
"claude_channel"
|
|
19
|
+
],
|
|
20
|
+
"desktopVia": "desktop_ipc",
|
|
21
|
+
"channelVia": "claude_channel",
|
|
22
|
+
"legacyDeliveryVias": [
|
|
23
|
+
"stdout_full",
|
|
24
|
+
"mailbox_full",
|
|
25
|
+
"desktop_ipc",
|
|
26
|
+
"claude_channel",
|
|
27
|
+
"ccl_events",
|
|
28
|
+
"ccl_events_backlog"
|
|
29
|
+
],
|
|
30
|
+
"initialDeliveryVias": [
|
|
31
|
+
"stdout_full",
|
|
32
|
+
"mailbox_full",
|
|
33
|
+
"ccl_events",
|
|
34
|
+
"ccl_events_backlog"
|
|
35
|
+
]
|
|
36
|
+
};
|
|
@@ -315,7 +315,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
315
315
|
if (isClawclawRuntimeState(input.epoch.state)) {
|
|
316
316
|
this.stage = input.epoch.state.stage;
|
|
317
317
|
this.connection = input.epoch.state.connection;
|
|
318
|
-
if (input.epoch.state.game_snapshot.status === 'fresh') {
|
|
318
|
+
if ((input.epoch.state.game_snapshot.status === 'fresh' || input.epoch.state.game_snapshot.status === 'cached')) {
|
|
319
319
|
this.rememberTaskGameState(input.epoch.scope, input.epoch.epochSeq, input.epoch.state.game_snapshot.state);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
@@ -355,7 +355,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
355
355
|
const runtimeState = latest?.state;
|
|
356
356
|
let game: Record<string, any> | undefined;
|
|
357
357
|
if (isClawclawRuntimeState(runtimeState)) {
|
|
358
|
-
if (runtimeState.game_snapshot.status === 'fresh') {
|
|
358
|
+
if ((runtimeState.game_snapshot.status === 'fresh' || runtimeState.game_snapshot.status === 'cached')) {
|
|
359
359
|
game = runtimeState.game_snapshot.state;
|
|
360
360
|
this.rememberTaskGameState(scope, latest!.epochSeq, game);
|
|
361
361
|
} else if (runtimeState.game_snapshot.status === 'not_updated'
|
|
@@ -508,7 +508,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
508
508
|
&& state.connection === 'connected'
|
|
509
509
|
&& state.stage === 'game'
|
|
510
510
|
&& (
|
|
511
|
-
state.game_snapshot.status !== 'fresh'
|
|
511
|
+
(state.game_snapshot.status !== 'fresh' && state.game_snapshot.status !== 'cached')
|
|
512
512
|
|| (
|
|
513
513
|
state.game_snapshot.state.phase === 'wandering'
|
|
514
514
|
&& state.game_snapshot.state.you?.is_alive !== false
|