@myclaw163/clawclaw-cli 0.8.27 → 0.8.29
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/docs/custom-modules/api-reference.md +2 -2
- package/docs/custom-modules/examples/task-reminder.ts +5 -3
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/reminders.md +88 -92
- package/docs/runtime/agent-notifications.md +2 -2
- package/docs/runtime/events-and-state.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -3
- package/skills/clawclaw/references/CHANNELS.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +2 -2
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +1 -1
- package/skills/clawclaw/references/CUSTOM-REMINDER-DEVELOPMENT.md +88 -92
- package/skills/clawclaw/references/STREAM.md +2 -2
- package/src/pipeline/event-format.ts +2 -0
- package/src/runtime/clawclaw/owner.ts +0 -1
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +38 -29
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +0 -3
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2 -26
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +10 -10
- package/src/runtime/clawclaw/runtime.ts +0 -3
- package/src/runtime/clawclaw-event-catalog.ts +6 -8
- package/src/sdk/perception-plugin/reminder-rules.ts +73 -20
- package/src/sdk/perception-plugin/reminder.ts +25 -2
|
@@ -1,41 +1,94 @@
|
|
|
1
|
-
import type { ReminderInput, ReminderMode, ReminderResult, ReminderTopic } from './reminder.js';
|
|
1
|
+
import type { ReminderInput, ReminderMode, ReminderResult, ReminderTopic, ReminderFact, ReminderTaskChange, ReminderEvent } from './reminder.js';
|
|
2
2
|
|
|
3
3
|
export const REMINDER_FACT_TYPES = [
|
|
4
4
|
'ability.ready', 'ability.remaining_uses_changed', 'ability.exhausted', 'tasks_changed',
|
|
5
5
|
'task_started', 'task_progress', 'task_assigned', 'task_completed', 'task_interrupted', 'task_sabotaged',
|
|
6
6
|
'role_assigned', 'emergency_started', 'emergency_resolved', 'emergency_interrupted', 'meeting_briefing',
|
|
7
7
|
] as const;
|
|
8
|
-
|
|
9
|
-
export const REMINDER_CONTROLLED_TYPES = ['tasks_changed'] as const;
|
|
8
|
+
export const REMINDER_EVENT_TYPES = ['reminder.task'] as const;
|
|
10
9
|
export const REMINDER_TOPICS: readonly ReminderTopic[] = ['tasks'];
|
|
11
|
-
export function deliveryClass(mode: ReminderMode) {
|
|
12
|
-
return mode === 'notify' ? 'monitor_and_events' : mode === 'query' ? 'events_only' : 'internal_only';
|
|
13
|
-
}
|
|
14
10
|
export function isReminderMode(value: unknown): value is ReminderMode {
|
|
15
|
-
return value === '
|
|
11
|
+
return value === 'wake' || value === 'silent' || value === 'state_only';
|
|
16
12
|
}
|
|
17
|
-
export function defaultConfig(topic: ReminderTopic): Record<string,
|
|
13
|
+
export function defaultConfig(topic: ReminderTopic): Record<string, ReminderMode> {
|
|
18
14
|
if (topic !== 'tasks') throw new Error('Unsupported reminder topic; countdown and ability notifications are owned by CCL.');
|
|
19
|
-
return { started: '
|
|
15
|
+
return { started: 'state_only', progress: 'state_only', added: 'silent', completed: 'silent',
|
|
16
|
+
interrupted: 'wake', sabotaged: 'wake', removed: 'silent', updated: 'silent' };
|
|
20
17
|
}
|
|
21
|
-
export function validateDefaultConfig(topic: ReminderTopic, input: unknown): Record<string,
|
|
18
|
+
export function validateDefaultConfig(topic: ReminderTopic, input: unknown): Record<string, ReminderMode> {
|
|
22
19
|
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('Reminder config must be an object.');
|
|
23
20
|
const defaults = defaultConfig(topic);
|
|
24
21
|
for (const key of Object.keys(input)) if (!Object.hasOwn(defaults, key)) throw new Error('Unknown reminder option: ' + key);
|
|
25
22
|
const value = { ...defaults, ...input };
|
|
26
|
-
if (!Object.values(value).every(isReminderMode)) throw new Error('Reminder mode must be
|
|
23
|
+
if (!Object.values(value).every(isReminderMode)) throw new Error('Reminder mode must be wake, silent, or state_only.');
|
|
27
24
|
return value;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
const kinds: Record<string, string> = { task_started: 'started', task_progress: 'progress', task_assigned: 'added',
|
|
27
|
+
task_completed: 'completed', task_interrupted: 'interrupted', task_sabotaged: 'sabotaged' };
|
|
28
|
+
const labels: Record<string, string> = { started: '开始任务', progress: '任务进度变化', added: '新增任务',
|
|
29
|
+
completed: '任务完成', interrupted: '任务中断', sabotaged: '破坏任务完成', removed: '任务不再出现在列表', updated: '任务信息变化' };
|
|
30
|
+
function record(value: unknown): Record<string, unknown> {
|
|
31
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
|
32
|
+
}
|
|
33
|
+
function ownFact(fact: ReminderFact, input: ReminderInput): boolean {
|
|
34
|
+
const actor = record(fact.payload.actor);
|
|
35
|
+
const seat = actor.seat ?? fact.payload.actor_seat;
|
|
36
|
+
const name = actor.name ?? fact.payload.actor_name;
|
|
37
|
+
const self = input.gameState?.you?.player;
|
|
38
|
+
if (seat !== undefined && self?.seat !== undefined) return seat === self.seat;
|
|
39
|
+
if (name !== undefined && self?.name !== undefined) return name === self.name;
|
|
40
|
+
return seat === undefined && name === undefined;
|
|
41
|
+
}
|
|
42
|
+
function matches(fact: ReminderFact, change: ReminderTaskChange, input: ReminderInput): boolean {
|
|
43
|
+
if (fact.epochId !== change.epochId || (fact.type.startsWith('task_') && !ownFact(fact, input))) return false;
|
|
44
|
+
const p = fact.payload;
|
|
45
|
+
if (p.task_id && change.task.task_id) return p.task_id === change.task.task_id;
|
|
46
|
+
const name = p.task_name;
|
|
47
|
+
if (!name || name !== change.task.name) return false;
|
|
48
|
+
if (p.room && change.task.room && p.room !== change.task.room) return false;
|
|
49
|
+
// Without IDs, only correlate an unambiguous task in this physical frame.
|
|
50
|
+
return input.taskChanges.filter(c => c.epochId === change.epochId && c.task.name === name
|
|
51
|
+
&& (!p.room || !c.task.room || c.task.room === p.room)).length === 1;
|
|
52
|
+
}
|
|
53
|
+
function explained(fact: ReminderFact, change: ReminderTaskChange, input: ReminderInput): boolean {
|
|
54
|
+
if (!matches(fact, change, input)) return false;
|
|
55
|
+
if (change.change === 'added') return fact.type === 'task_assigned' || fact.type === 'emergency_started';
|
|
56
|
+
if (change.change === 'removed') return ['task_completed', 'task_sabotaged', 'emergency_resolved', 'emergency_interrupted'].includes(fact.type);
|
|
57
|
+
if (change.change === 'status_changed') {
|
|
58
|
+
if (change.to_status === 'completed') return ['task_completed', 'task_sabotaged'].includes(fact.type);
|
|
59
|
+
if (change.to_status === 'in_progress') return fact.type === 'task_started';
|
|
60
|
+
if (change.from_status === 'in_progress' && change.to_status === 'normal') return fact.type === 'task_interrupted';
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
34
63
|
}
|
|
64
|
+
/** Optional task policy: classify individual changes, never re-deliver the whole raw fact. */
|
|
35
65
|
export function defaultReminder(topic: ReminderTopic, input: ReminderInput): ReminderResult {
|
|
36
66
|
const config = validateDefaultConfig(topic, input.config);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
const events: ReminderEvent[] = [];
|
|
68
|
+
if (input.boundary) return { events };
|
|
69
|
+
const emit = (kind: string, key: string, data: Record<string, unknown>, eventId: string) => {
|
|
70
|
+
const mode = config[kind];
|
|
71
|
+
if (mode === 'state_only') return;
|
|
72
|
+
const { tasks: _tasks, delta: _delta, newly_assigned_task: _assigned, ...detail } = data;
|
|
73
|
+
const name = String(detail.task_name ?? detail.name ?? '');
|
|
74
|
+
const actor = record(detail.actor);
|
|
75
|
+
const seat = actor.seat ?? detail.actor_seat;
|
|
76
|
+
const who = seat !== undefined && seat !== input.gameState?.you?.player?.seat ? `${seat}号玩家:` : '';
|
|
77
|
+
const room = detail.room ? `(${String(detail.room)})` : '';
|
|
78
|
+
events.push({ type: 'reminder.task', key, wakeAgent: mode === 'wake',
|
|
79
|
+
payload: { ...detail, kind, source_event_id: eventId, text: `${who}${labels[kind]}:${name}${room}。` } });
|
|
80
|
+
};
|
|
81
|
+
for (const fact of input.facts) {
|
|
82
|
+
const kind = kinds[fact.type];
|
|
83
|
+
if (kind) emit(kind, `fact:${fact.eventId}`, { ...fact.payload }, fact.eventId);
|
|
84
|
+
}
|
|
85
|
+
for (const change of input.taskChanges) {
|
|
86
|
+
if (change.baseline || input.facts.some(f => explained(f, change, input))) continue;
|
|
87
|
+
const kind = change.change === 'added' ? 'added' : change.change === 'removed' ? 'removed'
|
|
88
|
+
: change.change === 'status_changed' && change.to_status === 'in_progress' ? 'started'
|
|
89
|
+
: change.change === 'status_changed' && change.to_status === 'completed' ? 'completed' : 'updated';
|
|
90
|
+
emit(kind, change.key, { ...change.task, change: change.change,
|
|
91
|
+
from_status: change.from_status, to_status: change.to_status }, change.eventId);
|
|
92
|
+
}
|
|
93
|
+
return { events };
|
|
41
94
|
}
|
|
@@ -4,13 +4,29 @@ import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js';
|
|
|
4
4
|
/** Reminder classes use the same public Perception API version and resource lifecycle. */
|
|
5
5
|
export const REMINDER_PLUGIN_API_VERSION = 2 as const;
|
|
6
6
|
export type ReminderTopic = 'tasks';
|
|
7
|
-
export type ReminderMode = '
|
|
7
|
+
export type ReminderMode = 'wake' | 'silent' | 'state_only';
|
|
8
8
|
export interface ReminderFact extends GameEvent { readonly producer: 'backend_push' | 'local_synth' }
|
|
9
|
+
/** Structural task changes, not Agent notifications or inferred completion facts. */
|
|
10
|
+
export interface ReminderTaskChange {
|
|
11
|
+
readonly key: string;
|
|
12
|
+
readonly eventId: string;
|
|
13
|
+
readonly epochId?: number;
|
|
14
|
+
readonly change: 'added' | 'removed' | 'status_changed' | 'updated';
|
|
15
|
+
readonly task: Readonly<Record<string, unknown>>;
|
|
16
|
+
readonly before?: Readonly<Record<string, unknown>>;
|
|
17
|
+
readonly from_status?: string;
|
|
18
|
+
readonly to_status?: string;
|
|
19
|
+
readonly baseline: boolean;
|
|
20
|
+
}
|
|
9
21
|
export interface ReminderInput {
|
|
10
22
|
readonly scope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
11
23
|
readonly frame: Readonly<ObservationFrame> | null;
|
|
12
24
|
readonly gameState: Readonly<GameState> | null;
|
|
13
25
|
readonly facts: readonly Readonly<ReminderFact>[];
|
|
26
|
+
/** Reuses Source task comparison; independent of the facts subscription. */
|
|
27
|
+
readonly taskChanges: readonly ReminderTaskChange[];
|
|
28
|
+
/** Establish private baselines without replaying notifications. */
|
|
29
|
+
readonly boundary: 'initial' | 'recovery' | null;
|
|
14
30
|
readonly config: Readonly<Record<string, unknown>>;
|
|
15
31
|
/** Host-persisted state from the previous completed update; never use instance fields for recovery. */
|
|
16
32
|
readonly state: unknown;
|
|
@@ -18,7 +34,14 @@ export interface ReminderInput {
|
|
|
18
34
|
}
|
|
19
35
|
export interface ReminderResult {
|
|
20
36
|
readonly state?: unknown;
|
|
21
|
-
readonly
|
|
37
|
+
readonly events?: readonly ReminderEvent[];
|
|
38
|
+
}
|
|
39
|
+
export interface ReminderEvent {
|
|
40
|
+
readonly type: 'reminder.task';
|
|
41
|
+
/** Stable per occurrence, retained across retry/recovery. */
|
|
42
|
+
readonly key: string;
|
|
43
|
+
readonly wakeAgent: boolean;
|
|
44
|
+
readonly payload: Readonly<Record<string, unknown>> & { readonly text: string };
|
|
22
45
|
}
|
|
23
46
|
export interface ClawclawReminderManifest {
|
|
24
47
|
readonly apiVersion: typeof REMINDER_PLUGIN_API_VERSION;
|