@myclaw163/clawclaw-cli 0.9.1 → 0.10.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/QUICKSTART_OTHER.md +5 -5
- package/README.md +7 -8
- package/bin/clawclaw-channel.mjs +2 -2
- package/bin/clawclaw-cli.mjs +2 -2
- package/docs/configuration.md +25 -99
- package/docs/custom-modules/README.md +27 -40
- package/docs/custom-modules/api-reference.md +132 -273
- package/docs/custom-modules/behavior.md +185 -75
- package/docs/custom-modules/examples/auto-escape.ts +41 -0
- package/docs/custom-modules/examples/go-to-point.ts +11 -11
- package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
- package/docs/custom-modules/examples/task-reminder.ts +4 -5
- package/docs/custom-modules/perception.md +46 -806
- package/docs/custom-modules/skill.md +1 -1
- package/docs/desktop-event-push.md +3 -3
- package/docs/runtime/README.md +18 -19
- package/docs/runtime/agent-notifications.md +31 -12
- package/docs/runtime/behavior-runtime.md +54 -48
- package/docs/runtime/components-and-boundaries.md +87 -137
- package/docs/runtime/events-and-state.md +52 -17
- package/docs/runtime/framework-package.md +73 -0
- package/docs/runtime/official-perception-modules.md +5 -5
- package/docs/runtime/owner-lifecycle-and-observability.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +8 -9
- package/docs/user-guide/README.md +12 -9
- package/docs/user-guide/api-reference.md +132 -180
- package/docs/user-guide/behavior.md +175 -65
- package/docs/user-guide/installation.md +7 -7
- package/docs/user-guide/perception.md +46 -789
- package/docs/user-guide/skill.md +1 -1
- package/package.json +24 -9
- package/scripts/check-framework-boundaries.mjs +27 -0
- package/scripts/check-skill-command-surface.mjs +9 -14
- package/scripts/install-local-runtime.mjs +35 -0
- package/scripts/qa-install.mjs +105 -0
- package/skills/clawclaw/SKILL.md +50 -48
- package/skills/clawclaw/references/BEHAVIORS.md +45 -65
- package/skills/clawclaw/references/CHANNELS.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +65 -87
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +185 -75
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +145 -198
- package/skills/clawclaw/references/CUSTOM-MODULES.md +28 -29
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +46 -811
- package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
- package/skills/clawclaw/references/HUB.md +1 -1
- package/skills/clawclaw/references/STREAM.md +8 -8
- package/skills/clawclaw/references/TACTICS.md +1 -1
- package/src/channel/claude-channel-ipc-server.ts +1 -0
- package/src/cli.ts +4 -2
- package/src/commands/behavior.ts +49 -104
- package/src/commands/capability.ts +3 -3
- package/src/commands/load.ts +18 -25
- package/src/commands/module-runtime-control.ts +113 -0
- package/src/commands/perception.ts +23 -4
- package/src/commands/strategy.ts +2 -0
- package/src/commands/trigger.ts +1 -1
- package/src/lib/capability-load-diagnostics.ts +3 -3
- package/src/lib/perception-config.ts +18 -6
- package/src/lib/runtime-cadence-config.ts +16 -0
- package/src/lib/workspace-runtime-lock.ts +3 -46
- package/src/pipeline/canonical-event-presentation.ts +23 -124
- package/src/pipeline/event-format.ts +12 -21
- package/src/pipeline/event-hints.ts +6 -6
- package/src/pipeline/game-sync-event-normalization.ts +57 -63
- package/src/runtime/clawclaw/behavior-decision.ts +7 -3
- package/src/runtime/clawclaw/behavior-input.ts +8 -4
- package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
- package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
- package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
- package/src/runtime/clawclaw/notification-policy.ts +42 -0
- package/src/runtime/clawclaw/notification-turn.ts +19 -0
- package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
- package/src/runtime/clawclaw/owner.ts +67 -8
- package/src/runtime/clawclaw/perception-module-manifest.ts +22 -8
- package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
- package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
- package/src/runtime/clawclaw/plugins/assembly.ts +29 -41
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -482
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -186
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1707
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -271
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -960
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +9 -107
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +5 -4
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +27 -17
- package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
- package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -0
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
- package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +136 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +13 -0
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +13 -24
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +19 -8
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +23 -15
- package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +8 -103
- package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +3 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +5 -2
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +69 -13
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +13 -1
- package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +4 -0
- package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
- package/src/runtime/clawclaw/reaction-manifest.ts +18 -12
- package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
- package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
- package/src/runtime/clawclaw/runtime-state.ts +12 -1
- package/src/runtime/clawclaw/runtime.ts +11 -3
- package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -0
- package/src/runtime/clawclaw/strategy-memory.ts +1 -0
- package/src/runtime/clawclaw-event-catalog.ts +17 -17
- package/src/runtime/framework/action-diagnostics.ts +3 -83
- package/src/runtime/framework/capability-registry.ts +2 -395
- package/src/runtime/framework/contracts.ts +2 -144
- package/src/runtime/framework/control/control-scheduler.ts +2 -1268
- package/src/runtime/framework/control/domain-set.ts +2 -81
- package/src/runtime/framework/control/index.ts +1 -3
- package/src/runtime/framework/control/types.ts +2 -191
- package/src/runtime/framework/control-coordinator.ts +2 -11
- package/src/runtime/framework/events/event-catalog.ts +2 -74
- package/src/runtime/framework/events/event-delivery-service.ts +2 -200
- package/src/runtime/framework/events/event-ingress.ts +2 -99
- package/src/runtime/framework/events/event-repository.ts +2 -82
- package/src/runtime/framework/events/index.ts +2 -7
- package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
- package/src/runtime/framework/events/runtime-resume.ts +2 -20
- package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
- package/src/runtime/framework/events/test-helpers.ts +1 -1
- package/src/runtime/framework/events/types.ts +2 -312
- package/src/runtime/framework/index.ts +3 -7
- package/src/runtime/framework/load-node-sqlite.ts +2 -17
- package/src/runtime/framework/mailbox/coalescer.ts +2 -83
- package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
- package/src/runtime/framework/mailbox/identity.ts +2 -38
- package/src/runtime/framework/mailbox/index.ts +1 -7
- package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
- package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
- package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
- package/src/runtime/framework/mailbox/types.ts +2 -145
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
- package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
- package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
- package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
- package/src/runtime/framework/participation-manager.ts +2 -253
- package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
- package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
- package/src/runtime/framework/plugins/contracts.ts +2 -388
- package/src/runtime/framework/plugins/index.ts +1 -4
- package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
- package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2060
- package/src/runtime/framework/runtime.ts +5 -1843
- package/src/runtime/framework/serial-task-queue.ts +2 -14
- package/src/runtime/framework/state/contracts.ts +2 -49
- package/src/runtime/framework/state/current-state-store.ts +2 -184
- package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
- package/src/runtime/framework/state/freshness.ts +2 -72
- package/src/runtime/framework/state/history/contracts.ts +2 -158
- package/src/runtime/framework/state/history/history-writer.ts +2 -194
- package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
- package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
- package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
- package/src/runtime/framework/state/index.ts +1 -13
- package/src/runtime/framework/state/state-ingress.ts +2 -95
- package/src/runtime/framework/state/state-provider.ts +2 -62
- package/src/runtime/framework/state/types.ts +2 -155
- package/src/runtime/host-monitor-rate-gate.ts +1 -123
- package/src/runtime/mailbox-host-relay.ts +1 -326
- package/src/runtime/observability/detail-capture.ts +4 -108
- package/src/runtime/observability/process-timing.ts +2 -59
- package/src/runtime/observability/recorder.ts +2 -238
- package/src/runtime/observability/redaction.ts +2 -181
- package/src/runtime/observability/reporter.ts +2 -154
- package/src/runtime/observability/sinks.ts +2 -135
- package/src/runtime/observability/types.ts +2 -92
- package/src/runtime/owner-control.ts +45 -315
- package/src/runtime/parent-process-watch.ts +1 -51
- package/src/runtime/process-identity.ts +1 -72
- package/src/sdk/behavior-plugin/index.ts +13 -4
- package/src/sdk/index.ts +44 -3
- package/src/sdk/module-input/index.ts +5 -0
- package/src/sdk/perception-plugin/index.ts +9 -5
- package/src/sdk/perception-plugin/module.ts +25 -6
- package/src/sdk/perception-plugin/reaction.ts +1 -1
- package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
- package/src/sdk/perception-plugin/reminder.ts +2 -1
- package/src/{runtime/clawclaw/plugins/source → sdk/perception-plugin}/task-change-tracker.ts +1 -2
- package/src/sdk/strategy-memory.ts +1 -0
- package/src/sdk/strategy-plugin/index.ts +36 -0
- package/src/sdk/trigger-plugin/index.ts +4 -3
- package/docs/custom-modules/examples/nearby-escape.ts +0 -56
- package/docs/custom-modules/examples/nearby-notice.ts +0 -36
- package/docs/custom-modules/trigger.md +0 -295
- package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
- package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +0 -233
- package/src/runtime/clawclaw/plugins/perception/reaction-runner.ts +0 -49
- package/src/runtime/clawclaw/plugins/perception/reaction-worker.ts +0 -26
- /package/src/runtime/clawclaw/plugins/{source → derived-event}/player-change-tracker.ts +0 -0
|
@@ -1,72 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { readFileSync, readlinkSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
|
|
5
|
-
export interface ProcessIdentity {
|
|
6
|
-
/** OS process creation value, never the time the lock file was written. */
|
|
7
|
-
birth: string;
|
|
8
|
-
startedAtMs: number;
|
|
9
|
-
executable: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function inspectProcessIdentity(pid: number): ProcessIdentity | null {
|
|
13
|
-
if (!Number.isSafeInteger(pid) || pid <= 0) return null;
|
|
14
|
-
try {
|
|
15
|
-
if (process.platform === 'win32') {
|
|
16
|
-
const systemRoot = process.env.SystemRoot ?? 'C:\\Windows';
|
|
17
|
-
const script = `$ErrorActionPreference='Stop'; $p=[System.Diagnostics.Process]::GetProcessById(${pid}); `
|
|
18
|
-
+ '$t=$p.StartTime.ToUniversalTime(); '
|
|
19
|
-
+ '@{birth=$t.Ticks.ToString();startedAtMs=([DateTimeOffset]$t).ToUnixTimeMilliseconds();executable=$p.ProcessName} | ConvertTo-Json -Compress';
|
|
20
|
-
const output = execFileSync(join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
|
|
21
|
-
['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', script],
|
|
22
|
-
{ encoding: 'utf8', windowsHide: true, timeout: 5_000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
23
|
-
return JSON.parse(output) as ProcessIdentity;
|
|
24
|
-
}
|
|
25
|
-
if (process.platform === 'linux') {
|
|
26
|
-
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
27
|
-
const ticks = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]);
|
|
28
|
-
const boot = Number(/^btime (\d+)$/m.exec(readFileSync('/proc/stat', 'utf8'))?.[1]);
|
|
29
|
-
const hz = Number(execFileSync('getconf', ['CLK_TCK'], { encoding: 'utf8', timeout: 2_000 }));
|
|
30
|
-
return { birth: `${boot}:${ticks}`, startedAtMs: (boot + ticks / hz) * 1_000,
|
|
31
|
-
executable: readlinkSync(`/proc/${pid}/exe`) };
|
|
32
|
-
}
|
|
33
|
-
if (process.platform === 'darwin') {
|
|
34
|
-
const options = { encoding: 'utf8' as const, timeout: 2_000, env: { ...process.env, LC_ALL: 'C' } };
|
|
35
|
-
const birth = execFileSync('/bin/ps', ['-p', String(pid), '-o', 'lstart='], options).trim();
|
|
36
|
-
const executable = execFileSync('/bin/ps', ['-p', String(pid), '-o', 'comm='], options).trim();
|
|
37
|
-
const startedAtMs = Date.parse(birth);
|
|
38
|
-
return birth && executable && Number.isFinite(startedAtMs) ? { birth, startedAtMs, executable } : null;
|
|
39
|
-
}
|
|
40
|
-
} catch {}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function sameProcessIdentity(a: ProcessIdentity | null, b: ProcessIdentity | null): boolean {
|
|
45
|
-
return !!a && !!b && a.birth === b.birth && a.executable === b.executable;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Recheck immediately before signalling; a PID alone never authorizes a kill. */
|
|
49
|
-
export function terminateVerifiedProcess(pid: number, identity: ProcessIdentity, signal: NodeJS.Signals): void {
|
|
50
|
-
if (pid === process.pid || !sameProcessIdentity(identity, inspectProcessIdentity(pid))) {
|
|
51
|
-
throw new Error(`Refusing to terminate an unverified ClawClaw runtime (pid ${pid}).`);
|
|
52
|
-
}
|
|
53
|
-
if (process.platform === 'win32') {
|
|
54
|
-
const systemRoot = process.env.SystemRoot ?? 'C:\\Windows';
|
|
55
|
-
if (!/^\d+$/.test(identity.birth)) throw new Error('Invalid Windows process creation identity.');
|
|
56
|
-
// Retain the kernel handle before validating creation time. Killing via that
|
|
57
|
-
// Process object cannot target a later process that happens to reuse the PID.
|
|
58
|
-
// Runtime computation workers are threads of this process, so they exit too.
|
|
59
|
-
const script = `$ErrorActionPreference='Stop'; $p=[System.Diagnostics.Process]::GetProcessById(${pid}); `
|
|
60
|
-
+ `try { $null=$p.Handle; if ($p.StartTime.ToUniversalTime().Ticks.ToString() -ne '${identity.birth}') `
|
|
61
|
-
+ "{ throw 'runtime_identity_changed' }; $p.Kill(); } finally { $p.Dispose() }";
|
|
62
|
-
execFileSync(join(systemRoot, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe'),
|
|
63
|
-
['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', script],
|
|
64
|
-
{ stdio: 'ignore', windowsHide: true, timeout: 5_000 });
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (sameProcessIdentity(identity, inspectProcessIdentity(pid))) {
|
|
68
|
-
try { process.kill(pid, signal); } catch (error) {
|
|
69
|
-
if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw error;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
export * from '@myclaw163/game-agent-runtime/owner/process-identity.js';
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { Strategy } from '@myclaw163/game-agent-runtime/sdk/strategy.js';
|
|
1
2
|
import type {
|
|
2
3
|
BehaviorInput,
|
|
3
4
|
BehaviorDecisionAction,
|
|
4
5
|
Position,
|
|
5
6
|
} from '../module-input/index.js';
|
|
6
7
|
import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
|
|
8
|
+
import type { StrategyMemory } from '../strategy-memory.js';
|
|
9
|
+
export type { StrategyMemory, StrategyMemoryValue } from '../strategy-memory.js';
|
|
7
10
|
|
|
8
11
|
export const BEHAVIOR_PLUGIN_API_VERSION = 3 as const;
|
|
9
12
|
|
|
@@ -174,8 +177,9 @@ export interface ObservedCorpse extends Position {
|
|
|
174
177
|
readonly ageMs: number;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
/**
|
|
180
|
+
/** Epoch-bound game queries and resource-scoped private memory. */
|
|
178
181
|
export interface BehaviorReadApi {
|
|
182
|
+
readonly memory: StrategyMemory;
|
|
179
183
|
readonly spatial: SpatialApi;
|
|
180
184
|
readonly navigation: {
|
|
181
185
|
pathDistance(from: Readonly<Position>, to: Readonly<Position>): Promise<number | null>;
|
|
@@ -214,6 +218,10 @@ export interface BehaviorDelegation {
|
|
|
214
218
|
readonly behavior: string;
|
|
215
219
|
readonly input?: Readonly<Record<string, unknown>>;
|
|
216
220
|
}
|
|
221
|
+
export interface StrategyDelegation {
|
|
222
|
+
readonly strategy: string;
|
|
223
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
224
|
+
}
|
|
217
225
|
|
|
218
226
|
/** All semantic effects of one Behavior decision. */
|
|
219
227
|
export interface BehaviorDecision {
|
|
@@ -221,7 +229,7 @@ export interface BehaviorDecision {
|
|
|
221
229
|
readonly status?: Readonly<BehaviorStatus>;
|
|
222
230
|
readonly events?: readonly Readonly<BehaviorEventProposal>[];
|
|
223
231
|
/** Suspends this long Activation and starts one validated short Activation. */
|
|
224
|
-
readonly delegate?: Readonly<BehaviorDelegation>;
|
|
232
|
+
readonly delegate?: Readonly<BehaviorDelegation | StrategyDelegation>;
|
|
225
233
|
/** Ends this Activation after the Decision's preceding effects are committed. */
|
|
226
234
|
readonly finish?: Readonly<BehaviorFinish>;
|
|
227
235
|
}
|
|
@@ -265,7 +273,7 @@ export interface ClawclawBehaviorManifest {
|
|
|
265
273
|
readonly inputs: readonly BehaviorInputFieldSpec[];
|
|
266
274
|
/** Omitted means isolated parallel decide(); serial retains one Activation instance. */
|
|
267
275
|
readonly execution?: BehaviorExecution;
|
|
268
|
-
/**
|
|
276
|
+
/** Legacy input-driven cadence. The fixed-cadence Owner does not use this as a decision gate. */
|
|
269
277
|
readonly everyTicks?: number;
|
|
270
278
|
/** Event types this Behavior may propose. Omit when it produces no custom Events. */
|
|
271
279
|
readonly produces?: readonly string[];
|
|
@@ -305,7 +313,7 @@ export interface BehaviorNormalizationApi {
|
|
|
305
313
|
*/
|
|
306
314
|
export abstract class ClawclawBehavior<
|
|
307
315
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
308
|
-
> {
|
|
316
|
+
> extends Strategy<BehaviorInput<TInput>, BehaviorReadApi, BehaviorDecision> {
|
|
309
317
|
static readonly manifest?: ClawclawBehaviorManifest;
|
|
310
318
|
|
|
311
319
|
/** Optional one-time normalization. Schema defaults and validation run first. */
|
|
@@ -330,3 +338,4 @@ export interface ClawclawBehaviorClass<
|
|
|
330
338
|
readonly manifest?: ClawclawBehaviorManifest;
|
|
331
339
|
new(): ClawclawBehavior<TInput>;
|
|
332
340
|
}
|
|
341
|
+
export type { ProcessingCycleInfo } from '../module-input/index.js';
|
package/src/sdk/index.ts
CHANGED
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
* · MapRoom / GameResult / WsConnectionState / ActionErrorCode(客户端类型)
|
|
18
18
|
*
|
|
19
19
|
* 自定义模块的基类也可以从根入口导入;希望依赖更小的模块面时,从
|
|
20
|
-
* `
|
|
21
|
-
* `
|
|
20
|
+
* `strategy-plugin` 或 `perception-plugin` 导入。Strategy 使用
|
|
21
|
+
* `StrategyInput`;感知通过 `PerceptionModuleInput` 读取 `ObservationFrame` / `GameState`
|
|
22
22
|
* 数据边界。包内 `src/...` 深路径仍不是公开 API。
|
|
23
23
|
*
|
|
24
24
|
* 新增 / 删除本文件的 export 必须走 minor / major 版本号;字段语义变更同理。
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
export { Action } from './action.js';
|
|
28
|
+
export type { StrategyMemory, StrategyMemoryValue } from './strategy-memory.js';
|
|
28
29
|
export { getTaskAvailability, getAvailableTasks, isTaskAvailable, getTaskKind } from './task-availability.js';
|
|
29
30
|
export type { GameTaskAvailability, GameTaskKind } from './module-input/index.js';
|
|
30
31
|
export { GameClient } from '../lib/game-client.js';
|
|
@@ -57,7 +58,8 @@ export {
|
|
|
57
58
|
TRIGGER_PLUGIN_API_VERSION,
|
|
58
59
|
} from './trigger-plugin/index.js';
|
|
59
60
|
export type {
|
|
60
|
-
PerceptionModuleManifest, PerceptionModuleInput, PerceptionModuleResult, PerceptionModuleEvent,
|
|
61
|
+
PerceptionModuleManifest, PerceptionModuleInput, PerceptionModuleResult, PerceptionModuleEvent, PerceptionModuleApi,
|
|
62
|
+
ClawclawReactionManifest, ReactionBehaviorBinding, ReactionActivation, ReactionInput, ReactionResult,
|
|
61
63
|
ClawclawPerceptionClass, ClawclawPerceptionEventMetadata,
|
|
62
64
|
ClawclawPerceptionManifest, Direction, PerceptionAnalysisInput,
|
|
63
65
|
PerceptionApi, PerceptionBoundary, PerceptionBoundaryKind,
|
|
@@ -65,6 +67,7 @@ export type {
|
|
|
65
67
|
PerceptionSpatialApi, PerceptionSubjectScope, Vec,
|
|
66
68
|
} from './perception-plugin/index.js';
|
|
67
69
|
export {
|
|
70
|
+
ClawclawReaction,
|
|
68
71
|
ClawclawParallelPerception,
|
|
69
72
|
ClawclawPerception,
|
|
70
73
|
MOVE_MIN_PX,
|
|
@@ -93,3 +96,41 @@ export type {
|
|
|
93
96
|
MapRoom, GameResult,
|
|
94
97
|
WsConnectionState, ActionErrorCode,
|
|
95
98
|
} from './types.js';
|
|
99
|
+
|
|
100
|
+
export { ClawclawStrategy, STRATEGY_PLUGIN_API_VERSION } from './strategy-plugin/index.js';
|
|
101
|
+
export type {
|
|
102
|
+
StrategyActivationLayer,
|
|
103
|
+
StrategyBooleanInputField,
|
|
104
|
+
StrategyContinuation,
|
|
105
|
+
StrategyDecide,
|
|
106
|
+
StrategyDecision,
|
|
107
|
+
StrategyDecisionAction,
|
|
108
|
+
StrategyDecisionFrame,
|
|
109
|
+
StrategyDecisionFrameStatus,
|
|
110
|
+
StrategyDelegatedStrategyResult,
|
|
111
|
+
StrategyDelegation,
|
|
112
|
+
StrategyEnumInputField,
|
|
113
|
+
StrategyEventProposal,
|
|
114
|
+
StrategyExecution,
|
|
115
|
+
StrategyFinish,
|
|
116
|
+
StrategyInput,
|
|
117
|
+
StrategyInputFieldSpec,
|
|
118
|
+
StrategyNormalizationApi,
|
|
119
|
+
StrategyNumberInputField,
|
|
120
|
+
StrategyPathQuery,
|
|
121
|
+
StrategyPlayerSeatInputField,
|
|
122
|
+
StrategyPlayerSeatsInputField,
|
|
123
|
+
StrategyReadApi,
|
|
124
|
+
StrategyRuntimeDefaults,
|
|
125
|
+
StrategyScope,
|
|
126
|
+
StrategyStateMode,
|
|
127
|
+
StrategyStatus,
|
|
128
|
+
StrategyStringInputField,
|
|
129
|
+
StrategyStringListInputField,
|
|
130
|
+
StrategyTiming,
|
|
131
|
+
ClawclawStrategyClass,
|
|
132
|
+
ClawclawStrategyManifest,
|
|
133
|
+
FiniteStrategyDecision,
|
|
134
|
+
} from './strategy-plugin/index.js';
|
|
135
|
+
|
|
136
|
+
export type { PerceptionStrategyBinding, PerceptionStrategyActivation } from './perception-plugin/module.js';
|
|
@@ -288,6 +288,8 @@ export interface BehaviorDecisionFrame {
|
|
|
288
288
|
export interface BehaviorInput<
|
|
289
289
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
290
290
|
> {
|
|
291
|
+
/** Local cadence metadata; backend tick and observation age remain authoritative. */
|
|
292
|
+
readonly cycle?: ProcessingCycleInfo;
|
|
291
293
|
readonly epochId: number;
|
|
292
294
|
readonly scope: Readonly<BehaviorScope>;
|
|
293
295
|
/** Runtime-observed time for this accepted input, suitable for deterministic logic. */
|
|
@@ -303,3 +305,6 @@ export interface BehaviorInput<
|
|
|
303
305
|
/** Present for the first committed decision after delegated short work ends. */
|
|
304
306
|
readonly continuation?: Readonly<BehaviorContinuation>;
|
|
305
307
|
}
|
|
308
|
+
/** Local call timing and the provenance of the latest backend observation; not a State-history API. */
|
|
309
|
+
export type ProcessingCycleInfo = Readonly<Pick<import('../../runtime/framework/plugins/contracts.js').RuntimeCycleInfo,
|
|
310
|
+
'id' | 'intervalMs' | 'nowMs' | 'hasNewState' | 'stateVersion' | 'stateReceivedAtMs' | 'stateAgeMs' | 'connectionState'>>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** Frozen API v2 compatibility version; new modules use PERCEPTION_MODULE_API_VERSION (3). */
|
|
2
2
|
export const PERCEPTION_PLUGIN_API_VERSION = 2 as const;
|
|
3
3
|
export * from './module.js';
|
|
4
|
-
import
|
|
4
|
+
import { Perception } from '@myclaw163/game-agent-runtime/sdk/perception.js';
|
|
5
|
+
import type { PerceptionModuleManifest, PerceptionModuleInput, PerceptionModuleResult, PerceptionModuleApi } from './module.js';
|
|
6
|
+
export { ClawclawReaction } from './reaction.js';
|
|
7
|
+
export type { ClawclawReactionManifest, ReactionBehaviorBinding, ReactionActivation, ReactionInput, ReactionResult, ReactionEvent, ReactionFact } from './reaction.js';
|
|
5
8
|
export * from './reminder.js';
|
|
6
|
-
export * from './reaction.js';
|
|
7
9
|
import { defaultReminder } from './reminder-rules.js';
|
|
8
10
|
import type { ReminderInput, ReminderResult, ReminderTopic } from './reminder.js';
|
|
9
11
|
/** Optional task/speech helper accepts both the unified input and its v2 compatibility input. */
|
|
@@ -121,8 +123,9 @@ export interface PerceptionEventProposal {
|
|
|
121
123
|
/** Whether this Event may initiate Agent delivery; omitted means true. */
|
|
122
124
|
readonly wakeAgent?: boolean;
|
|
123
125
|
readonly type: string;
|
|
124
|
-
/** Stable
|
|
126
|
+
/** Stable semantic key for replaying the same epoch/output; not cross-frame suppression. */
|
|
125
127
|
readonly dedupeKey: string;
|
|
128
|
+
/** Identity namespace; epoch and output position still participate in event identity. */
|
|
126
129
|
readonly dedupeScope?: 'segment' | 'session';
|
|
127
130
|
readonly payload: Readonly<Record<string, unknown>>;
|
|
128
131
|
readonly occurredAt?: string;
|
|
@@ -167,11 +170,11 @@ export interface ClawclawPerceptionManifest {
|
|
|
167
170
|
* retains its original persistent reducer semantics on the compatibility path.
|
|
168
171
|
* A slow call can be terminated without blocking the Runtime Owner.
|
|
169
172
|
*/
|
|
170
|
-
export abstract class ClawclawPerception {
|
|
173
|
+
export abstract class ClawclawPerception extends Perception<PerceptionModuleInput, PerceptionModuleApi, PerceptionModuleResult> {
|
|
171
174
|
static readonly manifest?: ClawclawPerceptionManifest | PerceptionModuleManifest;
|
|
172
175
|
|
|
173
176
|
/** API v3 combines observation, notification and fixed Behavior activation. */
|
|
174
|
-
evaluate(_input: Readonly<PerceptionModuleInput
|
|
177
|
+
evaluate(_input: Readonly<PerceptionModuleInput>, _api?: PerceptionModuleApi): PerceptionModuleResult | Promise<PerceptionModuleResult> {
|
|
175
178
|
throw new Error('PERCEPTION_EVALUATE_NOT_IMPLEMENTED');
|
|
176
179
|
}
|
|
177
180
|
|
|
@@ -244,3 +247,4 @@ export interface ClawclawPerceptionClass {
|
|
|
244
247
|
readonly manifest?: ClawclawPerceptionManifest;
|
|
245
248
|
new(): ClawclawPerception;
|
|
246
249
|
}
|
|
250
|
+
export type { ProcessingCycleInfo } from '../module-input/index.js';
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { GameState, ObservationFrame } from '../module-input/index.js';
|
|
2
2
|
import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js';
|
|
3
3
|
import type { ClawclawResourceLocalizations } from '../resource-metadata.js';
|
|
4
|
-
import type { ReactionBehaviorBinding, ReactionActivation } from './reaction.js';
|
|
5
4
|
import type { ReminderFact, ReminderTaskChange } from './reminder.js';
|
|
5
|
+
import type { ReactionActivation, ReactionBehaviorBinding } from './reaction.js';
|
|
6
|
+
import type { StrategyMemory } from '../strategy-memory.js';
|
|
6
7
|
|
|
7
|
-
/** Unified
|
|
8
|
+
/** Unified perception contract with optional fixed Reflex bindings. */
|
|
8
9
|
export const PERCEPTION_MODULE_API_VERSION = 3 as const;
|
|
10
|
+
export type PerceptionStrategyBinding = ReactionBehaviorBinding;
|
|
11
|
+
export interface PerceptionStrategyActivation {
|
|
12
|
+
readonly strategy: string;
|
|
13
|
+
readonly input?: Readonly<Record<string, unknown>>;
|
|
14
|
+
readonly reason?: string;
|
|
15
|
+
}
|
|
9
16
|
export interface PerceptionModuleManifest {
|
|
10
17
|
readonly apiVersion: typeof PERCEPTION_MODULE_API_VERSION;
|
|
11
18
|
readonly id: string;
|
|
@@ -14,23 +21,34 @@ export interface PerceptionModuleManifest {
|
|
|
14
21
|
readonly localizations?: ClawclawResourceLocalizations;
|
|
15
22
|
readonly consumes?: readonly string[];
|
|
16
23
|
readonly produces?: readonly string[];
|
|
17
|
-
readonly behaviors?: Readonly<Record<string, ReactionBehaviorBinding>>;
|
|
18
24
|
readonly inputs?: readonly BehaviorInputFieldSpec[];
|
|
19
25
|
readonly config?: Readonly<Record<string, unknown>>;
|
|
26
|
+
readonly strategies?: Readonly<Record<string, PerceptionStrategyBinding>>;
|
|
27
|
+
readonly behaviors?: Readonly<Record<string, ReactionBehaviorBinding>>;
|
|
20
28
|
}
|
|
21
29
|
export interface PerceptionModuleInput {
|
|
30
|
+
readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo;
|
|
22
31
|
readonly moduleId: string;
|
|
23
32
|
readonly scope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
24
33
|
readonly gameState: Readonly<GameState> | null;
|
|
25
34
|
readonly frame: Readonly<ObservationFrame> | null;
|
|
26
|
-
/** Source/backend
|
|
35
|
+
/** Original Source/backend facts only; never another perception's output or a forwarded copy. */
|
|
27
36
|
readonly events: readonly Readonly<ReminderFact>[];
|
|
37
|
+
/** Compared independently against this module's own durable task baseline. */
|
|
28
38
|
readonly taskChanges: readonly ReminderTaskChange[];
|
|
29
39
|
readonly boundary: 'initial' | 'recovery' | null;
|
|
30
40
|
readonly nowMs: number;
|
|
31
41
|
readonly config: Readonly<Record<string, unknown>>;
|
|
32
42
|
readonly state: unknown;
|
|
33
|
-
|
|
43
|
+
/** Equipped, loadable dependencies; independent of the automatic-activation switch. */
|
|
44
|
+
readonly availableBindings?: readonly string[];
|
|
45
|
+
readonly availableBehaviors?: readonly string[];
|
|
46
|
+
readonly availableStrategies?: readonly string[];
|
|
47
|
+
readonly enabledBindings?: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
export interface PerceptionModuleApi {
|
|
50
|
+
/** Shared with a unique explicitly bound strategy; otherwise module-private. */
|
|
51
|
+
readonly memory: StrategyMemory;
|
|
34
52
|
}
|
|
35
53
|
export interface PerceptionModuleEvent {
|
|
36
54
|
readonly type: string;
|
|
@@ -42,5 +60,6 @@ export interface PerceptionModuleEvent {
|
|
|
42
60
|
export interface PerceptionModuleResult {
|
|
43
61
|
readonly state?: unknown;
|
|
44
62
|
readonly events?: readonly PerceptionModuleEvent[];
|
|
45
|
-
|
|
63
|
+
/** Keys in manifest.behaviors; never arbitrary strategy names or executable Actions. */
|
|
64
|
+
readonly activations?: readonly (PerceptionStrategyActivation | ReactionActivation)[];
|
|
46
65
|
}
|
|
@@ -7,7 +7,7 @@ export interface ReactionBehaviorBinding {
|
|
|
7
7
|
readonly name: string;
|
|
8
8
|
/** Preferred Hub identity. A missing match falls back to name and its duplicate aliases. */
|
|
9
9
|
readonly resourceId?: string;
|
|
10
|
-
readonly layer?: 'reflex'
|
|
10
|
+
readonly layer?: 'reflex';
|
|
11
11
|
readonly input?: Readonly<Record<string, unknown>>;
|
|
12
12
|
readonly reflexPriority?: number;
|
|
13
13
|
readonly cooldownMs?: number;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { ReminderInput, ReminderMode, ReminderResult, ReminderTopic,
|
|
1
|
+
import type { ReminderInput, ReminderMode, ReminderResult, ReminderTopic, ReminderEvent } from './reminder.js';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
'ability.ready', 'ability.remaining_uses_changed', 'ability.exhausted', 'tasks_changed',
|
|
3
|
+
export const TASK_LIFECYCLE_FACT_TYPES = [
|
|
5
4
|
'task_started', 'task_progress', 'task_assigned', 'task_completed', 'task_interrupted', 'task_sabotaged',
|
|
5
|
+
] as const;
|
|
6
|
+
export const TASK_REMINDER_FACT_TYPES = [
|
|
7
|
+
...TASK_LIFECYCLE_FACT_TYPES,
|
|
6
8
|
'role_assigned', 'emergency_started', 'emergency_resolved', 'emergency_interrupted', 'meeting_briefing',
|
|
7
9
|
] as const;
|
|
8
10
|
export const REMINDER_FACT_TYPES_BY_TOPIC = {
|
|
@@ -18,6 +20,7 @@ export function isReminderMode(value: unknown): value is ReminderMode {
|
|
|
18
20
|
}
|
|
19
21
|
export function defaultConfig(topic: ReminderTopic): Record<string, ReminderMode> {
|
|
20
22
|
if (topic !== 'tasks') throw new Error('Unsupported reminder topic; countdown and ability notifications are owned by CCL.');
|
|
23
|
+
// removed/updated remain accepted for existing installed v2 configs; this helper does not emit them.
|
|
21
24
|
return { started: 'state_only', progress: 'state_only', added: 'silent', completed: 'silent',
|
|
22
25
|
interrupted: 'wake', sabotaged: 'wake', removed: 'silent', updated: 'silent' };
|
|
23
26
|
}
|
|
@@ -36,37 +39,6 @@ const labels: Record<string, string> = { started: '开始任务', progress: '任
|
|
|
36
39
|
function record(value: unknown): Record<string, unknown> {
|
|
37
40
|
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
|
38
41
|
}
|
|
39
|
-
function ownFact(fact: ReminderFact, input: ReminderInput): boolean {
|
|
40
|
-
const actor = record(fact.payload.actor);
|
|
41
|
-
const seat = actor.seat ?? fact.payload.actor_seat;
|
|
42
|
-
const name = actor.name ?? fact.payload.actor_name;
|
|
43
|
-
const self = input.gameState?.you?.player;
|
|
44
|
-
if (seat !== undefined && self?.seat !== undefined) return seat === self.seat;
|
|
45
|
-
if (name !== undefined && self?.name !== undefined) return name === self.name;
|
|
46
|
-
return seat === undefined && name === undefined;
|
|
47
|
-
}
|
|
48
|
-
function matches(fact: ReminderFact, change: ReminderTaskChange, input: ReminderInput): boolean {
|
|
49
|
-
if (fact.epochId !== change.epochId || (fact.type.startsWith('task_') && !ownFact(fact, input))) return false;
|
|
50
|
-
const p = fact.payload;
|
|
51
|
-
if (p.task_id && change.task.task_id) return p.task_id === change.task.task_id;
|
|
52
|
-
const name = p.task_name;
|
|
53
|
-
if (!name || name !== change.task.name) return false;
|
|
54
|
-
if (p.room && change.task.room && p.room !== change.task.room) return false;
|
|
55
|
-
// Without IDs, only correlate an unambiguous task in this physical frame.
|
|
56
|
-
return input.taskChanges.filter(c => c.epochId === change.epochId && c.task.name === name
|
|
57
|
-
&& (!p.room || !c.task.room || c.task.room === p.room)).length === 1;
|
|
58
|
-
}
|
|
59
|
-
function explained(fact: ReminderFact, change: ReminderTaskChange, input: ReminderInput): boolean {
|
|
60
|
-
if (!matches(fact, change, input)) return false;
|
|
61
|
-
if (change.change === 'added') return fact.type === 'task_assigned' || fact.type === 'emergency_started';
|
|
62
|
-
if (change.change === 'removed') return ['task_completed', 'task_sabotaged', 'emergency_resolved', 'emergency_interrupted'].includes(fact.type);
|
|
63
|
-
if (change.change === 'status_changed') {
|
|
64
|
-
if (change.to_status === 'completed') return ['task_completed', 'task_sabotaged'].includes(fact.type);
|
|
65
|
-
if (change.to_status === 'in_progress') return fact.type === 'task_started';
|
|
66
|
-
if (change.from_status === 'in_progress' && change.to_status === 'normal') return fact.type === 'task_interrupted';
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
42
|
/** Nearby speech is a backend fact; only its Agent notification is optional. */
|
|
71
43
|
export function speechReminder(input: ReminderInput): ReminderResult {
|
|
72
44
|
if (Object.keys(input.config).some(key => key !== 'receive')
|
|
@@ -111,13 +83,7 @@ export function defaultReminder(topic: ReminderTopic, input: ReminderInput): Rem
|
|
|
111
83
|
const kind = kinds[fact.type];
|
|
112
84
|
if (kind) emit(kind, `fact:${fact.eventId}`, { ...fact.payload }, fact.eventId);
|
|
113
85
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const kind = change.change === 'added' ? 'added' : change.change === 'removed' ? 'removed'
|
|
117
|
-
: change.change === 'status_changed' && change.to_status === 'in_progress' ? 'started'
|
|
118
|
-
: change.change === 'status_changed' && change.to_status === 'completed' ? 'completed' : 'updated';
|
|
119
|
-
emit(kind, change.key, { ...change.task, change: change.change,
|
|
120
|
-
from_status: change.from_status, to_status: change.to_status }, change.eventId);
|
|
121
|
-
}
|
|
86
|
+
// Task lifecycle facts belong to this helper. State-only list changes stay
|
|
87
|
+
// available as input; emergency lifecycle notifications belong to emergency perception.
|
|
122
88
|
return { events };
|
|
123
89
|
}
|
|
@@ -22,11 +22,12 @@ export interface ReminderTaskChange {
|
|
|
22
22
|
readonly baseline: boolean;
|
|
23
23
|
}
|
|
24
24
|
export interface ReminderInput {
|
|
25
|
+
readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo;
|
|
25
26
|
readonly scope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
26
27
|
readonly frame: Readonly<ObservationFrame> | null;
|
|
27
28
|
readonly gameState: Readonly<GameState> | null;
|
|
28
29
|
readonly facts: readonly Readonly<ReminderFact>[];
|
|
29
|
-
/**
|
|
30
|
+
/** Module-local comparison of consecutive task snapshots; no cross-perception dependency. */
|
|
30
31
|
readonly taskChanges: readonly ReminderTaskChange[];
|
|
31
32
|
/** Establish private baselines without replaying notifications. */
|
|
32
33
|
readonly boundary: 'initial' | 'recovery' | null;
|
package/src/{runtime/clawclaw/plugins/source → sdk/perception-plugin}/task-change-tracker.ts
RENAMED
|
@@ -208,8 +208,7 @@ function updateReason(
|
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
210
|
* Diff the authoritative task list carried by one complete GameSync State.
|
|
211
|
-
*
|
|
212
|
-
* Reminder scripts own Agent-facing task notifications.
|
|
211
|
+
* Each perception owns its comparison baseline. This pure helper publishes no shared Event.
|
|
213
212
|
*/
|
|
214
213
|
export function nextTaskProjection(input: {
|
|
215
214
|
previous: readonly TaskSnapshot[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@myclaw163/game-agent-runtime/memory/contracts.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Public strategy authoring API; both import paths use the same runtime base. */
|
|
2
|
+
export * from '../behavior-plugin/index.js';
|
|
3
|
+
export { ClawclawBehavior as ClawclawStrategy, BEHAVIOR_PLUGIN_API_VERSION as STRATEGY_PLUGIN_API_VERSION } from '../behavior-plugin/index.js';
|
|
4
|
+
export type {
|
|
5
|
+
BehaviorActivationLayer as StrategyActivationLayer,
|
|
6
|
+
BehaviorBooleanInputField as StrategyBooleanInputField,
|
|
7
|
+
BehaviorContinuation as StrategyContinuation,
|
|
8
|
+
BehaviorDecide as StrategyDecide,
|
|
9
|
+
BehaviorDecision as StrategyDecision,
|
|
10
|
+
BehaviorDecisionAction as StrategyDecisionAction,
|
|
11
|
+
BehaviorDecisionFrame as StrategyDecisionFrame,
|
|
12
|
+
BehaviorDecisionFrameStatus as StrategyDecisionFrameStatus,
|
|
13
|
+
BehaviorDelegatedBehaviorResult as StrategyDelegatedStrategyResult,
|
|
14
|
+
BehaviorEnumInputField as StrategyEnumInputField,
|
|
15
|
+
BehaviorEventProposal as StrategyEventProposal,
|
|
16
|
+
BehaviorExecution as StrategyExecution,
|
|
17
|
+
BehaviorFinish as StrategyFinish,
|
|
18
|
+
BehaviorInput as StrategyInput,
|
|
19
|
+
BehaviorInputFieldSpec as StrategyInputFieldSpec,
|
|
20
|
+
BehaviorNormalizationApi as StrategyNormalizationApi,
|
|
21
|
+
BehaviorNumberInputField as StrategyNumberInputField,
|
|
22
|
+
BehaviorPathQuery as StrategyPathQuery,
|
|
23
|
+
BehaviorPlayerSeatInputField as StrategyPlayerSeatInputField,
|
|
24
|
+
BehaviorPlayerSeatsInputField as StrategyPlayerSeatsInputField,
|
|
25
|
+
BehaviorReadApi as StrategyReadApi,
|
|
26
|
+
BehaviorRuntimeDefaults as StrategyRuntimeDefaults,
|
|
27
|
+
BehaviorScope as StrategyScope,
|
|
28
|
+
BehaviorStateMode as StrategyStateMode,
|
|
29
|
+
BehaviorStatus as StrategyStatus,
|
|
30
|
+
BehaviorStringInputField as StrategyStringInputField,
|
|
31
|
+
BehaviorStringListInputField as StrategyStringListInputField,
|
|
32
|
+
BehaviorTiming as StrategyTiming,
|
|
33
|
+
ClawclawBehaviorClass as ClawclawStrategyClass,
|
|
34
|
+
ClawclawBehaviorManifest as ClawclawStrategyManifest,
|
|
35
|
+
FiniteBehaviorDecision as FiniteStrategyDecision,
|
|
36
|
+
} from '../behavior-plugin/index.js';
|
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
BehaviorInputFieldSpec,
|
|
3
3
|
BehaviorReadApi,
|
|
4
4
|
} from '../behavior-plugin/index.js';
|
|
5
|
+
export type { StrategyMemory, StrategyMemoryValue } from '../strategy-memory.js';
|
|
5
6
|
import type {
|
|
6
7
|
GameEvent,
|
|
7
8
|
ObservationFrame,
|
|
@@ -79,6 +80,7 @@ export interface ClawclawTriggerManifest {
|
|
|
79
80
|
export interface TriggerInput<
|
|
80
81
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
81
82
|
> {
|
|
83
|
+
readonly cycle?: import('../module-input/index.js').ProcessingCycleInfo;
|
|
82
84
|
readonly frame: Readonly<ObservationFrame>;
|
|
83
85
|
readonly events: readonly Readonly<GameEvent>[];
|
|
84
86
|
readonly input: Readonly<TInput>;
|
|
@@ -90,7 +92,7 @@ export type TriggerResetReason =
|
|
|
90
92
|
| 'segment_ending'
|
|
91
93
|
| 'shutdown';
|
|
92
94
|
|
|
93
|
-
/**
|
|
95
|
+
/** Read-only game queries plus private memory shared with the same resource's Behavior. */
|
|
94
96
|
export type TriggerReadApi = BehaviorReadApi;
|
|
95
97
|
|
|
96
98
|
/**
|
|
@@ -105,8 +107,7 @@ export interface TriggerMatch {
|
|
|
105
107
|
readonly behaviorInput?: Readonly<Record<string, unknown>>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
/** Public authoring surface for one
|
|
109
|
-
/** @deprecated Compatibility API; may be unsupported in a future release. Use unified Perception API v3 for new rules. */
|
|
110
|
+
/** Public authoring surface for one rule; game writes remain Behavior Actions. */
|
|
110
111
|
export abstract class ClawclawTrigger<
|
|
111
112
|
TInput extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>,
|
|
112
113
|
> {
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawReaction,
|
|
3
|
-
type ReactionInput,
|
|
4
|
-
type ReactionResult,
|
|
5
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
6
|
-
|
|
7
|
-
// 教学规则:靠近不代表敌意;撤离点需先在当前地图中验证。
|
|
8
|
-
export default class NearbyEscape extends ClawclawReaction {
|
|
9
|
-
static readonly manifest = {
|
|
10
|
-
apiVersion: 2,
|
|
11
|
-
kind: 'reaction',
|
|
12
|
-
id: 'nearby_escape',
|
|
13
|
-
description: '可见玩家靠近时记录通知,并请求前往已配置的撤离点。',
|
|
14
|
-
consumes: [],
|
|
15
|
-
produces: ['reaction.player_close'],
|
|
16
|
-
behaviors: {
|
|
17
|
-
escape: {
|
|
18
|
-
name: 'community.go-to-point',
|
|
19
|
-
layer: 'reflex',
|
|
20
|
-
reflexPriority: 10,
|
|
21
|
-
cooldownMs: 3000,
|
|
22
|
-
rearm: 'after_clear',
|
|
23
|
-
maxRuntimeMs: 10000,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
inputs: [
|
|
27
|
-
{ id: 'distance', type: 'number', description: '靠近阈值,单位像素。', default: 160 },
|
|
28
|
-
{ id: 'retreatX', type: 'number', description: '撤离点 X 坐标。', default: 640 },
|
|
29
|
-
{ id: 'retreatY', type: 'number', description: '撤离点 Y 坐标。', default: 360 },
|
|
30
|
-
],
|
|
31
|
-
config: { distance: 160, retreatX: 640, retreatY: 360 },
|
|
32
|
-
} as const;
|
|
33
|
-
|
|
34
|
-
evaluate(input: Readonly<ReactionInput>): ReactionResult {
|
|
35
|
-
const previous = input.state as { close?: boolean } | undefined;
|
|
36
|
-
const players = input.frame?.observation.players ?? [];
|
|
37
|
-
const self = players.find(player => player.observer);
|
|
38
|
-
const close = input.gameState?.phase === 'wandering' && input.gameState.you?.is_alive === true
|
|
39
|
-
&& !!self && players.some(player => !player.observer && player.alive !== false
|
|
40
|
-
&& Math.hypot(player.x - self.x, player.y - self.y) < Number(input.config.distance));
|
|
41
|
-
return {
|
|
42
|
-
state: { close },
|
|
43
|
-
events: close && !previous?.close ? [{
|
|
44
|
-
type: 'reaction.player_close',
|
|
45
|
-
key: `close:${input.gameState!.tick}`,
|
|
46
|
-
wakeAgent: false,
|
|
47
|
-
payload: { text: '有可见玩家靠近,触发撤离规则。' },
|
|
48
|
-
}] : [],
|
|
49
|
-
activations: close ? [{
|
|
50
|
-
behavior: 'escape',
|
|
51
|
-
input: { x: Number(input.config.retreatX), y: Number(input.config.retreatY) },
|
|
52
|
-
reason: 'visible_player_close',
|
|
53
|
-
}] : [],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawReaction,
|
|
3
|
-
type ReactionInput,
|
|
4
|
-
type ReactionResult,
|
|
5
|
-
} from '@myclaw163/clawclaw-cli/perception-plugin';
|
|
6
|
-
|
|
7
|
-
export default class NearbyNotice extends ClawclawReaction {
|
|
8
|
-
static readonly manifest = {
|
|
9
|
-
apiVersion: 2,
|
|
10
|
-
kind: 'reaction',
|
|
11
|
-
id: 'nearby_notice',
|
|
12
|
-
description: '其他可见玩家靠近时记录一条通知。',
|
|
13
|
-
consumes: [],
|
|
14
|
-
produces: ['reaction.player_close'],
|
|
15
|
-
inputs: [{ id: 'distance', type: 'number', description: '靠近阈值,单位像素。', default: 160 }],
|
|
16
|
-
config: { distance: 160 },
|
|
17
|
-
} as const;
|
|
18
|
-
|
|
19
|
-
evaluate(input: Readonly<ReactionInput>): ReactionResult {
|
|
20
|
-
const previous = input.state as { close?: boolean } | undefined;
|
|
21
|
-
const players = input.frame?.observation.players ?? [];
|
|
22
|
-
const self = players.find(player => player.observer);
|
|
23
|
-
const close = input.gameState?.phase === 'wandering' && input.gameState.you?.is_alive === true
|
|
24
|
-
&& !!self && players.some(player => !player.observer && player.alive !== false
|
|
25
|
-
&& Math.hypot(player.x - self.x, player.y - self.y) < Number(input.config.distance));
|
|
26
|
-
return {
|
|
27
|
-
state: { close },
|
|
28
|
-
events: close && !previous?.close ? [{
|
|
29
|
-
type: 'reaction.player_close',
|
|
30
|
-
key: `close:${input.gameState!.tick}`,
|
|
31
|
-
wakeAgent: false,
|
|
32
|
-
payload: { text: '有其他可见玩家靠近。' },
|
|
33
|
-
}] : [],
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|