@myclaw163/clawclaw-cli 0.9.0 → 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 +5 -3
- package/docs/custom-modules/README.md +19 -24
- package/docs/custom-modules/api-reference.md +85 -33
- package/docs/custom-modules/behavior.md +116 -22
- package/docs/custom-modules/examples/auto-escape.ts +41 -0
- package/docs/custom-modules/examples/first-sighting-v3.ts +29 -0
- package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
- package/docs/custom-modules/perception.md +158 -276
- package/docs/custom-modules/trigger.md +5 -3
- package/docs/runtime/README.md +17 -8
- package/docs/runtime/agent-notifications.md +32 -15
- package/docs/runtime/behavior-runtime.md +36 -24
- package/docs/runtime/components-and-boundaries.md +56 -108
- package/docs/runtime/events-and-state.md +55 -3
- package/docs/runtime/owner-lifecycle-and-observability.md +5 -3
- package/docs/user-guide/README.md +6 -6
- package/docs/user-guide/api-reference.md +80 -30
- package/docs/user-guide/behavior.md +116 -22
- package/docs/user-guide/perception.md +157 -275
- package/package.json +1 -1
- package/scripts/check-skill-command-surface.mjs +2 -2
- package/skills/clawclaw/SKILL.md +9 -7
- package/skills/clawclaw/references/BEHAVIORS.md +19 -6
- 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 +82 -35
- package/skills/clawclaw/references/CUSTOM-MODULES.md +18 -23
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +158 -276
- package/skills/clawclaw/references/STREAM.md +1 -1
- package/src/commands/behavior.ts +28 -99
- package/src/commands/load.ts +23 -29
- package/src/commands/module-runtime-control.ts +113 -0
- package/src/commands/perception.ts +20 -6
- package/src/commands/trigger.ts +1 -1
- package/src/lib/agent-workspace-sync.ts +2 -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/owner.ts +51 -5
- package/src/runtime/clawclaw/perception-module-manifest.ts +36 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +25 -23
- 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/perception-module-plugin.ts +314 -0
- 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 +39 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +30 -7
- 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 +9 -6
- 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 +5 -0
- package/src/sdk/perception-plugin/index.ts +29 -10
- package/src/sdk/perception-plugin/module.ts +55 -0
- package/src/sdk/perception-plugin/reaction.ts +2 -1
- package/src/sdk/perception-plugin/reminder.ts +1 -0
- package/src/sdk/strategy-memory.ts +12 -0
- package/src/sdk/trigger-plugin/index.ts +3 -2
- 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-plugin.ts +0 -198
- 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
|
@@ -81,7 +81,7 @@ ccl events <事件名>
|
|
|
81
81
|
| `known_status.death_cause` | 已公开死因:`killed` 为被击杀,`exiled` 为会议放逐 |
|
|
82
82
|
| `known_status.reported_in_current_meeting` | 会议中为 `true` 表示此人是触发本次会议的被报告尸体;`false` 表示已知死亡但不是本次被报告尸体;缺失表示后端没有公开该判断 |
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
系统派生在这些已知事实变化时生成 `players_changed`:Monitor 使用一句短摘要并列入 `details_required`,`ccl events` 详情给出本批 `changes[]` 和变化后的完整 `players[]`,整体替换此前玩家表。当前画面以持续收到的 visual Event 为准。
|
|
85
85
|
|
|
86
86
|
`state.emergency` 持续给出 `active`;激活时还可能给出 `task_name`、`room`、`x`、`y` 和实时 `remaining_secs`。倒计时本身保留在 State,不会每帧生成 Event。剩余时间首次跨过 30 秒、20 秒时,Derived Event 各生成一次高优 `emergency_countdown_warning`;收到后立即按当前 State 和任务列表调整目标。
|
|
87
87
|
|
package/src/commands/behavior.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runOwnerCommand } from './module-runtime-control.js';
|
|
1
2
|
import { Command, InvalidArgumentError, Option } from 'commander';
|
|
2
3
|
import { AuthStore, type AuthProfile } from '../lib/auth.js';
|
|
3
4
|
import {
|
|
@@ -148,102 +149,6 @@ function sourceEntry(
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
function ownerFailure(
|
|
152
|
-
response: OwnerControlResponse | null,
|
|
153
|
-
code: string,
|
|
154
|
-
fallbackMessage: string,
|
|
155
|
-
): ShortCommandOperationResult {
|
|
156
|
-
return {
|
|
157
|
-
kind: 'local_failure',
|
|
158
|
-
source: 'owner',
|
|
159
|
-
error: {
|
|
160
|
-
code: String(response?.code ?? response?.error ?? code),
|
|
161
|
-
message: String(response?.message ?? response?.error ?? fallbackMessage),
|
|
162
|
-
...(response?.details === undefined ? {} : { details: response.details }),
|
|
163
|
-
},
|
|
164
|
-
presentation: { guidance: response === null ? OWNER_RUNTIME_GUIDANCE : undefined },
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async function runOwnerCommand(
|
|
169
|
-
command: string,
|
|
170
|
-
type: OwnerControlType,
|
|
171
|
-
payload: Readonly<Record<string, unknown>>,
|
|
172
|
-
scoped: boolean,
|
|
173
|
-
dependencies: BehaviorCommandDependencies,
|
|
174
|
-
): Promise<void> {
|
|
175
|
-
const runner = new ShortCommandRunner();
|
|
176
|
-
const profile = (dependencies.activeProfile ?? (() => new AuthStore().getActive()))();
|
|
177
|
-
const send = dependencies.sendOwnerControlRequest ?? sendProfileOwnerControlRequest;
|
|
178
|
-
const io = dependencies.io ?? processIo;
|
|
179
|
-
await runner.run({
|
|
180
|
-
descriptor: {
|
|
181
|
-
command,
|
|
182
|
-
service: 'clawclaw-game-owner',
|
|
183
|
-
operation: type,
|
|
184
|
-
sensitivePolicy: {
|
|
185
|
-
sensitiveValues: profile ? [profile.apiKey] : [],
|
|
186
|
-
sensitiveFieldNames: ['api_key', 'apiKey', 'token', 'authorization'],
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
io,
|
|
190
|
-
operation: async (): Promise<ShortCommandOperationResult> => {
|
|
191
|
-
if (!profile) {
|
|
192
|
-
return {
|
|
193
|
-
kind: 'local_failure',
|
|
194
|
-
source: 'local',
|
|
195
|
-
error: {
|
|
196
|
-
code: 'NO_ACTIVE_ACCOUNT',
|
|
197
|
-
message: 'No active account. Run `ccl account register` or switch accounts first.',
|
|
198
|
-
},
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
let requestPayload: Record<string, unknown> = { ...payload };
|
|
202
|
-
if (scoped) {
|
|
203
|
-
let snapshot: OwnerControlResponse | null;
|
|
204
|
-
try {
|
|
205
|
-
snapshot = await send(profile, 'snapshot');
|
|
206
|
-
} catch (error) {
|
|
207
|
-
return {
|
|
208
|
-
kind: 'transport_failure',
|
|
209
|
-
error: {
|
|
210
|
-
code: 'OWNER_UNAVAILABLE',
|
|
211
|
-
message: error instanceof Error ? error.message : String(error),
|
|
212
|
-
},
|
|
213
|
-
presentation: { guidance: OWNER_RUNTIME_GUIDANCE },
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
if (!snapshot?.ok || snapshot.scope === undefined) {
|
|
217
|
-
return ownerFailure(snapshot, 'NO_GAME_START_OWNER', OWNER_RUNTIME_GUIDANCE);
|
|
218
|
-
}
|
|
219
|
-
requestPayload = { expected_scope: snapshot.scope, ...requestPayload };
|
|
220
|
-
}
|
|
221
|
-
let response: OwnerControlResponse | null;
|
|
222
|
-
try {
|
|
223
|
-
response = await send(profile, type, requestPayload, OWNER_CONTROL_TIMEOUT_MS);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
return {
|
|
226
|
-
kind: 'transport_failure',
|
|
227
|
-
error: {
|
|
228
|
-
code: 'OWNER_UNAVAILABLE',
|
|
229
|
-
message: error instanceof Error ? error.message : String(error),
|
|
230
|
-
},
|
|
231
|
-
presentation: { guidance: OWNER_RUNTIME_GUIDANCE },
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
if (!response?.ok) {
|
|
235
|
-
return ownerFailure(response, `${type.toUpperCase()}_REJECTED`, `The owner rejected ${type}.`);
|
|
236
|
-
}
|
|
237
|
-
const { ok: _ok, type: _type, ...value } = response;
|
|
238
|
-
return {
|
|
239
|
-
kind: 'local_success',
|
|
240
|
-
source: 'owner',
|
|
241
|
-
value: Object.keys(value).length > 0 ? value : { status: 'ok' },
|
|
242
|
-
};
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
152
|
async function tryApplyRuntimeConfig(
|
|
248
153
|
type: 'behavior_fallback' | 'behavior_idle',
|
|
249
154
|
payload: Readonly<Record<string, unknown>>,
|
|
@@ -484,9 +389,11 @@ export function createBehaviorCommand(dependencies: BehaviorCommandDependencies
|
|
|
484
389
|
}));
|
|
485
390
|
|
|
486
391
|
behavior.addCommand(new Command('status')
|
|
487
|
-
.description('Show
|
|
488
|
-
.
|
|
489
|
-
|
|
392
|
+
.description('Show execution stack and background watches, optionally for one Behavior')
|
|
393
|
+
.argument('[id]', 'Optional Behavior operation name')
|
|
394
|
+
.allowExcessArguments(false)
|
|
395
|
+
.action(async (id?: string) => {
|
|
396
|
+
await runOwnerCommand('ccl behavior status', 'behavior_status', id ? { behavior: id } : {}, false, dependencies);
|
|
490
397
|
}));
|
|
491
398
|
|
|
492
399
|
behavior.addCommand(new Command('cancel')
|
|
@@ -598,5 +505,27 @@ export function createBehaviorCommand(dependencies: BehaviorCommandDependencies
|
|
|
598
505
|
.action((opts: { role: ClawclawRoleId }) => removeFallback(opts.role, 'none')));
|
|
599
506
|
behavior.addCommand(fallback);
|
|
600
507
|
|
|
508
|
+
behavior.addCommand(new Command('watch')
|
|
509
|
+
.description('Allow equipped paired Perceptions to activate this Behavior automatically in the current game')
|
|
510
|
+
.argument('<id>', 'Equipped Behavior operation name')
|
|
511
|
+
.option('--input <json>', 'Optional execution parameter patch; perception parameters use perception update', value => parseJsonObject(value), {})
|
|
512
|
+
.allowExcessArguments(false).action(async (id: string, opts: { input: Record<string, unknown> }) => {
|
|
513
|
+
await runOwnerCommand('ccl behavior watch', 'behavior_watch', { behavior: id, input: opts.input }, true, dependencies);
|
|
514
|
+
}));
|
|
515
|
+
behavior.addCommand(new Command('unwatch')
|
|
516
|
+
.description('Block automatic activation and cancel associated Reflex; perceptions keep observing and notifying')
|
|
517
|
+
.argument('<id>', 'Equipped Behavior operation name')
|
|
518
|
+
.allowExcessArguments(false).action(async (id: string) => {
|
|
519
|
+
await runOwnerCommand('ccl behavior unwatch', 'behavior_unwatch', { behavior: id }, true, dependencies);
|
|
520
|
+
}));
|
|
521
|
+
behavior.addCommand(new Command('update')
|
|
522
|
+
.description('Patch this Behavior\'s match-local parameters and current executions; keep its watch switch')
|
|
523
|
+
.argument('<id>', 'Behavior operation name; with --activation, one activation ID')
|
|
524
|
+
.option('--activation', 'Update only the specified execution, without changing shared parameters')
|
|
525
|
+
.requiredOption('--input <json>', 'Parameter patch JSON object', value => parseJsonObject(value))
|
|
526
|
+
.allowExcessArguments(false).action(async (id: string, opts: { activation?: boolean; input: Record<string, unknown> }) => {
|
|
527
|
+
await runOwnerCommand('ccl behavior update', 'behavior_update',
|
|
528
|
+
opts.activation ? { activation_id: id, input: opts.input } : { behavior: id, input: opts.input }, true, dependencies);
|
|
529
|
+
}));
|
|
601
530
|
return behavior;
|
|
602
531
|
}
|
package/src/commands/load.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
30
30
|
import { TRIGGER_PLUGIN_API_VERSION } from '../sdk/trigger-plugin/index.js';
|
|
31
31
|
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
32
|
+
import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
32
33
|
import { resolveReactionBehavior } from '../runtime/clawclaw/reaction-behavior-resolution.js';
|
|
33
34
|
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
34
35
|
import {
|
|
@@ -612,65 +613,57 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
612
613
|
source: hubPerceptionIds.has(source.id) ? 'hub' : 'local', stage: 'selection', id: source.id,
|
|
613
614
|
reason: `perception_topic_conflict:${source.reminder!.topic}:${reminderTopics.get(source.reminder!.topic)!.join(',')}` });
|
|
614
615
|
}
|
|
616
|
+
const reflexBindings = enabledPerceptions.filter(isSupportedPerceptionSource).flatMap(source =>
|
|
617
|
+
Object.entries(source.module?.behaviors ?? {}).map(([key,binding]) => {
|
|
618
|
+
const id = resolveReactionBehavior(binding,behaviorEntries.map(entry => ({ id: entry.id,
|
|
619
|
+
declaredId: enabledBehaviors.find(source => source.id === entry.id)?.declaredId,
|
|
620
|
+
resourceId: entry.resource_id, loadable: entry.loadable })));
|
|
621
|
+
if (!id) configurationWarnings.push({ code: 'PERCEPTION_BEHAVIOR_NOT_LOADED',
|
|
622
|
+
perception_id: source.id, binding: key, behavior_name: binding.name,
|
|
623
|
+
message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.` });
|
|
624
|
+
return { perception_id: source.id, binding: key, behavior_id: id ?? binding.name,
|
|
625
|
+
available: !!id, default_enabled: false,
|
|
626
|
+
...(id ? {} : { reason: 'behavior_not_loaded' }) };
|
|
627
|
+
}));
|
|
615
628
|
const perceptionEntry = (source: typeof enabledPerceptions[number]) => ({
|
|
616
629
|
id: source.id,
|
|
617
630
|
name: source.name,
|
|
618
631
|
description: source.description,
|
|
619
632
|
source: hubPerceptionIds.has(source.id) ? 'hub' : 'workspace',
|
|
620
|
-
...pluginApiVersionStatus('perception',
|
|
633
|
+
...pluginApiVersionStatus('perception', expectedPerceptionApiVersion(source), source.apiVersion),
|
|
621
634
|
});
|
|
622
635
|
const perceptions = enabledPerceptions
|
|
623
|
-
.filter(
|
|
636
|
+
.filter(source => isSupportedPerceptionSource(source) && !conflictingPerceptions.has(source.id))
|
|
624
637
|
.map(perceptionEntry);
|
|
625
|
-
const behaviorDependencies = new Map<string, Array<Record<string, unknown>>>();
|
|
626
|
-
const availableBehaviorIdsForReactions = new Set(behaviors.map(entry => entry.id));
|
|
627
|
-
const reactionCandidates = enabledBehaviors.map(source => ({ id: source.id, declaredId: source.declaredId,
|
|
628
|
-
resourceId: source.resourceId, loadable: availableBehaviorIdsForReactions.has(source.id) }));
|
|
629
|
-
for (const source of enabledPerceptions.filter(source => source.reaction && source.apiVersion === PERCEPTION_PLUGIN_API_VERSION)) {
|
|
630
|
-
const bindings = Object.entries(source.reaction!.behaviors ?? {}).map(([key, binding]) => {
|
|
631
|
-
const resolved = resolveReactionBehavior(binding, reactionCandidates);
|
|
632
|
-
if (!resolved) configurationWarnings.push({ code: 'PERCEPTION_BEHAVIOR_UNAVAILABLE',
|
|
633
|
-
perception_id: source.id, binding: key, behavior_name: binding.name,
|
|
634
|
-
...(binding.resourceId ? { preferred_resource_id: binding.resourceId } : {}),
|
|
635
|
-
reason: 'no_loaded_matching_behavior',
|
|
636
|
-
message: `Perception ${source.id} cannot activate ${binding.name}: no matching Behavior is loaded. Only this reaction is unavailable; other perception output and CCL continue. Equip a matching Behavior and run ccl load again; changes take effect in the next Runtime.` });
|
|
637
|
-
return { binding: key, name: binding.name, layer: binding.layer ?? 'reflex', available: !!resolved,
|
|
638
|
-
...(binding.resourceId ? { preferred_resource_id: binding.resourceId } : {}),
|
|
639
|
-
...(resolved ? { behavior_id: resolved } : {}) };
|
|
640
|
-
});
|
|
641
|
-
behaviorDependencies.set(source.id, bindings);
|
|
642
|
-
}
|
|
643
638
|
const incompatiblePerceptions = enabledPerceptions
|
|
644
|
-
.filter(
|
|
639
|
+
.filter(source => !isSupportedPerceptionSource(source))
|
|
645
640
|
.map(perceptionEntry);
|
|
646
641
|
for (const source of enabledPerceptions) {
|
|
647
|
-
if (source
|
|
642
|
+
if (isSupportedPerceptionSource(source)) continue;
|
|
648
643
|
capabilityWarnings.push(compatibilityWarning(
|
|
649
644
|
'perception',
|
|
650
645
|
hubPerceptionIds.has(source.id) ? 'hub' : 'local',
|
|
651
646
|
source,
|
|
652
|
-
`perception_api_version_unsupported:expected=${
|
|
647
|
+
`perception_api_version_unsupported:expected=${expectedPerceptionApiVersion(source)}:received=${source.apiVersion ?? 'missing'}`,
|
|
653
648
|
));
|
|
654
649
|
}
|
|
655
650
|
const selectedLocalPerceptionPaths = new Set(localPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
|
|
656
651
|
for (const source of allLocalPerceptions) {
|
|
657
652
|
if (
|
|
658
653
|
selectedLocalPerceptionPaths.has(resolve(source.sourcePath))
|
|
659
|
-
|| source
|
|
654
|
+
|| isSupportedPerceptionSource(source)
|
|
660
655
|
) continue;
|
|
661
656
|
capabilityWarnings.push(compatibilityWarning(
|
|
662
657
|
'perception',
|
|
663
658
|
'local',
|
|
664
659
|
source,
|
|
665
|
-
`perception_api_version_unsupported:expected=${
|
|
660
|
+
`perception_api_version_unsupported:expected=${expectedPerceptionApiVersion(source)}:received=${source.apiVersion ?? 'missing'}`,
|
|
666
661
|
));
|
|
667
662
|
}
|
|
668
663
|
const disabledTriggers = new Set(gameplay.disabled_triggers);
|
|
669
664
|
const localTriggerDir = getUserDataAccountTriggersDir(workspaceDir, profile);
|
|
670
665
|
const triggerSources = listClawclawTriggerSources(localTriggerDir);
|
|
671
|
-
const enabledTriggers = triggerSources.filter((source) => !disabledTriggers.has(source.id)
|
|
672
|
-
&& !enabledPerceptions.some(perception => perception.reaction && perception.apiVersion === PERCEPTION_PLUGIN_API_VERSION
|
|
673
|
-
&& (perception.declaredId ?? perception.id) === source.id));
|
|
666
|
+
const enabledTriggers = triggerSources.filter((source) => !disabledTriggers.has(source.id));
|
|
674
667
|
const triggerSourcePaths = new Set(triggerSources.map(({ sourcePath }) => resolve(sourcePath)));
|
|
675
668
|
let expectedLocalTriggers = enabledTriggers.length;
|
|
676
669
|
for (const path of listCapabilityModuleCandidates(localTriggerDir)) {
|
|
@@ -966,7 +959,8 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
966
959
|
name: localized.name,
|
|
967
960
|
description: source.description,
|
|
968
961
|
source: entry.source,
|
|
969
|
-
...(
|
|
962
|
+
...(reflexBindings.some(binding => binding.perception_id === entry.id)
|
|
963
|
+
? { reflex_bindings: reflexBindings.filter(binding => binding.perception_id === entry.id) } : {}),
|
|
970
964
|
};
|
|
971
965
|
}),
|
|
972
966
|
triggers: triggers.map((entry) => {
|
|
@@ -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';
|
|
@@ -16,16 +17,14 @@ import {
|
|
|
16
17
|
listAgentWorkspacePerceptionSources,
|
|
17
18
|
mergeAgentWorkspacePerceptionSources,
|
|
18
19
|
} from '../lib/agent-workspace-runtime.js';
|
|
19
|
-
import {
|
|
20
|
+
import { expectedPerceptionApiVersion } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
20
21
|
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
21
22
|
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
22
23
|
import { capabilityEntryForPath, readCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
|
|
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,11 +111,11 @@ 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',
|
|
119
|
-
|
|
118
|
+
expectedPerceptionApiVersion(source),
|
|
120
119
|
source.apiVersion,
|
|
121
120
|
),
|
|
122
121
|
disabled: hubIds.has(source.id)
|
|
@@ -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()))();
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
import { inspectClawclawBehaviorSource, behaviorSourceCompatibilityError } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
42
42
|
import { listClawclawPerceptionSourcesInDirectory } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
43
43
|
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
44
|
-
import {
|
|
44
|
+
import { isSupportedPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
45
45
|
import { updateGameplayConfig } from './gameplay-config.js';
|
|
46
46
|
|
|
47
47
|
const RESOURCE_TYPES: readonly ResourceType[] = ['skill', 'strategy', 'persona', 'perception'];
|
|
@@ -1000,7 +1000,7 @@ export async function syncAgentWorkspaceConfig(
|
|
|
1000
1000
|
}
|
|
1001
1001
|
} else if (type === 'perception') {
|
|
1002
1002
|
const source = listClawclawPerceptionSourcesInDirectory(dirname(path)).find(source => source.sourcePath === path);
|
|
1003
|
-
if (!source || source
|
|
1003
|
+
if (!source || !isSupportedPerceptionSource(source)) {
|
|
1004
1004
|
throw new Error(`agent_workspace_resource_failed:perception:${item.resource_id}:cloud_module_invalid`);
|
|
1005
1005
|
}
|
|
1006
1006
|
}
|
|
@@ -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
|
+
}
|