@myclaw163/clawclaw-cli 0.8.41 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/docs/custom-modules/README.md +12 -16
- package/docs/custom-modules/api-reference.md +56 -3
- package/docs/custom-modules/behavior.md +6 -0
- package/docs/custom-modules/examples/first-sighting-v3.ts +29 -0
- package/docs/custom-modules/perception.md +139 -58
- package/docs/custom-modules/trigger.md +2 -0
- package/docs/runtime/README.md +17 -8
- package/docs/runtime/agent-notifications.md +32 -15
- package/docs/runtime/behavior-runtime.md +28 -21
- package/docs/runtime/components-and-boundaries.md +57 -17
- package/docs/runtime/events-and-state.md +42 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +5 -3
- package/docs/user-guide/README.md +50 -0
- package/docs/user-guide/api-reference.md +760 -0
- package/docs/user-guide/behavior.md +369 -0
- package/docs/user-guide/installation.md +123 -0
- package/docs/user-guide/perception.md +869 -0
- package/docs/user-guide/skill.md +67 -0
- package/package.json +4 -2
- package/skills/clawclaw/SKILL.md +4 -4
- package/skills/clawclaw/references/BEHAVIORS.md +2 -0
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +6 -0
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +56 -3
- package/skills/clawclaw/references/CUSTOM-MODULES.md +12 -16
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +139 -58
- package/src/commands/load.ts +13 -11
- package/src/commands/perception.ts +2 -2
- package/src/commands/trigger.ts +1 -1
- package/src/lib/agent-workspace-sync.ts +2 -2
- package/src/runtime/clawclaw/owner.ts +3 -2
- package/src/runtime/clawclaw/perception-module-manifest.ts +27 -0
- package/src/runtime/clawclaw/plugins/assembly.ts +17 -5
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +28 -0
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +21 -0
- package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +47 -12
- package/src/runtime/clawclaw/plugins/perception/reaction-runner.ts +2 -2
- package/src/runtime/clawclaw/task-choice-projection.ts +19 -25
- package/src/runtime/clawclaw-event-catalog.ts +5 -2
- package/src/sdk/behavior-plugin/index.ts +3 -0
- package/src/sdk/index.ts +4 -0
- package/src/sdk/module-input/index.ts +15 -1
- package/src/sdk/perception-plugin/index.ts +25 -8
- package/src/sdk/perception-plugin/module.ts +46 -0
- package/src/sdk/perception-plugin/reaction.ts +1 -0
- package/src/sdk/perception-plugin/reminder.ts +1 -0
- package/src/sdk/task-availability.ts +70 -0
- package/src/sdk/trigger-plugin/index.ts +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { GameState, ObservationFrame } from '../module-input/index.js';
|
|
2
|
+
import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js';
|
|
3
|
+
import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
|
|
4
|
+
import type { ReactionBehaviorBinding, ReactionActivation } from './reaction.js';
|
|
5
|
+
import type { ReminderFact, ReminderTaskChange } from './reminder.js';
|
|
6
|
+
|
|
7
|
+
/** Unified authoring contract; v2 visual/reminder/reaction scripts remain supported. */
|
|
8
|
+
export const PERCEPTION_MODULE_API_VERSION = 3 as const;
|
|
9
|
+
export interface PerceptionModuleManifest {
|
|
10
|
+
readonly apiVersion: typeof PERCEPTION_MODULE_API_VERSION;
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly localizations?: ClawclawResourceLocalizations;
|
|
15
|
+
readonly consumes?: readonly string[];
|
|
16
|
+
readonly produces?: readonly string[];
|
|
17
|
+
readonly behaviors?: Readonly<Record<string, ReactionBehaviorBinding>>;
|
|
18
|
+
readonly inputs?: readonly BehaviorInputFieldSpec[];
|
|
19
|
+
readonly config?: Readonly<Record<string, unknown>>;
|
|
20
|
+
}
|
|
21
|
+
export interface PerceptionModuleInput {
|
|
22
|
+
readonly moduleId: string;
|
|
23
|
+
readonly scope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
24
|
+
readonly gameState: Readonly<GameState> | null;
|
|
25
|
+
readonly frame: Readonly<ObservationFrame> | null;
|
|
26
|
+
/** Source/backend and system-derived facts only; never another perception's output. */
|
|
27
|
+
readonly events: readonly Readonly<ReminderFact>[];
|
|
28
|
+
readonly taskChanges: readonly ReminderTaskChange[];
|
|
29
|
+
readonly boundary: 'initial' | 'recovery' | null;
|
|
30
|
+
readonly nowMs: number;
|
|
31
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
32
|
+
readonly state: unknown;
|
|
33
|
+
readonly availableBehaviors: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
export interface PerceptionModuleEvent {
|
|
36
|
+
readonly type: string;
|
|
37
|
+
readonly key: string;
|
|
38
|
+
/** false retains the event for a later wake; omit the event to produce no notification. */
|
|
39
|
+
readonly wakeAgent?: boolean;
|
|
40
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
41
|
+
}
|
|
42
|
+
export interface PerceptionModuleResult {
|
|
43
|
+
readonly state?: unknown;
|
|
44
|
+
readonly events?: readonly PerceptionModuleEvent[];
|
|
45
|
+
readonly activations?: readonly ReactionActivation[];
|
|
46
|
+
}
|
|
@@ -72,6 +72,7 @@ export interface ReactionResult {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/** A perception resource that can notify the Agent and request fixed Behaviors. */
|
|
75
|
+
/** @deprecated API v2 compatibility; future support may end. New scripts use ClawclawPerception API v3. */
|
|
75
76
|
export abstract class ClawclawReaction {
|
|
76
77
|
static readonly manifest?: ClawclawReactionManifest;
|
|
77
78
|
abstract evaluate(input: Readonly<ReactionInput>): ReactionResult | Promise<ReactionResult>;
|
|
@@ -60,6 +60,7 @@ export interface ClawclawReminderManifest {
|
|
|
60
60
|
readonly config?: Readonly<Record<string, unknown>>;
|
|
61
61
|
}
|
|
62
62
|
/** Non-visual perception rule. Runtime supplies durable state and bounds the Worker. */
|
|
63
|
+
/** @deprecated API v2 compatibility; future support may end. New scripts use ClawclawPerception API v3. */
|
|
63
64
|
export abstract class ClawclawReminder {
|
|
64
65
|
static readonly manifest?: ClawclawReminderManifest;
|
|
65
66
|
abstract update(input: Readonly<ReminderInput>): ReminderResult | Promise<ReminderResult>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { GameState, GameTask, GameTaskAvailability, GameTaskKind } from './module-input/index.js';
|
|
2
|
+
|
|
3
|
+
type TaskRef = Pick<GameTask, 'name'> & Partial<GameTask>;
|
|
4
|
+
const label = (value: string | undefined): string => value?.trim().normalize('NFC').toLocaleLowerCase() ?? '';
|
|
5
|
+
|
|
6
|
+
/** Task readiness is independent of distance; Action/server still validate actual execution. */
|
|
7
|
+
export function getCrabSabotageAvailability(state: Readonly<GameState>): GameTaskAvailability {
|
|
8
|
+
const sabotage = state.crab_sabotage;
|
|
9
|
+
if (state.emergency?.active === true || sabotage?.status === 'emergency_active') {
|
|
10
|
+
return { state: 'blocked', reason: 'emergency_active' };
|
|
11
|
+
}
|
|
12
|
+
const remaining = sabotage?.cooldown_remaining_secs;
|
|
13
|
+
if (sabotage?.status === 'cooldown_charged' || (typeof remaining === 'number' && remaining > 0)) {
|
|
14
|
+
return { state: 'cooldown', reason: 'sabotage_cooldown',
|
|
15
|
+
...(typeof remaining === 'number' && Number.isFinite(remaining) && remaining >= 0
|
|
16
|
+
? { remaining_secs: remaining } : {}) };
|
|
17
|
+
}
|
|
18
|
+
return sabotage?.status === 'ready'
|
|
19
|
+
? { state: 'ready' }
|
|
20
|
+
: { state: 'unknown', reason: 'sabotage_state_unavailable' };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getTaskKind(state: Readonly<GameState>, task: Readonly<TaskRef>): GameTaskKind {
|
|
24
|
+
if (task.kind) return task.kind;
|
|
25
|
+
if (task.is_fake_shrimp === true) return 'fake_shrimp';
|
|
26
|
+
if (state.emergency?.active === true && label(state.emergency.task_name) === label(task.name)) return 'emergency';
|
|
27
|
+
return (state.you?.faction === 'crab' || state.you?.role === 'crab_generic') && task.is_fake_shrimp === false
|
|
28
|
+
? 'sabotage' : 'ordinary';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Recompute from this snapshot, never from a cached task's availability/countdown. */
|
|
32
|
+
export function getTaskAvailability(state: Readonly<GameState>, task: Readonly<TaskRef> | string): GameTaskAvailability {
|
|
33
|
+
const tasks = state.you?.tasks;
|
|
34
|
+
if (!Array.isArray(tasks)) return { state: 'unknown', reason: 'task_state_unavailable' };
|
|
35
|
+
const requested = typeof task === 'string'
|
|
36
|
+
? tasks.find(candidate => label(candidate.name) === label(task) || (!!candidate.task_id && label(candidate.task_id) === label(task))) ?? { name: task }
|
|
37
|
+
: task;
|
|
38
|
+
const current = tasks.find(candidate => requested.task_id
|
|
39
|
+
? candidate.task_id === requested.task_id
|
|
40
|
+
: label(candidate.name) === label(requested.name)
|
|
41
|
+
&& (!requested.room || label(candidate.room) === label(requested.room))
|
|
42
|
+
&& (requested.x === undefined || candidate.x === requested.x)
|
|
43
|
+
&& (requested.y === undefined || candidate.y === requested.y));
|
|
44
|
+
if (!current) return { state: 'blocked', reason: 'not_assigned' };
|
|
45
|
+
if (current.status === 'completed') return { state: 'completed', reason: 'task_completed' };
|
|
46
|
+
if (state.you?.is_alive === false) return { state: 'blocked', reason: 'not_alive' };
|
|
47
|
+
if (state.you?.is_alive !== true || state.phase === undefined) return { state: 'unknown', reason: 'player_state_unavailable' };
|
|
48
|
+
if (state.phase !== 'wandering') return { state: 'blocked', reason: 'not_wandering' };
|
|
49
|
+
if (current.status === 'in_progress'
|
|
50
|
+
|| (state.you?.activity?.kind === 'task' && label(state.you.activity.task_name) === label(current.name))) {
|
|
51
|
+
return { state: 'in_progress', reason: 'task_in_progress' };
|
|
52
|
+
}
|
|
53
|
+
if (current.status !== 'normal') return { state: 'unknown', reason: 'task_state_unavailable' };
|
|
54
|
+
const kind = getTaskKind(state, current);
|
|
55
|
+
if (kind === 'sabotage') return getCrabSabotageAvailability(state);
|
|
56
|
+
if (kind === 'emergency' && (state.emergency?.active !== true || label(state.emergency.task_name) !== label(current.name))) {
|
|
57
|
+
return { state: 'blocked', reason: 'emergency_inactive' };
|
|
58
|
+
}
|
|
59
|
+
return { state: 'ready' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Ready to select as a task goal; this does not imply that the player is already at its location. */
|
|
63
|
+
export function isTaskAvailable(state: Readonly<GameState>, task: Readonly<TaskRef> | string): boolean {
|
|
64
|
+
return getTaskAvailability(state, task).state === 'ready';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The full authoritative assignment list remains in you.tasks, including blocked tasks and facts. */
|
|
68
|
+
export function getAvailableTasks(state: Readonly<GameState>): readonly Readonly<GameTask>[] {
|
|
69
|
+
return (state.you?.tasks ?? []).filter(task => isTaskAvailable(state, task));
|
|
70
|
+
}
|
|
@@ -106,6 +106,7 @@ export interface TriggerMatch {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/** Public authoring surface for one read-only rule module. */
|
|
109
|
+
/** @deprecated Compatibility API; may be unsupported in a future release. Use unified Perception API v3 for new rules. */
|
|
109
110
|
export abstract class ClawclawTrigger<
|
|
110
111
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
111
112
|
> {
|