@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,388 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { RuntimeConnectionState, RuntimeScope } from '../state/types.js';
|
|
4
|
-
import type {
|
|
5
|
-
ActionCaller,
|
|
6
|
-
ActionResult,
|
|
7
|
-
ObservationProvider,
|
|
8
|
-
ObservationResult,
|
|
9
|
-
} from '../contracts.js';
|
|
10
|
-
import type { RegisteredActionService } from '../capability-registry.js';
|
|
11
|
-
import type { StateProviderResult } from '../state/types.js';
|
|
12
|
-
|
|
13
|
-
export type RuntimeInputCompleteness = 'complete' | 'best_effort';
|
|
14
|
-
export type RuntimeInputCoalescing = 'allowed' | 'forbidden';
|
|
15
|
-
/**
|
|
16
|
-
* `strict_ordered` never discards an accepted epoch: computation may overlap,
|
|
17
|
-
* but Runtime grants the effect boundary in epoch order. `every_epoch`
|
|
18
|
-
* processes each epoch only while it remains inside the bounded catch-up
|
|
19
|
-
* window; `latest_only` may supersede it as soon as a newer ready epoch exists.
|
|
20
|
-
* A `coalescing: forbidden` input overrides the coalescing policies, and a
|
|
21
|
-
* commit that has already started is never interrupted.
|
|
22
|
-
*/
|
|
23
|
-
export type RuntimeEpochCatchUp = 'strict_ordered' | 'every_epoch' | 'latest_only';
|
|
24
|
-
export type RuntimePluginFailureMode = 'failed_completion' | 'retry' | 'pause' | 'terminate';
|
|
25
|
-
export type RuntimePluginKind = 'source' | 'epoch';
|
|
26
|
-
export type RuntimeEpochFlushReason =
|
|
27
|
-
| 'segment_ending'
|
|
28
|
-
| 'shutdown';
|
|
29
|
-
|
|
30
|
-
export interface RuntimeSourceEvent<T = Record<string, unknown>> {
|
|
31
|
-
readonly type: string;
|
|
32
|
-
readonly producer?: EventProducer;
|
|
33
|
-
readonly payload: T;
|
|
34
|
-
readonly sourceEventId?: string;
|
|
35
|
-
readonly sourceSeq?: number | string;
|
|
36
|
-
readonly observedAt?: string;
|
|
37
|
-
readonly receivedAt?: string;
|
|
38
|
-
readonly replayed?: boolean;
|
|
39
|
-
readonly checkpoint?: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** One Source submission creates exactly one Runtime epoch. */
|
|
43
|
-
export interface RuntimeInputBatch<
|
|
44
|
-
TState = Record<string, unknown>,
|
|
45
|
-
TEvent = Record<string, unknown>,
|
|
46
|
-
> {
|
|
47
|
-
readonly scope: RuntimeScope;
|
|
48
|
-
readonly sourceId: string;
|
|
49
|
-
readonly connectionId: string;
|
|
50
|
-
/** Stable physical-message identity within source and scope. */
|
|
51
|
-
readonly sourceKey: string;
|
|
52
|
-
readonly sourceSeq?: number | string;
|
|
53
|
-
readonly domainTick?: number | string;
|
|
54
|
-
readonly state: TState;
|
|
55
|
-
/** Always present, including when the Source observed no Event. */
|
|
56
|
-
readonly events: readonly RuntimeSourceEvent<TEvent>[];
|
|
57
|
-
readonly eventWatermark?: number | string;
|
|
58
|
-
readonly completeness: RuntimeInputCompleteness;
|
|
59
|
-
/** A forbidden epoch must be processed by every loaded Epoch Plugin. */
|
|
60
|
-
readonly coalescing?: RuntimeInputCoalescing;
|
|
61
|
-
readonly observedAt?: string;
|
|
62
|
-
readonly receivedAt: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface RuntimePluginIdentity<K extends RuntimePluginKind = RuntimePluginKind> {
|
|
66
|
-
readonly kind: K;
|
|
67
|
-
readonly id: string;
|
|
68
|
-
readonly version: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface RuntimePluginCapabilityDeclaration {
|
|
72
|
-
/** Capability names registered by this plugin while its scope is active. */
|
|
73
|
-
readonly provides?: readonly string[];
|
|
74
|
-
/** Capability names this plugin may invoke while processing an epoch. */
|
|
75
|
-
readonly uses?: readonly string[];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export interface RuntimePluginFailurePolicy {
|
|
79
|
-
readonly mode: RuntimePluginFailureMode;
|
|
80
|
-
/** Total invocation attempts, including the first call. Only used by retry. */
|
|
81
|
-
readonly maxAttempts?: number;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Scope-bound capability surface exposed to an Epoch Plugin. Runtime performs
|
|
86
|
-
* declaration checks and routing; capability providers own all game behavior.
|
|
87
|
-
*/
|
|
88
|
-
export interface RuntimePluginCapabilityAccess {
|
|
89
|
-
provideObservation<Q, R>(provider: ObservationProvider<Q, R>): () => void;
|
|
90
|
-
provideAction<A, R>(service: RegisteredActionService<A, R>): () => void;
|
|
91
|
-
queryObservation<Q, R>(capability: string, request: Q): Promise<ObservationResult<R>>;
|
|
92
|
-
performAction<A, R>(
|
|
93
|
-
capability: string,
|
|
94
|
-
action: A,
|
|
95
|
-
caller?: ActionCaller,
|
|
96
|
-
): Promise<ActionResult<R>>;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** The persisted scheduling unit created from exactly one InputBatch. */
|
|
100
|
-
export interface RuntimeEpoch<
|
|
101
|
-
TState = Record<string, unknown>,
|
|
102
|
-
TEvent = Record<string, unknown>,
|
|
103
|
-
> extends RuntimeInputBatch<TState, TEvent> {
|
|
104
|
-
readonly epochSeq: number;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface RuntimeInputAcceptance<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
|
|
108
|
-
readonly inserted: boolean;
|
|
109
|
-
readonly epoch: RuntimeEpoch<TState, TEvent>;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface RuntimeStateProposal<T = unknown> {
|
|
113
|
-
readonly topic: string;
|
|
114
|
-
readonly value: T;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface RuntimeEventProposal {
|
|
118
|
-
/** Whether this Event may initiate Agent delivery; omitted means true. */
|
|
119
|
-
readonly wakeAgent?: boolean;
|
|
120
|
-
readonly type: string;
|
|
121
|
-
readonly dedupeKey: string;
|
|
122
|
-
readonly dedupeScope?: 'segment' | 'session';
|
|
123
|
-
readonly payload: Record<string, unknown>;
|
|
124
|
-
readonly occurredAt?: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export type RuntimeEpochPluginOutcome = 'processed' | 'noop' | 'failed' | 'coalesced';
|
|
128
|
-
export type RuntimeDiagnosticSeverity = 'debug' | 'info' | 'warn' | 'error';
|
|
129
|
-
|
|
130
|
-
export interface RuntimeEpochPluginResult {
|
|
131
|
-
readonly eventDeliveries?: readonly import('../events/types.js').EventDeliveryDecision[];
|
|
132
|
-
readonly outcome: 'processed' | 'noop';
|
|
133
|
-
readonly reason?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Opaque, cloneable computation output consumed by this plugin's ordered
|
|
136
|
-
* commit hook. Runtime never publishes a proposal directly.
|
|
137
|
-
*/
|
|
138
|
-
readonly proposal?: unknown;
|
|
139
|
-
readonly states?: readonly RuntimeStateProposal[];
|
|
140
|
-
readonly events?: readonly RuntimeEventProposal[];
|
|
141
|
-
/** Durable plugin-owned continuation state for this scope. */
|
|
142
|
-
readonly checkpoint?: unknown;
|
|
143
|
-
/** Omit to leave this plugin's independent Event cursor unchanged. */
|
|
144
|
-
readonly consumeEventsThroughCommitSeq?: number;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface RuntimeEpochPluginContext<TState = Record<string, unknown>> {
|
|
148
|
-
readonly scope: Readonly<RuntimeScope>;
|
|
149
|
-
readonly stateHistory: StateFrameHistoryReader<TState>;
|
|
150
|
-
/** Current logical segment without exposing Runtime internals. */
|
|
151
|
-
readonly currentSegment: () => {
|
|
152
|
-
readonly kind: string;
|
|
153
|
-
readonly identity?: string;
|
|
154
|
-
};
|
|
155
|
-
/** Last durable checkpoint committed by this plugin in the active scope. */
|
|
156
|
-
readonly checkpoint: () => unknown;
|
|
157
|
-
/** Durable completion, Event cursor and checkpoint for this plugin/scope. */
|
|
158
|
-
readonly progress: () => Readonly<RuntimeEpochPluginProgress>;
|
|
159
|
-
readonly capabilities: RuntimePluginCapabilityAccess;
|
|
160
|
-
/** Plugin-owned diagnostics. They never become game Events. */
|
|
161
|
-
readonly diagnostic: (
|
|
162
|
-
name: string,
|
|
163
|
-
attributes?: Readonly<Record<string, unknown>>,
|
|
164
|
-
severity?: RuntimeDiagnosticSeverity,
|
|
165
|
-
) => void;
|
|
166
|
-
readonly signal: AbortSignal;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export interface RuntimeEpochPluginInput<
|
|
170
|
-
TState = Record<string, unknown>,
|
|
171
|
-
TEvent = Record<string, unknown>,
|
|
172
|
-
> {
|
|
173
|
-
readonly epoch: Readonly<RuntimeEpoch<TState, TEvent>>;
|
|
174
|
-
readonly frame: Readonly<StoredStateFrame<TState>>;
|
|
175
|
-
/** Game-facing State associated with this exact Runtime epoch. */
|
|
176
|
-
readonly currentState: Readonly<StateProviderResult<Record<string, any> | null>>;
|
|
177
|
-
readonly previousState: Readonly<TState> | null;
|
|
178
|
-
/** Canonical Events committed from this InputBatch and upstream plugins. */
|
|
179
|
-
readonly epochEvents: readonly CanonicalEvent[];
|
|
180
|
-
/** Subscribed Events after this plugin's cursor, bounded by this epoch's watermark. */
|
|
181
|
-
readonly pendingEvents: readonly CanonicalEvent[];
|
|
182
|
-
/** Same-epoch State proposals produced by completed upstream plugins. */
|
|
183
|
-
readonly upstreamStates: Readonly<Record<string, unknown>>;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export interface RuntimeEpochPlugin<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
|
|
187
|
-
extends RuntimePluginIdentity<'epoch'> {
|
|
188
|
-
/** Only these existing Event types may have their pre-Ready delivery metadata resolved. */
|
|
189
|
-
readonly controlsEventDelivery?: readonly string[];
|
|
190
|
-
readonly consumes?: {
|
|
191
|
-
readonly states?: readonly string[];
|
|
192
|
-
readonly events?: readonly string[];
|
|
193
|
-
};
|
|
194
|
-
readonly produces?: {
|
|
195
|
-
readonly states?: readonly string[];
|
|
196
|
-
readonly events?: readonly string[];
|
|
197
|
-
};
|
|
198
|
-
readonly after?: readonly string[];
|
|
199
|
-
readonly capabilities?: RuntimePluginCapabilityDeclaration;
|
|
200
|
-
readonly catchUp?: RuntimeEpochCatchUp;
|
|
201
|
-
/** Preserve started computations under ordinary overload, then catch up to the latest boundary. */
|
|
202
|
-
readonly backlogPolicy?: 'finish_started';
|
|
203
|
-
/**
|
|
204
|
-
* Maximum overlapping update calls, from 1 through 10. Defaults to 1.
|
|
205
|
-
* Values above 1 are an explicit promise that update is re-entrant and
|
|
206
|
-
* performs no side effects; Runtime buffers its cloneable results and
|
|
207
|
-
* commits them in epoch order. With `strict_ordered`, reaching the bounded
|
|
208
|
-
* in-flight capacity delays newer computation instead of discarding work.
|
|
209
|
-
*/
|
|
210
|
-
readonly maxInFlight?: number;
|
|
211
|
-
/** Maximum retained epochs for non-strict catch-up before oldest work is coalesced. */
|
|
212
|
-
readonly maxPendingEpochs?: number;
|
|
213
|
-
readonly failurePolicy?: RuntimePluginFailureMode | RuntimePluginFailurePolicy;
|
|
214
|
-
/** Per-call deadline; Runtime still owns cancellation and stale-output rejection. */
|
|
215
|
-
readonly timeoutMs?: number;
|
|
216
|
-
/** Optional longer deadline for rebuilding plugin state when a scope is activated. */
|
|
217
|
-
readonly recoveryTimeoutMs?: number;
|
|
218
|
-
start?(context: RuntimeEpochPluginContext<TState>): void | Promise<void>;
|
|
219
|
-
recover?(context: RuntimeEpochPluginContext<TState>): void | Promise<void>;
|
|
220
|
-
update(
|
|
221
|
-
input: RuntimeEpochPluginInput<TState, TEvent>,
|
|
222
|
-
context: RuntimeEpochPluginContext<TState>,
|
|
223
|
-
): RuntimeEpochPluginResult | Promise<RuntimeEpochPluginResult>;
|
|
224
|
-
/**
|
|
225
|
-
* Optional ordered reducer/effect boundary. When present, update returns
|
|
226
|
-
* only outcome/reason/proposal and commit returns the final State/Event/
|
|
227
|
-
* checkpoint output. Exactly one commit call per plugin runs at a time, and
|
|
228
|
-
* once it starts Runtime lets that atomic effect boundary finish.
|
|
229
|
-
*/
|
|
230
|
-
commit?(
|
|
231
|
-
input: RuntimeEpochPluginInput<TState, TEvent>,
|
|
232
|
-
computation: Readonly<RuntimeEpochPluginResult>,
|
|
233
|
-
context: RuntimeEpochPluginContext<TState>,
|
|
234
|
-
): RuntimeEpochPluginResult | Promise<RuntimeEpochPluginResult>;
|
|
235
|
-
flush?(
|
|
236
|
-
reason: RuntimeEpochFlushReason,
|
|
237
|
-
context: RuntimeEpochPluginContext<TState>,
|
|
238
|
-
): void | Promise<void>;
|
|
239
|
-
stop?(
|
|
240
|
-
reason: 'segment_ending' | 'shutdown',
|
|
241
|
-
context: RuntimeEpochPluginContext<TState>,
|
|
242
|
-
): void | Promise<void>;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export interface RuntimeInputSink<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
|
|
246
|
-
acceptInputBatch(batch: RuntimeInputBatch<TState, TEvent>): Promise<RuntimeInputAcceptance<TState, TEvent>>;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export interface RuntimeSourceSegment {
|
|
250
|
-
readonly scope: RuntimeScope;
|
|
251
|
-
readonly kind: string;
|
|
252
|
-
readonly identity?: string;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* The game-neutral Runtime surface available to Source Plugins. A Source may
|
|
257
|
-
* own any transport, but it cannot reach Runtime repositories or schedulers.
|
|
258
|
-
*/
|
|
259
|
-
export interface RuntimeSourceContext<
|
|
260
|
-
TState = Record<string, unknown>,
|
|
261
|
-
TEvent = Record<string, unknown>,
|
|
262
|
-
> extends RuntimeInputSink<TState, TEvent> {
|
|
263
|
-
currentSegment(): RuntimeSourceSegment;
|
|
264
|
-
/** A Source-confirmed terminal scope revokes Actions without stopping queries or event delivery. */
|
|
265
|
-
closeActionScope(scope: RuntimeScope, reason: string): void;
|
|
266
|
-
activateSegment(kind: string, identity?: string): Promise<RuntimeScope>;
|
|
267
|
-
adoptResumeKey(resumeKey: string): RuntimeScope;
|
|
268
|
-
updateMode(mode: string): RuntimeScope;
|
|
269
|
-
bindConnection(sourceId: string, connectionId: string, atMs?: number): RuntimeScope;
|
|
270
|
-
rebindConnectionScope(sourceId: string, connectionId: string, atMs?: number): RuntimeScope;
|
|
271
|
-
connectionScope(sourceId: string, connectionId: string): RuntimeScope | null;
|
|
272
|
-
isActiveConnection(sourceId: string, connectionId: string): boolean;
|
|
273
|
-
connectionChanged(
|
|
274
|
-
sourceId: string,
|
|
275
|
-
connectionId: string,
|
|
276
|
-
state: RuntimeConnectionState,
|
|
277
|
-
atMs?: number,
|
|
278
|
-
): void;
|
|
279
|
-
connectionLiveness(sourceId: string, connectionId: string, atMs?: number): boolean;
|
|
280
|
-
/** Source-owned transport/protocol diagnostics. These never enter the game Event ledger. */
|
|
281
|
-
diagnostic(
|
|
282
|
-
name: string,
|
|
283
|
-
attributes?: Readonly<Record<string, unknown>>,
|
|
284
|
-
severity?: 'debug' | 'info' | 'warn' | 'error',
|
|
285
|
-
): void;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export interface RuntimeSourceStopHandle {
|
|
289
|
-
/** Stop external intake. The captured Source context may submit a final InputBatch before resolving. */
|
|
290
|
-
stop(reason: 'shutdown'): Promise<void> | void;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export interface RuntimeSourcePlugin<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
|
|
294
|
-
extends RuntimePluginIdentity<'source'> {
|
|
295
|
-
start(
|
|
296
|
-
context: RuntimeSourceContext<TState, TEvent>,
|
|
297
|
-
): RuntimeSourceStopHandle | Promise<RuntimeSourceStopHandle>;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/** The complete game-neutral plugin surface understood by Runtime. */
|
|
301
|
-
export type RuntimePlugin<
|
|
302
|
-
TState = Record<string, unknown>,
|
|
303
|
-
TEvent = Record<string, unknown>,
|
|
304
|
-
> = RuntimeSourcePlugin<TState, TEvent> | RuntimeEpochPlugin<TState, TEvent>;
|
|
305
|
-
|
|
306
|
-
export interface RuntimeSourcePluginDescriptor extends RuntimePluginIdentity<'source'> {}
|
|
307
|
-
|
|
308
|
-
export interface RuntimeEpochPluginDescriptor extends RuntimePluginIdentity<'epoch'> {
|
|
309
|
-
readonly after: readonly string[];
|
|
310
|
-
readonly catchUp: RuntimeEpochCatchUp;
|
|
311
|
-
readonly maxInFlight: number;
|
|
312
|
-
readonly maxPendingEpochs: number;
|
|
313
|
-
readonly consumes: Readonly<NonNullable<RuntimeEpochPlugin['consumes']>>;
|
|
314
|
-
readonly produces: Readonly<NonNullable<RuntimeEpochPlugin['produces']>>;
|
|
315
|
-
readonly capabilities: Readonly<RuntimePluginCapabilityDeclaration>;
|
|
316
|
-
readonly failurePolicy: Readonly<RuntimePluginFailurePolicy>;
|
|
317
|
-
readonly timeoutMs?: number;
|
|
318
|
-
readonly recoveryTimeoutMs?: number;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export type RuntimePluginDescriptor = RuntimeSourcePluginDescriptor | RuntimeEpochPluginDescriptor;
|
|
322
|
-
|
|
323
|
-
export interface RuntimeEpochPluginProgress {
|
|
324
|
-
readonly pluginId: string;
|
|
325
|
-
readonly completedThroughEpochSeq: number;
|
|
326
|
-
readonly eventCursor: number;
|
|
327
|
-
readonly checkpoint?: unknown;
|
|
328
|
-
readonly updatedAt: string;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export interface RuntimeEpochPluginRecord {
|
|
332
|
-
readonly epochSeq: number;
|
|
333
|
-
readonly pluginId: string;
|
|
334
|
-
readonly invocationId: string;
|
|
335
|
-
readonly outcome: RuntimeEpochPluginOutcome;
|
|
336
|
-
readonly reason?: string;
|
|
337
|
-
readonly durationMs: number;
|
|
338
|
-
readonly stateCount: number;
|
|
339
|
-
readonly eventCount: number;
|
|
340
|
-
readonly eventCursorBefore: number;
|
|
341
|
-
readonly eventCursorAfter: number;
|
|
342
|
-
readonly recordedAt: string;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
export interface RuntimeEpochStateRecord {
|
|
346
|
-
readonly epochSeq: number;
|
|
347
|
-
readonly pluginId: string;
|
|
348
|
-
readonly topic: string;
|
|
349
|
-
readonly value: unknown;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export interface RuntimeInputJournal<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
|
|
353
|
-
accept(batch: RuntimeInputBatch<TState, TEvent>): RuntimeInputAcceptance<TState, TEvent>;
|
|
354
|
-
epoch(epochSeq: number): RuntimeEpoch<TState, TEvent> | null;
|
|
355
|
-
list(scope: RuntimeScope, afterEpochSeq?: number, limit?: number): RuntimeEpoch<TState, TEvent>[];
|
|
356
|
-
listOpen(scope: RuntimeScope, afterEpochSeq?: number, limit?: number): RuntimeEpoch<TState, TEvent>[];
|
|
357
|
-
inputEventsCommitted(epochSeq: number): boolean;
|
|
358
|
-
markInputEventsCommitted(epochSeq: number, eventWatermark: number, committedAt?: string): void;
|
|
359
|
-
eventWatermarkThrough(scope: RuntimeScope, epochSeq: number): number;
|
|
360
|
-
markEventWatermark(epochSeq: number, eventWatermark: number): void;
|
|
361
|
-
markClosed(epochSeq: number, closedAt?: string, durationMs?: number): void;
|
|
362
|
-
close?(): void | Promise<void>;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/** Durable outcomes, derived State and independent Event cursors for plugins. */
|
|
366
|
-
export interface RuntimePluginStore {
|
|
367
|
-
recordPlugin(record: RuntimeEpochPluginRecord): void;
|
|
368
|
-
pluginRecords(epochSeq: number): RuntimeEpochPluginRecord[];
|
|
369
|
-
pluginProgress(pluginId: string, scope: RuntimeScope): RuntimeEpochPluginProgress;
|
|
370
|
-
savePluginProgress(progress: RuntimeEpochPluginProgress, scope: RuntimeScope): void;
|
|
371
|
-
saveStates(records: readonly RuntimeEpochStateRecord[]): void;
|
|
372
|
-
states(epochSeq: number): RuntimeEpochStateRecord[];
|
|
373
|
-
close?(): void | Promise<void>;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/** One physical database may implement both logical persistence contracts. */
|
|
377
|
-
export interface RuntimePersistenceStore<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
|
|
378
|
-
extends RuntimeInputJournal<TState, TEvent>, RuntimePluginStore {}
|
|
379
|
-
|
|
380
|
-
export interface RuntimeEpochExecutionResult {
|
|
381
|
-
readonly epochSeq: number;
|
|
382
|
-
/** Wall-clock time from scheduler enqueue until every plugin completion is durable. */
|
|
383
|
-
readonly durationMs: number;
|
|
384
|
-
readonly outcomes: readonly RuntimeEpochPluginRecord[];
|
|
385
|
-
readonly stateCount: number;
|
|
386
|
-
readonly eventCount: number;
|
|
387
|
-
readonly eventWatermark: number;
|
|
388
|
-
}
|
|
1
|
+
// Compatibility facade; implementation lives in the game-neutral runtime package.
|
|
2
|
+
export * from '@myclaw163/game-agent-runtime/framework/plugins/contracts.js';
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** Stable canonical Event identity for one Event inside a Source InputBatch. */
|
|
4
|
-
export function runtimeSourceEventId(
|
|
5
|
-
epoch: Pick<RuntimeEpoch, 'sourceId' | 'sourceKey' | 'scope'>,
|
|
6
|
-
event: Pick<RuntimeSourceEvent, 'sourceEventId'>,
|
|
7
|
-
eventIndex: number,
|
|
8
|
-
): string {
|
|
9
|
-
return JSON.stringify([
|
|
10
|
-
'runtime-source',
|
|
11
|
-
epoch.sourceId,
|
|
12
|
-
epoch.scope.sessionId,
|
|
13
|
-
epoch.scope.segmentId,
|
|
14
|
-
event.sourceEventId ?? epoch.sourceKey,
|
|
15
|
-
event.sourceEventId ? null : eventIndex,
|
|
16
|
-
]);
|
|
17
|
-
}
|
|
1
|
+
// Compatibility facade; implementation lives in the game-neutral runtime package.
|
|
2
|
+
export * from '@myclaw163/game-agent-runtime/framework/plugins/runtime-event-identity.js';
|