@myclaw163/clawclaw-cli 0.8.4 → 0.8.6
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/behavior.md +10 -19
- 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 +15 -2
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/find-hide-spots.py +2 -2
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/skills/clawclaw/SKILL.md +25 -18
- package/skills/clawclaw/references/BEHAVIORS.md +15 -11
- package/skills/clawclaw/references/COMMANDS.md +45 -41
- package/skills/clawclaw/references/HUB.md +25 -38
- package/skills/clawclaw/references/TACTICS.md +1 -1
- 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/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 +24 -11
- 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/runtime/clawclaw/behavior-read-api.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
- package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
- package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
- package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +63 -19
- 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/game-query/game-query-plugin.ts +1 -1
- 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/framework/modules/runtime-module-loader.ts +0 -54
- package/src/sdk/behavior-toolkit/escape.ts +2 -2
- 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/scripts/compare-perception-replays.test.ts +0 -188
- package/scripts/enable_ccl_permissions.test.mjs +0 -163
- package/scripts/enable_monitor.test.mjs +0 -201
- package/scripts/sync-bundled-skill.test.mjs +0 -152
- package/scripts/watch-perception-events.test.ts +0 -43
- package/src/behaviors/official-finite/do-task.ts +0 -211
- package/src/behaviors/official-finite/evade.ts +0 -78
- package/src/behaviors/official-finite/find-player.ts +0 -50
- package/src/behaviors/official-finite/follow-player.ts +0 -70
- package/src/behaviors/official-finite/go-to.ts +0 -69
- package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
- package/src/behaviors/official-finite/hold-position.ts +0 -48
- package/src/behaviors/official-finite/hunt-player.ts +0 -47
- package/src/behaviors/official-finite/index.test.ts +0 -249
- package/src/behaviors/official-finite/index.ts +0 -44
- package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
- package/src/behaviors/official-finite/patrol-area.ts +0 -80
- package/src/behaviors/official-finite/report-corpse.ts +0 -73
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
- package/src/behaviors/official-finite/shared.ts +0 -27
- 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 -326
- package/src/lib/behavior-export.ts +0 -537
- 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 -257
- package/src/pipeline/event-format.test.ts +0 -879
- package/src/pipeline/event-hints.test.ts +0 -337
- package/src/pipeline/game-sync-event-normalization.test.ts +0 -419
- 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 -60
- 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 -328
- 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 -43
- 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/official-goal-behavior.ts +0 -757
- 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 -853
- 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 -128
- 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/action.test.ts +0 -8
- 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/avoid-lone.ts +0 -32
- package/src/strategies/avoid-players.ts +0 -43
- package/src/strategies/corpse-patrol.ts +0 -50
- package/src/strategies/crab-sabotage.ts +0 -48
- package/src/strategies/custom-module.test.ts +0 -267
- package/src/strategies/find-player.ts +0 -49
- package/src/strategies/game-utils.test.ts +0 -305
- package/src/strategies/game-utils.ts +0 -927
- package/src/strategies/goals/anchor-linger.ts +0 -77
- package/src/strategies/goals/avoid-lone-top.ts +0 -189
- package/src/strategies/goals/avoid-players-top.test.ts +0 -95
- package/src/strategies/goals/avoid-players-top.ts +0 -122
- package/src/strategies/goals/conversation-goal.ts +0 -51
- package/src/strategies/goals/corpse-patrol-top.ts +0 -120
- package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -131
- package/src/strategies/goals/crab-sabotage-top.ts +0 -139
- package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
- package/src/strategies/goals/find-player-top.ts +0 -136
- package/src/strategies/goals/flee-players-goal.ts +0 -55
- package/src/strategies/goals/follow-companion-goal.ts +0 -130
- package/src/strategies/goals/goal-manager.ts +0 -41
- package/src/strategies/goals/goal-root-strategy.ts +0 -49
- package/src/strategies/goals/goal.ts +0 -28
- package/src/strategies/goals/hide-top.ts +0 -240
- package/src/strategies/goals/keep-away-goal.ts +0 -243
- package/src/strategies/goals/kill-frenzy-top.ts +0 -90
- package/src/strategies/goals/kill-lone-top.test.ts +0 -96
- package/src/strategies/goals/kill-lone-top.ts +0 -166
- package/src/strategies/goals/kill-target-goal.ts +0 -69
- package/src/strategies/goals/kill-target-top.test.ts +0 -65
- package/src/strategies/goals/kill-target-top.ts +0 -121
- package/src/strategies/goals/leaf-goal.ts +0 -27
- package/src/strategies/goals/linger-corpse-goal.ts +0 -43
- package/src/strategies/goals/lone-kill-core.ts +0 -86
- package/src/strategies/goals/lone-kill-goal.ts +0 -24
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -84
- package/src/strategies/goals/lone-kill-task-top.ts +0 -133
- package/src/strategies/goals/move-room-goal.ts +0 -102
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -112
- package/src/strategies/goals/normal-shrimp-top.ts +0 -248
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -203
- package/src/strategies/goals/paradise-fish-top.ts +0 -234
- package/src/strategies/goals/patrol-top.ts +0 -68
- package/src/strategies/goals/report-patrol-top.ts +0 -97
- package/src/strategies/goals/safe-task-goal.ts +0 -130
- package/src/strategies/goals/social-task-top.ts +0 -192
- package/src/strategies/goals/task-kill-report-top.ts +0 -187
- package/src/strategies/goals/task-only-top.test.ts +0 -88
- package/src/strategies/goals/task-only-top.ts +0 -64
- package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
- package/src/strategies/goals/task-report-top.ts +0 -57
- package/src/strategies/goals/wander-task-goal.ts +0 -33
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -138
- package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
- package/src/strategies/greeting.ts +0 -60
- package/src/strategies/hide.ts +0 -51
- package/src/strategies/kill-frenzy.ts +0 -32
- package/src/strategies/kill-lone.ts +0 -52
- package/src/strategies/kill-target.ts +0 -48
- package/src/strategies/lone-kill-task.ts +0 -48
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/meeting-gate.ts +0 -28
- package/src/strategies/move-room.ts +0 -46
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/paradise-fish.ts +0 -70
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/patrol.ts +0 -32
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/player-targets.ts +0 -18
- package/src/strategies/report-patrol.ts +0 -32
- package/src/strategies/shrimp-memory.ts +0 -87
- package/src/strategies/social-task.ts +0 -67
- package/src/strategies/speech-module.ts +0 -123
- package/src/strategies/task-kill-report.ts +0 -49
- package/src/strategies/task-only.test.ts +0 -138
- package/src/strategies/task-only.ts +0 -34
- package/src/strategies/task-report.ts +0 -50
- package/src/strategies/types.ts +0 -116
- package/src/strategies/warrior-memory.ts +0 -54
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
- /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
existsSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
mkdtempSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
readdirSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
writeFileSync,
|
|
10
|
-
} from 'node:fs';
|
|
11
|
-
import { tmpdir } from 'node:os';
|
|
12
|
-
import { dirname, join, resolve } from 'node:path';
|
|
13
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
14
|
-
|
|
15
|
-
const scriptPath = resolve('scripts', 'enable_monitor.cjs');
|
|
16
|
-
const tempRoots = [];
|
|
17
|
-
|
|
18
|
-
function makeRoot(prefix) {
|
|
19
|
-
const root = mkdtempSync(join(tmpdir(), prefix));
|
|
20
|
-
tempRoots.push(root);
|
|
21
|
-
return root;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function writeJson(file, value) {
|
|
25
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
26
|
-
writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function readJson(file) {
|
|
30
|
-
return JSON.parse(readFileSync(file, 'utf8'));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function runScript(root, args, extraEnv = {}) {
|
|
34
|
-
return spawnSync(process.execPath, [scriptPath, ...args], {
|
|
35
|
-
cwd: resolve('.'),
|
|
36
|
-
encoding: 'utf8',
|
|
37
|
-
env: {
|
|
38
|
-
...process.env,
|
|
39
|
-
APPDATA: join(root, 'appdata'),
|
|
40
|
-
CLAUDE_CODE_GIT_BASH_PATH: '',
|
|
41
|
-
...extraEnv,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function backupDirs(root) {
|
|
47
|
-
const backupRoot = join(root, 'appdata', 'clawclaw', 'claude-config-backups');
|
|
48
|
-
if (!existsSync(backupRoot)) return [];
|
|
49
|
-
return readdirSync(backupRoot, { withFileTypes: true })
|
|
50
|
-
.filter((entry) => entry.isDirectory() && entry.name.startsWith('enable-monitor-'))
|
|
51
|
-
.map((entry) => join(backupRoot, entry.name))
|
|
52
|
-
.sort();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function makeFakeBash(root) {
|
|
56
|
-
const bashPath = join(root, 'Git', 'bin', 'bash.exe');
|
|
57
|
-
mkdirSync(dirname(bashPath), { recursive: true });
|
|
58
|
-
writeFileSync(bashPath, '');
|
|
59
|
-
return bashPath;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
afterEach(() => {
|
|
63
|
-
while (tempRoots.length) {
|
|
64
|
-
rmSync(tempRoots.pop(), { recursive: true, force: true });
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('enable_monitor.cjs', () => {
|
|
69
|
-
it('repairs config and settings, backs up originals, and reverts a specified backup', () => {
|
|
70
|
-
const root = makeRoot('enable-monitor-ok-');
|
|
71
|
-
const configPath = join(root, 'claude.json');
|
|
72
|
-
const settingsPath = join(root, '.claude', 'settings.json');
|
|
73
|
-
const bashPath = makeFakeBash(root);
|
|
74
|
-
const originalConfig = {
|
|
75
|
-
cachedGrowthBookFeatures: { existing_flag: true },
|
|
76
|
-
cachedGrowthBookFeaturesAt: 123,
|
|
77
|
-
};
|
|
78
|
-
const originalSettings = {
|
|
79
|
-
env: {
|
|
80
|
-
ENABLE_TOOL_SEARCH: '0',
|
|
81
|
-
CLAUDE_CODE_GIT_BASH_PATH: 'C:\\missing\\bash.exe',
|
|
82
|
-
DISABLE_TELEMETRY: '1',
|
|
83
|
-
KEEP_ME: 'yes',
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
writeJson(configPath, originalConfig);
|
|
87
|
-
writeJson(settingsPath, originalSettings);
|
|
88
|
-
|
|
89
|
-
const result = runScript(root, [
|
|
90
|
-
'--config',
|
|
91
|
-
configPath,
|
|
92
|
-
'--settings',
|
|
93
|
-
settingsPath,
|
|
94
|
-
'--git-bash-path',
|
|
95
|
-
bashPath,
|
|
96
|
-
]);
|
|
97
|
-
|
|
98
|
-
expect(result.status).toBe(0);
|
|
99
|
-
const config = readJson(configPath);
|
|
100
|
-
const settings = readJson(settingsPath);
|
|
101
|
-
expect(config.cachedGrowthBookFeatures.tengu_amber_sentinel).toBe(true);
|
|
102
|
-
expect(config.cachedGrowthBookFeatures.existing_flag).toBe(true);
|
|
103
|
-
expect(settings.env.ENABLE_TOOL_SEARCH).toBe('true');
|
|
104
|
-
expect(settings.env.CLAUDE_CODE_GIT_BASH_PATH).toBe(bashPath);
|
|
105
|
-
expect(settings.env.DISABLE_TELEMETRY).toBeUndefined();
|
|
106
|
-
expect(settings.env.KEEP_ME).toBe('yes');
|
|
107
|
-
|
|
108
|
-
const backups = backupDirs(root);
|
|
109
|
-
expect(backups).toHaveLength(1);
|
|
110
|
-
expect(readJson(join(backups[0], 'claude.json'))).toEqual(originalConfig);
|
|
111
|
-
expect(readJson(join(backups[0], 'settings.json'))).toEqual(originalSettings);
|
|
112
|
-
const manifest = readJson(join(backups[0], 'manifest.json'));
|
|
113
|
-
expect(manifest.entries.map((entry) => entry.backupFile).sort()).toEqual([
|
|
114
|
-
'claude.json',
|
|
115
|
-
'settings.json',
|
|
116
|
-
]);
|
|
117
|
-
|
|
118
|
-
const revert = runScript(root, [
|
|
119
|
-
'--revert',
|
|
120
|
-
'--revert-backup',
|
|
121
|
-
backups[0],
|
|
122
|
-
'--config',
|
|
123
|
-
configPath,
|
|
124
|
-
'--settings',
|
|
125
|
-
settingsPath,
|
|
126
|
-
]);
|
|
127
|
-
|
|
128
|
-
expect(revert.status).toBe(0);
|
|
129
|
-
expect(readJson(configPath)).toEqual(originalConfig);
|
|
130
|
-
expect(readJson(settingsPath)).toEqual(originalSettings);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('dry-run reports changes without writing files or backups', () => {
|
|
134
|
-
const root = makeRoot('enable-monitor-dry-');
|
|
135
|
-
const configPath = join(root, 'claude.json');
|
|
136
|
-
const settingsPath = join(root, '.claude', 'settings.json');
|
|
137
|
-
const bashPath = makeFakeBash(root);
|
|
138
|
-
const originalConfig = { cachedGrowthBookFeatures: {} };
|
|
139
|
-
const originalSettings = { env: { ENABLE_TOOL_SEARCH: '0' } };
|
|
140
|
-
writeJson(configPath, originalConfig);
|
|
141
|
-
writeJson(settingsPath, originalSettings);
|
|
142
|
-
|
|
143
|
-
const result = runScript(root, [
|
|
144
|
-
'--dry-run',
|
|
145
|
-
'--config',
|
|
146
|
-
configPath,
|
|
147
|
-
'--settings',
|
|
148
|
-
settingsPath,
|
|
149
|
-
'--git-bash-path',
|
|
150
|
-
bashPath,
|
|
151
|
-
]);
|
|
152
|
-
|
|
153
|
-
expect(result.status).toBe(0);
|
|
154
|
-
expect(result.stdout).toContain('[DRY RUN] Would write');
|
|
155
|
-
expect(readJson(configPath)).toEqual(originalConfig);
|
|
156
|
-
expect(readJson(settingsPath)).toEqual(originalSettings);
|
|
157
|
-
expect(backupDirs(root)).toHaveLength(0);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('bad git-bash path blocks flag injection and leaves a backup that can restore partial cleanup', () => {
|
|
161
|
-
const root = makeRoot('enable-monitor-bad-bash-');
|
|
162
|
-
const configPath = join(root, 'claude.json');
|
|
163
|
-
const settingsPath = join(root, '.claude', 'settings.json');
|
|
164
|
-
const originalConfig = { cachedGrowthBookFeatures: {} };
|
|
165
|
-
const originalSettings = { env: { ENABLE_TOOL_SEARCH: '0' } };
|
|
166
|
-
writeJson(configPath, originalConfig);
|
|
167
|
-
writeJson(settingsPath, originalSettings);
|
|
168
|
-
|
|
169
|
-
const result = runScript(root, [
|
|
170
|
-
'--config',
|
|
171
|
-
configPath,
|
|
172
|
-
'--settings',
|
|
173
|
-
settingsPath,
|
|
174
|
-
'--git-bash-path',
|
|
175
|
-
join(root, 'missing', 'bash.exe'),
|
|
176
|
-
]);
|
|
177
|
-
|
|
178
|
-
expect(result.status).toBe(1);
|
|
179
|
-
expect(result.stdout).toContain('Backup at:');
|
|
180
|
-
expect(readJson(configPath)).toEqual(originalConfig);
|
|
181
|
-
expect(readJson(settingsPath).env.ENABLE_TOOL_SEARCH).toBe('true');
|
|
182
|
-
|
|
183
|
-
const backups = backupDirs(root);
|
|
184
|
-
expect(backups).toHaveLength(1);
|
|
185
|
-
expect(readJson(join(backups[0], 'settings.json'))).toEqual(originalSettings);
|
|
186
|
-
|
|
187
|
-
const revert = runScript(root, [
|
|
188
|
-
'--revert',
|
|
189
|
-
'--revert-backup',
|
|
190
|
-
backups[0],
|
|
191
|
-
'--config',
|
|
192
|
-
configPath,
|
|
193
|
-
'--settings',
|
|
194
|
-
settingsPath,
|
|
195
|
-
]);
|
|
196
|
-
|
|
197
|
-
expect(revert.status).toBe(0);
|
|
198
|
-
expect(readJson(configPath)).toEqual(originalConfig);
|
|
199
|
-
expect(readJson(settingsPath)).toEqual(originalSettings);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { backupInstalledSkillTargets, syncBundledSkill } from './sync-bundled-skill.mjs';
|
|
6
|
-
|
|
7
|
-
function writeSkill(dir, version, body) {
|
|
8
|
-
mkdirSync(dir, { recursive: true });
|
|
9
|
-
writeFileSync(join(dir, 'SKILL.md'), `---\nname: clawclaw\nversion: ${version}\n---\n${body}\n`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function writeInstallDir(root) {
|
|
13
|
-
const installDir = join(root, 'pkg');
|
|
14
|
-
writeSkill(join(installDir, 'skills', 'clawclaw'), '4.8.18', 'new');
|
|
15
|
-
mkdirSync(join(installDir, 'node_modules', 'skills'), { recursive: true });
|
|
16
|
-
writeFileSync(join(installDir, 'node_modules', 'skills', 'package.json'), JSON.stringify({
|
|
17
|
-
bin: { skills: 'bin/cli.mjs' },
|
|
18
|
-
}));
|
|
19
|
-
mkdirSync(join(installDir, 'node_modules', 'skills', 'bin'), { recursive: true });
|
|
20
|
-
writeFileSync(join(installDir, 'node_modules', 'skills', 'bin', 'cli.mjs'), '');
|
|
21
|
-
return installDir;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe('sync-bundled-skill', () => {
|
|
25
|
-
it('backs up only unique skill contents', () => {
|
|
26
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-'));
|
|
27
|
-
const one = join(root, 'home', '.claude', 'skills', 'clawclaw');
|
|
28
|
-
const two = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
29
|
-
const three = join(root, 'home', '.openclaw', 'skills', 'clawclaw');
|
|
30
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
31
|
-
writeSkill(one, '4.8.17', 'same');
|
|
32
|
-
writeSkill(two, '4.8.17', 'same');
|
|
33
|
-
writeSkill(three, '4.8.16', 'different');
|
|
34
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
35
|
-
|
|
36
|
-
const result = backupInstalledSkillTargets({
|
|
37
|
-
sourceDir: newSkill,
|
|
38
|
-
backupRoot: join(root, 'backups'),
|
|
39
|
-
candidateDirs: [one, two, three],
|
|
40
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(result.backupDir).toBe(join(root, 'backups', 'clawclaw-20260611-080910Z'));
|
|
44
|
-
expect(result.copies).toHaveLength(2);
|
|
45
|
-
expect(result.entries).toHaveLength(3);
|
|
46
|
-
expect(result.entries[0].copy).toBe(result.entries[1].copy);
|
|
47
|
-
expect(result.entries[2].copy).not.toBe(result.entries[0].copy);
|
|
48
|
-
const manifest = JSON.parse(readFileSync(join(result.backupDir, 'manifest.json'), 'utf8'));
|
|
49
|
-
expect(manifest.newSkillVersion).toBe('4.8.18');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('does not back up installed skills that already match the bundled skill', () => {
|
|
53
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-same-'));
|
|
54
|
-
const installed = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
55
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
56
|
-
writeSkill(installed, '4.8.18', 'new');
|
|
57
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
58
|
-
|
|
59
|
-
const result = backupInstalledSkillTargets({
|
|
60
|
-
sourceDir: newSkill,
|
|
61
|
-
backupRoot: join(root, 'backups'),
|
|
62
|
-
candidateDirs: [installed],
|
|
63
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(result).toBeNull();
|
|
67
|
-
expect(existsSync(join(root, 'backups'))).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('backs up only installed skills that differ from the bundled skill', () => {
|
|
71
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-mixed-'));
|
|
72
|
-
const same = join(root, 'home', '.claude', 'skills', 'clawclaw');
|
|
73
|
-
const different = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
74
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
75
|
-
writeSkill(same, '4.8.18', 'new');
|
|
76
|
-
writeSkill(different, '4.8.17', 'old');
|
|
77
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
78
|
-
|
|
79
|
-
const result = backupInstalledSkillTargets({
|
|
80
|
-
sourceDir: newSkill,
|
|
81
|
-
backupRoot: join(root, 'backups'),
|
|
82
|
-
candidateDirs: [same, different],
|
|
83
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(result.copies).toHaveLength(1);
|
|
87
|
-
expect(result.entries).toHaveLength(1);
|
|
88
|
-
expect(result.entries[0].sourcePath).toBe(different);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('runs skills add after a successful backup', () => {
|
|
92
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-sync-'));
|
|
93
|
-
const installDir = writeInstallDir(root);
|
|
94
|
-
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
95
|
-
writeSkill(old, '4.8.17', 'old');
|
|
96
|
-
const spawn = vi.fn(() => ({ status: 0 }));
|
|
97
|
-
|
|
98
|
-
const result = syncBundledSkill({
|
|
99
|
-
installDir,
|
|
100
|
-
backupRoot: join(root, 'backups'),
|
|
101
|
-
candidateDirs: [old],
|
|
102
|
-
spawnSync: spawn,
|
|
103
|
-
stdio: 'ignore',
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
expect(result.copyCount).toBe(1);
|
|
107
|
-
expect(spawn).toHaveBeenCalledOnce();
|
|
108
|
-
expect(spawn.mock.calls[0][1].slice(1)).toEqual([
|
|
109
|
-
'add',
|
|
110
|
-
join(installDir, 'skills', 'clawclaw'),
|
|
111
|
-
'-y',
|
|
112
|
-
'-g',
|
|
113
|
-
]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('does not run skills add when backup fails', () => {
|
|
117
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-fail-'));
|
|
118
|
-
const installDir = writeInstallDir(root);
|
|
119
|
-
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
120
|
-
writeSkill(old, '4.8.17', 'old');
|
|
121
|
-
const backupRootFile = join(root, 'backups-file');
|
|
122
|
-
writeFileSync(backupRootFile, 'not a directory');
|
|
123
|
-
const spawn = vi.fn(() => ({ status: 0 }));
|
|
124
|
-
|
|
125
|
-
expect(() => syncBundledSkill({
|
|
126
|
-
installDir,
|
|
127
|
-
backupRoot: backupRootFile,
|
|
128
|
-
candidateDirs: [old],
|
|
129
|
-
spawnSync: spawn,
|
|
130
|
-
stdio: 'ignore',
|
|
131
|
-
})).toThrow();
|
|
132
|
-
expect(spawn).not.toHaveBeenCalled();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('keeps backup when skills add fails', () => {
|
|
136
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-add-fail-'));
|
|
137
|
-
const installDir = writeInstallDir(root);
|
|
138
|
-
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
139
|
-
const backupRoot = join(root, 'backups');
|
|
140
|
-
writeSkill(old, '4.8.17', 'old');
|
|
141
|
-
const spawn = vi.fn(() => ({ status: 1 }));
|
|
142
|
-
|
|
143
|
-
expect(() => syncBundledSkill({
|
|
144
|
-
installDir,
|
|
145
|
-
backupRoot,
|
|
146
|
-
candidateDirs: [old],
|
|
147
|
-
spawnSync: spawn,
|
|
148
|
-
stdio: 'ignore',
|
|
149
|
-
})).toThrow(/skills add exited/);
|
|
150
|
-
expect(existsSync(backupRoot)).toBe(true);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import type { CanonicalEvent } from '../src/runtime/framework/events/index.js';
|
|
3
|
-
import {
|
|
4
|
-
formatPerceptionEvent,
|
|
5
|
-
parsePerceptionWatchOptions,
|
|
6
|
-
} from './watch-perception-events.js';
|
|
7
|
-
|
|
8
|
-
describe('perception Event live viewer', () => {
|
|
9
|
-
it('uses a fast non-consuming tail by default', () => {
|
|
10
|
-
expect(parsePerceptionWatchOptions([])).toEqual({
|
|
11
|
-
fromStart: false,
|
|
12
|
-
intervalMs: 100,
|
|
13
|
-
json: false,
|
|
14
|
-
maxEvents: null,
|
|
15
|
-
});
|
|
16
|
-
expect(parsePerceptionWatchOptions([
|
|
17
|
-
'--from-start', '--json', '--interval-ms', '250', '--max-events', '3',
|
|
18
|
-
])).toEqual({ fromStart: true, intervalMs: 250, json: true, maxEvents: 3 });
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('formats the generated interval and text without losing runtime identity', () => {
|
|
22
|
-
const event = {
|
|
23
|
-
commitSeq: 42,
|
|
24
|
-
epochSeq: 19,
|
|
25
|
-
eventId: 'visual-42',
|
|
26
|
-
sessionId: 'session-1',
|
|
27
|
-
segmentId: 'segment-1',
|
|
28
|
-
type: 'visual.player_moved',
|
|
29
|
-
producer: 'local_synth',
|
|
30
|
-
producerPluginId: 'clawclaw.perception',
|
|
31
|
-
deliveryClass: 'internal_only',
|
|
32
|
-
occurredAt: '2026-07-24T01:02:03.456Z',
|
|
33
|
-
receivedAt: '2026-07-24T01:02:03.500Z',
|
|
34
|
-
payload: { from_tick: 100, to_tick: 108, text: '7号向右移动。' },
|
|
35
|
-
sourceId: 'runtime',
|
|
36
|
-
replayed: false,
|
|
37
|
-
} satisfies CanonicalEvent;
|
|
38
|
-
|
|
39
|
-
expect(formatPerceptionEvent(event)).toBe(
|
|
40
|
-
'[01:02:03.456] #42 epoch 19 ticks 100-108 visual.player_moved | 7号向右移动。',
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawBehavior,
|
|
3
|
-
type BehaviorInput,
|
|
4
|
-
type BehaviorNormalizationApi,
|
|
5
|
-
type BehaviorReadApi,
|
|
6
|
-
type ClawclawBehaviorManifest,
|
|
7
|
-
} from '../../sdk/behavior-plugin/index.js';
|
|
8
|
-
import {
|
|
9
|
-
behaviorEventMentionsTarget,
|
|
10
|
-
behaviorSelf,
|
|
11
|
-
behaviorTaskAvailable,
|
|
12
|
-
behaviorTasks,
|
|
13
|
-
normalizedBehaviorLabel,
|
|
14
|
-
SemanticMoveGate,
|
|
15
|
-
type BehaviorTaskPoint,
|
|
16
|
-
} from '../../sdk/behavior-toolkit/index.js';
|
|
17
|
-
import { finished, running } from './shared.js';
|
|
18
|
-
|
|
19
|
-
type TaskSelector = 'nearest' | 'any';
|
|
20
|
-
type DoTaskInput = Readonly<Record<string, unknown>> & {
|
|
21
|
-
readonly task?: string;
|
|
22
|
-
readonly selector?: TaskSelector;
|
|
23
|
-
readonly timeout_ms?: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function matchingTaskEvent(
|
|
27
|
-
input: Readonly<BehaviorInput>,
|
|
28
|
-
type: string,
|
|
29
|
-
taskId?: string,
|
|
30
|
-
taskName?: string,
|
|
31
|
-
): Readonly<Record<string, unknown>> | undefined {
|
|
32
|
-
return input.events.find((event) => {
|
|
33
|
-
if (event.type !== type) return false;
|
|
34
|
-
const payload = event.payload;
|
|
35
|
-
const candidates = [payload.task_id, payload.task_name, payload.task]
|
|
36
|
-
.filter((value): value is string => typeof value === 'string' && value.length > 0)
|
|
37
|
-
.map(normalizedBehaviorLabel);
|
|
38
|
-
return [taskId, taskName]
|
|
39
|
-
.filter((value): value is string => typeof value === 'string' && value.length > 0)
|
|
40
|
-
.map(normalizedBehaviorLabel)
|
|
41
|
-
.some((value) => candidates.includes(value));
|
|
42
|
-
})?.payload;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function cooldownSummary(gameState: Readonly<BehaviorInput['gameState']>): string {
|
|
46
|
-
const remaining = gameState.crab_sabotage?.cooldown_remaining_secs;
|
|
47
|
-
return typeof remaining === 'number' && Number.isFinite(remaining)
|
|
48
|
-
? `,共享冷却剩余${remaining}秒`
|
|
49
|
-
: '';
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default class DoTaskBehavior extends ClawclawBehavior<DoTaskInput> {
|
|
53
|
-
static override readonly manifest = {
|
|
54
|
-
apiVersion: 3,
|
|
55
|
-
id: 'do_task',
|
|
56
|
-
name: 'Do Task',
|
|
57
|
-
description: 'Navigate to and submit one currently available task.',
|
|
58
|
-
localizations: { 'zh-CN': { name: '执行任务', description: '前往并提交一个当前可用任务。' } },
|
|
59
|
-
inputs: [
|
|
60
|
-
{ id: 'task', type: 'string', description: 'Exact task id or name. Mutually exclusive with selector.' },
|
|
61
|
-
{ id: 'selector', type: 'enum', description: 'Task selector. Mutually exclusive with task.', values: ['nearest', 'any'] },
|
|
62
|
-
],
|
|
63
|
-
execution: 'serial',
|
|
64
|
-
runtime: { defaultMs: 60_000, deadlineOutcome: 'failed' },
|
|
65
|
-
} as const satisfies ClawclawBehaviorManifest;
|
|
66
|
-
|
|
67
|
-
private readonly move = new SemanticMoveGate();
|
|
68
|
-
private selectedTaskId?: string;
|
|
69
|
-
private selectedTaskName?: string;
|
|
70
|
-
private submittedAtMs?: number;
|
|
71
|
-
|
|
72
|
-
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): DoTaskInput {
|
|
73
|
-
const task = api.optionalString(input.task, 'task');
|
|
74
|
-
const selector = input.selector === undefined
|
|
75
|
-
? undefined
|
|
76
|
-
: api.choice(input.selector, 'task_selection', ['nearest', 'any'] as const);
|
|
77
|
-
if (!!task === !!selector) throw new Error('behavior_task_selection_invalid');
|
|
78
|
-
return { ...api.timing(input), ...(task ? { task } : { selector }) };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
override async decide(input: Readonly<BehaviorInput<DoTaskInput>>, api: BehaviorReadApi) {
|
|
82
|
-
if (this.submittedAtMs !== undefined && this.selectedTaskName) {
|
|
83
|
-
const selected = behaviorTasks(input).find((task) => (
|
|
84
|
-
(this.selectedTaskId && task.id === this.selectedTaskId)
|
|
85
|
-
|| task.name === this.selectedTaskName
|
|
86
|
-
));
|
|
87
|
-
if (
|
|
88
|
-
selected?.status === 'completed'
|
|
89
|
-
|| behaviorEventMentionsTarget(input.events, ['task_completed'], this.selectedTaskName)
|
|
90
|
-
) return finished('completed', 'task_completed', `任务“${this.selectedTaskName}”已完成。`);
|
|
91
|
-
if (matchingTaskEvent(input, 'task_interrupted', this.selectedTaskId, this.selectedTaskName)) {
|
|
92
|
-
return finished(
|
|
93
|
-
'failed',
|
|
94
|
-
'task_interrupted',
|
|
95
|
-
`破坏任务“${this.selectedTaskName}”被紧急任务打断,任务未消耗${cooldownSummary(input.gameState)}。`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
if (selected && this.isCrabSabotage(input, selected)) {
|
|
99
|
-
const blocked = this.sabotageBlocked(input);
|
|
100
|
-
if (blocked) return blocked;
|
|
101
|
-
}
|
|
102
|
-
if (!selected && input.nowMs - this.submittedAtMs > 1_000) {
|
|
103
|
-
return finished('failed', 'task_unavailable', `任务“${this.selectedTaskName}”不再可用。`);
|
|
104
|
-
}
|
|
105
|
-
return running(`等待任务“${this.selectedTaskName}”的权威完成状态;不会重复提交。`, 'doing_task', [], { task: this.selectedTaskName });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const selected = await this.selectTask(input, api);
|
|
109
|
-
if (!selected) {
|
|
110
|
-
return finished('failed', 'task_unavailable', input.input.task
|
|
111
|
-
? `任务“${input.input.task}”已经不可执行。`
|
|
112
|
-
: '当前没有符合选择条件的可执行任务。');
|
|
113
|
-
}
|
|
114
|
-
if (this.isCrabSabotage(input, selected.task)) {
|
|
115
|
-
const blocked = this.sabotageBlocked(input);
|
|
116
|
-
if (blocked) return blocked;
|
|
117
|
-
}
|
|
118
|
-
if (selected.distance > 12) {
|
|
119
|
-
const summary = `正在前往${selected.task.room ?? '任务点'}执行“${selected.task.name}”。`;
|
|
120
|
-
const action = this.move.propose(input, selected.task, false, summary);
|
|
121
|
-
return running(summary, 'moving', action ? [action] : [], {
|
|
122
|
-
task: selected.task.name,
|
|
123
|
-
...(selected.task.room ? { room: selected.task.room } : {}),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
this.selectedTaskId = selected.task.id;
|
|
127
|
-
this.selectedTaskName = selected.task.name;
|
|
128
|
-
this.submittedAtMs = input.nowMs;
|
|
129
|
-
const summary = `正在提交任务“${selected.task.name}”并等待权威结果。`;
|
|
130
|
-
return running(summary, 'doing_task', [{ action: 'task', task_name: selected.task.name, thinking_content: summary }], { task: selected.task.name });
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private isCrabSabotage(
|
|
134
|
-
input: Readonly<BehaviorInput<DoTaskInput>>,
|
|
135
|
-
task: Readonly<BehaviorTaskPoint>,
|
|
136
|
-
): boolean {
|
|
137
|
-
return input.gameState.you?.faction === 'crab' && task.isFakeShrimp === false;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private sabotageBlocked(
|
|
141
|
-
input: Readonly<BehaviorInput<DoTaskInput>>,
|
|
142
|
-
): ReturnType<typeof finished> | undefined {
|
|
143
|
-
const status = input.gameState.crab_sabotage?.status;
|
|
144
|
-
if (status === 'ready') return undefined;
|
|
145
|
-
if (status === 'cooldown_charged') {
|
|
146
|
-
return finished(
|
|
147
|
-
'failed',
|
|
148
|
-
'sabotage_on_cooldown',
|
|
149
|
-
`蟹破坏任务仍在共享冷却中${cooldownSummary(input.gameState)}。`,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
if (status === 'emergency_active') {
|
|
153
|
-
return finished(
|
|
154
|
-
'failed',
|
|
155
|
-
'sabotage_blocked_during_emergency',
|
|
156
|
-
'紧急任务进行中,不能开始或继续新的蟹破坏任务。',
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
return finished('failed', 'sabotage_state_unavailable', '当前没有可确认的蟹破坏任务准入状态。');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private async selectTask(
|
|
163
|
-
input: Readonly<BehaviorInput<DoTaskInput>>,
|
|
164
|
-
api: BehaviorReadApi,
|
|
165
|
-
): Promise<{ task: BehaviorTaskPoint; distance: number } | undefined> {
|
|
166
|
-
const tasks = behaviorTasks(input);
|
|
167
|
-
if (this.selectedTaskName) {
|
|
168
|
-
const existing = tasks.find((task) => (
|
|
169
|
-
(this.selectedTaskId && task.id === this.selectedTaskId)
|
|
170
|
-
|| task.name === this.selectedTaskName
|
|
171
|
-
));
|
|
172
|
-
if (existing && behaviorTaskAvailable(existing)) {
|
|
173
|
-
const distance = await this.distance(input, api, existing);
|
|
174
|
-
return distance === null ? undefined : { task: existing, distance };
|
|
175
|
-
}
|
|
176
|
-
if (input.input.task) return undefined;
|
|
177
|
-
this.selectedTaskId = undefined;
|
|
178
|
-
this.selectedTaskName = undefined;
|
|
179
|
-
}
|
|
180
|
-
const candidates = tasks.filter(behaviorTaskAvailable);
|
|
181
|
-
const exact = input.input.task
|
|
182
|
-
? candidates.find((task) => (
|
|
183
|
-
normalizedBehaviorLabel(task.name) === normalizedBehaviorLabel(input.input.task!)
|
|
184
|
-
|| (!!task.id && normalizedBehaviorLabel(task.id) === normalizedBehaviorLabel(input.input.task!))
|
|
185
|
-
))
|
|
186
|
-
: undefined;
|
|
187
|
-
if (input.input.task && !exact) return undefined;
|
|
188
|
-
const considered = exact ? [exact] : candidates;
|
|
189
|
-
const self = behaviorSelf(input);
|
|
190
|
-
if (!self || considered.length === 0) return undefined;
|
|
191
|
-
const distances = await api.navigation.pathDistances(considered.map((to) => ({ from: self, to })));
|
|
192
|
-
const reachable = considered
|
|
193
|
-
.map((task, index) => ({ task, distance: distances[index] }))
|
|
194
|
-
.filter((entry): entry is { task: BehaviorTaskPoint; distance: number } => entry.distance !== null)
|
|
195
|
-
.sort((left, right) => left.distance - right.distance);
|
|
196
|
-
const selected = reachable[0];
|
|
197
|
-
if (!selected) return undefined;
|
|
198
|
-
this.selectedTaskId = selected.task.id;
|
|
199
|
-
this.selectedTaskName = selected.task.name;
|
|
200
|
-
return selected;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private async distance(
|
|
204
|
-
input: Readonly<BehaviorInput>,
|
|
205
|
-
api: BehaviorReadApi,
|
|
206
|
-
task: Readonly<BehaviorTaskPoint>,
|
|
207
|
-
): Promise<number | null> {
|
|
208
|
-
const self = behaviorSelf(input);
|
|
209
|
-
return self ? api.navigation.pathDistance(self, task) : null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClawclawBehavior,
|
|
3
|
-
type BehaviorInput,
|
|
4
|
-
type BehaviorNormalizationApi,
|
|
5
|
-
type BehaviorReadApi,
|
|
6
|
-
type ClawclawBehaviorManifest,
|
|
7
|
-
type Position,
|
|
8
|
-
} from '../../sdk/behavior-plugin/index.js';
|
|
9
|
-
import {
|
|
10
|
-
behaviorDistance,
|
|
11
|
-
behaviorSelf,
|
|
12
|
-
behaviorTeammateSeats,
|
|
13
|
-
behaviorVisiblePlayers,
|
|
14
|
-
planBehaviorEscape,
|
|
15
|
-
SemanticMoveGate,
|
|
16
|
-
} from '../../sdk/behavior-toolkit/index.js';
|
|
17
|
-
import { finished, running } from './shared.js';
|
|
18
|
-
|
|
19
|
-
type EvadeInput = Readonly<Record<string, unknown>> & {
|
|
20
|
-
readonly player_seats?: readonly number[];
|
|
21
|
-
readonly duration_ms?: number;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export default class EvadeBehavior extends ClawclawBehavior<EvadeInput> {
|
|
25
|
-
static override readonly manifest = {
|
|
26
|
-
apiVersion: 3,
|
|
27
|
-
id: 'evade',
|
|
28
|
-
name: 'Evade',
|
|
29
|
-
description: 'Keep distance from selected or nearby threats for a bounded duration.',
|
|
30
|
-
localizations: { 'zh-CN': { name: '躲避', description: '在有限时长内远离指定或附近威胁。' } },
|
|
31
|
-
inputs: [{ id: 'player_seats', type: 'player_seats', description: 'Optional authoritative player seats to evade (1-10).', maxItems: 8 }],
|
|
32
|
-
execution: 'serial',
|
|
33
|
-
runtime: { defaultMs: 15_000, deadlineOutcome: 'completed' },
|
|
34
|
-
} as const satisfies ClawclawBehaviorManifest;
|
|
35
|
-
|
|
36
|
-
private readonly move = new SemanticMoveGate();
|
|
37
|
-
private escapeTarget?: Position;
|
|
38
|
-
private plannedAtMs = 0;
|
|
39
|
-
|
|
40
|
-
override normalize(input: Readonly<Record<string, unknown>>, api: BehaviorNormalizationApi): EvadeInput {
|
|
41
|
-
const seats = input.player_seats === undefined ? [] : input.player_seats as readonly number[];
|
|
42
|
-
return { ...api.timing(input), ...(seats.length ? { player_seats: seats } : {}) };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
override decide(input: Readonly<BehaviorInput<EvadeInput>>, api: BehaviorReadApi) {
|
|
46
|
-
const self = behaviorSelf(input);
|
|
47
|
-
if (!self) return finished('failed', 'self_position_unavailable', '当前无法取得自身位置。');
|
|
48
|
-
const selected = input.input.player_seats ?? [];
|
|
49
|
-
const teammates = behaviorTeammateSeats(input);
|
|
50
|
-
let threats = behaviorVisiblePlayers(input).filter((player) => (
|
|
51
|
-
player.isAlive !== false
|
|
52
|
-
&& (selected.length ? selected.includes(player.seat) : !teammates.has(player.seat))
|
|
53
|
-
));
|
|
54
|
-
if (threats.length === 0 && selected.length) {
|
|
55
|
-
threats = selected.flatMap((seat) => {
|
|
56
|
-
const seen = api.observation.lastSeenPlayer(seat, 5_000);
|
|
57
|
-
return seen ? [{ ...seen, isAlive: seen.isAlive }] : [];
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (threats.length === 0) {
|
|
61
|
-
return finished('completed', 'threat_out_of_sight', selected.length
|
|
62
|
-
? '已在有限时间内持续躲避,当前看不到指定玩家;这不代表威胁已经解除。'
|
|
63
|
-
: '当前没有可见威胁,本次有限躲避结束。');
|
|
64
|
-
}
|
|
65
|
-
if (!this.escapeTarget || behaviorDistance(self, this.escapeTarget) <= 70 || this.plannedAtMs + 1_600 <= input.nowMs) {
|
|
66
|
-
const plan = planBehaviorEscape(self, threats);
|
|
67
|
-
if (plan.caught && plan.survivedSteps === 0) return finished('failed', 'no_escape_route', '当前没有可确认的逃生路线。');
|
|
68
|
-
this.escapeTarget = plan.target;
|
|
69
|
-
this.plannedAtMs = input.nowMs;
|
|
70
|
-
}
|
|
71
|
-
const visibleSeats = new Set(behaviorVisiblePlayers(input).map((player) => player.seat));
|
|
72
|
-
const summary = threats.some((threat) => visibleSeats.has(threat.seat))
|
|
73
|
-
? `正在远离${threats.map((threat) => threat.name).join('、')}。`
|
|
74
|
-
: '指定玩家暂时离开视野,正在根据最后目击位置继续有限拉开距离。';
|
|
75
|
-
const action = this.move.propose(input, this.escapeTarget, false, summary);
|
|
76
|
-
return running(summary, 'moving', action ? [action] : []);
|
|
77
|
-
}
|
|
78
|
-
}
|