@myclaw163/clawclaw-cli 0.9.2 → 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 +23 -35
- package/docs/custom-modules/api-reference.md +95 -273
- package/docs/custom-modules/behavior.md +94 -78
- package/docs/custom-modules/examples/auto-escape.ts +5 -5
- package/docs/custom-modules/examples/go-to-point.ts +11 -11
- package/docs/custom-modules/examples/nearby-reflex.ts +2 -2
- package/docs/custom-modules/examples/task-reminder.ts +4 -5
- package/docs/custom-modules/perception.md +42 -603
- package/docs/custom-modules/skill.md +1 -1
- package/docs/desktop-event-push.md +3 -3
- package/docs/runtime/README.md +16 -17
- package/docs/runtime/agent-notifications.md +31 -12
- package/docs/runtime/behavior-runtime.md +47 -46
- package/docs/runtime/components-and-boundaries.md +70 -28
- package/docs/runtime/events-and-state.md +41 -18
- 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 +10 -7
- package/docs/user-guide/api-reference.md +81 -164
- package/docs/user-guide/behavior.md +84 -68
- package/docs/user-guide/installation.md +7 -7
- package/docs/user-guide/perception.md +42 -586
- 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 +8 -13
- package/scripts/install-local-runtime.mjs +35 -0
- package/scripts/qa-install.mjs +105 -0
- package/skills/clawclaw/SKILL.md +49 -49
- package/skills/clawclaw/references/BEHAVIORS.md +42 -73
- package/skills/clawclaw/references/CHANNELS.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +60 -101
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +94 -78
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +95 -180
- package/skills/clawclaw/references/CUSTOM-MODULES.md +24 -24
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +42 -608
- 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 +26 -10
- package/src/commands/capability.ts +3 -3
- package/src/commands/load.ts +3 -2
- package/src/commands/perception.ts +5 -0
- package/src/commands/strategy.ts +2 -0
- 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/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 +18 -4
- package/src/runtime/clawclaw/perception-module-manifest.ts +8 -3
- 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 +7 -9
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -495
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -190
- package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1779
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -276
- 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 -972
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +8 -109
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +2 -2
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +25 -17
- package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
- package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +3 -3
- package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -259
- 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 +119 -297
- package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +7 -56
- package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +11 -33
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +18 -7
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +12 -6
- package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +6 -0
- 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/trigger-plugin.ts +8 -3
- package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
- 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 +11 -0
- package/src/runtime/clawclaw/runtime.ts +8 -0
- package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -63
- package/src/runtime/clawclaw/strategy-memory.ts +1 -77
- package/src/runtime/clawclaw-event-catalog.ts +12 -12
- 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 -396
- 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 -2071
- 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 -320
- package/src/runtime/parent-process-watch.ts +1 -51
- package/src/runtime/process-identity.ts +1 -72
- package/src/sdk/behavior-plugin/index.ts +9 -3
- package/src/sdk/index.ts +40 -2
- package/src/sdk/module-input/index.ts +5 -0
- package/src/sdk/perception-plugin/index.ts +3 -1
- package/src/sdk/perception-plugin/module.ts +12 -2
- package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
- package/src/sdk/perception-plugin/reminder.ts +2 -1
- package/src/sdk/perception-plugin/task-change-tracker.ts +258 -0
- package/src/sdk/strategy-memory.ts +1 -12
- package/src/sdk/strategy-plugin/index.ts +36 -0
- package/src/sdk/trigger-plugin/index.ts +1 -0
- package/docs/custom-modules/trigger.md +0 -295
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { projectTaskChoiceGameState } from './task-choice-projection.js';
|
|
2
|
+
import type { RuntimeCycleInfo } from '../framework/plugins/contracts.js';
|
|
2
3
|
|
|
3
4
|
export type ClawclawRuntimeStage =
|
|
4
5
|
| 'matching'
|
|
@@ -17,6 +18,7 @@ export type ClawclawRuntimeCause =
|
|
|
17
18
|
| 'matching_poll'
|
|
18
19
|
| 'room_update'
|
|
19
20
|
| 'game_snapshot'
|
|
21
|
+
| 'processing_cycle'
|
|
20
22
|
| 'backend_event'
|
|
21
23
|
| 'agent_events_query'
|
|
22
24
|
| 'control'
|
|
@@ -26,11 +28,13 @@ export type ClawclawRuntimeCause =
|
|
|
26
28
|
|
|
27
29
|
export type ClawclawGameSnapshot =
|
|
28
30
|
| { status: 'fresh'; state: Record<string, any>; origin?: 'snapshot' | 'update' | 'resume' }
|
|
31
|
+
| { status: 'cached'; state: Record<string, any>; origin?: 'snapshot' | 'update' | 'resume' }
|
|
29
32
|
| { status: 'not_updated' }
|
|
30
33
|
| { status: 'unavailable' };
|
|
31
34
|
|
|
32
35
|
export interface ClawclawRuntimeState {
|
|
33
36
|
schema: 'clawclaw.runtime-state.v1';
|
|
37
|
+
cycle?: Readonly<RuntimeCycleInfo>;
|
|
34
38
|
/** Internal monotonic token for Action-safety transitions; not Agent State. */
|
|
35
39
|
action_safety_generation?: number;
|
|
36
40
|
stage: ClawclawRuntimeStage;
|
|
@@ -98,3 +102,10 @@ export function freshClawclawGameState(
|
|
|
98
102
|
? state.game_snapshot.state
|
|
99
103
|
: null;
|
|
100
104
|
}
|
|
105
|
+
|
|
106
|
+
/** Available computation input; cached observations retain their real receipt time in cycle. */
|
|
107
|
+
export function clawclawComputationGameState(state: Record<string, any>): Record<string, any> | null {
|
|
108
|
+
if (!isClawclawRuntimeState(state)) return state;
|
|
109
|
+
return state.game_snapshot.status === 'fresh' || state.game_snapshot.status === 'cached'
|
|
110
|
+
? state.game_snapshot.state : null;
|
|
111
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { actionFailureDiagnosticSeverity } from '../framework/action-diagnostics.js';
|
|
2
|
+
import { clawclawNotificationFollowUp } from './notification-turn.js';
|
|
1
3
|
import type { AuthProfile } from '../../lib/auth.js';
|
|
2
4
|
import {
|
|
3
5
|
getProfileEventLedgerPath,
|
|
@@ -25,6 +27,7 @@ import {
|
|
|
25
27
|
CLAWCLAW_ROOM_WS_SOURCE,
|
|
26
28
|
} from './plugins/source/source-transports.js';
|
|
27
29
|
import { projectClawclawCurrentState } from './runtime-state.js';
|
|
30
|
+
import { createClawclawNotificationPolicy } from './notification-policy.js';
|
|
28
31
|
|
|
29
32
|
export const CLAWCLAW_ADAPTER_ID = 'clawclaw';
|
|
30
33
|
export const CLAWCLAW_GAME_LIVENESS_SILENCE_MS = 35_000;
|
|
@@ -41,6 +44,8 @@ export type ClawclawRuntimeOptions = Omit<
|
|
|
41
44
|
| 'inputJournalPath'
|
|
42
45
|
| 'historyObserverFactory'
|
|
43
46
|
| 'currentStateFromRuntimeState'
|
|
47
|
+
| 'notificationPolicy'
|
|
48
|
+
| 'followUpInput'
|
|
44
49
|
> & {
|
|
45
50
|
/** Tests and embedded hosts may replace or disable the durable current-State cache. */
|
|
46
51
|
durableStateSnapshot?: AtomicJsonAgentStateSnapshotStore<Record<string, any>> | false;
|
|
@@ -141,8 +146,11 @@ export function createClawclawRuntime(
|
|
|
141
146
|
|
|
142
147
|
return new Runtime<ClawclawPosition>({
|
|
143
148
|
...runtimeOptions,
|
|
149
|
+
actionFailureSeverity: actionFailureDiagnosticSeverity,
|
|
144
150
|
adapterId: CLAWCLAW_ADAPTER_ID,
|
|
145
151
|
accountId: getRuntimeAccountId(profile),
|
|
152
|
+
followUpInput: clawclawNotificationFollowUp,
|
|
153
|
+
notificationPolicy: createClawclawNotificationPolicy(runtimeOptions.runtimeEpochPlugins ?? []),
|
|
146
154
|
eventCatalog: createClawclawEventCatalog({
|
|
147
155
|
visualEventDelivery,
|
|
148
156
|
visualEventTypes,
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { validateStrategyMemoryValue } from './strategy-memory.js';
|
|
3
|
-
|
|
4
|
-
export interface StrategyMemoryRequest {
|
|
5
|
-
readonly type: 'strategy_memory';
|
|
6
|
-
readonly requestId: string;
|
|
7
|
-
readonly memoryRequestId: number;
|
|
8
|
-
readonly operation: 'get' | 'set' | 'delete';
|
|
9
|
-
readonly key: string;
|
|
10
|
-
readonly value?: StrategyMemoryValue;
|
|
11
|
-
}
|
|
12
|
-
export const unavailableStrategyMemory: StrategyMemory = {
|
|
13
|
-
get: async () => { throw Error('strategy_memory_unavailable'); },
|
|
14
|
-
set: async () => { throw Error('strategy_memory_unavailable'); },
|
|
15
|
-
delete: async () => { throw Error('strategy_memory_unavailable'); },
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/** Replies are handled outside the computation queue, so an awaited memory call cannot deadlock it. */
|
|
19
|
-
export class StrategyMemoryRpcClient {
|
|
20
|
-
private sequence = 0;
|
|
21
|
-
private pending = new Map<number, { requestId: string; resolve: (value: any) => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }>();
|
|
22
|
-
constructor(private readonly send: (value: Readonly<Record<string, unknown>>) => void) {}
|
|
23
|
-
receive(message: any): boolean {
|
|
24
|
-
if (message?.type !== 'strategy_memory_result') return false;
|
|
25
|
-
const pending = this.pending.get(message.memoryRequestId);
|
|
26
|
-
if (!pending || pending.requestId !== message.requestId) return true;
|
|
27
|
-
this.pending.delete(message.memoryRequestId); clearTimeout(pending.timer);
|
|
28
|
-
if (message.error) pending.reject(Error(String(message.error))); else pending.resolve(message.value);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
bind(requestId: string, isActive: () => boolean): StrategyMemory {
|
|
32
|
-
const call = (operation: StrategyMemoryRequest['operation'], key: string, value?: StrategyMemoryValue): Promise<any> => {
|
|
33
|
-
if (!isActive()) return Promise.reject(Error('strategy_memory_inactive'));
|
|
34
|
-
if (this.pending.size >= 64) return Promise.reject(Error('strategy_memory_request_limit'));
|
|
35
|
-
if (operation === 'set') { try { validateStrategyMemoryValue(value); } catch (error) { return Promise.reject(error); } }
|
|
36
|
-
const memoryRequestId = ++this.sequence;
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
const timer = setTimeout(() => { this.pending.delete(memoryRequestId); reject(Error('strategy_memory_timeout')); }, 5000);
|
|
39
|
-
timer.unref?.(); this.pending.set(memoryRequestId, {requestId, resolve, reject, timer});
|
|
40
|
-
try { this.send({type: 'strategy_memory', requestId, memoryRequestId, operation, key, ...(operation === 'set' ? {value} : {})}); }
|
|
41
|
-
catch (error) { this.pending.delete(memoryRequestId); clearTimeout(timer); reject(error); }
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
return Object.freeze({ get: <T extends StrategyMemoryValue>(key: string) => call('get', key) as Promise<T | undefined>,
|
|
45
|
-
set: (key: string, value: StrategyMemoryValue) => call('set', key, value), delete: (key: string) => call('delete', key) });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** The parent supplies an already-bound capability; messages cannot choose another resource or scope. */
|
|
50
|
-
export async function serveStrategyMemoryRequest(message: StrategyMemoryRequest, binding: StrategyMemory | (() => StrategyMemory),
|
|
51
|
-
send: (value: Readonly<Record<string, unknown>>) => void): Promise<void> {
|
|
52
|
-
let value: unknown, error: string | undefined;
|
|
53
|
-
try {
|
|
54
|
-
const memory = typeof binding === 'function' ? binding() : binding;
|
|
55
|
-
if (!Number.isSafeInteger(message.memoryRequestId) || typeof message.key !== 'string') throw Error('strategy_memory_request_invalid');
|
|
56
|
-
if (message.operation === 'get') value = await memory.get(message.key);
|
|
57
|
-
else if (message.operation === 'set') await memory.set(message.key, message.value!);
|
|
58
|
-
else if (message.operation === 'delete') await memory.delete(message.key);
|
|
59
|
-
else throw Error('strategy_memory_request_invalid');
|
|
60
|
-
} catch (failure) { error = failure instanceof Error ? failure.message : 'strategy_memory_failed'; }
|
|
61
|
-
try { send({type: 'strategy_memory_result', requestId: message.requestId, memoryRequestId: message.memoryRequestId,
|
|
62
|
-
...(error ? {error} : {value})}); } catch { /* the requesting Worker may have stopped */ }
|
|
63
|
-
}
|
|
1
|
+
export * from '@myclaw163/game-agent-runtime/memory/strategy-memory-rpc.js';
|
|
@@ -1,77 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const STRATEGY_MEMORY_MAX_BYTES = 64 * 1024;
|
|
4
|
-
const MAX_KEYS = 256, MAX_SCOPE_BYTES = 4 * 1024 * 1024;
|
|
5
|
-
type Scope = Readonly<{ sessionId: string; segmentId: string }>;
|
|
6
|
-
interface Namespace { values: Map<string, { value: StrategyMemoryValue; bytes: number }>; bytes: number }
|
|
7
|
-
interface Segment { namespaces: Map<string, Namespace>; bytes: number }
|
|
8
|
-
const scopeKey = (scope: Scope) => JSON.stringify([scope.sessionId, scope.segmentId]);
|
|
9
|
-
|
|
10
|
-
function keySize(key: string): number {
|
|
11
|
-
if (typeof key !== 'string' || !key || Buffer.byteLength(key) > 256) throw Error('strategy_memory_key_invalid');
|
|
12
|
-
return Buffer.byteLength(key);
|
|
13
|
-
}
|
|
14
|
-
export function validateStrategyMemoryValue(value: unknown): asserts value is StrategyMemoryValue {
|
|
15
|
-
const seen = new Set<object>();
|
|
16
|
-
const visit = (entry: unknown, depth: number): void => {
|
|
17
|
-
if (depth > 32) throw Error('strategy_memory_value_invalid');
|
|
18
|
-
if (entry === null || typeof entry === 'boolean' || typeof entry === 'string') return;
|
|
19
|
-
if (typeof entry === 'number' && Number.isFinite(entry)) return;
|
|
20
|
-
if (!entry || typeof entry !== 'object' || seen.has(entry)) throw Error('strategy_memory_value_invalid');
|
|
21
|
-
const prototype = Object.getPrototypeOf(entry);
|
|
22
|
-
if (!Array.isArray(entry) && prototype !== Object.prototype && prototype !== null) throw Error('strategy_memory_value_invalid');
|
|
23
|
-
seen.add(entry);
|
|
24
|
-
for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(entry))) {
|
|
25
|
-
if (!('value' in descriptor)) throw Error('strategy_memory_value_invalid');
|
|
26
|
-
// Array length is a finite number and is harmless to validate as well.
|
|
27
|
-
visit(descriptor.value, depth + 1);
|
|
28
|
-
}
|
|
29
|
-
if (Object.getOwnPropertySymbols(entry).length) throw Error('strategy_memory_value_invalid');
|
|
30
|
-
seen.delete(entry);
|
|
31
|
-
};
|
|
32
|
-
visit(value, 0);
|
|
33
|
-
if (Buffer.byteLength(JSON.stringify(value)) > STRATEGY_MEMORY_MAX_BYTES) throw Error('strategy_memory_limit_exceeded');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** One explicitly assembled Owner-local store. Never persisted or shared with another account/Owner. */
|
|
37
|
-
export class ClawclawStrategyMemory {
|
|
38
|
-
private readonly segments = new Map<string, Segment>();
|
|
39
|
-
open(scope: Scope): void {
|
|
40
|
-
const key = scopeKey(scope);
|
|
41
|
-
if (!this.segments.has(key)) this.segments.set(key, { namespaces: new Map(), bytes: 0 });
|
|
42
|
-
}
|
|
43
|
-
close(scope: Scope): void {
|
|
44
|
-
const key = scopeKey(scope), segment = this.segments.get(key);
|
|
45
|
-
if (segment) { segment.namespaces.clear(); segment.bytes = 0; this.segments.delete(key); }
|
|
46
|
-
}
|
|
47
|
-
bind(scope: Scope, namespace: string, isActive: () => boolean): StrategyMemory {
|
|
48
|
-
const key = scopeKey(scope), segment = this.segments.get(key);
|
|
49
|
-
const check = () => {
|
|
50
|
-
if (!segment || this.segments.get(key) !== segment || !isActive()) throw Error('strategy_memory_inactive');
|
|
51
|
-
return segment;
|
|
52
|
-
};
|
|
53
|
-
return Object.freeze({
|
|
54
|
-
get: async <T extends StrategyMemoryValue>(name: string): Promise<T | undefined> => {
|
|
55
|
-
keySize(name); const current = check();
|
|
56
|
-
const value = current.namespaces.get(namespace)?.values.get(name)?.value;
|
|
57
|
-
return value === undefined ? undefined : structuredClone(value) as T;
|
|
58
|
-
},
|
|
59
|
-
set: async (name: string, value: StrategyMemoryValue): Promise<void> => {
|
|
60
|
-
const keyBytes = keySize(name); const current = check(); validateStrategyMemoryValue(value);
|
|
61
|
-
const size = keyBytes + Buffer.byteLength(JSON.stringify(value));
|
|
62
|
-
const target = current.namespaces.get(namespace) ?? { values: new Map(), bytes: 0 };
|
|
63
|
-
const old = target.values.get(name)?.bytes ?? 0, delta = size - old;
|
|
64
|
-
if ((!target.values.has(name) && target.values.size >= MAX_KEYS)
|
|
65
|
-
|| target.bytes + delta > STRATEGY_MEMORY_MAX_BYTES || current.bytes + delta > MAX_SCOPE_BYTES) {
|
|
66
|
-
throw Error('strategy_memory_limit_exceeded');
|
|
67
|
-
}
|
|
68
|
-
target.values.set(name, { value: structuredClone(value), bytes: size });
|
|
69
|
-
target.bytes += delta; current.bytes += delta; current.namespaces.set(namespace, target);
|
|
70
|
-
},
|
|
71
|
-
delete: async (name: string): Promise<void> => {
|
|
72
|
-
keySize(name); const current = check(), target = current.namespaces.get(namespace), entry = target?.values.get(name);
|
|
73
|
-
if (target && entry) { target.values.delete(name); target.bytes -= entry.bytes; current.bytes -= entry.bytes; }
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
export { StrategyMemoryStore as ClawclawStrategyMemory, STRATEGY_MEMORY_MAX_BYTES, validateStrategyMemoryValue } from '@myclaw163/game-agent-runtime/memory/strategy-memory.js';
|
|
@@ -26,11 +26,13 @@ export const CLAWCLAW_VISUAL_EVENT_TYPES = [
|
|
|
26
26
|
] as const;
|
|
27
27
|
|
|
28
28
|
export type ClawclawVisualEventType = typeof CLAWCLAW_VISUAL_EVENT_TYPES[number];
|
|
29
|
+
export type ClawclawEventDelivery = EventDeliveryClass
|
|
30
|
+
| Readonly<Pick<EventCatalogEntry, 'deliveryClass' | 'wakeAgent'>>;
|
|
29
31
|
export type ClawclawVisualEventDelivery = EventDeliveryClass
|
|
30
|
-
| Readonly<Partial<Record<string,
|
|
32
|
+
| Readonly<Partial<Record<string, ClawclawEventDelivery>>>;
|
|
31
33
|
|
|
32
34
|
export interface ClawclawEventCatalogOptions {
|
|
33
|
-
/** Defaults to
|
|
35
|
+
/** Defaults to visible notifications while preserving the producer's wakeAgent choice. */
|
|
34
36
|
visualEventDelivery?: ClawclawVisualEventDelivery;
|
|
35
37
|
/** Additional visual Event types declared by selected user perception modules. */
|
|
36
38
|
visualEventTypes?: readonly string[];
|
|
@@ -241,21 +243,19 @@ export const CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES = new Set<string>([
|
|
|
241
243
|
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES,
|
|
242
244
|
]);
|
|
243
245
|
|
|
244
|
-
/** Intentionally empty for the current ClawClaw Agent contract. */
|
|
245
|
-
export const CLAWCLAW_EVENTS_ONLY_EVENT_TYPES = new Set<string>();
|
|
246
|
-
|
|
247
246
|
function visualDelivery(
|
|
248
247
|
config: ClawclawVisualEventDelivery | undefined,
|
|
249
248
|
type: string,
|
|
250
|
-
):
|
|
251
|
-
|
|
252
|
-
return
|
|
249
|
+
): Pick<EventCatalogEntry, 'deliveryClass' | 'wakeAgent'> {
|
|
250
|
+
const configured = typeof config === 'string' ? config : config?.[type];
|
|
251
|
+
return typeof configured === 'object' ? { ...configured }
|
|
252
|
+
: { deliveryClass: configured ?? 'monitor_and_events' };
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[] {
|
|
256
256
|
const perceptionOutputTypes = new Set(options.perceptionEventTypes ?? []);
|
|
257
257
|
const ownOutputDelivery = (type: string) => perceptionOutputTypes.has(type)
|
|
258
|
-
? visualDelivery(options.visualEventDelivery, type) : 'monitor_and_events' as const;
|
|
258
|
+
? visualDelivery(options.visualEventDelivery, type) : { deliveryClass: 'monitor_and_events' as const };
|
|
259
259
|
const visualEventTypes = [...new Set([
|
|
260
260
|
...CLAWCLAW_VISUAL_EVENT_TYPES,
|
|
261
261
|
...(options.visualEventTypes ?? []),
|
|
@@ -276,7 +276,7 @@ function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[]
|
|
|
276
276
|
...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.map((type) => ({
|
|
277
277
|
type,
|
|
278
278
|
producer: 'local_synth' as const,
|
|
279
|
-
|
|
279
|
+
...ownOutputDelivery(type),
|
|
280
280
|
})),
|
|
281
281
|
...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES.map((type) => ({
|
|
282
282
|
type,
|
|
@@ -291,12 +291,12 @@ function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[]
|
|
|
291
291
|
...visualEventTypes.map((type) => ({
|
|
292
292
|
type,
|
|
293
293
|
producer: 'local_synth' as const,
|
|
294
|
-
|
|
294
|
+
...visualDelivery(options.visualEventDelivery, type),
|
|
295
295
|
})),
|
|
296
296
|
...behaviorEventTypes.map((type) => ({
|
|
297
297
|
type,
|
|
298
298
|
producer: 'local_synth' as const,
|
|
299
|
-
|
|
299
|
+
...ownOutputDelivery(type),
|
|
300
300
|
})),
|
|
301
301
|
];
|
|
302
302
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
+
import { actionFailureDiagnosticSeverity as classify } from '@myclaw163/game-agent-runtime/framework/action-diagnostics.js';
|
|
1
2
|
import type { ActionResult } from './contracts.js';
|
|
2
|
-
|
|
3
|
-
export interface ActionErrorDiagnosticSummary {
|
|
4
|
-
readonly code?: string;
|
|
5
|
-
readonly httpStatus?: number;
|
|
6
|
-
readonly messagePresent: boolean;
|
|
7
|
-
readonly messageLength?: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
3
|
+
export { summarizeActionError, type ActionErrorDiagnosticSummary } from '@myclaw163/game-agent-runtime/framework/action-diagnostics.js';
|
|
10
4
|
const EXPLICIT_GAMEPLAY_REJECTIONS = new Set([
|
|
11
5
|
'action_failed',
|
|
12
6
|
'already_spoke',
|
|
@@ -70,78 +64,4 @@ const EXPLICIT_GAMEPLAY_REJECTIONS = new Set([
|
|
|
70
64
|
'you_are_dead',
|
|
71
65
|
]);
|
|
72
66
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
function record(value: unknown): Record<string, unknown> | null {
|
|
76
|
-
return value && typeof value === 'object' && !Array.isArray(value)
|
|
77
|
-
? value as Record<string, unknown>
|
|
78
|
-
: null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function machineCode(value: unknown): string | undefined {
|
|
82
|
-
if (typeof value !== 'string') return undefined;
|
|
83
|
-
const code = value.trim();
|
|
84
|
-
return /^[A-Za-z][A-Za-z0-9_.-]{0,119}$/.test(code) ? code : undefined;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function machineErrorCode(value: unknown): string | undefined {
|
|
88
|
-
const exact = machineCode(value);
|
|
89
|
-
if (exact) return exact;
|
|
90
|
-
if (typeof value !== 'string') return undefined;
|
|
91
|
-
return /^([A-Za-z][A-Za-z0-9_.-]{0,119})(?=\s*[:,])/.exec(value.trim())?.[1];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function httpStatus(value: unknown): number | undefined {
|
|
95
|
-
const status = Number(value);
|
|
96
|
-
return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Extract only machine-readable Action failure metadata; never copy the response body. */
|
|
100
|
-
export function summarizeActionError(error: unknown): ActionErrorDiagnosticSummary {
|
|
101
|
-
const root = record(error);
|
|
102
|
-
const nested = record(root?.error);
|
|
103
|
-
const message = error instanceof Error
|
|
104
|
-
? error.message
|
|
105
|
-
: typeof root?.message === 'string'
|
|
106
|
-
? root.message
|
|
107
|
-
: typeof nested?.message === 'string'
|
|
108
|
-
? nested.message
|
|
109
|
-
: typeof root?.error === 'string'
|
|
110
|
-
? root.error
|
|
111
|
-
: typeof error === 'string' ? error : undefined;
|
|
112
|
-
const code = machineCode(root?.code)
|
|
113
|
-
?? machineCode(nested?.code)
|
|
114
|
-
?? machineErrorCode(root?.error);
|
|
115
|
-
const status = httpStatus(root?.http_status) ?? httpStatus(nested?.http_status);
|
|
116
|
-
return {
|
|
117
|
-
...(code ? { code } : {}),
|
|
118
|
-
...(status ? { httpStatus: status } : {}),
|
|
119
|
-
messagePresent: !!message,
|
|
120
|
-
...(message ? { messageLength: message.length } : {}),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function explicitGameplayRejection(summary: ActionErrorDiagnosticSummary): boolean {
|
|
125
|
-
const code = summary.code?.toLowerCase();
|
|
126
|
-
const statusFromCode = code && /^http_(\d{3})$/.exec(code)?.[1];
|
|
127
|
-
const status = summary.httpStatus ?? (statusFromCode ? Number(statusFromCode) : undefined);
|
|
128
|
-
if (status !== undefined && status >= 500) return false;
|
|
129
|
-
if (code && EXPLICIT_GAMEPLAY_REJECTIONS.has(code)) return true;
|
|
130
|
-
return status !== undefined && CLIENT_REJECTION_HTTP_STATUSES.has(status);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Unknown, transport, protocol, auth and server failures stay error-level. */
|
|
134
|
-
export function actionFailureDiagnosticSeverity(
|
|
135
|
-
result: Pick<ActionResult, 'source' | 'actionOutcome' | 'error'>,
|
|
136
|
-
): 'warn' | 'error' {
|
|
137
|
-
const knownBoundary = (
|
|
138
|
-
result.source === 'backend'
|
|
139
|
-
&& (result.actionOutcome === 'confirmed' || result.actionOutcome === 'not_submitted')
|
|
140
|
-
) || (
|
|
141
|
-
result.source === 'local'
|
|
142
|
-
&& result.actionOutcome === 'not_submitted'
|
|
143
|
-
);
|
|
144
|
-
return knownBoundary && explicitGameplayRejection(summarizeActionError(result.error))
|
|
145
|
-
? 'warn'
|
|
146
|
-
: 'error';
|
|
147
|
-
}
|
|
67
|
+
export const actionFailureDiagnosticSeverity = (result: Pick<ActionResult, 'source' | 'actionOutcome' | 'error'>) => classify(result, EXPLICIT_GAMEPLAY_REJECTIONS);
|