@myclaw163/clawclaw-cli 0.10.15 → 0.10.17
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/cli-runtime/cli.js +16 -1
- package/cli-runtime/commands/runtime.js +35 -0
- package/cli-runtime/lib/account-resource-lock.js +15 -0
- package/cli-runtime/lib/agent-workspace-skills.js +3 -1
- package/cli-runtime/lib/desktop-mode.js +3 -0
- package/cli-runtime/lib/harness-context.js +20 -0
- package/cli-runtime/lib/init-command.js +2 -1
- package/cli-runtime/lib/lobby-host-context.js +1 -2
- package/cli-runtime/lib/skill-host.js +2 -0
- package/cli-runtime/lib/user-data.js +4 -2
- package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +27 -36
- package/cli-runtime/runtime/clawclaw/behavior-trigger.js +25 -46
- package/cli-runtime/runtime/clawclaw/owner-lock.js +2 -1
- package/cli-runtime/runtime/clawclaw/owner.js +7 -6
- package/cli-runtime/runtime/clawclaw/plugins/assembly.js +8 -7
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +6 -5
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +5 -2
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +2 -1
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +7 -1
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +7 -17
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +3 -30
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +0 -2
- package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +58 -1
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +46 -25
- package/docs/configuration.md +6 -0
- package/docs/custom-modules/README.md +1 -2
- package/docs/custom-modules/api-reference.md +8 -10
- package/docs/custom-modules/behavior.md +21 -23
- package/docs/custom-modules/examples/auto-escape.ts +17 -19
- package/docs/custom-modules/perception.md +2 -2
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/behavior-runtime.md +4 -5
- package/docs/runtime/components-and-boundaries.md +4 -5
- package/docs/runtime/events-and-state.md +1 -1
- package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/api-reference.md +8 -10
- package/docs/user-guide/behavior.md +21 -23
- package/docs/user-guide/perception.md +2 -2
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -3
- package/skills/clawclaw/references/BEHAVIORS.md +1 -1
- package/skills/clawclaw-creator/SKILL.md +1 -1
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +21 -23
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +8 -10
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -2
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +2 -2
- package/src/cli.ts +12 -1
- package/src/commands/runtime.ts +26 -0
- package/src/lib/account-resource-lock.ts +14 -0
- package/src/lib/agent-workspace-skills.ts +3 -2
- package/src/lib/desktop-mode.ts +4 -0
- package/src/lib/harness-context.ts +21 -0
- package/src/lib/init-command.ts +2 -1
- package/src/lib/lobby-host-context.ts +2 -2
- package/src/lib/skill-host.ts +2 -0
- package/src/lib/user-data.ts +5 -2
- package/src/runtime/clawclaw/behavior-reflex-control.ts +26 -22
- package/src/runtime/clawclaw/behavior-trigger.ts +20 -41
- package/src/runtime/clawclaw/owner-lock.ts +2 -1
- package/src/runtime/clawclaw/owner.ts +7 -6
- package/src/runtime/clawclaw/plugins/assembly.ts +11 -8
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +7 -6
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +6 -2
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +2 -1
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +1 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +8 -19
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +4 -37
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +0 -2
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
3
|
import { isDeepStrictEqual } from "node:util";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import {
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
importRuntimeModule,
|
|
12
12
|
runtimeModuleThreadLoaderConfig
|
|
13
13
|
} from "../../../framework/modules/runtime-module-loader.js";
|
|
14
|
-
import { normalizeStrategyTriggerManifest } from "../../behavior-trigger.js";
|
|
15
14
|
import { assertPluginApiVersion } from "../plugin-api-version.js";
|
|
16
15
|
function normalizedManifest(value) {
|
|
17
16
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
@@ -50,22 +49,17 @@ function normalizedManifest(value) {
|
|
|
50
49
|
return structuredClone({ ...manifest, inputs });
|
|
51
50
|
}
|
|
52
51
|
function validateClawclawTriggerModule(loaded, source) {
|
|
53
|
-
const entry =
|
|
52
|
+
const entry = "default";
|
|
54
53
|
if (typeof loaded[entry] !== "function") {
|
|
55
|
-
throw new Error(`Trigger module '${source.id}' has no
|
|
54
|
+
throw new Error(`Trigger module '${source.id}' has no default class.`);
|
|
56
55
|
}
|
|
57
56
|
const ModuleClass = loaded[entry];
|
|
58
|
-
const manifest =
|
|
59
|
-
if (!isDeepStrictEqual(manifest, source.
|
|
57
|
+
const manifest = normalizedManifest(ModuleClass.manifest);
|
|
58
|
+
if (!isDeepStrictEqual(manifest, source.manifest)) {
|
|
60
59
|
throw new Error(`Trigger module '${source.id}' changed after static discovery.`);
|
|
61
60
|
}
|
|
62
61
|
return ModuleClass;
|
|
63
62
|
}
|
|
64
|
-
function assertTriggerSourceDigest(source) {
|
|
65
|
-
if (source.embedded && createHash("sha256").update(readFileSync(source.sourcePath)).digest("hex") !== source.embedded.sha256) {
|
|
66
|
-
throw new Error("strategy_trigger_source_changed");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
63
|
class TriggerModuleLoader {
|
|
70
64
|
runtimeId = randomUUID();
|
|
71
65
|
loaded = /* @__PURE__ */ new Map();
|
|
@@ -92,10 +86,7 @@ class TriggerModuleLoader {
|
|
|
92
86
|
}
|
|
93
87
|
let pending = this.loaded.get(source.id);
|
|
94
88
|
if (pending) return pending;
|
|
95
|
-
pending =
|
|
96
|
-
assertTriggerSourceDigest(source);
|
|
97
|
-
return importRuntimeModule(new URL(this.sourceUrl(source)));
|
|
98
|
-
}).then((loaded) => validateClawclawTriggerModule(loaded, source));
|
|
89
|
+
pending = importRuntimeModule(new URL(this.sourceUrl(source))).then((loaded) => validateClawclawTriggerModule(loaded, source));
|
|
99
90
|
this.loaded.set(source.id, pending);
|
|
100
91
|
return pending;
|
|
101
92
|
}
|
|
@@ -110,6 +101,5 @@ class TriggerModuleLoader {
|
|
|
110
101
|
}
|
|
111
102
|
export {
|
|
112
103
|
TriggerModuleLoader,
|
|
113
|
-
assertTriggerSourceDigest,
|
|
114
104
|
validateClawclawTriggerModule
|
|
115
105
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isDeepStrictEqual } from "node:util";
|
|
2
1
|
import { isNotificationTurn } from "../../notification-turn.js";
|
|
3
2
|
import {
|
|
4
3
|
MAX_TRIGGER_RUNTIME_MS,
|
|
@@ -51,8 +50,7 @@ function normalizeRegistration(value) {
|
|
|
51
50
|
const { source } = value;
|
|
52
51
|
const manifest = source.manifest;
|
|
53
52
|
if (!source || source.id !== manifest.id) throw new Error("trigger_source_identity_invalid");
|
|
54
|
-
const input =
|
|
55
|
-
const waitingForInput = !!source.embedded && manifest.inputs.some((field) => field.required && !Object.hasOwn(input, field.id));
|
|
53
|
+
const input = value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs) : Object.freeze(structuredClone(value.input ?? {}));
|
|
56
54
|
const behavior = value.behavior ?? manifest.defaultBehavior;
|
|
57
55
|
const behaviorInput = {
|
|
58
56
|
...structuredClone(manifest.defaultBehaviorInput),
|
|
@@ -74,7 +72,6 @@ function normalizeRegistration(value) {
|
|
|
74
72
|
return Object.freeze({
|
|
75
73
|
source,
|
|
76
74
|
enabled: value.enabled,
|
|
77
|
-
waitingForInput,
|
|
78
75
|
scope: value.scope,
|
|
79
76
|
input,
|
|
80
77
|
behavior,
|
|
@@ -145,7 +142,6 @@ class ClawclawTriggerPlugin {
|
|
|
145
142
|
timeoutMs = DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS;
|
|
146
143
|
failurePolicy = "failed_completion";
|
|
147
144
|
registrations;
|
|
148
|
-
embeddedDefaults;
|
|
149
145
|
pendingActivations = /* @__PURE__ */ new Map();
|
|
150
146
|
invalidInputs = /* @__PURE__ */ new Map();
|
|
151
147
|
loader;
|
|
@@ -165,7 +161,7 @@ class ClawclawTriggerPlugin {
|
|
|
165
161
|
configGeneration = 1;
|
|
166
162
|
currentScope;
|
|
167
163
|
isEnabled(config) {
|
|
168
|
-
return config.enabled &&
|
|
164
|
+
return config.enabled && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId && config.scope.segmentId === this.currentScope?.segmentId);
|
|
169
165
|
}
|
|
170
166
|
started = false;
|
|
171
167
|
lastFrameSeq = 0;
|
|
@@ -176,7 +172,6 @@ class ClawclawTriggerPlugin {
|
|
|
176
172
|
this.memory = options.memory ?? new ClawclawStrategyMemory();
|
|
177
173
|
this.after = [...options.after ?? []];
|
|
178
174
|
this.registrations = normalizeRegistrations(options.triggers ?? []);
|
|
179
|
-
this.embeddedDefaults = new Map([...this.registrations].filter(([, config]) => config.source.embedded));
|
|
180
175
|
this.loader = options.loader ?? new TriggerModuleLoader();
|
|
181
176
|
this.driver = options.driver;
|
|
182
177
|
this.threaded = options.threaded ?? options.loader === void 0;
|
|
@@ -192,25 +187,6 @@ class ClawclawTriggerPlugin {
|
|
|
192
187
|
}
|
|
193
188
|
configure(triggers) {
|
|
194
189
|
const next = normalizeRegistrations(triggers);
|
|
195
|
-
for (const [id, config] of this.registrations) if (config.source.embedded) next.set(id, config);
|
|
196
|
-
this.replaceRegistrations(next);
|
|
197
|
-
}
|
|
198
|
-
configureEmbedded(behaviorId, patch) {
|
|
199
|
-
const id = "behavior:" + behaviorId;
|
|
200
|
-
const config = this.registrations.get(id);
|
|
201
|
-
if (!config?.source.embedded) return;
|
|
202
|
-
const updated = normalizeRegistration({
|
|
203
|
-
source: config.source,
|
|
204
|
-
enabled: patch.enabled ?? config.enabled,
|
|
205
|
-
input: patch.input ?? config.input
|
|
206
|
-
});
|
|
207
|
-
if (isDeepStrictEqual(config, updated)) return;
|
|
208
|
-
const next = new Map(this.registrations);
|
|
209
|
-
next.set(id, updated);
|
|
210
|
-
this.replaceRegistrations(next);
|
|
211
|
-
}
|
|
212
|
-
/** Replace effective config and invalidate computations from the previous generation. */
|
|
213
|
-
replaceRegistrations(next) {
|
|
214
190
|
for (const [id, config] of next) {
|
|
215
191
|
if (config.enabled && !this.registrations.get(id)?.enabled) {
|
|
216
192
|
const state = this.states.get(id);
|
|
@@ -237,8 +213,6 @@ class ClawclawTriggerPlugin {
|
|
|
237
213
|
return [...this.registrations.values()].map((entry) => Object.freeze({
|
|
238
214
|
id: entry.source.id,
|
|
239
215
|
enabled: this.isEnabled(entry),
|
|
240
|
-
waitingForInput: entry.waitingForInput,
|
|
241
|
-
embedded: !!entry.source.embedded,
|
|
242
216
|
armed: this.states.get(entry.source.id)?.armed ?? true,
|
|
243
217
|
cooldownRemainingMs: Math.max(0, entry.cooldownMs - (Date.now() - (this.states.get(entry.source.id)?.lastAcceptedAtMs ?? 0))),
|
|
244
218
|
behavior: entry.behavior,
|
|
@@ -652,7 +626,6 @@ class ClawclawTriggerPlugin {
|
|
|
652
626
|
this.states.clear();
|
|
653
627
|
this.pendingActivations.clear();
|
|
654
628
|
this.invalidInputs.clear();
|
|
655
|
-
for (const [id, config] of this.embeddedDefaults) this.registrations.set(id, config);
|
|
656
629
|
this.observationMemory.clear();
|
|
657
630
|
this.clearFrameBoundary();
|
|
658
631
|
this.threadPool = void 0;
|
|
@@ -662,7 +635,7 @@ class ClawclawTriggerPlugin {
|
|
|
662
635
|
this.loader.stop();
|
|
663
636
|
}
|
|
664
637
|
memoryNamespace(source) {
|
|
665
|
-
return
|
|
638
|
+
return "trigger:" + source.id;
|
|
666
639
|
}
|
|
667
640
|
async ensureThreadPool(context) {
|
|
668
641
|
if (!this.started || this.threadPool || this.threadPoolFailed) return;
|
|
@@ -3,7 +3,6 @@ import { createBehaviorReadApi } from "../../behavior-read-api.js";
|
|
|
3
3
|
import { ClawclawBehaviorObservationMemory } from "../../behavior-observation-memory.js";
|
|
4
4
|
import { assertRuntimeModuleOutputSize } from "../../../framework/modules/runtime-module-output.js";
|
|
5
5
|
import {
|
|
6
|
-
assertTriggerSourceDigest,
|
|
7
6
|
validateClawclawTriggerModule
|
|
8
7
|
} from "./trigger-module-loader.js";
|
|
9
8
|
import { StrategyMemoryRpcClient } from "../../strategy-memory-rpc.js";
|
|
@@ -38,7 +37,6 @@ const modules = /* @__PURE__ */ new Map();
|
|
|
38
37
|
const observationMemories = /* @__PURE__ */ new Map();
|
|
39
38
|
try {
|
|
40
39
|
for (const spec of data.modules) {
|
|
41
|
-
assertTriggerSourceDigest(spec.source);
|
|
42
40
|
const loaded = await import(spec.sourceUrl);
|
|
43
41
|
const ModuleClass = validateClawclawTriggerModule(loaded, spec.source);
|
|
44
42
|
classes.set(spec.triggerId, ModuleClass);
|
|
@@ -10,7 +10,6 @@ import { createBehaviorReadApi } from '../../behavior-read-api.js';
|
|
|
10
10
|
import { ClawclawBehaviorObservationMemory } from '../../behavior-observation-memory.js';
|
|
11
11
|
import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
|
|
12
12
|
import {
|
|
13
|
-
assertTriggerSourceDigest,
|
|
14
13
|
validateClawclawTriggerModule,
|
|
15
14
|
type TriggerThreadModuleSpec,
|
|
16
15
|
} from './trigger-module-loader.js';
|
|
@@ -79,7 +78,6 @@ const modules = new Map<string, ClawclawTrigger>();
|
|
|
79
78
|
const observationMemories = new Map<string, ClawclawBehaviorObservationMemory>();
|
|
80
79
|
try {
|
|
81
80
|
for (const spec of data.modules) {
|
|
82
|
-
assertTriggerSourceDigest(spec.source);
|
|
83
81
|
const loaded = await import(spec.sourceUrl) as Record<string, unknown>;
|
|
84
82
|
const ModuleClass = validateClawclawTriggerModule(loaded, spec.source);
|
|
85
83
|
classes.set(spec.triggerId, ModuleClass);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BEHAVIOR_PLUGIN_API_VERSION
|
|
3
3
|
} from "./chunk-3VLVCU6P.js";
|
|
4
|
-
import "./chunk-CF6IEQ4V.js";
|
|
5
4
|
import {
|
|
6
5
|
__reExport,
|
|
7
6
|
hasValidClawclawResourceLocalizations
|
|
@@ -673,6 +672,54 @@ var CLAWCLAW_VISUAL_EVENT_TYPES = [
|
|
|
673
672
|
"visual.following",
|
|
674
673
|
"visual.following_ended"
|
|
675
674
|
];
|
|
675
|
+
var CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES = [
|
|
676
|
+
"enter_room",
|
|
677
|
+
"move_start",
|
|
678
|
+
"move_end",
|
|
679
|
+
"move_interrupted",
|
|
680
|
+
"move",
|
|
681
|
+
"task_started",
|
|
682
|
+
"task_progress",
|
|
683
|
+
"task_completed",
|
|
684
|
+
"task_interrupted",
|
|
685
|
+
"task_sabotaged",
|
|
686
|
+
"task_assigned",
|
|
687
|
+
"kill",
|
|
688
|
+
"killed",
|
|
689
|
+
"murder_witnessed",
|
|
690
|
+
"body_dropped",
|
|
691
|
+
"warrior_shrimp_self_destruct",
|
|
692
|
+
"meeting_start",
|
|
693
|
+
"meeting_briefing",
|
|
694
|
+
"speech_turn",
|
|
695
|
+
"speech_your_turn",
|
|
696
|
+
"speech_next_turn",
|
|
697
|
+
"speech",
|
|
698
|
+
"speech_skipped",
|
|
699
|
+
"vote_phase_start",
|
|
700
|
+
"vote_cast",
|
|
701
|
+
"vote_speech",
|
|
702
|
+
"vote_speech_phase_ended",
|
|
703
|
+
"exile",
|
|
704
|
+
"no_exile",
|
|
705
|
+
"meeting_ended",
|
|
706
|
+
"meeting_result_pending",
|
|
707
|
+
"exile_game_over",
|
|
708
|
+
"game_started",
|
|
709
|
+
"game_over",
|
|
710
|
+
"role_assigned",
|
|
711
|
+
"emergency_started",
|
|
712
|
+
"emergency_resolved",
|
|
713
|
+
"emergency_interrupted",
|
|
714
|
+
"player_spotted",
|
|
715
|
+
"corpse_spotted",
|
|
716
|
+
"octopus_time_start",
|
|
717
|
+
"octopus_time_win",
|
|
718
|
+
"win_blocked_by_octopus",
|
|
719
|
+
"wandering_speech",
|
|
720
|
+
"death_speech",
|
|
721
|
+
"think"
|
|
722
|
+
];
|
|
676
723
|
var CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
|
|
677
724
|
"service_status",
|
|
678
725
|
"move_interrupted",
|
|
@@ -1146,6 +1193,16 @@ function normalizeClawclawBehaviorManifest(value, options = {}) {
|
|
|
1146
1193
|
});
|
|
1147
1194
|
}
|
|
1148
1195
|
|
|
1196
|
+
// src/runtime/clawclaw/perception-module-manifest.ts
|
|
1197
|
+
var INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
1198
|
+
...CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES,
|
|
1199
|
+
...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES,
|
|
1200
|
+
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter((type) => !/^(behavior|reminder|perception)\./.test(type)),
|
|
1201
|
+
"tasks_changed",
|
|
1202
|
+
"meeting_state"
|
|
1203
|
+
]);
|
|
1204
|
+
var PERCEPTION_OWNED_TYPES = /* @__PURE__ */ new Set([...CLAWCLAW_VISUAL_EVENT_TYPES, "reminder.task", "reminder.speech"]);
|
|
1205
|
+
|
|
1149
1206
|
// src/runtime/clawclaw/plugins/behavior/behavior-source.ts
|
|
1150
1207
|
var MAX_BEHAVIOR_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
1151
1208
|
|
|
@@ -172,8 +172,28 @@ var Action = class _Action {
|
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
174
|
|
|
175
|
+
// src/lib/harness-context.ts
|
|
176
|
+
import { createHash } from "node:crypto";
|
|
177
|
+
import { join } from "node:path";
|
|
178
|
+
function harnessContext(env = process.env) {
|
|
179
|
+
const { CLAWCLAW_HOST_KIND: kind, CLAWCLAW_HOST_INSTANCE_ID: instance, CLAWCLAW_HOST_SESSION_ID: session, CLAWCLAW_AUTH_MODE: auth } = env;
|
|
180
|
+
if (kind === void 0 && auth === void 0) return void 0;
|
|
181
|
+
if (!kind || !/^[a-z][a-z0-9-]{0,63}$/.test(kind) || !instance || !/^[^\s\p{Cc}]{1,128}$/u.test(instance) || session !== void 0 && !/^[^\s\p{Cc}]{1,128}$/u.test(session) || auth !== void 0 && auth !== "managed" && auth !== "standalone") {
|
|
182
|
+
throw new Error("INVALID_HARNESS_CONTEXT: provide a valid kind, persistent instance ID and optional session/auth mode.");
|
|
183
|
+
}
|
|
184
|
+
return { kind, instance, session, auth };
|
|
185
|
+
}
|
|
186
|
+
function stateRoot(workspace) {
|
|
187
|
+
const context = harnessContext();
|
|
188
|
+
if (!context) return workspace;
|
|
189
|
+
const id = createHash("sha256").update(JSON.stringify([context.kind, context.instance])).digest("hex");
|
|
190
|
+
return join(workspace, "contexts", id);
|
|
191
|
+
}
|
|
192
|
+
|
|
175
193
|
// src/lib/desktop-mode.ts
|
|
176
194
|
function isDesktopMode(env = process.env) {
|
|
195
|
+
const mode = harnessContext(env)?.auth;
|
|
196
|
+
if (mode) return mode === "managed";
|
|
177
197
|
return env.CLAWCLAW_IS_DESKTOP === "true";
|
|
178
198
|
}
|
|
179
199
|
var DESKTOP_LOGIN_MESSAGE = "\u8BF7\u5728\u5BA2\u6237\u7AEF\u767B\u5F55\u6E38\u620F\u8D26\u53F7\u3002CCL \u7684\u767B\u5F55\u8D26\u53F7\u7531\u5BA2\u6237\u7AEF\u7BA1\u7406\u3002";
|
|
@@ -184,10 +204,10 @@ function accountRequiredMessage(standaloneMessage) {
|
|
|
184
204
|
// src/lib/auth.ts
|
|
185
205
|
import { chmodSync, existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
186
206
|
import { randomUUID } from "crypto";
|
|
187
|
-
import { join as
|
|
207
|
+
import { join as join4, dirname as dirname2 } from "path";
|
|
188
208
|
|
|
189
209
|
// src/lib/init-command.ts
|
|
190
|
-
import { isAbsolute, join as
|
|
210
|
+
import { isAbsolute, join as join3, resolve, win32 } from "path";
|
|
191
211
|
import { homedir } from "os";
|
|
192
212
|
|
|
193
213
|
// src/lib/user-data.ts
|
|
@@ -198,8 +218,8 @@ import {
|
|
|
198
218
|
readFileSync,
|
|
199
219
|
writeFileSync
|
|
200
220
|
} from "fs";
|
|
201
|
-
import { createHash } from "crypto";
|
|
202
|
-
import { dirname, join } from "path";
|
|
221
|
+
import { createHash as createHash2 } from "crypto";
|
|
222
|
+
import { dirname, join as join2 } from "path";
|
|
203
223
|
var USER_DATA_DIR = "user-data";
|
|
204
224
|
var RUNTIME_DIR = "runtime";
|
|
205
225
|
var EMPTY_RESULT = () => ({
|
|
@@ -208,37 +228,37 @@ var EMPTY_RESULT = () => ({
|
|
|
208
228
|
skippedExisting: []
|
|
209
229
|
});
|
|
210
230
|
function getUserDataDir(workspaceDir) {
|
|
211
|
-
return
|
|
231
|
+
return join2(workspaceDir, USER_DATA_DIR);
|
|
212
232
|
}
|
|
213
233
|
function getRuntimeDir(workspaceDir) {
|
|
214
|
-
return
|
|
234
|
+
return join2(stateRoot(workspaceDir), RUNTIME_DIR);
|
|
215
235
|
}
|
|
216
236
|
function getUserDataAuthFile(workspaceDir) {
|
|
217
|
-
return
|
|
237
|
+
return join2(getUserDataDir(stateRoot(workspaceDir)), "auth.json");
|
|
218
238
|
}
|
|
219
239
|
function getRuntimeAuthStateFile(workspaceDir) {
|
|
220
|
-
return
|
|
240
|
+
return join2(getRuntimeDir(workspaceDir), "auth-state.json");
|
|
221
241
|
}
|
|
222
242
|
function getUserDataAccountsDir(workspaceDir) {
|
|
223
|
-
return
|
|
243
|
+
return join2(getUserDataDir(workspaceDir), "accounts");
|
|
224
244
|
}
|
|
225
245
|
function getUserDataAccountHash(apiKey) {
|
|
226
|
-
return
|
|
246
|
+
return createHash2("sha256").update(apiKey).digest("hex").slice(0, 16);
|
|
227
247
|
}
|
|
228
248
|
function getUserDataAccountDir(workspaceDir, profile) {
|
|
229
|
-
return
|
|
249
|
+
return join2(getUserDataAccountsDir(workspaceDir), getUserDataAccountHash(profile.apiKey));
|
|
230
250
|
}
|
|
231
251
|
function getUserDataBehaviorsDir(workspaceDir) {
|
|
232
|
-
return
|
|
252
|
+
return join2(getUserDataDir(workspaceDir), "behaviors");
|
|
233
253
|
}
|
|
234
254
|
function getUserDataPerceptionsDir(workspaceDir) {
|
|
235
|
-
return
|
|
255
|
+
return join2(getUserDataDir(workspaceDir), "perceptions");
|
|
236
256
|
}
|
|
237
257
|
function getUserDataTriggersDir(workspaceDir) {
|
|
238
|
-
return
|
|
258
|
+
return join2(getUserDataDir(workspaceDir), "triggers");
|
|
239
259
|
}
|
|
240
260
|
function getUserDataHubDir(workspaceDir) {
|
|
241
|
-
return
|
|
261
|
+
return join2(getUserDataDir(workspaceDir), "hub");
|
|
242
262
|
}
|
|
243
263
|
function ensureDir(path) {
|
|
244
264
|
mkdirSync(path, { recursive: true });
|
|
@@ -311,7 +331,7 @@ function mergeRuntimeAuthState(path, incoming, result) {
|
|
|
311
331
|
}
|
|
312
332
|
}
|
|
313
333
|
function migrateAuth(workspaceDir, result) {
|
|
314
|
-
const legacyAuthFile =
|
|
334
|
+
const legacyAuthFile = join2(workspaceDir, ".auth.json");
|
|
315
335
|
const authFile = getUserDataAuthFile(workspaceDir);
|
|
316
336
|
const runtimeFile = getRuntimeAuthStateFile(workspaceDir);
|
|
317
337
|
const source = existsSync(authFile) ? readJson(authFile) : readJson(legacyAuthFile);
|
|
@@ -330,11 +350,11 @@ function migrateAuth(workspaceDir, result) {
|
|
|
330
350
|
function migrateAccountFiles(workspaceDir, auth, result) {
|
|
331
351
|
if (!auth) return;
|
|
332
352
|
for (const profile of Object.values(auth.profiles ?? {})) {
|
|
333
|
-
const legacyDir =
|
|
353
|
+
const legacyDir = join2(workspaceDir, "accounts", profile.apiKey);
|
|
334
354
|
const newDir = getUserDataAccountDir(workspaceDir, profile);
|
|
335
355
|
for (const fileName of ["persona.md", "memory.md"]) {
|
|
336
|
-
const from =
|
|
337
|
-
const to =
|
|
356
|
+
const from = join2(legacyDir, fileName);
|
|
357
|
+
const to = join2(newDir, fileName);
|
|
338
358
|
if (!existsSync(from)) continue;
|
|
339
359
|
if (existsSync(to)) {
|
|
340
360
|
result.skippedExisting.push(`user-data/accounts/${getUserDataAccountHash(profile.apiKey)}/${fileName}`);
|
|
@@ -348,7 +368,7 @@ function migrateAccountFiles(workspaceDir, auth, result) {
|
|
|
348
368
|
}
|
|
349
369
|
function writeMigrationMarker(workspaceDir, result) {
|
|
350
370
|
if (result.copied.length === 0 && result.skipped.length === 0 && result.skippedExisting.length === 0) return;
|
|
351
|
-
const marker =
|
|
371
|
+
const marker = join2(getUserDataDir(workspaceDir), ".migration.json");
|
|
352
372
|
if (existsSync(marker)) return;
|
|
353
373
|
writeJson(marker, {
|
|
354
374
|
from: "legacy-workspace-layout",
|
|
@@ -367,6 +387,7 @@ function ensureUserDataLayout(workspaceDir) {
|
|
|
367
387
|
ensureDir(getUserDataTriggersDir(workspaceDir));
|
|
368
388
|
ensureDir(getUserDataHubDir(workspaceDir));
|
|
369
389
|
ensureDir(getRuntimeDir(workspaceDir));
|
|
390
|
+
if (harnessContext()) return result;
|
|
370
391
|
const auth = migrateAuth(workspaceDir, result);
|
|
371
392
|
migrateAccountFiles(workspaceDir, auth, result);
|
|
372
393
|
writeMigrationMarker(workspaceDir, result);
|
|
@@ -383,7 +404,7 @@ function resolveWorkspaceDir({
|
|
|
383
404
|
cwd = process.cwd()
|
|
384
405
|
} = {}) {
|
|
385
406
|
const rawWorkspaceDir = env[CLAWCLAW_WORKSPACE_DIR];
|
|
386
|
-
const pathApi = platform === "win32" ? win32 : { isAbsolute, join:
|
|
407
|
+
const pathApi = platform === "win32" ? win32 : { isAbsolute, join: join3, resolve };
|
|
387
408
|
if (typeof rawWorkspaceDir === "string") {
|
|
388
409
|
const trimmedWorkspaceDir = rawWorkspaceDir.trim();
|
|
389
410
|
if (trimmedWorkspaceDir !== "") {
|
|
@@ -394,13 +415,13 @@ function resolveWorkspaceDir({
|
|
|
394
415
|
const appData = env.APPDATA ?? win32.join(homeDir, "AppData", "Roaming");
|
|
395
416
|
return win32.join(appData, "clawclaw");
|
|
396
417
|
}
|
|
397
|
-
return
|
|
418
|
+
return join3(homeDir, ".clawclaw");
|
|
398
419
|
}
|
|
399
420
|
function getWorkspaceDir() {
|
|
400
421
|
return resolveWorkspaceDir();
|
|
401
422
|
}
|
|
402
423
|
function getWorkspaceConfigFile(workspaceDir = getWorkspaceDir()) {
|
|
403
|
-
return
|
|
424
|
+
return join3(workspaceDir, WORKSPACE_CONFIG_FILE);
|
|
404
425
|
}
|
|
405
426
|
|
|
406
427
|
// src/lib/workspace-runtime-lock.ts
|
|
@@ -440,7 +461,7 @@ var AuthStore = class {
|
|
|
440
461
|
constructor(authFile, runtimeAuthStateFile) {
|
|
441
462
|
if (authFile) {
|
|
442
463
|
this.authFile = authFile;
|
|
443
|
-
this.runtimeAuthStateFile = runtimeAuthStateFile ??
|
|
464
|
+
this.runtimeAuthStateFile = runtimeAuthStateFile ?? join4(dirname2(authFile), "auth-state.json");
|
|
444
465
|
return;
|
|
445
466
|
}
|
|
446
467
|
const workspaceDir = getWorkspaceDir();
|
|
@@ -2531,7 +2552,7 @@ function validateLobbyHostContext(value) {
|
|
|
2531
2552
|
function resolveLobbyHostContext(env = process.env) {
|
|
2532
2553
|
const instanceId = env.CLAWCLAW_HOST_INSTANCE_ID;
|
|
2533
2554
|
const sessionId = env.CLAWCLAW_HOST_SESSION_ID;
|
|
2534
|
-
if (
|
|
2555
|
+
if (env.CLAWCLAW_IS_DESKTOP === "true") {
|
|
2535
2556
|
if (!validId(instanceId) || !validId(sessionId)) {
|
|
2536
2557
|
throw new InvalidHostContextError("Desktop must provide CLAWCLAW_HOST_INSTANCE_ID and CLAWCLAW_HOST_SESSION_ID (1\u2013128 characters, no whitespace/control characters).");
|
|
2537
2558
|
}
|
package/docs/configuration.md
CHANGED
|
@@ -297,3 +297,9 @@ deliveryClass 决定是否对 Agent 可见,wakeAgent 决定是否允许主动
|
|
|
297
297
|
本地感知入口放在 `<workspace>/user-data/accounts/<account-hash>/capabilities/perceptions/`,默认导出一个 `ClawclawPerception` 子类;其静态 manifest 声明模块 ID、主体范围和可生成 Event type。安装模块、选择模块和选择 Event 投递方式是三个独立动作。完整输入、输出、切片生命周期与安全限制见 [开发 Perception](./custom-modules/perception.md)。
|
|
298
298
|
|
|
299
299
|
开局延迟可用 `cli.business_start` 区分模块加载和命令执行。`start match` 的 `http.queue.join.sent` 记录 HTTP 请求头实际发送,`http.queue.join.headers` 记录响应头到达。Owner 计时还包括进程身份、系统锁和 Runtime 启动。诊断宿主传入的 `launch_id` 可用于连接两份 JSONL。
|
|
300
|
+
|
|
301
|
+
## Harness 客户端上下文(协议 v1)
|
|
302
|
+
|
|
303
|
+
客户端使用终端安装的 `ccl`,继承相同的 workspace。每次调用传入 `CLAWCLAW_HOST_KIND`(例如 `dsh-client`)与持久化的 `CLAWCLAW_HOST_INSTANCE_ID`。开局、加房和恢复时传入发起会话的 `CLAWCLAW_HOST_SESSION_ID`。认证方式 `CLAWCLAW_AUTH_MODE` 可选 `managed` 或 `standalone`。DSH 的托管登录继续用 stdin,Lobby 的 Desktop 标记与实例、会话字段遵循客户端托管协议。
|
|
304
|
+
|
|
305
|
+
`ccl runtime info --json` 可在未登录时读取协议版本、CCL 版本、实际 Node 和 CLI 入口、内置 Skill、workspace 与本实例运行目录。同一账号共享 `user-data/accounts` 的技能、策略与记忆。实例凭据、Owner 锁、日志和控制端点位于 `contexts/<实例哈希>`;终端使用原有位置。客户端切号不修改终端 Skill 链接。
|
|
@@ -61,8 +61,7 @@ flowchart LR
|
|
|
61
61
|
Input["当前 State / 可见观察 / 源与后端原始事实"] --> Perception["统一感知 API v3"]
|
|
62
62
|
Perception --> Events["提交自己的事件"]
|
|
63
63
|
Events --> Mailbox["Mailbox / Agent"]
|
|
64
|
-
|
|
65
|
-
Trigger -->|"请求所属策略"| Strategy["策略执行类"]
|
|
64
|
+
Perception -->|"请求所属策略"| Strategy["策略执行类"]
|
|
66
65
|
Strategy --> Runtime["Runtime 检查并提交动作"]
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -95,16 +95,16 @@ const maySelect = candidates[0] && isTaskAvailable(input.gameState, candidates[0
|
|
|
95
95
|
|
|
96
96
|
从公开 perception-plugin 入口导入 ClawclawPerception、PerceptionModuleInput、PerceptionModuleResult、PerceptionModuleEvent 和 PerceptionModuleManifest;版本常量为 PERCEPTION_MODULE_API_VERSION=3。新脚本没有三选一的 kind,通过同一个 evaluate(input, api) 组合观察、通知和私有记忆。
|
|
97
97
|
|
|
98
|
-
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、lifecycle、source、roomState、queueState、eventStates、nowMs、cycle、config、state。frame/gameState 可以为 null;events 只含订阅的源/后端原始事实,taskChanges 由该模块自己的基线与本轮权威任务列表比较得到,结合同轮后端事实;不是订阅 tasks_changed。 内置任务感知及 evaluateReminder('tasks') 只把后端 task_* 事实转为基础任务通知,不按 taskChanges 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
98
|
+
Manifest 的必需项为 apiVersion:3、id、description;可选 name、localizations、consumes、produces、inputs、config、strategies。输入包含 moduleId、scope、gameState、frame、events、taskChanges、boundary、lifecycle、source、roomState、queueState、eventStates、nowMs、cycle、config、state。frame/gameState 可以为 null;events 只含订阅的源/后端原始事实,taskChanges 由该模块自己的基线与本轮权威任务列表比较得到,结合同轮后端事实;不是订阅 tasks_changed。 内置任务感知及 evaluateReminder('tasks') 只把后端 task_* 事实转为基础任务通知,不按 taskChanges 再输出同一信息;紧急生命周期和阈值由内置紧急感知负责。
|
|
99
99
|
|
|
100
100
|
阶段变化不清空 state。`enteredPhase` / `leftPhase` 匹配本轮实际阶段转换,`hasPerceptionBoundary` 检查 initial、recovery 等边界;`resetPerceptionState(state, patch)` 纯函数式替换指定字段,原状态与 api.memory 不受影响。恢复不伪造阶段转换。API 还提供只读 `api.spatial`。事件可带 `occurredAt` 保留观察发生时间;`forwards` 只能由宿主授予转发权限的原生模块使用。
|
|
101
101
|
|
|
102
|
-
结果为 { state?, events? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
102
|
+
结果为 { state?, events?, activations? }。events 项为 { type, key, wakeAgent?, occurredAt?, payload },type 必须在 produces 中声明,key 是稳定发生标识,wakeAgent 省略为 true。false 不独立唤醒且保留事件;不生成事件表示没有这条通知。事件类型的可见范围仍受 Catalog 和配置约束,模块不能重写原始事件或其他模块的通知。
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
每次计算使用 fresh 实例,跨回调状态必须从 input.state 读取并作为结果 state 返回,由 Host 检查点恢复。新脚本不能订阅其他感知、Strategy 或 decision 输出;运行时还按 producerPluginId 过滤,只接纳 Source/后端原始事实。produces 不能冒充系统保留类型;reminder.task/reminder.speech 是兼容通知输出,不是权威任务事实。
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
策略文件中的具名触发感知通过 activations 请求同文件策略的 Reflex。
|
|
108
108
|
|
|
109
109
|
## Strategy API
|
|
110
110
|
|
|
@@ -492,15 +492,13 @@ interface StrategyNormalizationApi {
|
|
|
492
492
|
|
|
493
493
|
这里没有动态 `GameState` 或 Action 能力;动态判断放在 `decide()` 中。
|
|
494
494
|
|
|
495
|
-
##
|
|
495
|
+
## 策略内置触发感知
|
|
496
496
|
|
|
497
|
-
|
|
497
|
+
CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
498
498
|
|
|
499
|
-
|
|
500
|
-
evaluate(input: Readonly<TriggerInput>, api: TriggerReadApi): TriggerMatch | void | Promise<TriggerMatch | void>
|
|
501
|
-
```
|
|
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` 绑定,激活参数覆盖策略默认值。
|
|
502
500
|
|
|
503
|
-
|
|
501
|
+
跨帧判断保存在返回的 `state` 中。触发感知与执行类需要共享的局内记录使用 `api.memory`。例如触发感知按尸体 ID 查询,执行类接手后记录,避免一次未获准的请求占用现场。
|
|
504
502
|
|
|
505
503
|
## 共享数据结构
|
|
506
504
|
|
|
@@ -697,7 +695,7 @@ import type {
|
|
|
697
695
|
|
|
698
696
|
### api.memory:局内持续记忆
|
|
699
697
|
|
|
700
|
-
StrategyReadApi
|
|
698
|
+
StrategyReadApi 和 PerceptionModuleApi 均提供以下接口。
|
|
701
699
|
|
|
702
700
|
```ts
|
|
703
701
|
type StrategyMemoryValue = null | boolean | number | string
|
|
@@ -101,7 +101,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
101
|
|
|
102
102
|
## 单文件反射与局中控制
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
107
|
import {
|
|
@@ -109,13 +109,12 @@ import {
|
|
|
109
109
|
} from '@myclaw163/clawclaw-cli/strategy-plugin';
|
|
110
110
|
|
|
111
111
|
import {
|
|
112
|
-
|
|
113
|
-
} from '@myclaw163/clawclaw-cli/
|
|
112
|
+
ClawclawPerception, type PerceptionModuleInput, type PerceptionModuleResult,
|
|
113
|
+
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
114
114
|
|
|
115
115
|
type Parameters = {
|
|
116
116
|
readonly x: number;
|
|
117
117
|
readonly y: number;
|
|
118
|
-
readonly triggerDistance: number;
|
|
119
118
|
};
|
|
120
119
|
|
|
121
120
|
/** The strategy executes when it is granted control. */
|
|
@@ -126,9 +125,8 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
126
125
|
description: '有人进入设定范围时,前往 Agent 指定的撤离点。靠近不等于对方有敌意。',
|
|
127
126
|
execution: 'serial',
|
|
128
127
|
inputs: [
|
|
129
|
-
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。',
|
|
130
|
-
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。',
|
|
131
|
-
{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 },
|
|
128
|
+
{ id: 'x', type: 'number', description: '当前地图上可达的撤离点 X。', default: 2708 },
|
|
129
|
+
{ id: 'y', type: 'number', description: '当前地图上可达的撤离点 Y。', default: 2320 },
|
|
132
130
|
],
|
|
133
131
|
runtime: { defaultMs: 10000 },
|
|
134
132
|
} as const satisfies ClawclawStrategyManifest;
|
|
@@ -152,22 +150,22 @@ export default class AutoEscape extends ClawclawStrategy<Parameters> {
|
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
152
|
|
|
155
|
-
export class Trigger extends
|
|
153
|
+
export class Trigger extends ClawclawPerception {
|
|
156
154
|
static readonly manifest = {
|
|
157
|
-
apiVersion:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
} as const
|
|
163
|
-
|
|
164
|
-
evaluate(input: Readonly<
|
|
165
|
-
const players = input.frame
|
|
155
|
+
apiVersion: 3,
|
|
156
|
+
id: 'community.nearby',
|
|
157
|
+
description: '有玩家靠近时请求本策略撤离。',
|
|
158
|
+
inputs: [{ id: 'triggerDistance', type: 'number', description: '触发距离(像素)。', default: 160, min: 1, max: 1000 }],
|
|
159
|
+
strategies: { escape: { name: 'community.auto-escape', reflexPriority: 40, cooldownMs: 3000, rearm: 'after_clear', maxRuntimeMs: 10000 } },
|
|
160
|
+
} as const;
|
|
161
|
+
|
|
162
|
+
evaluate(input: Readonly<PerceptionModuleInput>): PerceptionModuleResult {
|
|
163
|
+
const players = input.frame?.observation.players ?? [];
|
|
166
164
|
const self = players.find(player => player.observer);
|
|
167
|
-
if (!self) return;
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
if (!self) return {};
|
|
166
|
+
const distance = Number(input.config.triggerDistance);
|
|
167
|
+
const nearby = players.some(player => !player.observer && Math.hypot(player.x - self.x, player.y - self.y) <= distance);
|
|
168
|
+
return { activations: nearby ? [{ strategy: 'escape', reason: 'player_nearby' }] : [] };
|
|
171
169
|
}
|
|
172
170
|
}
|
|
173
171
|
```
|
|
@@ -181,9 +179,9 @@ ccl strategy status community.auto-escape
|
|
|
181
179
|
ccl strategy unwatch community.auto-escape
|
|
182
180
|
```
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
185
183
|
|
|
186
|
-
`strategy update`
|
|
184
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
187
185
|
|
|
188
186
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
189
187
|
|