@myclaw163/clawclaw-cli 0.10.17 → 0.10.19
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/cli-runtime/commands/behavior.js +7 -0
- package/cli-runtime/commands/prepare.js +17 -15
- package/cli-runtime/lib/agent-workspace-runtime.js +37 -15
- package/cli-runtime/lib/user-data.js +3 -1
- package/cli-runtime/runtime/clawclaw/behavior-start-control.js +4 -2
- package/cli-runtime/runtime/clawclaw/behavior-trigger.js +17 -1
- package/cli-runtime/runtime/clawclaw/owner.js +12 -4
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +6 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +49 -4
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +27 -2
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +1 -0
- package/docs/custom-modules/README.md +1 -1
- package/docs/custom-modules/api-reference.md +2 -2
- package/docs/custom-modules/behavior.md +6 -4
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/api-reference.md +2 -2
- package/docs/user-guide/behavior.md +6 -4
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +2 -2
- package/skills/clawclaw/references/BEHAVIORS.md +2 -0
- package/skills/clawclaw-creator/SKILL.md +1 -1
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +6 -4
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +2 -2
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -1
- package/src/commands/behavior.ts +7 -0
- package/src/commands/prepare.ts +16 -17
- package/src/lib/agent-workspace-runtime.ts +41 -25
- package/src/lib/user-data.ts +4 -1
- package/src/runtime/clawclaw/behavior-start-control.ts +3 -1
- package/src/runtime/clawclaw/behavior-trigger.ts +21 -1
- package/src/runtime/clawclaw/owner.ts +9 -4
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +8 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +60 -7
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +31 -4
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
classifyStrategyLifecycle,
|
|
34
34
|
readCapabilityWorkspaceRegistry
|
|
35
35
|
} from "../lib/capability-workspace.js";
|
|
36
|
+
import { strategyActivationError, strategyActivationMode } from "../runtime/clawclaw/behavior-trigger.js";
|
|
36
37
|
import { readFileSync } from "node:fs";
|
|
37
38
|
import { selectCapability } from "../lib/capability-selection.js";
|
|
38
39
|
import { renameCapabilityOperationWhenIdle } from "../lib/capability-operation-rename.js";
|
|
@@ -106,6 +107,8 @@ function sourceEntry(source, disabled) {
|
|
|
106
107
|
inputs: source.inputs,
|
|
107
108
|
produces: source.produces ?? [],
|
|
108
109
|
...source.runtime === void 0 ? {} : { runtime: source.runtime },
|
|
110
|
+
activation_mode: strategyActivationMode(source),
|
|
111
|
+
...source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {},
|
|
109
112
|
strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, "utf8")),
|
|
110
113
|
source: source.management.source,
|
|
111
114
|
managed_by: source.management.managedBy,
|
|
@@ -305,6 +308,8 @@ ${commandName === "strategy" ? "Strategy" : "Behavior"} modules:
|
|
|
305
308
|
if (!hub && gameplay.disabled_behaviors.includes(id)) {
|
|
306
309
|
throw new Error(`Behavior '${id}' is disabled in user-data/gameplay.json.`);
|
|
307
310
|
}
|
|
311
|
+
const error = strategyActivationError(source);
|
|
312
|
+
if (error) throw new Error(`${id}: ${error}. \u8BE5\u7B56\u7565\u4EC5\u81EA\u52A8\u89E6\u53D1\uFF0C\u7531\u540C\u6587\u4EF6\u7684\u611F\u77E5\u8BF7\u6C42\u542F\u52A8\u3002`);
|
|
308
313
|
await runOwnerCommand(`ccl ${commandName} start`, "behavior_start", {
|
|
309
314
|
behavior: id,
|
|
310
315
|
layer: opts.layer,
|
|
@@ -346,6 +351,8 @@ ${commandName === "strategy" ? "Strategy" : "Behavior"} modules:
|
|
|
346
351
|
if (entry.loadable !== true || !hub && gameplay.disabled_behaviors.includes(id)) {
|
|
347
352
|
throw new Error(`Behavior '${id}' is not enabled and loadable.`);
|
|
348
353
|
}
|
|
354
|
+
const error = strategyActivationError(source);
|
|
355
|
+
if (error) throw new Error(`${id}: ${error}. \u8BE5\u7B56\u7565\u4EC5\u81EA\u52A8\u89E6\u53D1\uFF0C\u8BF7\u9009\u62E9\u666E\u901A\u7B56\u7565\u4F5C\u4E3A\u89D2\u8272\u9ED8\u8BA4\u7B56\u7565\u3002`);
|
|
349
356
|
const updated = updateGameplayConfig((current) => {
|
|
350
357
|
current.fallback_behaviors[role] = id;
|
|
351
358
|
}, workspaceDir, profile);
|
|
@@ -33,6 +33,7 @@ import { BEHAVIOR_PLUGIN_API_VERSION } from "../sdk/behavior-plugin/index.js";
|
|
|
33
33
|
import { TRIGGER_PLUGIN_API_VERSION } from "../sdk/trigger-plugin/index.js";
|
|
34
34
|
import { PERCEPTION_PLUGIN_API_VERSION } from "../sdk/perception-plugin/index.js";
|
|
35
35
|
import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from "../runtime/clawclaw/plugins/perception/perception-source.js";
|
|
36
|
+
import { strategyActivationMode } from "../runtime/clawclaw/behavior-trigger.js";
|
|
36
37
|
import { resolveReactionBehavior } from "../runtime/clawclaw/reaction-behavior-resolution.js";
|
|
37
38
|
import { pluginApiVersionStatus } from "../runtime/clawclaw/plugins/plugin-api-version.js";
|
|
38
39
|
import {
|
|
@@ -296,19 +297,19 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
296
297
|
});
|
|
297
298
|
}
|
|
298
299
|
if (activeWorkspace) {
|
|
299
|
-
const
|
|
300
|
+
const discoveredResources = new Set(hubBehaviors.map((source) => source.management.resourceId));
|
|
300
301
|
for (const item of activeWorkspace.items.strategy) {
|
|
301
302
|
if (!item.runtimeEntryPath) {
|
|
302
303
|
capabilityWarnings.push(missingProjectionWarning("behavior", item));
|
|
303
304
|
continue;
|
|
304
305
|
}
|
|
306
|
+
if (discoveredResources.has(item.resourceId)) continue;
|
|
305
307
|
const path = resolveLocalAgentWorkspacePath(
|
|
306
308
|
workspaceDir,
|
|
307
309
|
profile,
|
|
308
310
|
activeWorkspace,
|
|
309
311
|
item.runtimeEntryPath
|
|
310
312
|
);
|
|
311
|
-
if (discoveredPaths.has(resolve(path))) continue;
|
|
312
313
|
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
313
314
|
"behavior",
|
|
314
315
|
"hub",
|
|
@@ -333,6 +334,7 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
333
334
|
api_version: source.apiVersion ?? null,
|
|
334
335
|
expected_api_version: BEHAVIOR_PLUGIN_API_VERSION,
|
|
335
336
|
loadable,
|
|
337
|
+
activation_mode: strategyActivationMode(source),
|
|
336
338
|
...loadable ? {} : {
|
|
337
339
|
compatibility_error: versionCompatible ? compatibilityError : `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? "missing"}`
|
|
338
340
|
},
|
|
@@ -390,12 +392,14 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
390
392
|
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
391
393
|
const fallback = gameplay.fallback_behaviors[role];
|
|
392
394
|
if (fallback === null) continue;
|
|
393
|
-
|
|
395
|
+
const entry = behaviors.find(({ id }) => id === fallback);
|
|
396
|
+
if (!entry || entry.activation_mode === "automatic_only") {
|
|
397
|
+
const unavailableReason = disabledBehaviors.has(fallback) ? "local_disabled_or_unselected" : "not_loaded";
|
|
394
398
|
configurationWarnings.push({
|
|
395
399
|
code: "DEFAULT_LONG_BEHAVIOR_UNAVAILABLE",
|
|
396
400
|
role,
|
|
397
401
|
behavior_id: fallback,
|
|
398
|
-
reason:
|
|
402
|
+
reason: entry ? "strategy_automatic_only" : unavailableReason
|
|
399
403
|
});
|
|
400
404
|
}
|
|
401
405
|
}
|
|
@@ -403,12 +407,7 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
403
407
|
const hubPerceptions = activeWorkspace ? listAgentWorkspacePerceptionSources(workspaceDir, profile, activeWorkspace) : [];
|
|
404
408
|
if (activeWorkspace) {
|
|
405
409
|
for (const source of hubPerceptions) {
|
|
406
|
-
const item = activeWorkspace.items.perception.find((candidate) =>
|
|
407
|
-
workspaceDir,
|
|
408
|
-
profile,
|
|
409
|
-
activeWorkspace,
|
|
410
|
-
candidate.runtimeEntryPath
|
|
411
|
-
) === source.sourcePath);
|
|
410
|
+
const item = activeWorkspace.items.perception.find((candidate) => candidate.resourceId === source.resourceId);
|
|
412
411
|
const workingPath = item ? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item) : void 0;
|
|
413
412
|
if (!item || !workingPath) continue;
|
|
414
413
|
registerDiscoveredCapability(workspaceDir, profile, {
|
|
@@ -449,19 +448,19 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
449
448
|
});
|
|
450
449
|
}
|
|
451
450
|
if (activeWorkspace) {
|
|
452
|
-
const
|
|
451
|
+
const discoveredResources = new Set(hubPerceptions.map((source) => source.resourceId));
|
|
453
452
|
for (const item of activeWorkspace.items.perception) {
|
|
454
453
|
if (!item.runtimeEntryPath) {
|
|
455
454
|
capabilityWarnings.push(missingProjectionWarning("perception", item));
|
|
456
455
|
continue;
|
|
457
456
|
}
|
|
457
|
+
if (discoveredResources.has(item.resourceId)) continue;
|
|
458
458
|
const path = resolveLocalAgentWorkspacePath(
|
|
459
459
|
workspaceDir,
|
|
460
460
|
profile,
|
|
461
461
|
activeWorkspace,
|
|
462
462
|
item.runtimeEntryPath
|
|
463
463
|
);
|
|
464
|
-
if (discoveredPaths.has(resolve(path))) continue;
|
|
465
464
|
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
466
465
|
"perception",
|
|
467
466
|
"hub",
|
|
@@ -507,13 +506,15 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
507
506
|
behavior_name: binding.name,
|
|
508
507
|
message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.`
|
|
509
508
|
});
|
|
509
|
+
const target = behaviors.find((entry) => entry.id === id);
|
|
510
|
+
const available = !!target && target.activation_mode !== "automatic_only";
|
|
510
511
|
return {
|
|
511
512
|
perception_id: source.id,
|
|
512
513
|
binding: key,
|
|
513
514
|
behavior_id: id ?? binding.name,
|
|
514
|
-
available
|
|
515
|
-
default_enabled:
|
|
516
|
-
...
|
|
515
|
+
available,
|
|
516
|
+
default_enabled: available,
|
|
517
|
+
...available ? {} : { reason: target ? "strategy_automatic_only" : "behavior_not_loaded" }
|
|
517
518
|
};
|
|
518
519
|
}));
|
|
519
520
|
const perceptionEntry = (source) => ({
|
|
@@ -798,6 +799,7 @@ function createPrepareCommand(dependencies = {}) {
|
|
|
798
799
|
name: localized.name,
|
|
799
800
|
description: source.description,
|
|
800
801
|
source: entry.source,
|
|
802
|
+
activation_mode: entry.activation_mode,
|
|
801
803
|
strategy_type: strategyLifecycle(source.sourcePath),
|
|
802
804
|
...source.trigger ? { reflex: { available: true } } : source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {},
|
|
803
805
|
...source.management.versionNumber ? {
|
|
@@ -18,6 +18,27 @@ import {
|
|
|
18
18
|
function currentSnapshot(workspaceDir, profile, snapshot) {
|
|
19
19
|
return snapshot ?? readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
|
|
20
20
|
}
|
|
21
|
+
function existingFilePath(path) {
|
|
22
|
+
try {
|
|
23
|
+
return realpathSync.native(path);
|
|
24
|
+
} catch {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function matchHubProjections(workspaceDir, profile, snapshot, items, sources) {
|
|
29
|
+
const itemsByPath = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
if (!item.runtimeEntryPath) continue;
|
|
32
|
+
const projection = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.runtimeEntryPath);
|
|
33
|
+
const path = existingFilePath(projection);
|
|
34
|
+
if (path !== void 0) itemsByPath.set(path, item);
|
|
35
|
+
}
|
|
36
|
+
return sources.flatMap((source) => {
|
|
37
|
+
const path = existingFilePath(source.sourcePath);
|
|
38
|
+
const item = path === void 0 ? void 0 : itemsByPath.get(path);
|
|
39
|
+
return item ? [{ source, item }] : [];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
21
42
|
function assertUniqueBehaviorIds(sources, origin) {
|
|
22
43
|
const ids = /* @__PURE__ */ new Set();
|
|
23
44
|
for (const source of sources) {
|
|
@@ -32,17 +53,14 @@ function listAgentWorkspaceBehaviorSources(workspaceDir, profile, snapshot) {
|
|
|
32
53
|
if (!active || active.items.strategy.length === 0) return [];
|
|
33
54
|
const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), "runtime", "behaviors");
|
|
34
55
|
if (!existsSync(root)) return [];
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)), item]] : [])
|
|
56
|
+
const projections = matchHubProjections(
|
|
57
|
+
workspaceDir,
|
|
58
|
+
profile,
|
|
59
|
+
active,
|
|
60
|
+
active.items.strategy,
|
|
61
|
+
listClawclawBehaviorSources(root)
|
|
42
62
|
);
|
|
43
|
-
const sources =
|
|
44
|
-
const item = itemByPath.get(realpathSync(source.sourcePath));
|
|
45
|
-
if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
|
|
63
|
+
const sources = projections.map(({ source, item }) => {
|
|
46
64
|
const trusted = item.sourceFiles[0] && item.resolution !== "local_modified" && item.resolution !== "concurrent_difference" && item.resolution !== "local_origin_unrecognized";
|
|
47
65
|
const managed = {
|
|
48
66
|
...source,
|
|
@@ -98,10 +116,14 @@ function listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot) {
|
|
|
98
116
|
const active = currentSnapshot(workspaceDir, profile, snapshot);
|
|
99
117
|
if (!active || active.items.perception.length === 0) return [];
|
|
100
118
|
const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), "runtime", "perceptions");
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
119
|
+
const projections = matchHubProjections(
|
|
120
|
+
workspaceDir,
|
|
121
|
+
profile,
|
|
122
|
+
active,
|
|
123
|
+
active.items.perception,
|
|
124
|
+
listClawclawPerceptionSourcesInDirectory(root)
|
|
125
|
+
);
|
|
126
|
+
const namedSources = projections.map(({ source, item }) => {
|
|
105
127
|
const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item) ?? join(
|
|
106
128
|
getUserDataAccountCapabilitiesDir(workspaceDir, profile),
|
|
107
129
|
"perceptions",
|
|
@@ -128,7 +150,7 @@ function listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot) {
|
|
|
128
150
|
baseSha256: item.sourceFiles[0]?.sha256
|
|
129
151
|
}
|
|
130
152
|
});
|
|
131
|
-
return perceptionOperationName({ ...source, workingCopyPath }, entry);
|
|
153
|
+
return perceptionOperationName({ ...source, workingCopyPath, resourceId: item.resourceId }, entry);
|
|
132
154
|
});
|
|
133
155
|
const ids = /* @__PURE__ */ new Set();
|
|
134
156
|
for (const source of namedSources) {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
existsSync,
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readFileSync,
|
|
7
|
+
realpathSync,
|
|
7
8
|
writeFileSync
|
|
8
9
|
} from "fs";
|
|
9
10
|
import { createHash } from "crypto";
|
|
@@ -43,7 +44,8 @@ function getUserDataMemoryFile(workspaceDir, profile) {
|
|
|
43
44
|
return join(getUserDataAccountDir(workspaceDir, profile), "memory.md");
|
|
44
45
|
}
|
|
45
46
|
function getUserDataAgentWorkspaceDir(workspaceDir, profile) {
|
|
46
|
-
|
|
47
|
+
const directory = join(getUserDataAccountDir(workspaceDir, profile), "hub-loadout");
|
|
48
|
+
return existsSync(directory) ? realpathSync(directory) : directory;
|
|
47
49
|
}
|
|
48
50
|
function getUserDataAgentWorkspaceCurrentFile(workspaceDir, profile) {
|
|
49
51
|
return join(getUserDataAgentWorkspaceDir(workspaceDir, profile), "current.json");
|
|
@@ -69,6 +69,8 @@ class DeferredMeetingShortStrategy {
|
|
|
69
69
|
async start(request) {
|
|
70
70
|
const rejection = startRejection(this.runtime, request);
|
|
71
71
|
if (rejection) return rejection;
|
|
72
|
+
const error = this.behavior.startError(request.behavior);
|
|
73
|
+
if (error) return { ok: false, type: "behavior_start", error };
|
|
72
74
|
if (request.layer !== "short") return startOwnerBehavior(this.runtime, this.behavior, request);
|
|
73
75
|
const version = ++this.requestVersion;
|
|
74
76
|
const inMeeting = () => this.runtime.readState().state?.phase === "meeting";
|
|
@@ -89,8 +91,8 @@ class DeferredMeetingShortStrategy {
|
|
|
89
91
|
if (!display) return { ok: false, type: "behavior_start", error: "behavior_not_found" };
|
|
90
92
|
this.pending = { request: structuredClone(request), requestId: randomUUID(), display, starting: false };
|
|
91
93
|
return { ok: true, type: "behavior_start", status: "queued", pending: this.status() };
|
|
92
|
-
} catch (
|
|
93
|
-
return { ok: false, type: "behavior_start", error:
|
|
94
|
+
} catch (error2) {
|
|
95
|
+
return { ok: false, type: "behavior_start", error: error2 instanceof Error ? error2.message : String(error2) };
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
status(behaviorId) {
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { normalizePerceptionModuleManifest } from "./perception-module-manifest.js";
|
|
2
|
+
function strategyActivationMode(source) {
|
|
3
|
+
return source.trigger || source.triggerError ? "automatic_only" : "standard";
|
|
4
|
+
}
|
|
5
|
+
function strategyActivationError(source, request) {
|
|
6
|
+
if (source.triggerError) return source.triggerError;
|
|
7
|
+
if (!source.trigger) return void 0;
|
|
8
|
+
if (request?.source === "perception" && Object.keys(source.trigger.manifest.behaviors ?? {}).some(
|
|
9
|
+
(key) => request.triggerId === `perception:${strategyPerceptionId(source.id)}:${key}`
|
|
10
|
+
)) return void 0;
|
|
11
|
+
return "strategy_automatic_only";
|
|
12
|
+
}
|
|
13
|
+
function strategyPerceptionId(strategyId) {
|
|
14
|
+
return "strategy:" + strategyId;
|
|
15
|
+
}
|
|
2
16
|
function normalizeStrategyPerception(value, strategyId) {
|
|
3
17
|
const manifest = normalizePerceptionModuleManifest(value);
|
|
4
18
|
const bindings = Object.values(manifest.behaviors ?? {});
|
|
@@ -10,7 +24,7 @@ function normalizeStrategyPerception(value, strategyId) {
|
|
|
10
24
|
function strategyTriggerSource(source) {
|
|
11
25
|
if (!source.trigger) return void 0;
|
|
12
26
|
const { manifest, sha256 } = source.trigger;
|
|
13
|
-
const id =
|
|
27
|
+
const id = strategyPerceptionId(source.id);
|
|
14
28
|
const name = manifest.name ?? manifest.id;
|
|
15
29
|
const behaviors = Object.fromEntries(Object.entries(manifest.behaviors).map(([key, binding]) => [key, { ...binding, name: source.id }]));
|
|
16
30
|
return {
|
|
@@ -34,5 +48,7 @@ function strategyTriggerSource(source) {
|
|
|
34
48
|
}
|
|
35
49
|
export {
|
|
36
50
|
normalizeStrategyPerception,
|
|
51
|
+
strategyActivationError,
|
|
52
|
+
strategyActivationMode,
|
|
37
53
|
strategyTriggerSource
|
|
38
54
|
};
|
|
@@ -177,13 +177,18 @@ const EVENTS_QUERY_BARRIER_TIMEOUT_MS = 1e4;
|
|
|
177
177
|
const LOCAL_STOP_FORCE_EXIT_MS = 1e4;
|
|
178
178
|
function roleFallbackBehaviors(config, catalog, warning = () => {
|
|
179
179
|
}) {
|
|
180
|
-
const
|
|
180
|
+
const entries = new Map(catalog.list().map((entry) => [entry.id, entry]));
|
|
181
181
|
const result = {};
|
|
182
182
|
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
183
183
|
const behaviorId = config.fallback_behaviors[role];
|
|
184
184
|
if (behaviorId === null) continue;
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
const entry = entries.get(behaviorId);
|
|
186
|
+
if (!entry?.loadable || entry.activationMode === "automatic_only") {
|
|
187
|
+
warning("behavior_fallback_unavailable", {
|
|
188
|
+
role,
|
|
189
|
+
behavior_id: behaviorId,
|
|
190
|
+
...entry?.activationMode === "automatic_only" ? { reason: "strategy_automatic_only" } : {}
|
|
191
|
+
});
|
|
187
192
|
continue;
|
|
188
193
|
}
|
|
189
194
|
result[role] = { behaviorId, input: {} };
|
|
@@ -1116,6 +1121,9 @@ async function runClawclawOwner(options) {
|
|
|
1116
1121
|
return { ok: false, type: "behavior_fallback", error: "stale_runtime_scope" };
|
|
1117
1122
|
}
|
|
1118
1123
|
const latest = readGameplayConfig(workspaceDir, options.profile);
|
|
1124
|
+
const selected = latest.fallback_behaviors[role];
|
|
1125
|
+
const error = request.action === "set" && selected && behaviorCatalog.activationError(selected);
|
|
1126
|
+
if (error) return { ok: false, type: "behavior_fallback", error };
|
|
1119
1127
|
const currentRole = readyRoleForScope(runtime, expected);
|
|
1120
1128
|
if (currentRole === role) {
|
|
1121
1129
|
await assembly.behavior.noteAgentActivity();
|
|
@@ -1129,7 +1137,7 @@ async function runClawclawOwner(options) {
|
|
|
1129
1137
|
ok: true,
|
|
1130
1138
|
type: "behavior_fallback",
|
|
1131
1139
|
role,
|
|
1132
|
-
fallback:
|
|
1140
|
+
fallback: selected
|
|
1133
1141
|
};
|
|
1134
1142
|
}
|
|
1135
1143
|
if (request.type === "behavior_idle") {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "./behavior-source.js";
|
|
9
9
|
import { prepareBehaviorInWorker } from "./thread-behavior-executor.js";
|
|
10
10
|
import { deepFreezeBehaviorValue } from "./behavior-manifest.js";
|
|
11
|
+
import { strategyActivationError, strategyActivationMode } from "../../behavior-trigger.js";
|
|
11
12
|
import { normalizeBehaviorInput } from "../../behavior-input-fields.js";
|
|
12
13
|
function catalogEntry(source) {
|
|
13
14
|
const apiError = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION ? void 0 : pluginApiVersionDiagnostic(
|
|
@@ -32,6 +33,7 @@ function catalogEntry(source) {
|
|
|
32
33
|
...source.produces === void 0 ? {} : { produces: source.produces },
|
|
33
34
|
...source.runtime === void 0 ? {} : { runtime: source.runtime },
|
|
34
35
|
...source.provenance === void 0 ? {} : { provenance: source.provenance },
|
|
36
|
+
activationMode: strategyActivationMode(source),
|
|
35
37
|
loadable: compatibilityError === void 0,
|
|
36
38
|
...compatibilityError === void 0 ? {} : { compatibilityError }
|
|
37
39
|
});
|
|
@@ -53,6 +55,10 @@ class ClawclawBehaviorCatalog {
|
|
|
53
55
|
has(id) {
|
|
54
56
|
return this.sources.has(id);
|
|
55
57
|
}
|
|
58
|
+
activationError(id, request) {
|
|
59
|
+
const source = this.sources.get(id);
|
|
60
|
+
return source && strategyActivationError(source, request);
|
|
61
|
+
}
|
|
56
62
|
load(id) {
|
|
57
63
|
const source = this.sources.get(id);
|
|
58
64
|
if (!source) return Promise.reject(new Error(`Unknown behavior module '${id}'.`));
|
|
@@ -42,7 +42,14 @@ function sdkFrame(frame) {
|
|
|
42
42
|
function preparedValue(prepared) {
|
|
43
43
|
return { ...prepared.value, ...prepared.module ? { module: prepared.module } : {} };
|
|
44
44
|
}
|
|
45
|
-
function createAdapter(deferredDisplay, useAdaptiveWorkers) {
|
|
45
|
+
function createAdapter(deferredDisplay, useAdaptiveWorkers, assertStartAllowed) {
|
|
46
|
+
const checkDelegation = (decision) => {
|
|
47
|
+
if (decision.delegate) {
|
|
48
|
+
const target = decision.delegate;
|
|
49
|
+
assertStartAllowed("strategy" in target ? target.strategy : target.behavior);
|
|
50
|
+
}
|
|
51
|
+
return decision;
|
|
52
|
+
};
|
|
46
53
|
const observations = new ClawclawBehaviorObservationMemory();
|
|
47
54
|
return {
|
|
48
55
|
input: (input, parameters, continuation, history) => {
|
|
@@ -104,8 +111,8 @@ function createAdapter(deferredDisplay, useAdaptiveWorkers) {
|
|
|
104
111
|
prepare: () => runner.prepare(),
|
|
105
112
|
stop: (reason) => runner.stop(reason),
|
|
106
113
|
diagnosticSnapshot: () => runner.diagnosticSnapshot(),
|
|
107
|
-
decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation),
|
|
108
|
-
decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation)
|
|
114
|
+
decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation).then(checkDelegation),
|
|
115
|
+
decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation).then(checkDelegation)
|
|
109
116
|
};
|
|
110
117
|
},
|
|
111
118
|
action: (action, epoch, safety, generation, tick) => ({ ...normalizeClawclawBehaviorAction(action, epoch, safety, generation, tick) }),
|
|
@@ -127,14 +134,23 @@ function createAdapter(deferredDisplay, useAdaptiveWorkers) {
|
|
|
127
134
|
}
|
|
128
135
|
class ClawclawBehaviorPlugin extends StrategyHost {
|
|
129
136
|
deferredShort;
|
|
137
|
+
catalogAccess;
|
|
138
|
+
assertStartAllowed;
|
|
130
139
|
constructor(options) {
|
|
140
|
+
const assertStartAllowed = (id) => {
|
|
141
|
+
const error = options.catalog.activationError?.(id);
|
|
142
|
+
if (error) throw new Error(error);
|
|
143
|
+
};
|
|
144
|
+
for (const binding of Object.values(options.fallbackBehaviors ?? {})) {
|
|
145
|
+
if (binding) assertStartAllowed(binding.behaviorId);
|
|
146
|
+
}
|
|
131
147
|
const deferredShort = {};
|
|
132
148
|
super({
|
|
133
149
|
...options,
|
|
134
150
|
id: CLAWCLAW_BEHAVIOR_PLUGIN_ID,
|
|
135
151
|
stateTopic: CLAWCLAW_BEHAVIOR_STATE_TOPIC,
|
|
136
152
|
actionCapability: CLAWCLAW_ACTION_CAPABILITY,
|
|
137
|
-
adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation),
|
|
153
|
+
adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation, assertStartAllowed),
|
|
138
154
|
captureActions: resolveDetailCapture().actions,
|
|
139
155
|
catalog: { has: (id) => options.catalog.has(id), prepare: async (id, input) => {
|
|
140
156
|
const prepared = await options.catalog.prepare(id, input);
|
|
@@ -146,6 +162,35 @@ class ClawclawBehaviorPlugin extends StrategyHost {
|
|
|
146
162
|
after: options.after ?? [CLAWCLAW_ACTION_PLUGIN_ID, CLAWCLAW_GAME_QUERY_PLUGIN_ID, CLAWCLAW_PERCEPTION_PLUGIN_ID, CLAWCLAW_TRIGGER_PLUGIN_ID]
|
|
147
163
|
});
|
|
148
164
|
this.deferredShort = deferredShort;
|
|
165
|
+
this.catalogAccess = options.catalog;
|
|
166
|
+
this.assertStartAllowed = assertStartAllowed;
|
|
167
|
+
}
|
|
168
|
+
startError(id) {
|
|
169
|
+
return this.catalogAccess.activationError?.(id);
|
|
170
|
+
}
|
|
171
|
+
async startLong(id, input, options) {
|
|
172
|
+
this.assertStartAllowed(id);
|
|
173
|
+
return super.startLong(id, input, options);
|
|
174
|
+
}
|
|
175
|
+
async startShort(id, input, options) {
|
|
176
|
+
this.assertStartAllowed(id);
|
|
177
|
+
return super.startShort(id, input, options);
|
|
178
|
+
}
|
|
179
|
+
async bindFallback(id, input) {
|
|
180
|
+
this.assertStartAllowed(id);
|
|
181
|
+
return super.bindFallback(id, input);
|
|
182
|
+
}
|
|
183
|
+
async configureFallbackBehaviors(bindings, currentRole) {
|
|
184
|
+
for (const binding of Object.values(bindings)) {
|
|
185
|
+
if (binding) this.assertStartAllowed(binding.behaviorId);
|
|
186
|
+
}
|
|
187
|
+
return super.configureFallbackBehaviors(bindings, currentRole);
|
|
188
|
+
}
|
|
189
|
+
async requestReflex(request, guard) {
|
|
190
|
+
if (this.catalogAccess.activationError?.(request.behavior, request)) {
|
|
191
|
+
return { accepted: false, reason: "activation_ineligible" };
|
|
192
|
+
}
|
|
193
|
+
return super.requestReflex(request, guard);
|
|
149
194
|
}
|
|
150
195
|
attachDeferredShortControl(control) {
|
|
151
196
|
this.deferredShort.control = control;
|
|
@@ -3,6 +3,7 @@ import { prepareNotificationContent, notificationStateAt } from "./notification-
|
|
|
3
3
|
import { preparePerceptionNotification } from "./report-content.js";
|
|
4
4
|
import { isNotificationTurn } from "../../notification-turn.js";
|
|
5
5
|
import { normalizeBehaviorInput } from "../../behavior-input-fields.js";
|
|
6
|
+
import { resolveReactionBehavior } from "../../reaction-behavior-resolution.js";
|
|
6
7
|
import { clawclawComputationGameState, isClawclawRuntimeState } from "../../runtime-state.js";
|
|
7
8
|
import { projectTaskChoiceEventPayload } from "../../task-choice-projection.js";
|
|
8
9
|
import { PerceptionModuleRunner } from "./perception-module-runner.js";
|
|
@@ -15,7 +16,7 @@ import { REACTION_HOST_EVENT_TYPES } from "@myclaw163/game-agent-runtime/percept
|
|
|
15
16
|
function sourceValue(source) {
|
|
16
17
|
return source.value;
|
|
17
18
|
}
|
|
18
|
-
function createAdapter(options) {
|
|
19
|
+
function createAdapter(options, blockedBindings) {
|
|
19
20
|
function prepare(input, previous, context) {
|
|
20
21
|
const checkpoint = structuredClone(previous ?? { modules: {} });
|
|
21
22
|
const oldBoundary = checkpoint.gameId ? {
|
|
@@ -94,6 +95,14 @@ function createAdapter(options) {
|
|
|
94
95
|
const { input, game, frame, facts, eventStates, boundary, common } = prepared.value;
|
|
95
96
|
const events = facts.filter((event) => source.module.consumes?.includes(event.type));
|
|
96
97
|
const comparison = comparePerceptionTasks(baseline, input, boundary);
|
|
98
|
+
const blocked = blockedBindings.get(source.id);
|
|
99
|
+
if (blocked) {
|
|
100
|
+
bindings = {
|
|
101
|
+
...bindings,
|
|
102
|
+
availableBindings: bindings.availableBindings.filter((key) => !blocked.has(key)),
|
|
103
|
+
enabledBindings: bindings.enabledBindings.filter((key) => !blocked.has(key))
|
|
104
|
+
};
|
|
105
|
+
}
|
|
97
106
|
const embedded = sourceValue(source).embedded;
|
|
98
107
|
const declaredTargets = embedded && bindings.availableBindings.length ? Object.values(embedded.declaredManifest.behaviors ?? {}).map((binding) => binding.name) : [];
|
|
99
108
|
const moduleInput = {
|
|
@@ -126,14 +135,30 @@ function createAdapter(options) {
|
|
|
126
135
|
};
|
|
127
136
|
}
|
|
128
137
|
class ClawclawPerceptionModulePlugin extends PerceptionHost {
|
|
138
|
+
blockedBindings;
|
|
129
139
|
constructor(options) {
|
|
140
|
+
const blockedBindings = /* @__PURE__ */ new Map();
|
|
141
|
+
const candidates = options.behaviors?.() ?? [];
|
|
142
|
+
const automatic = new Set(candidates.filter((entry) => entry.activationMode === "automatic_only").map((entry) => entry.id));
|
|
143
|
+
for (const source of options.sources) {
|
|
144
|
+
if (source.embedded) continue;
|
|
145
|
+
const blocked = Object.entries(source.module?.behaviors ?? {}).filter(([, binding]) => {
|
|
146
|
+
const id = resolveReactionBehavior(binding, candidates);
|
|
147
|
+
return id !== void 0 && automatic.has(id);
|
|
148
|
+
}).map(([key]) => key);
|
|
149
|
+
if (blocked.length) blockedBindings.set(source.id, new Set(blocked));
|
|
150
|
+
}
|
|
130
151
|
super({
|
|
131
152
|
id: CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID,
|
|
132
153
|
after: options.after,
|
|
133
154
|
behaviors: options.behaviors,
|
|
134
|
-
adapter: createAdapter(options),
|
|
155
|
+
adapter: createAdapter(options, blockedBindings),
|
|
135
156
|
sources: options.sources.filter((source) => source.module).map((source) => ({ id: source.id, name: source.name, module: source.module, value: source }))
|
|
136
157
|
});
|
|
158
|
+
this.blockedBindings = blockedBindings;
|
|
159
|
+
}
|
|
160
|
+
bindings(id) {
|
|
161
|
+
return super.bindings(id).map((binding) => this.blockedBindings.get(binding.perception_id)?.has(binding.binding) ? { ...binding, enabled: false, available: false, reason: "strategy_automatic_only" } : binding);
|
|
137
162
|
}
|
|
138
163
|
localizedModuleDescriptors(locale) {
|
|
139
164
|
const descriptors = super.localizedModuleDescriptors(locale);
|
|
@@ -75,7 +75,7 @@ flowchart LR
|
|
|
75
75
|
| `short` | 暂时完成一件有限工作 |
|
|
76
76
|
| `reflex` | 策略内置 Trigger 条件命中后请求优先执行即时反应 |
|
|
77
77
|
|
|
78
|
-
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long
|
|
78
|
+
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。角色默认策略从普通策略中选择。具体启动、暂停恢复与会议边界见[策略教程](./behavior.md#长期短期和反射)。
|
|
79
79
|
|
|
80
80
|
## 一个模块文件由什么组成
|
|
81
81
|
|
|
@@ -406,7 +406,7 @@ interface StrategyDelegation {
|
|
|
406
406
|
}
|
|
407
407
|
```
|
|
408
408
|
|
|
409
|
-
|
|
409
|
+
当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short/reflex 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
|
|
410
410
|
|
|
411
411
|
#### `StrategyFinish`
|
|
412
412
|
|
|
@@ -494,7 +494,7 @@ interface StrategyNormalizationApi {
|
|
|
494
494
|
|
|
495
495
|
## 策略内置触发感知
|
|
496
496
|
|
|
497
|
-
|
|
497
|
+
策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
498
498
|
|
|
499
499
|
`evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
|
|
500
500
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## 长期、短期和反射
|
|
13
13
|
|
|
14
|
-
所有策略都继承 `ClawclawStrategy
|
|
14
|
+
所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
|
|
15
15
|
|
|
16
16
|
| 运行方式 | 代码值 | 用途 | 启动入口 |
|
|
17
17
|
|---|---|---|---|
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
|
|
25
|
+
|
|
26
|
+
`ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
|
|
25
27
|
|
|
26
28
|
`long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
|
|
27
29
|
|
|
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
103
|
|
|
102
104
|
## 单文件反射与局中控制
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
107
|
|
|
106
108
|
```ts
|
|
107
109
|
import {
|
|
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
|
|
|
181
183
|
|
|
182
184
|
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
183
185
|
|
|
184
|
-
`strategy update`
|
|
186
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
185
187
|
|
|
186
188
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
187
189
|
|
|
@@ -35,7 +35,7 @@ CCL 内置玩家、任务、能力、紧急任务、房间与流程、会议、
|
|
|
35
35
|
| 短期策略 | `--layer short` | 前往指定地点、完成一次追踪或处理当前任务 |
|
|
36
36
|
| 反射策略 | 策略内置 Trigger 请求 | 条件命中后优先撤离或处理即时情况 |
|
|
37
37
|
|
|
38
|
-
三种方式都使用 `ClawclawStrategy`,优先级是 `reflex > short > long
|
|
38
|
+
三种方式都使用 `ClawclawStrategy`,优先级是 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。启用表示模块可供使用,启动才表示开始执行。
|
|
39
39
|
|
|
40
40
|
## 开发前须知
|
|
41
41
|
|
|
@@ -365,7 +365,7 @@ interface StrategyDelegation {
|
|
|
365
365
|
}
|
|
366
366
|
```
|
|
367
367
|
|
|
368
|
-
|
|
368
|
+
当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过策略 Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
|
|
369
369
|
|
|
370
370
|
#### `StrategyFinish`
|
|
371
371
|
|
|
@@ -646,7 +646,7 @@ import type {
|
|
|
646
646
|
|
|
647
647
|
## 策略内置触发感知
|
|
648
648
|
|
|
649
|
-
|
|
649
|
+
策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
650
650
|
|
|
651
651
|
`evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
|
|
652
652
|
|