@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,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { normalizeClawclawBehaviorAction } from './behavior-action.js';
|
|
3
|
-
|
|
4
|
-
describe('normalizeClawclawBehaviorAction', () => {
|
|
5
|
-
it('preserves only the shared allowed Action payload and adds Behavior fences', () => {
|
|
6
|
-
expect(normalizeClawclawBehaviorAction({
|
|
7
|
-
action: 'kill',
|
|
8
|
-
target_seat: 7,
|
|
9
|
-
thinking_content: 'commit',
|
|
10
|
-
}, 12, 4, 3)).toEqual({
|
|
11
|
-
route: 'auto',
|
|
12
|
-
action: {
|
|
13
|
-
action: 'kill',
|
|
14
|
-
target_seat: 7,
|
|
15
|
-
thinking_content: 'commit',
|
|
16
|
-
},
|
|
17
|
-
behaviorOriginEpochSeq: 12,
|
|
18
|
-
behaviorActionSafetyGeneration: 4,
|
|
19
|
-
behaviorActivationGeneration: 3,
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('applies authoritative seat validation and rejects voting', () => {
|
|
24
|
-
expect(() => normalizeClawclawBehaviorAction({
|
|
25
|
-
action: 'kill', target_seat: 0,
|
|
26
|
-
}, 12, 4, 1)).toThrowError('invalid_behavior_target');
|
|
27
|
-
expect(() => normalizeClawclawBehaviorAction({
|
|
28
|
-
action: 'vote', target_seat: 3,
|
|
29
|
-
}, 12, 4, 1)).toThrowError('unsupported_behavior_action');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('requires epoch, safety, and activation-generation fences', () => {
|
|
33
|
-
expect(() => normalizeClawclawBehaviorAction({ action: 'think' }, 0, 4, 1))
|
|
34
|
-
.toThrowError('invalid_behavior_action_epoch');
|
|
35
|
-
expect(() => normalizeClawclawBehaviorAction({ action: 'think' }, 12, undefined, 1))
|
|
36
|
-
.toThrowError('invalid_behavior_action_safety_generation');
|
|
37
|
-
expect(() => normalizeClawclawBehaviorAction({ action: 'think' }, 12, 4, 0))
|
|
38
|
-
.toThrowError('invalid_behavior_activation_generation');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
-
import { ClawclawBehaviorCatalog } from './behavior-catalog.js';
|
|
6
|
-
import { listClawclawBehaviorSources } from './behavior-source.js';
|
|
7
|
-
|
|
8
|
-
const roots: string[] = [];
|
|
9
|
-
|
|
10
|
-
function createCatalogFixture(): {
|
|
11
|
-
root: string;
|
|
12
|
-
catalog: ClawclawBehaviorCatalog;
|
|
13
|
-
markerA: string;
|
|
14
|
-
markerB: string;
|
|
15
|
-
} {
|
|
16
|
-
const root = mkdtempSync(join(tmpdir(), 'clawclaw-behavior-catalog-'));
|
|
17
|
-
roots.push(root);
|
|
18
|
-
const suffix = root.replace(/[^a-z0-9]/gi, '_');
|
|
19
|
-
const markerA = `__behavior_lazy_a_${suffix}`;
|
|
20
|
-
const markerB = `__behavior_lazy_b_${suffix}`;
|
|
21
|
-
writeFileSync(join(root, 'a.ts'), `
|
|
22
|
-
import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
|
|
23
|
-
globalThis.${markerA} = (globalThis.${markerA} ?? 0) + 1;
|
|
24
|
-
export default class LazyA extends ClawclawBehavior {
|
|
25
|
-
static readonly manifest = {
|
|
26
|
-
apiVersion: 3,
|
|
27
|
-
id: 'lazy_a',
|
|
28
|
-
name: 'Lazy A',
|
|
29
|
-
description: 'Selected lazy module.',
|
|
30
|
-
inputs: [{
|
|
31
|
-
id: 'label',
|
|
32
|
-
type: 'string',
|
|
33
|
-
description: 'Label.',
|
|
34
|
-
default: ' ready ',
|
|
35
|
-
}, {
|
|
36
|
-
id: 'mode',
|
|
37
|
-
type: 'enum',
|
|
38
|
-
description: 'Mode.',
|
|
39
|
-
values: ['safe', 'fast'],
|
|
40
|
-
default: 'safe',
|
|
41
|
-
}],
|
|
42
|
-
runtime: { defaultMs: 5_000, controlGraceMs: 250 },
|
|
43
|
-
} as const;
|
|
44
|
-
override normalize(input, api) {
|
|
45
|
-
return {
|
|
46
|
-
label: api.string(input.label, 'label'),
|
|
47
|
-
mode: api.choice(input.mode, 'mode', ['safe', 'fast']),
|
|
48
|
-
...api.timing(input),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
override decide() {}
|
|
52
|
-
}
|
|
53
|
-
`);
|
|
54
|
-
writeFileSync(join(root, 'b.ts'), `
|
|
55
|
-
import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
|
|
56
|
-
globalThis.${markerB} = (globalThis.${markerB} ?? 0) + 1;
|
|
57
|
-
export default class LazyB extends ClawclawBehavior {
|
|
58
|
-
static readonly manifest = {
|
|
59
|
-
apiVersion: 3,
|
|
60
|
-
id: 'lazy_b',
|
|
61
|
-
name: 'Lazy B',
|
|
62
|
-
description: 'Unselected lazy module.',
|
|
63
|
-
inputs: [],
|
|
64
|
-
} as const;
|
|
65
|
-
override decide() {}
|
|
66
|
-
}
|
|
67
|
-
`);
|
|
68
|
-
return {
|
|
69
|
-
root,
|
|
70
|
-
catalog: new ClawclawBehaviorCatalog(listClawclawBehaviorSources(root)),
|
|
71
|
-
markerA,
|
|
72
|
-
markerB,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
afterEach(() => {
|
|
77
|
-
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('ClawclawBehaviorCatalog', () => {
|
|
81
|
-
it('keeps list/has static and imports only the selected module on prepare', async () => {
|
|
82
|
-
const { catalog, markerA, markerB } = createCatalogFixture();
|
|
83
|
-
const globals = globalThis as Record<string, unknown>;
|
|
84
|
-
|
|
85
|
-
expect(catalog.has('lazy_a')).toBe(true);
|
|
86
|
-
expect(catalog.list().map(({ id, loadable }) => ({ id, loadable }))).toEqual([
|
|
87
|
-
{ id: 'lazy_a', loadable: true },
|
|
88
|
-
{ id: 'lazy_b', loadable: true },
|
|
89
|
-
]);
|
|
90
|
-
expect(globals[markerA]).toBeUndefined();
|
|
91
|
-
expect(globals[markerB]).toBeUndefined();
|
|
92
|
-
|
|
93
|
-
const prepared = await catalog.prepare('lazy_a', {});
|
|
94
|
-
expect(prepared.input).toEqual({
|
|
95
|
-
label: 'ready',
|
|
96
|
-
mode: 'safe',
|
|
97
|
-
timeout_ms: 5_000,
|
|
98
|
-
});
|
|
99
|
-
expect(prepared.timing).toEqual({ timeout_ms: 5_000 });
|
|
100
|
-
expect(Object.isFrozen(prepared.input)).toBe(true);
|
|
101
|
-
expect(globals[markerA]).toBe(1);
|
|
102
|
-
expect(globals[markerB]).toBeUndefined();
|
|
103
|
-
|
|
104
|
-
await catalog.prepare('lazy_a', { label: 'again', duration_ms: 2_000 });
|
|
105
|
-
expect(globals[markerA]).toBe(1);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('validates schema, timing, and normalized values before Activation', async () => {
|
|
109
|
-
const { catalog } = createCatalogFixture();
|
|
110
|
-
await expect(catalog.prepare('lazy_a', { unknown: true }))
|
|
111
|
-
.rejects.toThrow('behavior_input_field_unknown:unknown');
|
|
112
|
-
await expect(catalog.prepare('lazy_a', { mode: 'unsafe' }))
|
|
113
|
-
.rejects.toThrow('behavior_input_value_enum_invalid:mode');
|
|
114
|
-
await expect(catalog.prepare('lazy_a', {
|
|
115
|
-
timeout_ms: 2_000,
|
|
116
|
-
duration_ms: 2_000,
|
|
117
|
-
})).rejects.toThrow('behavior_runtime_ms_ambiguous');
|
|
118
|
-
await expect(catalog.prepare('lazy_a', { timeout_ms: 999 }))
|
|
119
|
-
.rejects.toThrow('behavior_runtime_ms_invalid');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('reports incompatible static entries without evaluating them and rejects duplicates', async () => {
|
|
123
|
-
const { root, catalog } = createCatalogFixture();
|
|
124
|
-
const legacyMarker = `__legacy_catalog_${root.replace(/[^a-z0-9]/gi, '_')}`;
|
|
125
|
-
writeFileSync(join(root, 'legacy.ts'), `
|
|
126
|
-
import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
|
|
127
|
-
globalThis.${legacyMarker} = true;
|
|
128
|
-
export default class Legacy extends ClawclawBehavior {
|
|
129
|
-
static readonly manifest = {
|
|
130
|
-
apiVersion: 2,
|
|
131
|
-
id: 'legacy',
|
|
132
|
-
name: 'Legacy',
|
|
133
|
-
description: 'Unsupported API.',
|
|
134
|
-
inputs: [],
|
|
135
|
-
} as const;
|
|
136
|
-
override decide() {}
|
|
137
|
-
}
|
|
138
|
-
`);
|
|
139
|
-
const sources = listClawclawBehaviorSources(root);
|
|
140
|
-
const withLegacy = new ClawclawBehaviorCatalog(sources);
|
|
141
|
-
expect(withLegacy.list().find(({ id }) => id === 'legacy')).toMatchObject({
|
|
142
|
-
apiVersion: 2,
|
|
143
|
-
expectedApiVersion: 3,
|
|
144
|
-
loadable: false,
|
|
145
|
-
compatibilityError: 'behavior_api_version_unsupported:expected=3:received=2',
|
|
146
|
-
});
|
|
147
|
-
await expect(withLegacy.load('legacy'))
|
|
148
|
-
.rejects.toThrow('behavior_api_version_unsupported:expected=3:received=2');
|
|
149
|
-
expect((globalThis as Record<string, unknown>)[legacyMarker]).toBeUndefined();
|
|
150
|
-
|
|
151
|
-
const [first] = listClawclawBehaviorSources(root);
|
|
152
|
-
expect(() => new ClawclawBehaviorCatalog([first, first]))
|
|
153
|
-
.toThrow(`Duplicate behavior module id '${first.id}'.`);
|
|
154
|
-
expect(catalog.has('legacy')).toBe(false);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
-
import { ClawclawBehavior } from '../../../../sdk/behavior-plugin/index.js';
|
|
6
|
-
import {
|
|
7
|
-
loadClawclawBehaviorModule,
|
|
8
|
-
validateClawclawBehaviorModule,
|
|
9
|
-
} from './behavior-module-loader.js';
|
|
10
|
-
import { listClawclawBehaviorSources } from './behavior-source.js';
|
|
11
|
-
|
|
12
|
-
const roots: string[] = [];
|
|
13
|
-
|
|
14
|
-
function fixture(id = 'loaded_behavior'): { root: string; path: string } {
|
|
15
|
-
const root = mkdtempSync(join(tmpdir(), 'clawclaw-behavior-loader-'));
|
|
16
|
-
roots.push(root);
|
|
17
|
-
const path = join(root, `${id}.ts`);
|
|
18
|
-
writeFileSync(path, `
|
|
19
|
-
import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
|
|
20
|
-
export default class LoadedBehavior extends ClawclawBehavior {
|
|
21
|
-
static override readonly manifest = {
|
|
22
|
-
apiVersion: 3,
|
|
23
|
-
id: '${id}',
|
|
24
|
-
name: 'Loaded behavior',
|
|
25
|
-
description: 'Loader parity fixture.',
|
|
26
|
-
inputs: [{
|
|
27
|
-
id: 'target',
|
|
28
|
-
type: 'string',
|
|
29
|
-
description: 'Target.',
|
|
30
|
-
required: true,
|
|
31
|
-
}],
|
|
32
|
-
execution: 'serial',
|
|
33
|
-
everyTicks: 2,
|
|
34
|
-
produces: ['custom.loaded'],
|
|
35
|
-
runtime: { defaultMs: 4_000, deadlineOutcome: 'completed' },
|
|
36
|
-
} as const;
|
|
37
|
-
override normalize(input) {
|
|
38
|
-
return { target: input.target };
|
|
39
|
-
}
|
|
40
|
-
override decide() {}
|
|
41
|
-
}
|
|
42
|
-
`);
|
|
43
|
-
return { root, path };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('Behavior module loader', () => {
|
|
51
|
-
it('loads one API v3 class and returns an immutable canonical manifest', async () => {
|
|
52
|
-
const { root } = fixture();
|
|
53
|
-
const [source] = listClawclawBehaviorSources(root);
|
|
54
|
-
const loaded = await loadClawclawBehaviorModule(source);
|
|
55
|
-
|
|
56
|
-
expect(typeof loaded.BehaviorClass.prototype.decide).toBe('function');
|
|
57
|
-
expect(loaded.manifest).toMatchObject({
|
|
58
|
-
id: 'loaded_behavior',
|
|
59
|
-
execution: 'serial',
|
|
60
|
-
everyTicks: 2,
|
|
61
|
-
runtime: { defaultMs: 4_000, deadlineOutcome: 'completed' },
|
|
62
|
-
});
|
|
63
|
-
expect(Object.isFrozen(loaded.manifest)).toBe(true);
|
|
64
|
-
expect(Object.isFrozen(loaded.manifest.inputs)).toBe(true);
|
|
65
|
-
expect(Object.isFrozen(loaded.manifest.runtime)).toBe(true);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('rejects every scanner/loader parity drift after import', async () => {
|
|
69
|
-
const { root } = fixture('parity_behavior');
|
|
70
|
-
const [source] = listClawclawBehaviorSources(root);
|
|
71
|
-
await expect(loadClawclawBehaviorModule({
|
|
72
|
-
...source,
|
|
73
|
-
runtime: { defaultMs: 5_000, deadlineOutcome: 'completed' },
|
|
74
|
-
})).rejects.toThrow('behavior_runtime_source_mismatch');
|
|
75
|
-
|
|
76
|
-
const loaded = await loadClawclawBehaviorModule(source);
|
|
77
|
-
const loadedModule = { default: loaded.BehaviorClass };
|
|
78
|
-
expect(() => validateClawclawBehaviorModule(loadedModule, {
|
|
79
|
-
...source,
|
|
80
|
-
execution: 'parallel',
|
|
81
|
-
})).toThrow('behavior_execution_source_mismatch');
|
|
82
|
-
expect(() => validateClawclawBehaviorModule(loadedModule, {
|
|
83
|
-
...source,
|
|
84
|
-
inputs: [],
|
|
85
|
-
})).toThrow('behavior_inputs_source_mismatch');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('rejects structural classes, invalid runtime declarations, and escaped paths', async () => {
|
|
89
|
-
class MissingDecision {
|
|
90
|
-
static readonly manifest = {
|
|
91
|
-
apiVersion: 3,
|
|
92
|
-
id: 'structural',
|
|
93
|
-
name: 'Structural',
|
|
94
|
-
description: 'Does not extend the public base.',
|
|
95
|
-
inputs: [],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
expect(() => validateClawclawBehaviorModule({ default: MissingDecision }))
|
|
99
|
-
.toThrow('behavior_decide_missing');
|
|
100
|
-
|
|
101
|
-
class InvalidRuntime extends ClawclawBehavior {
|
|
102
|
-
static override readonly manifest: any = {
|
|
103
|
-
apiVersion: 3,
|
|
104
|
-
id: 'invalid_runtime',
|
|
105
|
-
name: 'Invalid runtime',
|
|
106
|
-
description: 'Runtime budget exceeds the contract.',
|
|
107
|
-
inputs: [],
|
|
108
|
-
runtime: { defaultMs: 999 },
|
|
109
|
-
};
|
|
110
|
-
override decide() {}
|
|
111
|
-
}
|
|
112
|
-
expect(() => validateClawclawBehaviorModule({ default: InvalidRuntime }))
|
|
113
|
-
.toThrow('behavior_runtime_default_invalid');
|
|
114
|
-
|
|
115
|
-
const first = fixture('inside');
|
|
116
|
-
const second = fixture('outside');
|
|
117
|
-
const [outside] = listClawclawBehaviorSources(second.root);
|
|
118
|
-
await expect(loadClawclawBehaviorModule({
|
|
119
|
-
...outside,
|
|
120
|
-
sourceRoot: first.root,
|
|
121
|
-
})).rejects.toThrow("Behavior 'outside' source is outside its root.");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('allows fixed Events only through an explicit Host-owned source grant', async () => {
|
|
125
|
-
const { root, path } = fixture('official_event');
|
|
126
|
-
const original = String.raw`
|
|
127
|
-
import { ClawclawBehavior } from '@myclaw163/clawclaw-cli/behavior-plugin';
|
|
128
|
-
export default class OfficialEvent extends ClawclawBehavior {
|
|
129
|
-
static readonly manifest = {
|
|
130
|
-
apiVersion: 3,
|
|
131
|
-
id: 'official_event',
|
|
132
|
-
name: 'Official event',
|
|
133
|
-
description: 'Host-authenticated fixed Event fixture.',
|
|
134
|
-
inputs: [],
|
|
135
|
-
produces: ['strategy_alert'],
|
|
136
|
-
} as const;
|
|
137
|
-
override decide() {}
|
|
138
|
-
}
|
|
139
|
-
`;
|
|
140
|
-
writeFileSync(path, original);
|
|
141
|
-
const [source] = listClawclawBehaviorSources(root);
|
|
142
|
-
expect(source.compatibilityError).toBe('behavior_produces_reserved:strategy_alert');
|
|
143
|
-
await expect(loadClawclawBehaviorModule(source))
|
|
144
|
-
.rejects.toThrow('behavior_produces_reserved:strategy_alert');
|
|
145
|
-
await expect(loadClawclawBehaviorModule({
|
|
146
|
-
...source,
|
|
147
|
-
allowReservedProduces: ['strategy_alert'],
|
|
148
|
-
})).resolves.toMatchObject({
|
|
149
|
-
manifest: { produces: ['strategy_alert'] },
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('rejects unknown manifest and runtime fields after import', () => {
|
|
154
|
-
class UnknownManifestField extends ClawclawBehavior {
|
|
155
|
-
static override readonly manifest: any = {
|
|
156
|
-
apiVersion: 3,
|
|
157
|
-
id: 'unknown_manifest',
|
|
158
|
-
name: 'Unknown manifest',
|
|
159
|
-
description: 'Contains a removed field.',
|
|
160
|
-
inputs: [],
|
|
161
|
-
defaultRuntimeMs: 5_000,
|
|
162
|
-
};
|
|
163
|
-
override decide() {}
|
|
164
|
-
}
|
|
165
|
-
expect(() => validateClawclawBehaviorModule({ default: UnknownManifestField }))
|
|
166
|
-
.toThrow('behavior_manifest_field_unknown:defaultRuntimeMs');
|
|
167
|
-
|
|
168
|
-
class UnknownRuntimeField extends ClawclawBehavior {
|
|
169
|
-
static override readonly manifest: any = {
|
|
170
|
-
apiVersion: 3,
|
|
171
|
-
id: 'unknown_runtime',
|
|
172
|
-
name: 'Unknown runtime',
|
|
173
|
-
description: 'Contains an unknown runtime field.',
|
|
174
|
-
inputs: [],
|
|
175
|
-
runtime: { defaultMs: 5_000, retry: true },
|
|
176
|
-
};
|
|
177
|
-
override decide() {}
|
|
178
|
-
}
|
|
179
|
-
expect(() => validateClawclawBehaviorModule({ default: UnknownRuntimeField }))
|
|
180
|
-
.toThrow('behavior_runtime_field_unknown:retry');
|
|
181
|
-
});
|
|
182
|
-
});
|