@myclaw163/clawclaw-cli 0.10.6 → 0.10.8

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.
Files changed (68) hide show
  1. package/dist/strategy-worker/assets/clawclaw-spatial-facts.json +1383 -0
  2. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-3VLVCU6P.js +71 -0
  3. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-ATQQZA4X.js +44 -0
  4. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-CF6IEQ4V.js +12 -0
  5. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-JMX6D6A3.js +260 -0
  6. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-QEPKDSLE.js +278 -0
  7. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-ZQILO6OM.js +0 -0
  8. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/clawclaw-walkable.bin +0 -0
  9. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +1389 -0
  10. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-behavior-plugin.js +22 -0
  11. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-module-input.js +0 -0
  12. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-perception-plugin.js +72 -0
  13. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +3108 -0
  14. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-strategy-plugin.js +25 -0
  15. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-trigger-plugin.js +16 -0
  16. package/docs/custom-modules/api-reference.md +10 -8
  17. package/docs/custom-modules/perception.md +26 -3
  18. package/docs/desktop-event-push.md +2 -1
  19. package/docs/runtime/behavior-runtime.md +3 -1
  20. package/docs/runtime/official-perception-modules.md +2 -2
  21. package/docs/user-guide/behavior.md +3 -1
  22. package/docs/user-guide/desktop-auth.md +33 -1
  23. package/package.json +5 -3
  24. package/scripts/build-strategy-worker.mjs +28 -0
  25. package/scripts/migrate-official-perceptions.mjs +157 -0
  26. package/skills/clawclaw/SKILL.md +3 -3
  27. package/skills/clawclaw/references/BEHAVIORS.md +2 -0
  28. package/skills/clawclaw/references/TACTICS.md +4 -0
  29. package/skills/clawclaw-creator/SKILL.md +3 -1
  30. package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +10 -8
  31. package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +26 -3
  32. package/skills/clawclaw-creator/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
  33. package/src/commands/capability.ts +4 -2
  34. package/src/commands/load.ts +5 -2
  35. package/src/lib/agent-workspace-skills.ts +12 -7
  36. package/src/lib/capability-cloud-sync.ts +13 -7
  37. package/src/lib/capability-discovery.ts +10 -3
  38. package/src/lib/capability-selection.ts +7 -0
  39. package/src/lib/game-client.ts +33 -6
  40. package/src/lib/lobby-host-context.ts +74 -0
  41. package/src/lib/package-skills.ts +11 -1
  42. package/src/lib/participation-status.ts +5 -0
  43. package/src/pipeline/event-format.ts +2 -0
  44. package/src/pipeline/event-hints.ts +1 -0
  45. package/src/runtime/clawclaw/behavior-start-control.ts +114 -0
  46. package/src/runtime/clawclaw/notification-policy.ts +1 -0
  47. package/src/runtime/clawclaw/owner.ts +21 -4
  48. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +1 -0
  49. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +11 -6
  50. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +48 -1
  51. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +2 -0
  52. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +28 -6
  53. package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +25 -3
  54. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +1 -1
  55. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +9 -0
  56. package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +3 -0
  57. package/src/runtime/clawclaw/plugins/perception/module-input-boundary.ts +64 -0
  58. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +37 -49
  59. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +3 -1
  60. package/src/runtime/clawclaw/plugins/source/room-transport.ts +46 -9
  61. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +18 -4
  62. package/src/runtime/clawclaw/plugins/source/types.ts +2 -0
  63. package/src/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.ts +2 -0
  64. package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +122 -61
  65. package/src/runtime/clawclaw-event-catalog.ts +1 -0
  66. package/src/sdk/perception-plugin/index.ts +1 -0
  67. package/src/sdk/perception-plugin/lifecycle.ts +15 -0
  68. package/src/sdk/perception-plugin/module.ts +15 -0
@@ -0,0 +1,71 @@
1
+ // src/sdk/behavior-plugin/index.ts
2
+ import { Strategy } from "@myclaw163/game-agent-runtime/sdk/strategy.js";
3
+
4
+ // src/sdk/task-availability.ts
5
+ var label = (value) => value?.trim().normalize("NFC").toLocaleLowerCase() ?? "";
6
+ function getCrabSabotageAvailability(state) {
7
+ const sabotage = state.crab_sabotage;
8
+ if (state.emergency?.active === true || sabotage?.status === "emergency_active") {
9
+ return { state: "blocked", reason: "emergency_active" };
10
+ }
11
+ const remaining = sabotage?.cooldown_remaining_secs;
12
+ if (sabotage?.status === "cooldown_charged" || typeof remaining === "number" && remaining > 0) {
13
+ return {
14
+ state: "cooldown",
15
+ reason: "sabotage_cooldown",
16
+ ...typeof remaining === "number" && Number.isFinite(remaining) && remaining >= 0 ? { remaining_secs: remaining } : {}
17
+ };
18
+ }
19
+ return sabotage?.status === "ready" ? { state: "ready" } : { state: "unknown", reason: "sabotage_state_unavailable" };
20
+ }
21
+ function getTaskKind(state, task) {
22
+ if (task.kind) return task.kind;
23
+ if (task.is_fake_shrimp === true) return "fake_shrimp";
24
+ if (state.emergency?.active === true && label(state.emergency.task_name) === label(task.name)) return "emergency";
25
+ return (state.you?.faction === "crab" || state.you?.role === "crab_generic") && task.is_fake_shrimp === false ? "sabotage" : "ordinary";
26
+ }
27
+ function getTaskAvailability(state, task) {
28
+ const tasks = state.you?.tasks;
29
+ if (!Array.isArray(tasks)) return { state: "unknown", reason: "task_state_unavailable" };
30
+ const requested = typeof task === "string" ? tasks.find((candidate) => label(candidate.name) === label(task) || !!candidate.task_id && label(candidate.task_id) === label(task)) ?? { name: task } : task;
31
+ const current = tasks.find((candidate) => requested.task_id ? candidate.task_id === requested.task_id : label(candidate.name) === label(requested.name) && (!requested.room || label(candidate.room) === label(requested.room)) && (requested.x === void 0 || candidate.x === requested.x) && (requested.y === void 0 || candidate.y === requested.y));
32
+ if (!current) return { state: "blocked", reason: "not_assigned" };
33
+ if (current.status === "completed") return { state: "completed", reason: "task_completed" };
34
+ if (state.you?.is_alive === false) return { state: "blocked", reason: "not_alive" };
35
+ if (state.you?.is_alive !== true || state.phase === void 0) return { state: "unknown", reason: "player_state_unavailable" };
36
+ if (state.phase !== "wandering") return { state: "blocked", reason: "not_wandering" };
37
+ if (current.status === "in_progress" || state.you?.activity?.kind === "task" && label(state.you.activity.task_name) === label(current.name)) {
38
+ return { state: "in_progress", reason: "task_in_progress" };
39
+ }
40
+ if (current.status !== "normal") return { state: "unknown", reason: "task_state_unavailable" };
41
+ const kind = getTaskKind(state, current);
42
+ if (kind === "sabotage") return getCrabSabotageAvailability(state);
43
+ if (kind === "emergency" && (state.emergency?.active !== true || label(state.emergency.task_name) !== label(current.name))) {
44
+ return { state: "blocked", reason: "emergency_inactive" };
45
+ }
46
+ return { state: "ready" };
47
+ }
48
+ function isTaskAvailable(state, task) {
49
+ return getTaskAvailability(state, task).state === "ready";
50
+ }
51
+ function getAvailableTasks(state) {
52
+ return (state.you?.tasks ?? []).filter((task) => isTaskAvailable(state, task));
53
+ }
54
+
55
+ // src/sdk/behavior-plugin/index.ts
56
+ var BEHAVIOR_PLUGIN_API_VERSION = 3;
57
+ var ClawclawBehavior = class extends Strategy {
58
+ static manifest;
59
+ status(value) {
60
+ return { status: value };
61
+ }
62
+ };
63
+
64
+ export {
65
+ getTaskKind,
66
+ getTaskAvailability,
67
+ isTaskAvailable,
68
+ getAvailableTasks,
69
+ BEHAVIOR_PLUGIN_API_VERSION,
70
+ ClawclawBehavior
71
+ };
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+
15
+ // src/sdk/resource-metadata.ts
16
+ function normalizedLocale(value) {
17
+ return value.trim().replaceAll("_", "-").toLowerCase();
18
+ }
19
+ function hasValidClawclawResourceLocalizations(localizations) {
20
+ if (localizations === void 0) return true;
21
+ if (!localizations || typeof localizations !== "object" || Array.isArray(localizations)) return false;
22
+ return Object.entries(localizations).every(([locale, text]) => normalizedLocale(locale).length > 0 && !!text && typeof text === "object" && !Array.isArray(text) && typeof text.name === "string" && text.name.trim().length > 0 && typeof text.description === "string" && text.description.trim().length > 0);
23
+ }
24
+ function resolveClawclawResourceMetadata(metadata, locale) {
25
+ if (metadata.display) return { id: metadata.id, ...metadata.display };
26
+ const requested = normalizedLocale(locale);
27
+ const entries = Object.entries(metadata.localizations ?? {});
28
+ const exact = entries.find(([key]) => normalizedLocale(key) === requested)?.[1];
29
+ const language = requested.split("-")[0];
30
+ const languageMatch = entries.find(([key]) => normalizedLocale(key) === language)?.[1];
31
+ const regionalMatch = entries.find(([key]) => normalizedLocale(key).startsWith(`${language}-`))?.[1];
32
+ const localized = exact ?? languageMatch ?? regionalMatch;
33
+ return {
34
+ id: metadata.id,
35
+ name: localized?.name ?? metadata.name ?? metadata.id,
36
+ description: localized?.description ?? metadata.description
37
+ };
38
+ }
39
+
40
+ export {
41
+ __reExport,
42
+ hasValidClawclawResourceLocalizations,
43
+ resolveClawclawResourceMetadata
44
+ };
@@ -0,0 +1,12 @@
1
+ // src/sdk/trigger-plugin/index.ts
2
+ var TRIGGER_PLUGIN_API_VERSION = 4;
3
+ var MAX_TRIGGER_RUNTIME_MS = 12e4;
4
+ var ClawclawTrigger = class {
5
+ static manifest;
6
+ };
7
+
8
+ export {
9
+ TRIGGER_PLUGIN_API_VERSION,
10
+ MAX_TRIGGER_RUNTIME_MS,
11
+ ClawclawTrigger
12
+ };
@@ -0,0 +1,260 @@
1
+ // src/sdk/perception-plugin/module.ts
2
+ var PERCEPTION_MODULE_API_VERSION = 3;
3
+
4
+ // src/sdk/perception-plugin/index.ts
5
+ import { Perception } from "@myclaw163/game-agent-runtime/sdk/perception.js";
6
+
7
+ // src/sdk/perception-plugin/reaction.ts
8
+ var ClawclawReaction = class {
9
+ static manifest;
10
+ };
11
+
12
+ // src/sdk/perception-plugin/reminder.ts
13
+ var REMINDER_PLUGIN_API_VERSION = 2;
14
+ var ClawclawReminder = class {
15
+ static manifest;
16
+ };
17
+
18
+ // src/sdk/perception-plugin/reminder-rules.ts
19
+ var TASK_LIFECYCLE_FACT_TYPES = [
20
+ "task_started",
21
+ "task_progress",
22
+ "task_assigned",
23
+ "task_completed",
24
+ "task_interrupted",
25
+ "task_sabotaged"
26
+ ];
27
+ var TASK_REMINDER_FACT_TYPES = [
28
+ ...TASK_LIFECYCLE_FACT_TYPES,
29
+ "role_assigned",
30
+ "emergency_started",
31
+ "emergency_resolved",
32
+ "emergency_interrupted",
33
+ "meeting_briefing"
34
+ ];
35
+ var REMINDER_FACT_TYPES = [...TASK_REMINDER_FACT_TYPES, "wandering_speech"];
36
+ function isReminderMode(value) {
37
+ return value === "wake" || value === "silent" || value === "state_only";
38
+ }
39
+ function defaultConfig(topic) {
40
+ if (topic !== "tasks") throw new Error("Unsupported reminder topic; countdown and ability notifications are owned by CCL.");
41
+ return {
42
+ started: "state_only",
43
+ progress: "state_only",
44
+ added: "silent",
45
+ completed: "silent",
46
+ interrupted: "wake",
47
+ sabotaged: "wake",
48
+ removed: "silent",
49
+ updated: "silent"
50
+ };
51
+ }
52
+ function validateDefaultConfig(topic, input) {
53
+ if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Reminder config must be an object.");
54
+ const defaults = defaultConfig(topic);
55
+ for (const key of Object.keys(input)) if (!Object.hasOwn(defaults, key)) throw new Error("Unknown reminder option: " + key);
56
+ const value = { ...defaults, ...input };
57
+ if (!Object.values(value).every(isReminderMode)) throw new Error("Reminder mode must be wake, silent, or state_only.");
58
+ return value;
59
+ }
60
+ var kinds = {
61
+ task_started: "started",
62
+ task_progress: "progress",
63
+ task_assigned: "added",
64
+ task_completed: "completed",
65
+ task_interrupted: "interrupted",
66
+ task_sabotaged: "sabotaged"
67
+ };
68
+ var labels = {
69
+ started: "\u5F00\u59CB\u4EFB\u52A1",
70
+ progress: "\u4EFB\u52A1\u8FDB\u5EA6\u53D8\u5316",
71
+ added: "\u65B0\u589E\u4EFB\u52A1",
72
+ completed: "\u4EFB\u52A1\u5B8C\u6210",
73
+ interrupted: "\u4EFB\u52A1\u4E2D\u65AD",
74
+ sabotaged: "\u7834\u574F\u4EFB\u52A1\u5B8C\u6210",
75
+ removed: "\u4EFB\u52A1\u4E0D\u518D\u51FA\u73B0\u5728\u5217\u8868",
76
+ updated: "\u4EFB\u52A1\u4FE1\u606F\u53D8\u5316"
77
+ };
78
+ function record(value) {
79
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
80
+ }
81
+ function speechReminder(input) {
82
+ if (Object.keys(input.config).some((key) => key !== "receive") || input.config.receive !== void 0 && typeof input.config.receive !== "boolean") {
83
+ throw new Error("Speech reminder config must contain only a boolean receive.");
84
+ }
85
+ if (input.config.receive === false) return { events: [] };
86
+ const self = input.gameState?.you?.player;
87
+ return { events: input.facts.flatMap((fact) => {
88
+ if (fact.type !== "wandering_speech" || fact.replayed) return [];
89
+ const actor = record(fact.payload.actor);
90
+ const seat = actor.seat ?? fact.payload.actor_seat;
91
+ const name = actor.name ?? fact.payload.actor_name;
92
+ const own = seat !== void 0 && self?.seat !== void 0 ? seat === self.seat : typeof name === "string" && self?.name !== void 0 && name === self.name;
93
+ if (own || typeof fact.payload.text !== "string" || !fact.payload.text.trim()) return [];
94
+ return [{
95
+ type: "reminder.speech",
96
+ key: `fact:${fact.eventId}`,
97
+ wakeAgent: true,
98
+ payload: { ...fact.payload, text: fact.payload.text, source_event_id: fact.eventId }
99
+ }];
100
+ }) };
101
+ }
102
+ function defaultReminder(topic, input) {
103
+ if (topic === "speech") return speechReminder(input);
104
+ const config = validateDefaultConfig(topic, input.config);
105
+ const events = [];
106
+ if (input.boundary) return { events };
107
+ const emit = (kind, key, data, eventId) => {
108
+ const mode = config[kind];
109
+ if (mode === "state_only") return;
110
+ const { tasks: _tasks, delta: _delta, newly_assigned_task: _assigned, ...detail } = data;
111
+ const name = String(detail.task_name ?? detail.name ?? "");
112
+ const actor = record(detail.actor);
113
+ const seat = actor.seat ?? detail.actor_seat;
114
+ const who = seat !== void 0 && seat !== input.gameState?.you?.player?.seat ? `${seat}\u53F7\u73A9\u5BB6\uFF1A` : "";
115
+ const room = detail.room ? `\uFF08${String(detail.room)}\uFF09` : "";
116
+ events.push({
117
+ type: "reminder.task",
118
+ key,
119
+ wakeAgent: mode === "wake",
120
+ payload: { ...detail, kind, source_event_id: eventId, text: `${who}${labels[kind]}\uFF1A${name}${room}\u3002` }
121
+ });
122
+ };
123
+ for (const fact of input.facts) {
124
+ const kind = kinds[fact.type];
125
+ if (kind) emit(kind, `fact:${fact.eventId}`, { ...fact.payload }, fact.eventId);
126
+ }
127
+ return { events };
128
+ }
129
+
130
+ // src/sdk/perception-plugin/math.ts
131
+ var TICK_MS = 100;
132
+ var MOVE_MIN_PX = 18;
133
+ var STEP_MOVE_MIN_PX = 4;
134
+ var STILL_STEP_MAX_PX = 3;
135
+ function vector(from, to) {
136
+ return { x: to.x - from.x, y: to.y - from.y };
137
+ }
138
+ function length(value) {
139
+ return Math.hypot(value.x, value.y);
140
+ }
141
+ function distance(a, b) {
142
+ return Math.hypot(a.x - b.x, a.y - b.y);
143
+ }
144
+ function dot(a, b) {
145
+ return a.x * b.x + a.y * b.y;
146
+ }
147
+ function cross(a, b) {
148
+ return a.x * b.y - a.y * b.x;
149
+ }
150
+ function unit(value) {
151
+ const magnitude = length(value);
152
+ return magnitude <= 0 ? { x: 0, y: 0 } : { x: value.x / magnitude, y: value.y / magnitude };
153
+ }
154
+ function cosine(a, b) {
155
+ const denominator = length(a) * length(b);
156
+ return denominator <= 0 ? 0 : dot(a, b) / denominator;
157
+ }
158
+ function angleDegrees(a, b) {
159
+ return Math.acos(Math.max(-1, Math.min(1, cosine(a, b)))) * (180 / Math.PI);
160
+ }
161
+ function direction(from, to, minimum = MOVE_MIN_PX) {
162
+ const dx = to.x - from.x;
163
+ const dy = to.y - from.y;
164
+ if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
165
+ const horizontal = Math.abs(dx) >= minimum / 2 ? dx > 0 ? "\u53F3" : "\u5DE6" : "";
166
+ const vertical = Math.abs(dy) >= minimum / 2 ? dy > 0 ? "\u4E0B" : "\u4E0A" : "";
167
+ return `${horizontal}${vertical}` || "\u539F\u5730";
168
+ }
169
+ function headingDirection(from, to, minimum = MOVE_MIN_PX) {
170
+ const dx = to.x - from.x;
171
+ const dy = to.y - from.y;
172
+ if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
173
+ const octant = Math.round(Math.atan2(dy, dx) / (Math.PI / 4));
174
+ const directions = [
175
+ "\u53F3",
176
+ "\u53F3\u4E0B",
177
+ "\u4E0B",
178
+ "\u5DE6\u4E0B",
179
+ "\u5DE6",
180
+ "\u5DE6\u4E0A",
181
+ "\u4E0A",
182
+ "\u53F3\u4E0A"
183
+ ];
184
+ return directions[(octant + directions.length) % directions.length];
185
+ }
186
+ function actorLabel(actor) {
187
+ if (actor.observer) return "\u4F60";
188
+ if (actor.seat !== void 0) return `${actor.seat}\u53F7`;
189
+ return actor.name ?? actor.id;
190
+ }
191
+ function actorValue(actor) {
192
+ return actor.seat ?? actor.id;
193
+ }
194
+ function timeRange(fromTick, toTick) {
195
+ const format = (tick) => {
196
+ const total = Math.max(0, Math.floor(tick * TICK_MS / 1e3));
197
+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
198
+ };
199
+ const from = format(fromTick);
200
+ const to = format(toTick);
201
+ return from === to ? from : `${from}-${to}`;
202
+ }
203
+ function round1(value) {
204
+ return Math.round(value * 10) / 10;
205
+ }
206
+ function positionCopy(position) {
207
+ return { x: position.x, y: position.y, room: position.room };
208
+ }
209
+
210
+ // src/sdk/perception-plugin/index.ts
211
+ var PERCEPTION_PLUGIN_API_VERSION = 2;
212
+ function evaluateReminder(topic, input) {
213
+ return defaultReminder(topic, "events" in input ? { ...input, facts: input.events } : input);
214
+ }
215
+ var ClawclawPerception = class extends Perception {
216
+ static manifest;
217
+ /** API v3 combines observation, notification and fixed Behavior activation. */
218
+ evaluate(_input, _api) {
219
+ throw new Error("PERCEPTION_EVALUATE_NOT_IMPLEMENTED");
220
+ }
221
+ /** @deprecated API v2 compatibility; new modules implement evaluate(). */
222
+ update(frame, api) {
223
+ throw new Error("PERCEPTION_UPDATE_NOT_IMPLEMENTED");
224
+ }
225
+ };
226
+ var ClawclawParallelPerception = class extends ClawclawPerception {
227
+ update() {
228
+ throw new Error("parallel_perception_uses_analyze_and_commit");
229
+ }
230
+ };
231
+
232
+ export {
233
+ PERCEPTION_MODULE_API_VERSION,
234
+ ClawclawReaction,
235
+ REMINDER_PLUGIN_API_VERSION,
236
+ ClawclawReminder,
237
+ TICK_MS,
238
+ MOVE_MIN_PX,
239
+ STEP_MOVE_MIN_PX,
240
+ STILL_STEP_MAX_PX,
241
+ vector,
242
+ length,
243
+ distance,
244
+ dot,
245
+ cross,
246
+ unit,
247
+ cosine,
248
+ angleDegrees,
249
+ direction,
250
+ headingDirection,
251
+ actorLabel,
252
+ actorValue,
253
+ timeRange,
254
+ round1,
255
+ positionCopy,
256
+ PERCEPTION_PLUGIN_API_VERSION,
257
+ evaluateReminder,
258
+ ClawclawPerception,
259
+ ClawclawParallelPerception
260
+ };
@@ -0,0 +1,278 @@
1
+ // src/sdk/perception-plugin/module.ts
2
+ var PERCEPTION_MODULE_API_VERSION = 3;
3
+
4
+ // src/sdk/perception-plugin/lifecycle.ts
5
+ function hasPerceptionBoundary(input, kind) {
6
+ return input.lifecycle?.some((change) => change.kind === kind) ?? false;
7
+ }
8
+ function enteredPhase(input, phase) {
9
+ return input.lifecycle?.some((change) => change.kind === "phase_changed" && change.to === phase) ?? false;
10
+ }
11
+ function leftPhase(input, phase) {
12
+ return input.lifecycle?.some((change) => change.kind === "phase_changed" && change.from === phase) ?? false;
13
+ }
14
+ function resetPerceptionState(state, replacement) {
15
+ return { ...state, ...replacement };
16
+ }
17
+
18
+ // src/sdk/perception-plugin/index.ts
19
+ import { Perception } from "@myclaw163/game-agent-runtime/sdk/perception.js";
20
+
21
+ // src/sdk/perception-plugin/reaction.ts
22
+ var ClawclawReaction = class {
23
+ static manifest;
24
+ };
25
+
26
+ // src/sdk/perception-plugin/reminder.ts
27
+ var REMINDER_PLUGIN_API_VERSION = 2;
28
+ var ClawclawReminder = class {
29
+ static manifest;
30
+ };
31
+
32
+ // src/sdk/perception-plugin/reminder-rules.ts
33
+ var TASK_LIFECYCLE_FACT_TYPES = [
34
+ "task_started",
35
+ "task_progress",
36
+ "task_assigned",
37
+ "task_completed",
38
+ "task_interrupted",
39
+ "task_sabotaged"
40
+ ];
41
+ var TASK_REMINDER_FACT_TYPES = [
42
+ ...TASK_LIFECYCLE_FACT_TYPES,
43
+ "role_assigned",
44
+ "emergency_started",
45
+ "emergency_resolved",
46
+ "emergency_interrupted",
47
+ "meeting_briefing"
48
+ ];
49
+ var REMINDER_FACT_TYPES = [...TASK_REMINDER_FACT_TYPES, "wandering_speech"];
50
+ function isReminderMode(value) {
51
+ return value === "wake" || value === "silent" || value === "state_only";
52
+ }
53
+ function defaultConfig(topic) {
54
+ if (topic !== "tasks") throw new Error("Unsupported reminder topic; countdown and ability notifications are owned by CCL.");
55
+ return {
56
+ started: "state_only",
57
+ progress: "state_only",
58
+ added: "silent",
59
+ completed: "silent",
60
+ interrupted: "wake",
61
+ sabotaged: "wake",
62
+ removed: "silent",
63
+ updated: "silent"
64
+ };
65
+ }
66
+ function validateDefaultConfig(topic, input) {
67
+ if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Reminder config must be an object.");
68
+ const defaults = defaultConfig(topic);
69
+ for (const key of Object.keys(input)) if (!Object.hasOwn(defaults, key)) throw new Error("Unknown reminder option: " + key);
70
+ const value = { ...defaults, ...input };
71
+ if (!Object.values(value).every(isReminderMode)) throw new Error("Reminder mode must be wake, silent, or state_only.");
72
+ return value;
73
+ }
74
+ var kinds = {
75
+ task_started: "started",
76
+ task_progress: "progress",
77
+ task_assigned: "added",
78
+ task_completed: "completed",
79
+ task_interrupted: "interrupted",
80
+ task_sabotaged: "sabotaged"
81
+ };
82
+ var labels = {
83
+ started: "\u5F00\u59CB\u4EFB\u52A1",
84
+ progress: "\u4EFB\u52A1\u8FDB\u5EA6\u53D8\u5316",
85
+ added: "\u65B0\u589E\u4EFB\u52A1",
86
+ completed: "\u4EFB\u52A1\u5B8C\u6210",
87
+ interrupted: "\u4EFB\u52A1\u4E2D\u65AD",
88
+ sabotaged: "\u7834\u574F\u4EFB\u52A1\u5B8C\u6210",
89
+ removed: "\u4EFB\u52A1\u4E0D\u518D\u51FA\u73B0\u5728\u5217\u8868",
90
+ updated: "\u4EFB\u52A1\u4FE1\u606F\u53D8\u5316"
91
+ };
92
+ function record(value) {
93
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
94
+ }
95
+ function speechReminder(input) {
96
+ if (Object.keys(input.config).some((key) => key !== "receive") || input.config.receive !== void 0 && typeof input.config.receive !== "boolean") {
97
+ throw new Error("Speech reminder config must contain only a boolean receive.");
98
+ }
99
+ if (input.config.receive === false) return { events: [] };
100
+ const self = input.gameState?.you?.player;
101
+ return { events: input.facts.flatMap((fact) => {
102
+ if (fact.type !== "wandering_speech" || fact.replayed) return [];
103
+ const actor = record(fact.payload.actor);
104
+ const seat = actor.seat ?? fact.payload.actor_seat;
105
+ const name = actor.name ?? fact.payload.actor_name;
106
+ const own = seat !== void 0 && self?.seat !== void 0 ? seat === self.seat : typeof name === "string" && self?.name !== void 0 && name === self.name;
107
+ if (own || typeof fact.payload.text !== "string" || !fact.payload.text.trim()) return [];
108
+ return [{
109
+ type: "reminder.speech",
110
+ key: `fact:${fact.eventId}`,
111
+ wakeAgent: true,
112
+ payload: { ...fact.payload, text: fact.payload.text, source_event_id: fact.eventId }
113
+ }];
114
+ }) };
115
+ }
116
+ function defaultReminder(topic, input) {
117
+ if (topic === "speech") return speechReminder(input);
118
+ const config = validateDefaultConfig(topic, input.config);
119
+ const events = [];
120
+ if (input.boundary) return { events };
121
+ const emit = (kind, key, data, eventId) => {
122
+ const mode = config[kind];
123
+ if (mode === "state_only") return;
124
+ const { tasks: _tasks, delta: _delta, newly_assigned_task: _assigned, ...detail } = data;
125
+ const name = String(detail.task_name ?? detail.name ?? "");
126
+ const actor = record(detail.actor);
127
+ const seat = actor.seat ?? detail.actor_seat;
128
+ const who = seat !== void 0 && seat !== input.gameState?.you?.player?.seat ? `${seat}\u53F7\u73A9\u5BB6\uFF1A` : "";
129
+ const room = detail.room ? `\uFF08${String(detail.room)}\uFF09` : "";
130
+ events.push({
131
+ type: "reminder.task",
132
+ key,
133
+ wakeAgent: mode === "wake",
134
+ payload: { ...detail, kind, source_event_id: eventId, text: `${who}${labels[kind]}\uFF1A${name}${room}\u3002` }
135
+ });
136
+ };
137
+ for (const fact of input.facts) {
138
+ const kind = kinds[fact.type];
139
+ if (kind) emit(kind, `fact:${fact.eventId}`, { ...fact.payload }, fact.eventId);
140
+ }
141
+ return { events };
142
+ }
143
+
144
+ // src/sdk/perception-plugin/math.ts
145
+ var TICK_MS = 100;
146
+ var MOVE_MIN_PX = 18;
147
+ var STEP_MOVE_MIN_PX = 4;
148
+ var STILL_STEP_MAX_PX = 3;
149
+ function vector(from, to) {
150
+ return { x: to.x - from.x, y: to.y - from.y };
151
+ }
152
+ function length(value) {
153
+ return Math.hypot(value.x, value.y);
154
+ }
155
+ function distance(a, b) {
156
+ return Math.hypot(a.x - b.x, a.y - b.y);
157
+ }
158
+ function dot(a, b) {
159
+ return a.x * b.x + a.y * b.y;
160
+ }
161
+ function cross(a, b) {
162
+ return a.x * b.y - a.y * b.x;
163
+ }
164
+ function unit(value) {
165
+ const magnitude = length(value);
166
+ return magnitude <= 0 ? { x: 0, y: 0 } : { x: value.x / magnitude, y: value.y / magnitude };
167
+ }
168
+ function cosine(a, b) {
169
+ const denominator = length(a) * length(b);
170
+ return denominator <= 0 ? 0 : dot(a, b) / denominator;
171
+ }
172
+ function angleDegrees(a, b) {
173
+ return Math.acos(Math.max(-1, Math.min(1, cosine(a, b)))) * (180 / Math.PI);
174
+ }
175
+ function direction(from, to, minimum = MOVE_MIN_PX) {
176
+ const dx = to.x - from.x;
177
+ const dy = to.y - from.y;
178
+ if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
179
+ const horizontal = Math.abs(dx) >= minimum / 2 ? dx > 0 ? "\u53F3" : "\u5DE6" : "";
180
+ const vertical = Math.abs(dy) >= minimum / 2 ? dy > 0 ? "\u4E0B" : "\u4E0A" : "";
181
+ return `${horizontal}${vertical}` || "\u539F\u5730";
182
+ }
183
+ function headingDirection(from, to, minimum = MOVE_MIN_PX) {
184
+ const dx = to.x - from.x;
185
+ const dy = to.y - from.y;
186
+ if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
187
+ const octant = Math.round(Math.atan2(dy, dx) / (Math.PI / 4));
188
+ const directions = [
189
+ "\u53F3",
190
+ "\u53F3\u4E0B",
191
+ "\u4E0B",
192
+ "\u5DE6\u4E0B",
193
+ "\u5DE6",
194
+ "\u5DE6\u4E0A",
195
+ "\u4E0A",
196
+ "\u53F3\u4E0A"
197
+ ];
198
+ return directions[(octant + directions.length) % directions.length];
199
+ }
200
+ function actorLabel(actor) {
201
+ if (actor.observer) return "\u4F60";
202
+ if (actor.seat !== void 0) return `${actor.seat}\u53F7`;
203
+ return actor.name ?? actor.id;
204
+ }
205
+ function actorValue(actor) {
206
+ return actor.seat ?? actor.id;
207
+ }
208
+ function timeRange(fromTick, toTick) {
209
+ const format = (tick) => {
210
+ const total = Math.max(0, Math.floor(tick * TICK_MS / 1e3));
211
+ return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
212
+ };
213
+ const from = format(fromTick);
214
+ const to = format(toTick);
215
+ return from === to ? from : `${from}-${to}`;
216
+ }
217
+ function round1(value) {
218
+ return Math.round(value * 10) / 10;
219
+ }
220
+ function positionCopy(position) {
221
+ return { x: position.x, y: position.y, room: position.room };
222
+ }
223
+
224
+ // src/sdk/perception-plugin/index.ts
225
+ var PERCEPTION_PLUGIN_API_VERSION = 2;
226
+ function evaluateReminder(topic, input) {
227
+ return defaultReminder(topic, "events" in input ? { ...input, facts: input.events } : input);
228
+ }
229
+ var ClawclawPerception = class extends Perception {
230
+ static manifest;
231
+ /** API v3 combines observation, notification and fixed Behavior activation. */
232
+ evaluate(_input, _api) {
233
+ throw new Error("PERCEPTION_EVALUATE_NOT_IMPLEMENTED");
234
+ }
235
+ /** @deprecated API v2 compatibility; new modules implement evaluate(). */
236
+ update(frame, api) {
237
+ throw new Error("PERCEPTION_UPDATE_NOT_IMPLEMENTED");
238
+ }
239
+ };
240
+ var ClawclawParallelPerception = class extends ClawclawPerception {
241
+ update() {
242
+ throw new Error("parallel_perception_uses_analyze_and_commit");
243
+ }
244
+ };
245
+
246
+ export {
247
+ PERCEPTION_MODULE_API_VERSION,
248
+ hasPerceptionBoundary,
249
+ enteredPhase,
250
+ leftPhase,
251
+ resetPerceptionState,
252
+ ClawclawReaction,
253
+ REMINDER_PLUGIN_API_VERSION,
254
+ ClawclawReminder,
255
+ TICK_MS,
256
+ MOVE_MIN_PX,
257
+ STEP_MOVE_MIN_PX,
258
+ STILL_STEP_MAX_PX,
259
+ vector,
260
+ length,
261
+ distance,
262
+ dot,
263
+ cross,
264
+ unit,
265
+ cosine,
266
+ angleDegrees,
267
+ direction,
268
+ headingDirection,
269
+ actorLabel,
270
+ actorValue,
271
+ timeRange,
272
+ round1,
273
+ positionCopy,
274
+ PERCEPTION_PLUGIN_API_VERSION,
275
+ evaluateReminder,
276
+ ClawclawPerception,
277
+ ClawclawParallelPerception
278
+ };