@myclaw163/clawclaw-cli 0.9.1 → 0.9.2
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/README.md +1 -1
- package/docs/custom-modules/README.md +14 -15
- package/docs/custom-modules/api-reference.md +73 -36
- package/docs/custom-modules/behavior.md +116 -22
- package/docs/custom-modules/examples/auto-escape.ts +41 -0
- package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
- package/docs/custom-modules/perception.md +48 -247
- package/docs/custom-modules/trigger.md +5 -5
- package/docs/runtime/README.md +5 -5
- package/docs/runtime/agent-notifications.md +2 -2
- package/docs/runtime/behavior-runtime.md +34 -29
- package/docs/runtime/components-and-boundaries.md +55 -147
- package/docs/runtime/events-and-state.md +17 -5
- package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
- package/docs/user-guide/README.md +6 -6
- package/docs/user-guide/api-reference.md +69 -34
- package/docs/user-guide/behavior.md +116 -22
- package/docs/user-guide/perception.md +48 -247
- package/package.json +1 -1
- package/scripts/check-skill-command-surface.mjs +2 -2
- package/skills/clawclaw/SKILL.md +8 -6
- package/skills/clawclaw/references/BEHAVIORS.md +18 -7
- package/skills/clawclaw/references/COMMANDS.md +19 -0
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +116 -22
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +70 -38
- package/skills/clawclaw/references/CUSTOM-MODULES.md +13 -14
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +48 -247
- package/skills/clawclaw/references/STREAM.md +1 -1
- package/src/commands/behavior.ts +28 -99
- package/src/commands/load.ts +15 -23
- package/src/commands/module-runtime-control.ts +113 -0
- package/src/commands/perception.ts +18 -4
- package/src/commands/trigger.ts +1 -1
- package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
- package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
- package/src/runtime/clawclaw/owner.ts +50 -5
- package/src/runtime/clawclaw/perception-module-manifest.ts +16 -7
- package/src/runtime/clawclaw/plugins/assembly.ts +22 -32
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +16 -3
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +4 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +129 -57
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +7 -2
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -1
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +21 -18
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +3 -2
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +2 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
- package/src/runtime/clawclaw/plugins/{source → derived-event}/task-change-tracker.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/{reaction-plugin.ts → perception-module-plugin.ts} +151 -70
- package/src/runtime/clawclaw/plugins/perception/{reaction-runner.ts → perception-module-runner.ts} +26 -13
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +17 -6
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -9
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2 -103
- 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 +61 -10
- 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-manifest.ts +18 -12
- package/src/runtime/clawclaw/runtime-state.ts +1 -1
- package/src/runtime/clawclaw/runtime.ts +3 -3
- package/src/runtime/clawclaw/strategy-memory-rpc.ts +63 -0
- package/src/runtime/clawclaw/strategy-memory.ts +77 -0
- package/src/runtime/clawclaw-event-catalog.ts +5 -5
- package/src/runtime/framework/plugins/contracts.ts +8 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +17 -6
- package/src/runtime/owner-control.ts +5 -0
- package/src/sdk/behavior-plugin/index.ts +4 -1
- package/src/sdk/index.ts +4 -1
- package/src/sdk/perception-plugin/index.ts +6 -4
- package/src/sdk/perception-plugin/module.ts +13 -4
- package/src/sdk/perception-plugin/reaction.ts +1 -1
- package/src/sdk/strategy-memory.ts +12 -0
- package/src/sdk/trigger-plugin/index.ts +3 -3
- package/docs/custom-modules/examples/nearby-escape.ts +0 -56
- package/docs/custom-modules/examples/nearby-notice.ts +0 -36
- package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
- 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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { AuthStore, type AuthProfile } from '../lib/auth.js';
|
|
2
|
+
import { InvalidArgumentError } from 'commander';
|
|
3
|
+
import { sendProfileOwnerControlRequest, type OwnerControlResponse, type OwnerControlType } from '../runtime/owner-control.js';
|
|
4
|
+
import { ShortCommandRunner, type CommandIo, type ShortCommandOperationResult } from '../short-command/runner.js';
|
|
5
|
+
export interface ModuleRuntimeCommandDependencies {
|
|
6
|
+
activeProfile?: () => AuthProfile | null;
|
|
7
|
+
sendOwnerControlRequest?: typeof sendProfileOwnerControlRequest;
|
|
8
|
+
io?: CommandIo;
|
|
9
|
+
}
|
|
10
|
+
const OWNER_CONTROL_TIMEOUT_MS = 30000;
|
|
11
|
+
const OWNER_RUNTIME_GUIDANCE = 'Attach the foreground game Runtime with ccl join before changing runtime module settings.';
|
|
12
|
+
const processIo: CommandIo = { writeStdout: text => { process.stdout.write(text); }, setExitCode: code => { process.exitCode = code; } };
|
|
13
|
+
export function parseModuleInput(value: string): Record<string, unknown> {
|
|
14
|
+
let input: unknown;
|
|
15
|
+
try { input = JSON.parse(value); } catch { throw new InvalidArgumentError('input must be a JSON object'); }
|
|
16
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new InvalidArgumentError('input must be a JSON object');
|
|
17
|
+
return input as Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
function ownerFailure(
|
|
20
|
+
response: OwnerControlResponse | null,
|
|
21
|
+
code: string,
|
|
22
|
+
fallbackMessage: string,
|
|
23
|
+
): ShortCommandOperationResult {
|
|
24
|
+
return {
|
|
25
|
+
kind: 'local_failure',
|
|
26
|
+
source: 'owner',
|
|
27
|
+
error: {
|
|
28
|
+
code: String(response?.code ?? response?.error ?? code),
|
|
29
|
+
message: String(response?.message ?? response?.error ?? fallbackMessage),
|
|
30
|
+
...(response?.details === undefined ? {} : { details: response.details }),
|
|
31
|
+
},
|
|
32
|
+
presentation: { guidance: response === null ? OWNER_RUNTIME_GUIDANCE : undefined },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function runOwnerCommand(
|
|
37
|
+
command: string,
|
|
38
|
+
type: OwnerControlType,
|
|
39
|
+
payload: Readonly<Record<string, unknown>>,
|
|
40
|
+
scoped: boolean,
|
|
41
|
+
dependencies: ModuleRuntimeCommandDependencies,
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
const runner = new ShortCommandRunner();
|
|
44
|
+
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
45
|
+
const send = dependencies.sendOwnerControlRequest ?? sendProfileOwnerControlRequest;
|
|
46
|
+
const io = dependencies.io ?? processIo;
|
|
47
|
+
await runner.run({
|
|
48
|
+
descriptor: {
|
|
49
|
+
command,
|
|
50
|
+
service: 'clawclaw-game-owner',
|
|
51
|
+
operation: type,
|
|
52
|
+
sensitivePolicy: {
|
|
53
|
+
sensitiveValues: profile ? [profile.apiKey] : [],
|
|
54
|
+
sensitiveFieldNames: ['api_key', 'apiKey', 'token', 'authorization'],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
io,
|
|
58
|
+
operation: async (): Promise<ShortCommandOperationResult> => {
|
|
59
|
+
if (!profile) {
|
|
60
|
+
return {
|
|
61
|
+
kind: 'local_failure',
|
|
62
|
+
source: 'local',
|
|
63
|
+
error: {
|
|
64
|
+
code: 'NO_ACTIVE_ACCOUNT',
|
|
65
|
+
message: 'No active account. Run `ccl account register` or switch accounts first.',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
let requestPayload: Record<string, unknown> = { ...payload };
|
|
70
|
+
if (scoped) {
|
|
71
|
+
let snapshot: OwnerControlResponse | null;
|
|
72
|
+
try {
|
|
73
|
+
snapshot = await send(profile, 'snapshot');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
kind: 'transport_failure',
|
|
77
|
+
error: {
|
|
78
|
+
code: 'OWNER_UNAVAILABLE',
|
|
79
|
+
message: error instanceof Error ? error.message : String(error),
|
|
80
|
+
},
|
|
81
|
+
presentation: { guidance: OWNER_RUNTIME_GUIDANCE },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!snapshot?.ok || snapshot.scope === undefined) {
|
|
85
|
+
return ownerFailure(snapshot, 'NO_GAME_START_OWNER', OWNER_RUNTIME_GUIDANCE);
|
|
86
|
+
}
|
|
87
|
+
requestPayload = { expected_scope: snapshot.scope, ...requestPayload };
|
|
88
|
+
}
|
|
89
|
+
let response: OwnerControlResponse | null;
|
|
90
|
+
try {
|
|
91
|
+
response = await send(profile, type, requestPayload, OWNER_CONTROL_TIMEOUT_MS);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return {
|
|
94
|
+
kind: 'transport_failure',
|
|
95
|
+
error: {
|
|
96
|
+
code: 'OWNER_UNAVAILABLE',
|
|
97
|
+
message: error instanceof Error ? error.message : String(error),
|
|
98
|
+
},
|
|
99
|
+
presentation: { guidance: OWNER_RUNTIME_GUIDANCE },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (!response?.ok) {
|
|
103
|
+
return ownerFailure(response, `${type.toUpperCase()}_REJECTED`, `The owner rejected ${type}.`);
|
|
104
|
+
}
|
|
105
|
+
const { ok: _ok, type: _type, ...value } = response;
|
|
106
|
+
return {
|
|
107
|
+
kind: 'local_success',
|
|
108
|
+
source: 'owner',
|
|
109
|
+
value: Object.keys(value).length > 0 ? value : { status: 'ok' },
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runOwnerCommand, parseModuleInput, type ModuleRuntimeCommandDependencies } from './module-runtime-control.js';
|
|
1
2
|
import { Command } from 'commander';
|
|
2
3
|
import { AuthStore, type AuthProfile } from '../lib/auth.js';
|
|
3
4
|
import { getWorkspaceDir } from '../lib/init-command.js';
|
|
@@ -23,9 +24,7 @@ import { capabilityEntryForPath, readCapabilityWorkspaceRegistry } from '../lib/
|
|
|
23
24
|
import { selectCapability } from '../lib/capability-selection.js';
|
|
24
25
|
import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
|
|
25
26
|
|
|
26
|
-
export interface PerceptionCommandDependencies {
|
|
27
|
-
activeProfile?: () => AuthProfile | null;
|
|
28
|
-
}
|
|
27
|
+
export interface PerceptionCommandDependencies extends ModuleRuntimeCommandDependencies {}
|
|
29
28
|
|
|
30
29
|
function activeProfile(dependencies: PerceptionCommandDependencies): AuthProfile {
|
|
31
30
|
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
@@ -112,7 +111,7 @@ Perception modules:
|
|
|
112
111
|
runtime_source_path: source.sourcePath,
|
|
113
112
|
name: source.name,
|
|
114
113
|
description: source.description,
|
|
115
|
-
...(source.
|
|
114
|
+
...(source.module?.behaviors ? { behaviors: source.module.behaviors } : {}),
|
|
116
115
|
source: hubIds.has(source.id) ? 'hub' : 'local',
|
|
117
116
|
...pluginApiVersionStatus(
|
|
118
117
|
'perception',
|
|
@@ -138,6 +137,21 @@ Perception modules:
|
|
|
138
137
|
}
|
|
139
138
|
cmd.help();
|
|
140
139
|
});
|
|
140
|
+
cmd.addCommand(new Command('update')
|
|
141
|
+
.description('Patch an equipped perception configuration in the current game; observing and notifying continue')
|
|
142
|
+
.argument('<perception-id>')
|
|
143
|
+
.requiredOption('--input <json>', 'Configuration patch as a JSON object', parseModuleInput)
|
|
144
|
+
.allowExcessArguments(false)
|
|
145
|
+
.action(async (id: string, opts: { input: Record<string, unknown> }) => {
|
|
146
|
+
await runOwnerCommand('ccl perception update','perception_update',{ perception: id, input: opts.input },true,dependencies);
|
|
147
|
+
}));
|
|
148
|
+
cmd.addCommand(new Command('status')
|
|
149
|
+
.description('Inspect current perception configuration, observation health and strategy bindings')
|
|
150
|
+
.argument('[perception-id]')
|
|
151
|
+
.allowExcessArguments(false)
|
|
152
|
+
.action(async (id?: string) => {
|
|
153
|
+
await runOwnerCommand('ccl perception status','perception_status',id ? { perception: id } : {},false,dependencies);
|
|
154
|
+
}));
|
|
141
155
|
cmd.addCommand(new Command('rename')
|
|
142
156
|
.description('Rename one equipped Perception operation for the active account')
|
|
143
157
|
.argument('<current-id>', 'Current CCL operation name')
|
package/src/commands/trigger.ts
CHANGED
|
@@ -223,7 +223,7 @@ async function updateTrigger(
|
|
|
223
223
|
export function createTriggerCommand(dependencies: TriggerCommandDependencies = {}): Command {
|
|
224
224
|
const trigger = new Command('trigger')
|
|
225
225
|
.alias('trg')
|
|
226
|
-
.description('
|
|
226
|
+
.description('Configure legacy standalone Reflex triggers; new automatic reflexes use paired Perception and Behavior resources.')
|
|
227
227
|
.addHelpText('after', () => {
|
|
228
228
|
const workspaceDir = getWorkspaceDir();
|
|
229
229
|
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
@@ -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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { BehaviorReflexControl } from './behavior-reflex-control.js';
|
|
2
3
|
import { acquireOwnerLock, type OwnerLock } from './owner-lock.js';
|
|
3
4
|
import { createStartingOwnerControl } from './starting-owner-control.js';
|
|
4
5
|
export { acquireOwnerLock, type OwnerLock, type OwnerLockOperations } from './owner-lock.js';
|
|
@@ -585,7 +586,7 @@ export async function runClawclawOwner(
|
|
|
585
586
|
agentBehaviorSources,
|
|
586
587
|
disabledBehaviors,
|
|
587
588
|
);
|
|
588
|
-
const behaviorSourceById = new Map(behaviorSources.map(
|
|
589
|
+
const behaviorSourceById = new Map(behaviorSources.map(source => [source.id,source]));
|
|
589
590
|
const behaviorCatalog = new ClawclawBehaviorCatalog(behaviorSources);
|
|
590
591
|
const behaviorEventTypes = [...new Set(
|
|
591
592
|
behaviorCatalog.list()
|
|
@@ -600,12 +601,13 @@ export async function runClawclawOwner(
|
|
|
600
601
|
const triggerSources = listClawclawTriggerSources(
|
|
601
602
|
getUserDataAccountTriggersDir(workspaceDir, options.profile),
|
|
602
603
|
);
|
|
603
|
-
const
|
|
604
|
+
const legacyTriggers = triggerRegistrations(
|
|
604
605
|
triggerSources,
|
|
605
606
|
gameplayConfig,
|
|
606
607
|
behaviorCatalog,
|
|
607
608
|
configurationWarning,
|
|
608
609
|
);
|
|
610
|
+
const triggers = legacyTriggers;
|
|
609
611
|
const disabledPerceptions = new Set(gameplayConfig.disabled_perception_modules);
|
|
610
612
|
const agentPerceptionSources = agentWorkspace
|
|
611
613
|
? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace)
|
|
@@ -647,6 +649,8 @@ export async function runClawclawOwner(
|
|
|
647
649
|
await client.getQueueStatus('clawclaw'),
|
|
648
650
|
options.intent,
|
|
649
651
|
);
|
|
652
|
+
const reflexControl = new BehaviorReflexControl(assembly.modules,
|
|
653
|
+
assembly.behavior, behaviorCatalog, () => runtime!.publicScope());
|
|
650
654
|
runtime = createClawclawRuntime(options.profile, {
|
|
651
655
|
initialSegment: runtimeStart.initialSegment,
|
|
652
656
|
mode: runtimeStart.mode,
|
|
@@ -657,7 +661,7 @@ export async function runClawclawOwner(
|
|
|
657
661
|
visualEventDelivery: perceptionConfig.events.delivery,
|
|
658
662
|
visualEventTypes: assembly.perception.produces.events,
|
|
659
663
|
behaviorEventTypes: assembly.behavior.produces?.events ?? [],
|
|
660
|
-
|
|
664
|
+
perceptionEventTypes: assembly.modules?.produces.events,
|
|
661
665
|
});
|
|
662
666
|
if (fullDiagnosticsEnabled) {
|
|
663
667
|
processTimingSampler = new RuntimeProcessTimingSampler();
|
|
@@ -787,7 +791,6 @@ export async function runClawclawOwner(
|
|
|
787
791
|
})(),
|
|
788
792
|
perceptions: [...assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
789
793
|
...assembly.reminders.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
790
|
-
...(assembly.reactions?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? []),
|
|
791
794
|
...(assembly.modules?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? [])],
|
|
792
795
|
}),
|
|
793
796
|
eventDescriptors: () => assembly.perception
|
|
@@ -1122,6 +1125,48 @@ export async function runClawclawOwner(
|
|
|
1122
1125
|
);
|
|
1123
1126
|
return { ok: true, type: 'action', result };
|
|
1124
1127
|
}
|
|
1128
|
+
if (request.type === 'perception_status') {
|
|
1129
|
+
return { ok: true, type: request.type, status: assembly.modules?.status(request.perception) ?? [] };
|
|
1130
|
+
}
|
|
1131
|
+
if (request.type === 'perception_update') {
|
|
1132
|
+
const expected = ownerExpectedScope(request.expected_scope);
|
|
1133
|
+
if (!expected || !request.input || typeof request.input !== 'object' || Array.isArray(request.input)
|
|
1134
|
+
|| typeof request.perception !== 'string') return { ok: false, type: request.type, error: 'invalid_perception_control_request' };
|
|
1135
|
+
if (runtime!.currentSegment().kind !== 'game') return { ok: false, type: request.type, error: 'no_active_game' };
|
|
1136
|
+
if (!ownerScopeIsCurrent(runtime!,expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
|
|
1137
|
+
try {
|
|
1138
|
+
if (!assembly.modules) throw Error('perception_not_found');
|
|
1139
|
+
const result = assembly.modules.configure(request.perception,request.input,() => ownerScopeIsCurrent(runtime!,expected));
|
|
1140
|
+
return { ok: true, type: request.type, result };
|
|
1141
|
+
} catch (error) { return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'perception_control_failed' }; }
|
|
1142
|
+
}
|
|
1143
|
+
if (request.type === 'behavior_watch' || request.type === 'behavior_unwatch' || request.type === 'behavior_update') {
|
|
1144
|
+
if (runtime!.currentSegment().kind !== 'game') {
|
|
1145
|
+
return { ok: false, type: request.type, error: 'no_active_game' };
|
|
1146
|
+
}
|
|
1147
|
+
const expected = ownerExpectedScope(request.expected_scope);
|
|
1148
|
+
const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
|
|
1149
|
+
const activationId = typeof request.activation_id === 'string' ? request.activation_id.trim() : '';
|
|
1150
|
+
const patch = request.type === 'behavior_unwatch' ? {} : request.input;
|
|
1151
|
+
if (!expected || !patch || typeof patch !== 'object' || Array.isArray(patch)
|
|
1152
|
+
|| (request.type === 'behavior_update' ? (Boolean(behavior) === Boolean(activationId)) : (!behavior || !!activationId))) {
|
|
1153
|
+
return { ok: false, type: request.type, error: 'invalid_behavior_control_request' };
|
|
1154
|
+
}
|
|
1155
|
+
if (!ownerScopeIsCurrent(runtime!, expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
|
|
1156
|
+
try {
|
|
1157
|
+
if (activationId) {
|
|
1158
|
+
const activation = await assembly.behavior.updateInput(activationId, patch,
|
|
1159
|
+
() => ownerScopeIsCurrent(runtime!, expected));
|
|
1160
|
+
return { ok: true, type: request.type, updated: true, activation };
|
|
1161
|
+
}
|
|
1162
|
+
const operation = request.type === 'behavior_watch' ? 'enable'
|
|
1163
|
+
: request.type === 'behavior_unwatch' ? 'disable' : 'update';
|
|
1164
|
+
const result = await reflexControl.apply(operation, behavior, patch, expected);
|
|
1165
|
+
return { ok: true, type: request.type, result };
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'behavior_control_failed' };
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1125
1170
|
if (request.type === 'behavior_start') {
|
|
1126
1171
|
const expected = ownerExpectedScope(request.expected_scope);
|
|
1127
1172
|
const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
|
|
@@ -1164,7 +1209,7 @@ export async function runClawclawOwner(
|
|
|
1164
1209
|
}
|
|
1165
1210
|
}
|
|
1166
1211
|
if (request.type === 'behavior_status') {
|
|
1167
|
-
return { ok: true, type: 'behavior_status', status:
|
|
1212
|
+
return { ok: true, type: 'behavior_status', status: reflexControl.view(typeof request.behavior === 'string' ? request.behavior : undefined) };
|
|
1168
1213
|
}
|
|
1169
1214
|
if (request.type === 'behavior_cancel') {
|
|
1170
1215
|
const expected = ownerExpectedScope(request.expected_scope);
|
|
@@ -1,5 +1,7 @@
|
|
|
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
|
|
|
@@ -12,16 +14,23 @@ const record = (value: unknown): value is Record<string, any> => !!value && type
|
|
|
12
14
|
export function normalizePerceptionModuleManifest(value: unknown, current = true): PerceptionModuleManifest {
|
|
13
15
|
if (!record(value) || !Number.isInteger(value.apiVersion) || current && value.apiVersion !== 3
|
|
14
16
|
|| Object.keys(value).some(key => !['apiVersion', 'id', 'name', 'description', 'localizations', 'consumes',
|
|
15
|
-
'produces', '
|
|
17
|
+
'produces', 'inputs', 'config', 'behaviors'].includes(key))
|
|
18
|
+
|| typeof value.id !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/.test(value.id)
|
|
19
|
+
|| typeof value.description !== 'string' || !value.description.trim()
|
|
20
|
+
|| value.name !== undefined && (typeof value.name !== 'string' || !value.name.trim())
|
|
21
|
+
|| !hasValidClawclawResourceLocalizations(value.localizations)
|
|
22
|
+
|| value.config !== undefined && !record(value.config)) throw new Error('perception_module_manifest_invalid');
|
|
16
23
|
const consumes = value.consumes ?? [], produces = value.produces ?? [];
|
|
17
24
|
if (!Array.isArray(produces) || produces.some(type => typeof type !== 'string'
|
|
18
25
|
|| !/^[a-z0-9][a-z0-9._-]*$/.test(type)
|
|
19
26
|
|| isClawclawFixedEventType(type) && !PERCEPTION_OWNED_TYPES.has(type))
|
|
20
27
|
|| !Array.isArray(consumes) || consumes.some(type => typeof type !== 'string' || !INPUT_TYPES.has(type)
|
|
21
28
|
|| /^(visual|reminder|reaction|perception|behavior|decision)\./.test(type))) throw new Error('perception_module_event_contract_invalid');
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
const inputs = value.inputs ? normalizeBehaviorInputFields(value.inputs) : undefined;
|
|
30
|
+
const config = inputs ? normalizeBehaviorInput(value.config ?? {}, inputs) : structuredClone(value.config ?? {});
|
|
31
|
+
return { apiVersion: value.apiVersion, id: value.id, description: value.description,
|
|
32
|
+
...(value.name === undefined ? {} : { name: value.name }),
|
|
33
|
+
...(value.localizations === undefined ? {} : { localizations: structuredClone(value.localizations) }),
|
|
34
|
+
...(value.behaviors === undefined ? {} : { behaviors: normalizePerceptionBehaviorBindings(value.behaviors) }),
|
|
35
|
+
consumes: [...new Set(consumes)], produces: [...new Set(produces)], ...(inputs ? { inputs } : {}), config };
|
|
27
36
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { GameClient } from '../../../lib/game-client.js';
|
|
2
|
+
import { ClawclawStrategyMemory } from '../strategy-memory.js';
|
|
2
3
|
import { ClawclawReminderPlugin, CLAWCLAW_REMINDER_PLUGIN_ID } from './derived-event/reminder-plugin.js';
|
|
3
|
-
import { listClawclawPerceptionSources } from './perception/perception-source.js';
|
|
4
|
+
import { listClawclawPerceptionSources, isSupportedPerceptionSource } from './perception/perception-source.js';
|
|
4
5
|
import { DEFAULT_PERCEPTION_MODULES } from './perception/official-module-ids.js';
|
|
5
|
-
import {
|
|
6
|
+
import { ClawclawPerceptionModulePlugin, CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID } from './perception/perception-module-plugin.js';
|
|
6
7
|
import type { RuntimeEpochPlugin } from '../../framework/plugins/index.js';
|
|
7
8
|
import {
|
|
8
9
|
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
@@ -50,8 +51,7 @@ export interface ClawclawPluginAssemblyOptions {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export interface ClawclawPluginAssembly {
|
|
53
|
-
modules?:
|
|
54
|
-
reactions?: ClawclawReactionPlugin;
|
|
54
|
+
modules?: ClawclawPerceptionModulePlugin;
|
|
55
55
|
plugins: RuntimeEpochPlugin<Record<string, any>, Record<string, unknown>>[];
|
|
56
56
|
action: ClawclawActionPlugin;
|
|
57
57
|
gameQuery: ClawclawGameQueryPlugin;
|
|
@@ -95,17 +95,15 @@ export function assembleClawclawPlugins(
|
|
|
95
95
|
throw new Error(`Runtime Plugin ${CLAWCLAW_REMINDER_PLUGIN_ID} is not a ClawclawReminderPlugin.`);
|
|
96
96
|
}
|
|
97
97
|
const selected = new Set(options.perception?.modules ?? DEFAULT_PERCEPTION_MODULES);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const moduleSources =
|
|
101
|
-
.filter(source => source.module && source
|
|
102
|
-
const
|
|
103
|
-
const legacyReadsUnifiedOutput = reactionSources.some(source => source.reaction?.consumes.some(type => moduleOutputTypes.has(type)));
|
|
98
|
+
const availableSources = options.perception?.moduleSources ?? listClawclawPerceptionSources(options.perception?.workspaceDir);
|
|
99
|
+
const explicitlyRequired = (id: string) => plugins.some(plugin => plugin.after?.includes(id));
|
|
100
|
+
const moduleSources = availableSources
|
|
101
|
+
.filter(source => source.module && isSupportedPerceptionSource(source) && selected.has(source.id));
|
|
102
|
+
const reminderSources = availableSources.filter(source => source.reminder && selected.has(source.id));
|
|
104
103
|
const reminders = configuredReminders as ClawclawReminderPlugin | undefined ?? new ClawclawReminderPlugin({
|
|
105
|
-
sources:
|
|
106
|
-
.filter(source => source.reminder && selected.has(source.id)),
|
|
104
|
+
sources: reminderSources,
|
|
107
105
|
});
|
|
108
|
-
if (!configuredReminders) plugins.push(reminders);
|
|
106
|
+
if (!configuredReminders && (reminderSources.length > 0 || explicitlyRequired(reminders.id))) plugins.push(reminders);
|
|
109
107
|
|
|
110
108
|
const configuredGameQuery = plugins.find((plugin) => plugin.id === CLAWCLAW_GAME_QUERY_PLUGIN_ID);
|
|
111
109
|
if (configuredGameQuery && !(configuredGameQuery instanceof ClawclawGameQueryPlugin)) {
|
|
@@ -120,8 +118,8 @@ export function assembleClawclawPlugins(
|
|
|
120
118
|
throw new Error(`Runtime Plugin ${CLAWCLAW_PERCEPTION_PLUGIN_ID} is not a ClawclawPerceptionPlugin.`);
|
|
121
119
|
}
|
|
122
120
|
const perception = configuredPerception as ClawclawPerceptionPlugin | undefined
|
|
123
|
-
?? new ClawclawPerceptionPlugin(options.perception);
|
|
124
|
-
if (!configuredPerception) plugins.push(perception);
|
|
121
|
+
?? new ClawclawPerceptionPlugin({ ...options.perception, moduleSources: availableSources });
|
|
122
|
+
if (!configuredPerception && (perception.produces.events.length > 0 || explicitlyRequired(perception.id))) plugins.push(perception);
|
|
125
123
|
|
|
126
124
|
const configuredTrigger = plugins.find((plugin) => plugin.id === CLAWCLAW_TRIGGER_PLUGIN_ID);
|
|
127
125
|
if (configuredTrigger && !(configuredTrigger instanceof ClawclawTriggerPlugin)) {
|
|
@@ -130,23 +128,12 @@ export function assembleClawclawPlugins(
|
|
|
130
128
|
const trigger = configuredTrigger as ClawclawTriggerPlugin | undefined
|
|
131
129
|
?? new ClawclawTriggerPlugin({
|
|
132
130
|
after: [],
|
|
133
|
-
|
|
134
|
-
// Its old file/config can remain for rollback without evaluating the rule twice.
|
|
135
|
-
triggers: options.triggers?.map(entry => [...reactionSources, ...moduleSources].some(source =>
|
|
136
|
-
(source.declaredId ?? source.id) === entry.source.id) ? { ...entry, enabled: false } : entry),
|
|
131
|
+
triggers: options.triggers,
|
|
137
132
|
diagnosticsEnabled: options.triggerDiagnosticsEnabled,
|
|
138
133
|
});
|
|
139
134
|
if (!configuredTrigger) plugins.push(trigger);
|
|
140
135
|
|
|
141
|
-
const
|
|
142
|
-
sources: reactionSources,
|
|
143
|
-
after: [CLAWCLAW_DERIVED_EVENT_PLUGIN_ID, CLAWCLAW_REMINDER_PLUGIN_ID,
|
|
144
|
-
CLAWCLAW_GAME_QUERY_PLUGIN_ID, CLAWCLAW_PERCEPTION_PLUGIN_ID, CLAWCLAW_TRIGGER_PLUGIN_ID,
|
|
145
|
-
...(legacyReadsUnifiedOutput ? [CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID] : [])],
|
|
146
|
-
behaviors: () => options.behaviorCatalog?.list?.() ?? [],
|
|
147
|
-
}) : undefined;
|
|
148
|
-
if (reactions) plugins.push(reactions);
|
|
149
|
-
const modules = moduleSources.length ? new ClawclawReactionPlugin({ unified: true, sources: moduleSources,
|
|
136
|
+
const modules = moduleSources.length ? new ClawclawPerceptionModulePlugin({ sources: moduleSources,
|
|
150
137
|
after: [CLAWCLAW_DERIVED_EVENT_PLUGIN_ID],
|
|
151
138
|
behaviors: () => options.behaviorCatalog?.list?.() ?? [],
|
|
152
139
|
}) : undefined;
|
|
@@ -158,7 +145,6 @@ export function assembleClawclawPlugins(
|
|
|
158
145
|
}
|
|
159
146
|
const behavior = configuredBehavior as ClawclawBehaviorPlugin | undefined
|
|
160
147
|
?? new ClawclawBehaviorPlugin({
|
|
161
|
-
perceptionActivations: !!reactions || !!modules,
|
|
162
148
|
catalog: options.behaviorCatalog ?? new ClawclawBehaviorCatalog([]),
|
|
163
149
|
fallbackBehaviors: options.fallbackBehaviors,
|
|
164
150
|
after: [
|
|
@@ -168,14 +154,18 @@ export function assembleClawclawPlugins(
|
|
|
168
154
|
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
169
155
|
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
170
156
|
CLAWCLAW_TRIGGER_PLUGIN_ID,
|
|
171
|
-
...(reactions ? [CLAWCLAW_REACTION_PLUGIN_ID] : []),
|
|
172
157
|
...(modules ? [CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID] : []),
|
|
173
|
-
],
|
|
158
|
+
].filter(id => plugins.some(plugin => plugin.id === id)),
|
|
174
159
|
eventTypes: options.behaviorEventTypes,
|
|
175
160
|
diagnosticsEnabled: options.behaviorDiagnosticsEnabled,
|
|
176
161
|
});
|
|
177
162
|
if (!configuredBehavior) plugins.push(behavior);
|
|
178
163
|
|
|
164
|
+
const strategyMemory = new ClawclawStrategyMemory();
|
|
165
|
+
trigger.attachMemory(strategyMemory);
|
|
166
|
+
behavior.attachMemory(strategyMemory);
|
|
167
|
+
modules?.attachMemory(strategyMemory);
|
|
168
|
+
modules?.attachDriver(behavior);
|
|
179
169
|
trigger.attachDriver(behavior);
|
|
180
170
|
// Direct Agent/user commands remain ActionPlugin calls this round. Preserve
|
|
181
171
|
// their original activity timing: mark activity at Action admission, before
|
|
@@ -196,5 +186,5 @@ export function assembleClawclawPlugins(
|
|
|
196
186
|
?? new ClawclawMailboxPlugin({ after: eventProducers });
|
|
197
187
|
if (!configuredMailbox) plugins.push(mailbox);
|
|
198
188
|
|
|
199
|
-
return { plugins, action, gameQuery, perception, reminders, trigger, behavior, mailbox,
|
|
189
|
+
return { plugins, action, gameQuery, perception, reminders, trigger, behavior, mailbox, modules };
|
|
200
190
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BehaviorActivationLayer } from '../../../../sdk/behavior-plugin/index.js';
|
|
2
2
|
|
|
3
|
-
export type BehaviorActivationSource = 'user' | 'agent' | 'idle' | 'trigger' | '
|
|
3
|
+
export type BehaviorActivationSource = 'user' | 'agent' | 'idle' | 'trigger' | 'perception' | 'behavior' | 'system';
|
|
4
4
|
export type BehaviorActivationState = 'running' | 'suspended';
|
|
5
5
|
|
|
6
6
|
export interface BehaviorActivationSpec {
|
|
@@ -266,11 +266,11 @@ export class BehaviorActivationManager {
|
|
|
266
266
|
requestReflex(
|
|
267
267
|
spec: Omit<BehaviorActivationSpec, 'layer' | 'source'> & {
|
|
268
268
|
readonly layer?: 'reflex';
|
|
269
|
-
readonly source?: 'trigger';
|
|
269
|
+
readonly source?: 'trigger' | 'perception';
|
|
270
270
|
},
|
|
271
271
|
now: number,
|
|
272
272
|
): readonly BehaviorActivationTransition[] {
|
|
273
|
-
const candidate = this.activation({ ...spec, layer: 'reflex', source: 'trigger' }, now);
|
|
273
|
+
const candidate = this.activation({ ...spec, layer: 'reflex', source: spec.source ?? 'trigger' }, now);
|
|
274
274
|
const active = this.reflex;
|
|
275
275
|
if (active) {
|
|
276
276
|
const sameTrigger = active.spec.triggerId === candidate.spec.triggerId;
|
|
@@ -365,6 +365,19 @@ export class BehaviorActivationManager {
|
|
|
365
365
|
);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
/** New immutable input, same activation and deadline; old decision generations expire. */
|
|
369
|
+
updateInput(activationId: string, input: Readonly<Record<string, unknown>>, now: number): readonly BehaviorActivationTransition[] {
|
|
370
|
+
const active = [this.long, this.short, this.reflex].find(entry => entry?.spec.activationId === activationId);
|
|
371
|
+
if (!active) throw new Error('behavior_activation_not_found');
|
|
372
|
+
active.spec = { ...active.spec, input: cloneInput(input) };
|
|
373
|
+
active.instanceGeneration += 1;
|
|
374
|
+
return [this.transition(active, active.state === 'running' ? 'restarted' : 'suspended', now, 'behavior_input_updated')];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
updateFallbackInput(behaviorId: string, input: Readonly<Record<string, unknown>>): void {
|
|
378
|
+
if (this.fallback?.behaviorId === behaviorId) this.fallback = { behaviorId, input: cloneInput(input) };
|
|
379
|
+
}
|
|
380
|
+
|
|
368
381
|
snapshot(): Readonly<{
|
|
369
382
|
long?: BehaviorActivationSnapshot;
|
|
370
383
|
short?: BehaviorActivationSnapshot;
|
|
@@ -16,6 +16,7 @@ import type { ResolvedClawclawBehaviorSource } from './behavior-source.js';
|
|
|
16
16
|
import type { ClawclawBehaviorObservationSnapshot } from '../../behavior-observation-memory.js';
|
|
17
17
|
import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
|
|
18
18
|
import { captureBehaviorInstance, restoreBehaviorInstance, type BehaviorInstanceSnapshot } from './behavior-instance-snapshot.js';
|
|
19
|
+
import { StrategyMemoryRpcClient } from '../../strategy-memory-rpc.js';
|
|
19
20
|
|
|
20
21
|
interface BehaviorThreadWorkerData {
|
|
21
22
|
readonly poolId: string;
|
|
@@ -77,6 +78,7 @@ function diagnosticMemory(): Readonly<Record<string, number>> {
|
|
|
77
78
|
: {};
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
const memoryClient = new StrategyMemoryRpcClient(send);
|
|
80
82
|
let loaded: ReturnType<typeof validateClawclawBehaviorModule>;
|
|
81
83
|
let execution: ResolvedClawclawBehaviorSource['execution'];
|
|
82
84
|
let preparation: ReturnType<typeof prepareClawclawBehavior> | undefined;
|
|
@@ -143,6 +145,7 @@ async function run(request: BehaviorThreadRunRequest | BehaviorThreadStopRequest
|
|
|
143
145
|
restoreBehaviorInstance(instance, request.instanceSnapshot);
|
|
144
146
|
}
|
|
145
147
|
const api = createBehaviorReadApi(input, {
|
|
148
|
+
memory: memoryClient.bind(request.requestId, () => invocationActive),
|
|
146
149
|
onQuery: () => { queryCount += 1; },
|
|
147
150
|
isActive: () => invocationActive,
|
|
148
151
|
...(request.observationSnapshot === undefined
|
|
@@ -169,6 +172,7 @@ async function run(request: BehaviorThreadRunRequest | BehaviorThreadStopRequest
|
|
|
169
172
|
|
|
170
173
|
let operationTail = Promise.resolve();
|
|
171
174
|
port.on('message', (request: BehaviorThreadRunRequest | BehaviorThreadStopRequest) => {
|
|
175
|
+
if (memoryClient.receive(request)) return;
|
|
172
176
|
operationTail = operationTail.then(() => run(request)).catch((error) => {
|
|
173
177
|
send({
|
|
174
178
|
type: 'error',
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from './behavior-source.js';
|
|
14
14
|
import { prepareBehaviorInWorker } from './thread-behavior-executor.js';
|
|
15
15
|
import { deepFreezeBehaviorValue } from './behavior-manifest.js';
|
|
16
|
+
import { normalizeBehaviorInput } from '../../behavior-input-fields.js';
|
|
16
17
|
|
|
17
18
|
export interface ClawclawBehaviorCatalogEntry {
|
|
18
19
|
readonly apiVersion: number | null;
|
|
@@ -107,6 +108,7 @@ export class ClawclawBehaviorCatalog {
|
|
|
107
108
|
return Object.freeze({
|
|
108
109
|
manifest: deepFreezeBehaviorValue(structuredClone(prepared.manifest)),
|
|
109
110
|
input: deepFreezeBehaviorValue(structuredClone(prepared.input)),
|
|
111
|
+
rawInput: deepFreezeBehaviorValue(normalizeBehaviorInput(input, source.inputs, { allowedKeys: ['timeout_ms', 'duration_ms'] })),
|
|
110
112
|
source: prepared.source,
|
|
111
113
|
display: source.display,
|
|
112
114
|
...(prepared.timing === undefined ? {} : { timing: prepared.timing }),
|