@myclaw163/clawclaw-cli 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/docs/configuration.md +44 -26
- package/docs/custom-modules/README.md +7 -10
- package/docs/custom-modules/api-reference.md +3 -7
- package/docs/custom-modules/behavior.md +6 -4
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +4 -4
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +9 -2
- package/scripts/build-official-hub-behaviors.mjs +136 -0
- package/scripts/build-official-hub-behaviors.test.mjs +178 -0
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/enable_ccl_permissions.test.mjs +8 -4
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/scripts/sync-bundled-skill.test.mjs +9 -74
- package/skills/clawclaw/SKILL.md +18 -13
- package/skills/clawclaw/references/BEHAVIORS.md +4 -4
- package/skills/clawclaw/references/COMMANDS.md +33 -18
- package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
- package/skills/clawclaw/references/HUB.md +25 -38
- package/skills/clawclaw/references/STREAM.md +9 -11
- package/src/behaviors/official-finite/do-task.ts +70 -0
- package/src/behaviors/official-finite/index.ts +0 -3
- package/src/commands/account.ts +58 -14
- package/src/commands/behavior.ts +116 -38
- package/src/commands/hub.ts +110 -153
- package/src/commands/load.ts +138 -33
- package/src/commands/perception.ts +55 -24
- package/src/commands/persona.ts +66 -20
- package/src/commands/skill.ts +12 -48
- package/src/commands/trigger.ts +68 -40
- package/src/hub-official-behaviors/kill-lone.ts +138 -0
- package/src/hub-official-behaviors/patrol.ts +30 -0
- package/src/hub-official-behaviors/shared.ts +125 -0
- package/src/hub-official-behaviors/task-only.ts +158 -0
- package/src/lib/account-guidance.ts +54 -9
- package/src/lib/agent-workspace-client.ts +135 -0
- package/src/lib/agent-workspace-runtime.ts +154 -0
- package/src/lib/agent-workspace-skills.ts +177 -0
- package/src/lib/agent-workspace-sync.ts +852 -0
- package/src/lib/gameplay-config.ts +29 -15
- package/src/lib/hub-client.ts +252 -34
- package/src/lib/hub-reminder.ts +22 -7
- package/src/lib/init-command.ts +0 -6
- package/src/lib/load-context.ts +12 -6
- package/src/lib/persona.ts +141 -69
- package/src/lib/server-status.ts +78 -0
- package/src/lib/skill-host.ts +160 -0
- package/src/lib/user-data.ts +197 -4
- package/src/pipeline/event-format.ts +20 -4
- package/src/pipeline/event-hints.ts +20 -6
- package/src/pipeline/game-sync-event-normalization.ts +9 -0
- package/src/pipeline/role-display.ts +22 -0
- package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +63 -19
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
- package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
- package/src/runtime/clawclaw-event-catalog.ts +2 -0
- package/src/runtime/framework/action-diagnostics.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
- package/src/sdk/action.ts +8 -6
- package/src/sdk/behavior-plugin/index.ts +1 -2
- package/src/sdk/behavior-toolkit/model.ts +2 -0
- package/src/sdk/module-input/index.ts +0 -2
- package/src/strategies/goals/crab-sabotage-top.ts +5 -61
- package/src/strategies/types.ts +0 -6
- package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
- package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
- package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
- package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
- package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
- package/src/behaviors/official-finite/index.test.ts +0 -202
- package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
- package/src/channel/claude-channel-server.test.ts +0 -202
- package/src/commands/account.test.ts +0 -570
- package/src/commands/behavior.test.ts +0 -158
- package/src/commands/communication.test.ts +0 -282
- package/src/commands/competition.test.ts +0 -116
- package/src/commands/data.test.ts +0 -89
- package/src/commands/events-canonical-state.test.ts +0 -406
- package/src/commands/events.test.ts +0 -58
- package/src/commands/game/index.test.ts +0 -1251
- package/src/commands/game-map.test.ts +0 -69
- package/src/commands/hub.test.ts +0 -124
- package/src/commands/load.test.ts +0 -440
- package/src/commands/perception.test.ts +0 -75
- package/src/commands/setup/hermes.test.ts +0 -96
- package/src/commands/setup/openclaw.test.ts +0 -124
- package/src/commands/trigger.test.ts +0 -140
- package/src/commands/upgrade.test.ts +0 -82
- package/src/lib/account-guidance.test.ts +0 -36
- package/src/lib/auth.test.ts +0 -151
- package/src/lib/behavior-export.test.ts +0 -282
- package/src/lib/behavior-export.ts +0 -514
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
- package/src/lib/custom-tts.test.ts +0 -387
- package/src/lib/diagnostics-config.test.ts +0 -59
- package/src/lib/game-client-tts.test.ts +0 -151
- package/src/lib/game-client.test.ts +0 -250
- package/src/lib/gameplay-config.test.ts +0 -301
- package/src/lib/host-config-patcher.test.ts +0 -130
- package/src/lib/http-transport.test.ts +0 -124
- package/src/lib/hub-client.test.ts +0 -57
- package/src/lib/hub-install.test.ts +0 -135
- package/src/lib/hub-install.ts +0 -185
- package/src/lib/hub-unzip.test.ts +0 -69
- package/src/lib/init-command.test.ts +0 -103
- package/src/lib/load-context.test.ts +0 -62
- package/src/lib/match-state.test.ts +0 -134
- package/src/lib/official-resource-sync.test.ts +0 -199
- package/src/lib/official-resource-sync.ts +0 -221
- package/src/lib/perception-config.test.ts +0 -143
- package/src/lib/perception-export.test.ts +0 -145
- package/src/lib/perception-export.ts +0 -178
- package/src/lib/persona.test.ts +0 -84
- package/src/lib/room.test.ts +0 -88
- package/src/lib/server-registry.test.ts +0 -64
- package/src/lib/service-status.test.ts +0 -81
- package/src/lib/skill-version.test.ts +0 -48
- package/src/lib/trigger-config.test.ts +0 -102
- package/src/lib/trigger-export.test.ts +0 -80
- package/src/lib/trigger-export.ts +0 -210
- package/src/lib/user-data.test.ts +0 -121
- package/src/lib/workspace-argv.test.ts +0 -49
- package/src/pipeline/canonical-event-presentation.test.ts +0 -255
- package/src/pipeline/event-format.test.ts +0 -828
- package/src/pipeline/event-hints.test.ts +0 -316
- package/src/pipeline/game-sync-event-normalization.test.ts +0 -371
- package/src/pipeline/player-projection.test.ts +0 -247
- package/src/runtime/auto-upgrade.test.ts +0 -66
- package/src/runtime/canonical-event-emitter.test.ts +0 -70
- package/src/runtime/canonical-monitor.test.ts +0 -577
- package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -58
- package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
- package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
- package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
- package/src/runtime/clawclaw/notifications.test.ts +0 -47
- package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
- package/src/runtime/clawclaw/owner.test.ts +0 -203
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -40
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -854
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
- package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
- package/src/runtime/clawclaw-event-catalog.test.ts +0 -126
- package/src/runtime/framework/action-diagnostics.test.ts +0 -81
- package/src/runtime/framework/capability-registry.test.ts +0 -423
- package/src/runtime/framework/control-coordinator.test.ts +0 -675
- package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
- package/src/runtime/framework/events/event-ingress.test.ts +0 -203
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
- package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
- package/src/runtime/framework/mailbox/identity.test.ts +0 -38
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
- package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
- package/src/runtime/framework/participation-manager.test.ts +0 -108
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
- package/src/runtime/framework/state/history/state-history.test.ts +0 -251
- package/src/runtime/framework/state/state-core.test.ts +0 -197
- package/src/runtime/game-sync-protocol.test.ts +0 -123
- package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
- package/src/runtime/mailbox-host-relay.test.ts +0 -293
- package/src/runtime/observability/observability.test.ts +0 -583
- package/src/runtime/owner-control.test.ts +0 -153
- package/src/runtime/parent-process-watch.test.ts +0 -27
- package/src/runtime/pending-event-handoff.test.ts +0 -29
- package/src/runtime/raw-ws-log.test.ts +0 -102
- package/src/runtime/runtime-logger.test.ts +0 -58
- package/src/runtime/runtime-persistence.test.ts +0 -26
- package/src/runtime/runtime.test.ts +0 -1770
- package/src/runtime/ws-client.test.ts +0 -562
- package/src/sdk/behavior-plugin/index.test.ts +0 -74
- package/src/sdk/index.test.ts +0 -45
- package/src/sdk/module-input/index.test.ts +0 -49
- package/src/sdk/perception-plugin/index.test.ts +0 -22
- package/src/sdk/resource-metadata.test.ts +0 -40
- package/src/sdk/trigger-plugin/index.test.ts +0 -41
- package/src/short-command/classifier.test.ts +0 -107
- package/src/short-command/presenter.test.ts +0 -119
- package/src/short-command/runner.test.ts +0 -78
- package/src/short-command/sensitive-data-filter.test.ts +0 -56
- package/src/short-command/transport-response.test.ts +0 -39
- package/src/strategies/custom-module.test.ts +0 -268
- package/src/strategies/game-utils.test.ts +0 -306
- package/src/strategies/goals/avoid-players-top.test.ts +0 -96
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -145
- package/src/strategies/goals/kill-lone-top.test.ts +0 -97
- package/src/strategies/goals/kill-target-top.test.ts +0 -66
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -85
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -113
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -204
- package/src/strategies/goals/task-only-top.test.ts +0 -89
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -139
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/task-only.test.ts +0 -138
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
ActionRegistry,
|
|
4
|
-
CapabilityConflictError,
|
|
5
|
-
ObservationRegistry,
|
|
6
|
-
actionControllerId,
|
|
7
|
-
behaviorControllerSpec,
|
|
8
|
-
} from './capability-registry.js';
|
|
9
|
-
import type { ScopeRef } from './contracts.js';
|
|
10
|
-
|
|
11
|
-
const scope: ScopeRef = {
|
|
12
|
-
adapterId: 'test',
|
|
13
|
-
accountId: 'account',
|
|
14
|
-
sessionId: 'session',
|
|
15
|
-
segmentId: 'segment',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('runtime capability registries', () => {
|
|
19
|
-
it('requires Host-owned Behavior controllers and fixes layer precedence in their specs', async () => {
|
|
20
|
-
const registry = new ActionRegistry();
|
|
21
|
-
registry.activateScope(scope);
|
|
22
|
-
const perform = vi.fn(async (_action, actionScope) => ({
|
|
23
|
-
scope: actionScope,
|
|
24
|
-
actionId: 'behavior-action',
|
|
25
|
-
status: 'success' as const,
|
|
26
|
-
}));
|
|
27
|
-
registry.register({
|
|
28
|
-
capability: 'player.move',
|
|
29
|
-
describeControl: () => ({ domains: ['physical'] }),
|
|
30
|
-
perform,
|
|
31
|
-
});
|
|
32
|
-
const callers = [
|
|
33
|
-
{ kind: 'behavior' as const, activationId: 'same/id', layer: 'long' as const, activationGeneration: 1 },
|
|
34
|
-
{ kind: 'behavior' as const, activationId: 'short-1', layer: 'short' as const, activationGeneration: 2 },
|
|
35
|
-
{ kind: 'behavior' as const, activationId: 'reflex-1', layer: 'reflex' as const, activationGeneration: 1 },
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
await expect(registry.perform('player.move', {}, scope, callers[0]!)).resolves.toMatchObject({
|
|
39
|
-
status: 'deferred',
|
|
40
|
-
error: { code: 'CONTROL_UNKNOWN_CONTROLLER' },
|
|
41
|
-
});
|
|
42
|
-
expect(perform).not.toHaveBeenCalled();
|
|
43
|
-
expect(callers.map((caller) => behaviorControllerSpec(caller, {
|
|
44
|
-
scope,
|
|
45
|
-
domains: ['physical'],
|
|
46
|
-
lifecycle: 'finite',
|
|
47
|
-
maxRuntimeMs: 1_000,
|
|
48
|
-
ready: true,
|
|
49
|
-
}).priority)).toEqual([100, 200, 350]);
|
|
50
|
-
|
|
51
|
-
const spec = behaviorControllerSpec(callers[0]!, {
|
|
52
|
-
scope,
|
|
53
|
-
domains: ['physical'],
|
|
54
|
-
lifecycle: 'persistent',
|
|
55
|
-
ready: true,
|
|
56
|
-
});
|
|
57
|
-
expect(spec).toMatchObject({
|
|
58
|
-
controllerId: 'behavior:same%2Fid@generation-1',
|
|
59
|
-
kind: 'behavior',
|
|
60
|
-
priority: 100,
|
|
61
|
-
metadata: {
|
|
62
|
-
behaviorActivationId: 'same/id',
|
|
63
|
-
behaviorLayer: 'long',
|
|
64
|
-
behaviorActivationGeneration: 1,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
registry.controls.registerController(spec);
|
|
68
|
-
await expect(registry.perform('player.move', {}, scope, callers[0]!))
|
|
69
|
-
.resolves.toMatchObject({ status: 'success' });
|
|
70
|
-
expect(perform).toHaveBeenCalledOnce();
|
|
71
|
-
|
|
72
|
-
expect(actionControllerId({ ...callers[0]!, activationGeneration: 2 }))
|
|
73
|
-
.toBe('behavior:same%2Fid@generation-2');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('supports games that expose pull observations without pushed events', async () => {
|
|
77
|
-
const registry = new ObservationRegistry();
|
|
78
|
-
registry.register({
|
|
79
|
-
capability: 'map.full',
|
|
80
|
-
query: async () => ({
|
|
81
|
-
scope,
|
|
82
|
-
capability: 'map.full',
|
|
83
|
-
receivedAt: '2026-07-15T00:00:00.000Z',
|
|
84
|
-
freshness: 'fresh',
|
|
85
|
-
value: { rooms: 4 },
|
|
86
|
-
}),
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
await expect(registry.query('map.full', {}, scope)).resolves.toMatchObject({
|
|
90
|
-
value: { rooms: 4 },
|
|
91
|
-
});
|
|
92
|
-
expect(registry.capabilities()).toEqual(['map.full']);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('routes Agent and Behavior actions through the same service', async () => {
|
|
96
|
-
const perform = vi.fn(async (_action, actionScope, caller) => ({
|
|
97
|
-
scope: actionScope,
|
|
98
|
-
actionId: 'action-1',
|
|
99
|
-
status: 'success' as const,
|
|
100
|
-
value: { caller },
|
|
101
|
-
}));
|
|
102
|
-
const registry = new ActionRegistry();
|
|
103
|
-
registry.activateScope(scope);
|
|
104
|
-
registry.register({ capability: 'player.move', perform });
|
|
105
|
-
|
|
106
|
-
const agent = { kind: 'agent' as const, id: 'a' };
|
|
107
|
-
const behavior = {
|
|
108
|
-
kind: 'behavior' as const,
|
|
109
|
-
activationId: 'long-1',
|
|
110
|
-
layer: 'long' as const,
|
|
111
|
-
activationGeneration: 1,
|
|
112
|
-
};
|
|
113
|
-
registry.controls.registerController(behaviorControllerSpec(behavior, {
|
|
114
|
-
scope, domains: ['*'], lifecycle: 'persistent', ready: true,
|
|
115
|
-
}));
|
|
116
|
-
await registry.perform('player.move', { x: 1, y: 2 }, scope, agent);
|
|
117
|
-
registry.releaseCaller(agent, 'agent_finished', scope);
|
|
118
|
-
await registry.perform('player.move', { x: 3, y: 4 }, scope, behavior);
|
|
119
|
-
|
|
120
|
-
expect(perform).toHaveBeenCalledTimes(2);
|
|
121
|
-
expect(perform.mock.calls.map((call) => call[2].kind)).toEqual(['agent', 'behavior']);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('gives the Action provider a live latest-accepted-State revalidation hook', async () => {
|
|
125
|
-
const registry = new ActionRegistry();
|
|
126
|
-
const accepted = {
|
|
127
|
-
epochSeq: 7,
|
|
128
|
-
state: { phase: 'meeting' },
|
|
129
|
-
};
|
|
130
|
-
const observed: unknown[] = [];
|
|
131
|
-
registry.register({
|
|
132
|
-
capability: 'player.safe-action',
|
|
133
|
-
perform: async (_action, actionScope, _caller, context) => {
|
|
134
|
-
observed.push(context.latestAcceptedState());
|
|
135
|
-
return { actionId: 'safe-1', scope: actionScope, status: 'success' as const };
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
await registry.perform(
|
|
140
|
-
'player.safe-action',
|
|
141
|
-
{},
|
|
142
|
-
scope,
|
|
143
|
-
{ kind: 'system', id: 'test' },
|
|
144
|
-
{ latestAcceptedState: () => accepted },
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(observed).toEqual([accepted]);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('holds a long Behavior after direct Agent control without queueing its action', async () => {
|
|
151
|
-
const perform = vi.fn(async (_action, actionScope, caller) => ({
|
|
152
|
-
scope: actionScope,
|
|
153
|
-
actionId: `${caller.kind}-action`,
|
|
154
|
-
status: 'success' as const,
|
|
155
|
-
}));
|
|
156
|
-
const registry = new ActionRegistry();
|
|
157
|
-
registry.activateScope(scope);
|
|
158
|
-
registry.register({
|
|
159
|
-
capability: 'player.move',
|
|
160
|
-
describeControl: () => ({ domains: ['physical'], agentLeaseMs: 1_000 }),
|
|
161
|
-
perform,
|
|
162
|
-
});
|
|
163
|
-
const behavior = {
|
|
164
|
-
kind: 'behavior' as const,
|
|
165
|
-
activationId: 'worker-secret-id',
|
|
166
|
-
layer: 'long' as const,
|
|
167
|
-
activationGeneration: 1,
|
|
168
|
-
};
|
|
169
|
-
const agent = { kind: 'agent' as const };
|
|
170
|
-
registry.controls.registerController(behaviorControllerSpec(behavior, {
|
|
171
|
-
scope, domains: ['physical'], lifecycle: 'persistent', ready: true,
|
|
172
|
-
}));
|
|
173
|
-
|
|
174
|
-
await registry.perform('player.move', {}, scope, behavior);
|
|
175
|
-
await registry.perform('player.move', {}, scope, agent);
|
|
176
|
-
await expect(registry.perform('player.move', {}, scope, behavior)).resolves.toMatchObject({
|
|
177
|
-
status: 'deferred',
|
|
178
|
-
error: {
|
|
179
|
-
code: 'CONTROL_HELD',
|
|
180
|
-
details: { phase: 'control', action_endpoint_called: false, domains: ['physical'] },
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
expect(perform).toHaveBeenCalledTimes(2);
|
|
184
|
-
const deferred = await registry.perform('player.move', {}, scope, behavior);
|
|
185
|
-
expect(JSON.stringify(deferred)).not.toContain('worker-secret-id');
|
|
186
|
-
expect(perform).toHaveBeenCalledTimes(2);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('requires the Behavior Host to register finite control before any Action', async () => {
|
|
190
|
-
const movement = deferred<void>();
|
|
191
|
-
const starts: string[] = [];
|
|
192
|
-
const registry = new ActionRegistry();
|
|
193
|
-
registry.activateScope(scope);
|
|
194
|
-
registry.register({
|
|
195
|
-
capability: 'player.action',
|
|
196
|
-
describeControl: (action: { resource: string }) => ({ domains: [action.resource] }),
|
|
197
|
-
perform: async (action, actionScope, caller) => {
|
|
198
|
-
starts.push(`${caller.kind}:${action.resource}`);
|
|
199
|
-
if (action.resource === 'movement') await movement.promise;
|
|
200
|
-
return { scope: actionScope, actionId: action.resource, status: 'success' as const };
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const caller = {
|
|
205
|
-
kind: 'behavior' as const,
|
|
206
|
-
activationId: 'short-1',
|
|
207
|
-
layer: 'short' as const,
|
|
208
|
-
activationGeneration: 1,
|
|
209
|
-
};
|
|
210
|
-
await expect(registry.perform(
|
|
211
|
-
'player.action',
|
|
212
|
-
{ resource: 'movement' },
|
|
213
|
-
scope,
|
|
214
|
-
caller,
|
|
215
|
-
)).resolves.toMatchObject({
|
|
216
|
-
status: 'deferred',
|
|
217
|
-
error: { code: 'CONTROL_UNKNOWN_CONTROLLER' },
|
|
218
|
-
});
|
|
219
|
-
expect(starts).toEqual([]);
|
|
220
|
-
|
|
221
|
-
registry.controls.registerController(behaviorControllerSpec(caller, {
|
|
222
|
-
scope,
|
|
223
|
-
domains: ['movement', 'communication'],
|
|
224
|
-
lifecycle: 'finite',
|
|
225
|
-
maxRuntimeMs: 60_000,
|
|
226
|
-
ready: true,
|
|
227
|
-
holdMode: 'per_resource',
|
|
228
|
-
}));
|
|
229
|
-
const behaviorMove = registry.perform(
|
|
230
|
-
'player.action',
|
|
231
|
-
{ resource: 'movement' },
|
|
232
|
-
scope,
|
|
233
|
-
caller,
|
|
234
|
-
);
|
|
235
|
-
const behaviorSpeech = registry.perform(
|
|
236
|
-
'player.action',
|
|
237
|
-
{ resource: 'communication' },
|
|
238
|
-
scope,
|
|
239
|
-
caller,
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
await expect(behaviorSpeech).resolves.toMatchObject({ actionId: 'communication' });
|
|
243
|
-
expect(starts).toEqual(['behavior:movement', 'behavior:communication']);
|
|
244
|
-
movement.resolve();
|
|
245
|
-
await behaviorMove;
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('does not resurrect a released finite Behavior from a stale same-activation Action', async () => {
|
|
249
|
-
const perform = vi.fn(async (_action, actionScope) => ({
|
|
250
|
-
scope: actionScope,
|
|
251
|
-
actionId: 'behavior-action',
|
|
252
|
-
status: 'success' as const,
|
|
253
|
-
}));
|
|
254
|
-
const registry = new ActionRegistry();
|
|
255
|
-
registry.register({ capability: 'player.action', perform });
|
|
256
|
-
const caller = {
|
|
257
|
-
kind: 'behavior' as const,
|
|
258
|
-
activationId: 'short-1',
|
|
259
|
-
layer: 'short' as const,
|
|
260
|
-
activationGeneration: 1,
|
|
261
|
-
};
|
|
262
|
-
const spec = behaviorControllerSpec(caller, {
|
|
263
|
-
scope,
|
|
264
|
-
domains: ['*'],
|
|
265
|
-
lifecycle: 'finite',
|
|
266
|
-
maxRuntimeMs: 60_000,
|
|
267
|
-
ready: true,
|
|
268
|
-
});
|
|
269
|
-
registry.controls.registerController(spec);
|
|
270
|
-
registry.releaseController(spec.controllerId, 'behavior_completed');
|
|
271
|
-
|
|
272
|
-
await expect(registry.perform(
|
|
273
|
-
'player.action', {}, scope, caller,
|
|
274
|
-
)).resolves.toMatchObject({
|
|
275
|
-
status: 'deferred',
|
|
276
|
-
error: { code: 'CONTROL_RELEASED' },
|
|
277
|
-
});
|
|
278
|
-
expect(perform).not.toHaveBeenCalled();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('returns a local deferred result when worker authority is revoked before provider submission', async () => {
|
|
282
|
-
const perform = vi.fn(async (_action, actionScope) => ({
|
|
283
|
-
scope: actionScope,
|
|
284
|
-
actionId: 'must-not-run',
|
|
285
|
-
status: 'success' as const,
|
|
286
|
-
}));
|
|
287
|
-
const registry = new ActionRegistry();
|
|
288
|
-
registry.register({ capability: 'player.move', perform });
|
|
289
|
-
|
|
290
|
-
await expect(registry.perform(
|
|
291
|
-
'player.move',
|
|
292
|
-
{ x: 1 },
|
|
293
|
-
scope,
|
|
294
|
-
{
|
|
295
|
-
kind: 'behavior',
|
|
296
|
-
activationId: 'revoked-worker',
|
|
297
|
-
layer: 'long',
|
|
298
|
-
activationGeneration: 1,
|
|
299
|
-
},
|
|
300
|
-
{ isAuthorized: () => false },
|
|
301
|
-
)).resolves.toMatchObject({
|
|
302
|
-
status: 'deferred',
|
|
303
|
-
error: { code: 'CONTROL_AUTHORITY_REVOKED' },
|
|
304
|
-
});
|
|
305
|
-
expect(perform).not.toHaveBeenCalled();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('revokes Action admission, aborts admitted work, and drains before shutdown', async () => {
|
|
309
|
-
const registry = new ActionRegistry();
|
|
310
|
-
let observedSignal: AbortSignal | undefined;
|
|
311
|
-
registry.register({
|
|
312
|
-
capability: 'player.wait',
|
|
313
|
-
perform: async (_action, actionScope, _caller, context) => {
|
|
314
|
-
observedSignal = context.signal;
|
|
315
|
-
await new Promise<void>((resolve) => {
|
|
316
|
-
if (context.signal.aborted) resolve();
|
|
317
|
-
else context.signal.addEventListener('abort', () => resolve(), { once: true });
|
|
318
|
-
});
|
|
319
|
-
return { actionId: 'stopped', scope: actionScope, status: 'failure' as const };
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
const admitted = registry.perform('player.wait', {}, scope, { kind: 'agent', id: 'a' });
|
|
323
|
-
await Promise.resolve();
|
|
324
|
-
|
|
325
|
-
registry.beginStopping('owner_stopping');
|
|
326
|
-
await registry.waitForIdle();
|
|
327
|
-
|
|
328
|
-
expect(observedSignal?.aborted).toBe(true);
|
|
329
|
-
await expect(admitted).resolves.toMatchObject({ actionId: 'stopped' });
|
|
330
|
-
await expect(registry.perform('player.wait', {}, scope, { kind: 'agent' }))
|
|
331
|
-
.rejects.toThrow('Action registry is stopping');
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it('releases control at a provider receipt but retains shutdown settlement ownership', async () => {
|
|
335
|
-
const settlement = deferred<{
|
|
336
|
-
scope: ScopeRef;
|
|
337
|
-
actionId: string;
|
|
338
|
-
status: 'success';
|
|
339
|
-
source: 'backend';
|
|
340
|
-
actionOutcome: 'confirmed';
|
|
341
|
-
}>();
|
|
342
|
-
const registry = new ActionRegistry();
|
|
343
|
-
registry.activateScope(scope);
|
|
344
|
-
const caller = {
|
|
345
|
-
kind: 'behavior' as const,
|
|
346
|
-
activationId: 'detached-behavior',
|
|
347
|
-
layer: 'long' as const,
|
|
348
|
-
activationGeneration: 1,
|
|
349
|
-
};
|
|
350
|
-
registry.controls.registerController(behaviorControllerSpec(caller, {
|
|
351
|
-
scope, domains: ['physical'], lifecycle: 'persistent', ready: true,
|
|
352
|
-
}));
|
|
353
|
-
registry.register({
|
|
354
|
-
capability: 'player.detached',
|
|
355
|
-
describeControl: () => ({ domains: ['physical'] }),
|
|
356
|
-
perform: (_action, actionScope) => ({
|
|
357
|
-
receipt: {
|
|
358
|
-
scope: actionScope,
|
|
359
|
-
actionId: 'detached-1',
|
|
360
|
-
status: 'success' as const,
|
|
361
|
-
source: 'local' as const,
|
|
362
|
-
actionOutcome: 'unknown' as const,
|
|
363
|
-
},
|
|
364
|
-
settled: settlement.promise,
|
|
365
|
-
}),
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
await expect(registry.perform(
|
|
369
|
-
'player.detached', {}, scope, caller,
|
|
370
|
-
)).resolves.toMatchObject({
|
|
371
|
-
actionId: 'detached-1',
|
|
372
|
-
status: 'success',
|
|
373
|
-
source: 'local',
|
|
374
|
-
actionOutcome: 'unknown',
|
|
375
|
-
});
|
|
376
|
-
expect(registry.controls.snapshot().inFlight).toHaveLength(0);
|
|
377
|
-
|
|
378
|
-
await expect(registry.perform(
|
|
379
|
-
'player.detached', {}, scope, caller,
|
|
380
|
-
)).resolves.toMatchObject({
|
|
381
|
-
actionId: 'detached-1',
|
|
382
|
-
status: 'success',
|
|
383
|
-
source: 'local',
|
|
384
|
-
actionOutcome: 'unknown',
|
|
385
|
-
});
|
|
386
|
-
expect(registry.controls.snapshot().inFlight).toHaveLength(0);
|
|
387
|
-
|
|
388
|
-
let drained = false;
|
|
389
|
-
const drain = registry.waitForIdle().then(() => { drained = true; });
|
|
390
|
-
await Promise.resolve();
|
|
391
|
-
expect(drained).toBe(false);
|
|
392
|
-
|
|
393
|
-
settlement.resolve({
|
|
394
|
-
scope,
|
|
395
|
-
actionId: 'detached-1',
|
|
396
|
-
status: 'success',
|
|
397
|
-
source: 'backend',
|
|
398
|
-
actionOutcome: 'confirmed',
|
|
399
|
-
});
|
|
400
|
-
await drain;
|
|
401
|
-
expect(registry.controls.snapshot().inFlight).toHaveLength(0);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it('rejects ambiguous duplicate providers', () => {
|
|
405
|
-
const registry = new ObservationRegistry();
|
|
406
|
-
const provider = {
|
|
407
|
-
capability: 'inventory',
|
|
408
|
-
query: async () => ({ scope, capability: 'inventory', receivedAt: '', freshness: 'fresh' as const, value: [] }),
|
|
409
|
-
};
|
|
410
|
-
registry.register(provider);
|
|
411
|
-
expect(() => registry.register(provider)).toThrow(CapabilityConflictError);
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
function deferred<T>() {
|
|
416
|
-
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
417
|
-
let reject!: (reason?: unknown) => void;
|
|
418
|
-
const promise = new Promise<T>((resolvePromise, rejectPromise) => {
|
|
419
|
-
resolve = resolvePromise;
|
|
420
|
-
reject = rejectPromise;
|
|
421
|
-
});
|
|
422
|
-
return { promise, resolve, reject };
|
|
423
|
-
}
|