@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
package/src/lib/user-data.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
cpSync,
|
|
2
3
|
copyFileSync,
|
|
3
4
|
existsSync,
|
|
4
5
|
mkdirSync,
|
|
6
|
+
readdirSync,
|
|
5
7
|
readFileSync,
|
|
8
|
+
statSync,
|
|
6
9
|
writeFileSync,
|
|
7
10
|
} from 'fs';
|
|
8
11
|
import { createHash } from 'crypto';
|
|
@@ -69,6 +72,125 @@ export function getUserDataMemoryFile(workspaceDir: string, profile: Pick<AuthPr
|
|
|
69
72
|
return join(getUserDataAccountDir(workspaceDir, profile), 'memory.md');
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
export function getUserDataAgentWorkspaceDir(
|
|
76
|
+
workspaceDir: string,
|
|
77
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
78
|
+
): string {
|
|
79
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'hub-loadout');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getUserDataAgentWorkspaceCurrentFile(
|
|
83
|
+
workspaceDir: string,
|
|
84
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
85
|
+
): string {
|
|
86
|
+
return join(getUserDataAgentWorkspaceDir(workspaceDir, profile), 'current.json');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function getUserDataAgentWorkspaceRevisionsDir(
|
|
90
|
+
workspaceDir: string,
|
|
91
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
92
|
+
): string {
|
|
93
|
+
return join(getUserDataAgentWorkspaceDir(workspaceDir, profile), 'revisions');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function getUserDataAccountLocalDir(
|
|
97
|
+
workspaceDir: string,
|
|
98
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
99
|
+
): string {
|
|
100
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'local');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function getUserDataAccountBehaviorsRoot(
|
|
104
|
+
workspaceDir: string,
|
|
105
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
106
|
+
): string {
|
|
107
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'behaviors');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function getUserDataAccountBehaviorsDir(
|
|
111
|
+
workspaceDir: string,
|
|
112
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
113
|
+
): string {
|
|
114
|
+
return join(getUserDataAccountBehaviorsRoot(workspaceDir, profile), 'local');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getUserDataAccountHubBehaviorsDir(
|
|
118
|
+
workspaceDir: string,
|
|
119
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
120
|
+
): string {
|
|
121
|
+
return join(getUserDataAccountBehaviorsRoot(workspaceDir, profile), 'hub');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getUserDataAccountPerceptionsRoot(
|
|
125
|
+
workspaceDir: string,
|
|
126
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
127
|
+
): string {
|
|
128
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'perceptions');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function getUserDataAccountPerceptionsDir(
|
|
132
|
+
workspaceDir: string,
|
|
133
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
134
|
+
): string {
|
|
135
|
+
return join(getUserDataAccountPerceptionsRoot(workspaceDir, profile), 'local');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getUserDataAccountHubPerceptionsDir(
|
|
139
|
+
workspaceDir: string,
|
|
140
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
141
|
+
): string {
|
|
142
|
+
return join(getUserDataAccountPerceptionsRoot(workspaceDir, profile), 'hub');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function getUserDataAccountPersonasRoot(
|
|
146
|
+
workspaceDir: string,
|
|
147
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
148
|
+
): string {
|
|
149
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'personas');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function getUserDataAccountPersonasDir(
|
|
153
|
+
workspaceDir: string,
|
|
154
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
155
|
+
): string {
|
|
156
|
+
return join(getUserDataAccountPersonasRoot(workspaceDir, profile), 'local');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function getUserDataAccountHubPersonasDir(
|
|
160
|
+
workspaceDir: string,
|
|
161
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
162
|
+
): string {
|
|
163
|
+
return join(getUserDataAccountPersonasRoot(workspaceDir, profile), 'hub');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function getUserDataAccountPersonaSelectionFile(
|
|
167
|
+
workspaceDir: string,
|
|
168
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
169
|
+
): string {
|
|
170
|
+
return join(getUserDataAccountPersonasRoot(workspaceDir, profile), 'selection.json');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function getUserDataAccountTriggersRoot(
|
|
174
|
+
workspaceDir: string,
|
|
175
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
176
|
+
): string {
|
|
177
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'triggers');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function getUserDataAccountTriggersDir(
|
|
181
|
+
workspaceDir: string,
|
|
182
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
183
|
+
): string {
|
|
184
|
+
return join(getUserDataAccountTriggersRoot(workspaceDir, profile), 'local');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function getUserDataAccountGameplayConfigFile(
|
|
188
|
+
workspaceDir: string,
|
|
189
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
190
|
+
): string {
|
|
191
|
+
return join(getUserDataAccountDir(workspaceDir, profile), 'gameplay.json');
|
|
192
|
+
}
|
|
193
|
+
|
|
72
194
|
export function getUserDataBehaviorsDir(workspaceDir: string): string {
|
|
73
195
|
return join(getUserDataDir(workspaceDir), 'behaviors');
|
|
74
196
|
}
|
|
@@ -105,10 +227,6 @@ export function getUserDataHubDir(workspaceDir: string): string {
|
|
|
105
227
|
return join(getUserDataDir(workspaceDir), 'hub');
|
|
106
228
|
}
|
|
107
229
|
|
|
108
|
-
export function getUserDataHubStrategyLockfile(workspaceDir: string): string {
|
|
109
|
-
return join(getUserDataHubDir(workspaceDir), 'installed-strategies.json');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
230
|
function ensureDir(path: string): void {
|
|
113
231
|
mkdirSync(path, { recursive: true });
|
|
114
232
|
}
|
|
@@ -127,6 +245,30 @@ function writeJson(path: string, data: unknown): void {
|
|
|
127
245
|
writeFileSync(path, JSON.stringify(data, null, 2) + '\n', 'utf8');
|
|
128
246
|
}
|
|
129
247
|
|
|
248
|
+
function contentHash(path: string): string {
|
|
249
|
+
return createHash('sha256').update(readFileSync(path)).digest('hex').slice(0, 16);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function copyLegacyLocalModules(from: string, to: string): void {
|
|
253
|
+
if (!existsSync(from)) return;
|
|
254
|
+
const manifest = readJson<Record<string, { installedHash?: string }>>(
|
|
255
|
+
join(from, '.official-manifest.json'),
|
|
256
|
+
) ?? {};
|
|
257
|
+
for (const entry of readdirSync(from)) {
|
|
258
|
+
if (entry === '.official-manifest.json') continue;
|
|
259
|
+
const source = join(from, entry);
|
|
260
|
+
const target = join(to, entry);
|
|
261
|
+
if (statSync(source).isDirectory()) {
|
|
262
|
+
cpSync(source, target, { recursive: true, force: false, errorOnExist: false });
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
const id = entry.replace(/\.(?:ts|js)$/, '');
|
|
266
|
+
const tracked = manifest[id];
|
|
267
|
+
if (tracked?.installedHash && tracked.installedHash === contentHash(source)) continue;
|
|
268
|
+
if (!existsSync(target)) copyFileSync(source, target);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
130
272
|
export function splitAuthData(data: AuthData): {
|
|
131
273
|
auth: AuthData;
|
|
132
274
|
runtime: RuntimeAuthState;
|
|
@@ -265,3 +407,54 @@ export function ensureUserDataLayout(workspaceDir: string): UserDataMigrationRes
|
|
|
265
407
|
writeMigrationMarker(workspaceDir, result);
|
|
266
408
|
return result;
|
|
267
409
|
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Materialize the account-scoped type/local + type/hub authoring layout without
|
|
413
|
+
* deleting either legacy workspace-scoped or account/local source. The copy is
|
|
414
|
+
* intentionally one-shot per account: after migration, accounts evolve independently.
|
|
415
|
+
*/
|
|
416
|
+
export function ensureAccountUserDataLayout(
|
|
417
|
+
workspaceDir: string,
|
|
418
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
419
|
+
): UserDataMigrationResult {
|
|
420
|
+
ensureUserDataLayout(workspaceDir);
|
|
421
|
+
const result = EMPTY_RESULT();
|
|
422
|
+
const accountDir = getUserDataAccountDir(workspaceDir, profile);
|
|
423
|
+
const marker = join(accountDir, '.capability-layout-v2.json');
|
|
424
|
+
ensureDir(accountDir);
|
|
425
|
+
ensureDir(getUserDataAccountBehaviorsDir(workspaceDir, profile));
|
|
426
|
+
ensureDir(getUserDataAccountHubBehaviorsDir(workspaceDir, profile));
|
|
427
|
+
ensureDir(getUserDataAccountPerceptionsDir(workspaceDir, profile));
|
|
428
|
+
ensureDir(getUserDataAccountHubPerceptionsDir(workspaceDir, profile));
|
|
429
|
+
ensureDir(getUserDataAccountPersonasDir(workspaceDir, profile));
|
|
430
|
+
ensureDir(getUserDataAccountHubPersonasDir(workspaceDir, profile));
|
|
431
|
+
ensureDir(getUserDataAccountTriggersDir(workspaceDir, profile));
|
|
432
|
+
if (existsSync(marker)) return result;
|
|
433
|
+
|
|
434
|
+
const copies: Array<[string, string, string]> = [
|
|
435
|
+
[join(getUserDataAccountLocalDir(workspaceDir, profile), 'behaviors'), getUserDataAccountBehaviorsDir(workspaceDir, profile), 'account-local/behaviors'],
|
|
436
|
+
[join(getUserDataAccountLocalDir(workspaceDir, profile), 'perceptions'), getUserDataAccountPerceptionsDir(workspaceDir, profile), 'account-local/perceptions'],
|
|
437
|
+
[join(getUserDataAccountLocalDir(workspaceDir, profile), 'personas'), getUserDataAccountPersonasDir(workspaceDir, profile), 'account-local/personas'],
|
|
438
|
+
[join(getUserDataAccountLocalDir(workspaceDir, profile), 'triggers'), getUserDataAccountTriggersDir(workspaceDir, profile), 'account-local/triggers'],
|
|
439
|
+
[getUserDataBehaviorsDir(workspaceDir), getUserDataAccountBehaviorsDir(workspaceDir, profile), 'behaviors'],
|
|
440
|
+
[getUserDataPerceptionsDir(workspaceDir), getUserDataAccountPerceptionsDir(workspaceDir, profile), 'perceptions'],
|
|
441
|
+
[getUserDataTriggersDir(workspaceDir), getUserDataAccountTriggersDir(workspaceDir, profile), 'triggers'],
|
|
442
|
+
];
|
|
443
|
+
for (const [from, to, label] of copies) {
|
|
444
|
+
if (!existsSync(from)) continue;
|
|
445
|
+
copyLegacyLocalModules(from, to);
|
|
446
|
+
result.copied.push(`user-data/${label} -> user-data/accounts/<account-hash>/<type>/local`);
|
|
447
|
+
}
|
|
448
|
+
const legacyGameplay = getUserDataGameplayConfigFile(workspaceDir);
|
|
449
|
+
const accountGameplay = getUserDataAccountGameplayConfigFile(workspaceDir, profile);
|
|
450
|
+
if (existsSync(legacyGameplay) && !existsSync(accountGameplay)) {
|
|
451
|
+
copyFileSync(legacyGameplay, accountGameplay);
|
|
452
|
+
result.copied.push('user-data/gameplay.json -> user-data/accounts/<account-hash>/gameplay.json');
|
|
453
|
+
}
|
|
454
|
+
writeJson(marker, {
|
|
455
|
+
format: 2,
|
|
456
|
+
migrated_at: new Date().toISOString(),
|
|
457
|
+
copied: result.copied,
|
|
458
|
+
});
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
@@ -3,6 +3,7 @@ import { headingDirection } from '../runtime/clawclaw/plugins/perception/shared/
|
|
|
3
3
|
import { isRoomMode } from '../lib/room.js';
|
|
4
4
|
import { isSelfKillerMurderWitnessed } from './event-hints.js';
|
|
5
5
|
import { projectAgentAbilities } from '../runtime/clawclaw/agent-ability-state.js';
|
|
6
|
+
import { roleDisplayName } from './role-display.js';
|
|
6
7
|
|
|
7
8
|
export interface EventFormatContext {
|
|
8
9
|
summary?: any | null;
|
|
@@ -50,6 +51,12 @@ function stringValue(value: unknown): string | undefined {
|
|
|
50
51
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
function killerRoleSuffix(event: Record<string, any>): string {
|
|
55
|
+
if (event.killer_kind === 'system') return '';
|
|
56
|
+
const role = roleDisplayName(event.killer_role, 'zh-CN');
|
|
57
|
+
return role ? `(${role})` : '';
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
function trainingRoomTypeLabel(value: unknown): string {
|
|
54
61
|
if (value === 'training_simulation') return '模拟训练';
|
|
55
62
|
if (value === 'training_dummy') return '木桩训练';
|
|
@@ -376,7 +383,7 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
376
383
|
case 'kill':
|
|
377
384
|
return `你在${firstString(event, ['room'])}击杀了${playerLabel(event.target_name, firstNumber(event, ['target_seat', 'target_player_seat']), ctx)}。`;
|
|
378
385
|
case 'killed':
|
|
379
|
-
return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}击杀了,你已死亡。`;
|
|
386
|
+
return `你在${firstString(event, ['room'])}被${killerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']), event.killer_kind, ctx)}${killerRoleSuffix(event)}击杀了,你已死亡。`;
|
|
380
387
|
case 'murder_witnessed':
|
|
381
388
|
if (isSelfKillerMurderWitnessed(event, ctx.summary)) {
|
|
382
389
|
return '收到一条与自身击杀身份冲突的 murder_witnessed 事件;该事件已降级为诊断信息,不能据此判断任何目击者。';
|
|
@@ -404,6 +411,11 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
404
411
|
}
|
|
405
412
|
case 'task_sabotaged':
|
|
406
413
|
return `破坏任务完成:${firstString(event, ['task_name'])}(${firstString(event, ['room'])})。`;
|
|
414
|
+
case 'task_interrupted': {
|
|
415
|
+
const cooldown = numberValue(event.cooldown_remaining_secs);
|
|
416
|
+
const cooldownText = cooldown === undefined ? '' : `;共享冷却剩余${cooldown}秒`;
|
|
417
|
+
return `破坏任务“${firstString(event, ['task_name'])}”因紧急任务开始而中断,任务未消耗${cooldownText}。`;
|
|
418
|
+
}
|
|
407
419
|
case 'tasks_changed':
|
|
408
420
|
return `任务列表已更新(${firstString(event, ['reason'])})。`;
|
|
409
421
|
case 'players_changed':
|
|
@@ -423,8 +435,12 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
423
435
|
return `你听到${firstString(event, ['room'])}附近有尸体倒地。`;
|
|
424
436
|
case 'octopus_time_start':
|
|
425
437
|
return '章鱼时间开始:存活人数已降至3人或更少,章鱼存活60秒将获胜;会议已禁用,但虾方任务完成或紧急任务超时仍可先结束本局。';
|
|
426
|
-
case 'emergency_started':
|
|
427
|
-
|
|
438
|
+
case 'emergency_started': {
|
|
439
|
+
const sabotageCause = event.cause === 'sabotage'
|
|
440
|
+
? '蟹刚完成对应破坏任务并触发了该紧急事件;'
|
|
441
|
+
: '';
|
|
442
|
+
return `紧急任务:${firstString(event, ['task_name'])}在${firstString(event, ['room'])},${sabotageCause}${text(event.timeout_secs, '?')}秒内处理。`;
|
|
443
|
+
}
|
|
428
444
|
case 'emergency_countdown_warning':
|
|
429
445
|
return `紧急任务${firstString(event, ['task_name'])}只剩${text(event.remaining_secs, '?')}秒(${text(event.threshold_secs, '?')}秒提醒)。`;
|
|
430
446
|
case 'emergency_resolved':
|
|
@@ -436,7 +452,7 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
436
452
|
}
|
|
437
453
|
return `紧急任务已解决:${firstString(event, ['task_name'])}。`;
|
|
438
454
|
case 'emergency_interrupted':
|
|
439
|
-
return
|
|
455
|
+
return `你在处理${firstString(event, ['task_name'])}时死亡,紧急任务仍未解除。`;
|
|
440
456
|
case 'ability.ready':
|
|
441
457
|
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”现在可以使用。`;
|
|
442
458
|
case 'ability.remaining_uses_changed':
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isRoomMode, isTrainingRoomMode } from '../lib/room.js';
|
|
2
|
+
import { roleDisplayName } from './role-display.js';
|
|
2
3
|
|
|
3
4
|
export interface EventHintContext {
|
|
4
5
|
summary?: any | null;
|
|
@@ -38,6 +39,12 @@ function nonEmptyString(value: unknown): string | undefined {
|
|
|
38
39
|
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function killerRoleSuffix(event: Record<string, any>): string {
|
|
43
|
+
if (event.killer_kind === 'system') return '';
|
|
44
|
+
const role = roleDisplayName(event.killer_role, 'en');
|
|
45
|
+
return role ? ` (${role})` : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
/** Defensive recipient check for a backend event that contradicts witness semantics. */
|
|
42
49
|
export function isSelfKillerMurderWitnessed(
|
|
43
50
|
event: Record<string, any>,
|
|
@@ -168,7 +175,7 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
168
175
|
+ "Blood is on the floor, one voice is gone, and the killer's side moves closer to victory."
|
|
169
176
|
),
|
|
170
177
|
killed: (event) => (
|
|
171
|
-
`YOU ARE DEAD: ${optionalSeatPlayerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']))} removed you from play.`
|
|
178
|
+
`YOU ARE DEAD: ${optionalSeatPlayerLabel(event.killer_name, firstNumber(event, ['killer_seat', 'killer_player_seat']))}${killerRoleSuffix(event)} removed you from play.`
|
|
172
179
|
),
|
|
173
180
|
murder_witnessed: (event, ctx) => (
|
|
174
181
|
isSelfKillerMurderWitnessed(event, ctx.summary)
|
|
@@ -188,11 +195,18 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
188
195
|
octopus_time_start: () => (
|
|
189
196
|
'⚠️ OCTOPUS TIME. At most three players remain; if the Octopus survives 60 seconds, it wins. Meetings are disabled, but Lobster task completion or an emergency timeout can still end the match first.'
|
|
190
197
|
),
|
|
191
|
-
|
|
192
|
-
`
|
|
193
|
-
+ `
|
|
194
|
-
+ `${text(event.timeout_secs, '30')}s until Crabs turn sabotage into victory. Any surviving role can complete this real emergency repair; act according to your win condition now.`
|
|
198
|
+
task_interrupted: (event) => (
|
|
199
|
+
`Your sabotage task ${text(event.task_name, 'your task')} was interrupted because an emergency started. `
|
|
200
|
+
+ `The task was not consumed; wait for the authoritative shared cooldown${event.cooldown_remaining_secs === undefined ? '' : ` (${text(event.cooldown_remaining_secs)}s remaining)`}.`
|
|
195
201
|
),
|
|
202
|
+
emergency_started: (event) => {
|
|
203
|
+
const cause = event.cause === 'sabotage'
|
|
204
|
+
? "A Crab completed the paired sabotage task here and activated this emergency; the saboteur's identity is not exposed. "
|
|
205
|
+
: '';
|
|
206
|
+
return `EMERGENCY: ${text(event.task_name, 'A sabotage')} detonated in ${text(event.room, 'somewhere')} `
|
|
207
|
+
+ `at ${coordPair(event.x ?? event.task_x, event.y ?? event.task_y)}. ${cause}`
|
|
208
|
+
+ `${text(event.timeout_secs, '30')}s until Crabs turn sabotage into victory. Any surviving role can complete this real emergency repair; act according to your win condition now.`;
|
|
209
|
+
},
|
|
196
210
|
emergency_resolved: (event) => {
|
|
197
211
|
const taskName = text(event.task_name, 'The emergency');
|
|
198
212
|
if (event.reason === 'meeting_started') {
|
|
@@ -204,7 +218,7 @@ export const BACKEND_EVENT_HINT_FORMATTERS: Readonly<Record<string, EventHintFor
|
|
|
204
218
|
return `${taskName} was resolved. The repairer's identity is not visible to you. Crab pressure collapses, for now.`;
|
|
205
219
|
},
|
|
206
220
|
emergency_interrupted: (event) => (
|
|
207
|
-
|
|
221
|
+
`You died while resolving ${text(event.task_name, 'the emergency')}. `
|
|
208
222
|
+ 'The emergency is still active and needs another response.'
|
|
209
223
|
),
|
|
210
224
|
exile: (event) => (
|
|
@@ -194,6 +194,15 @@ export function normalizeGameSyncEvent(value: unknown): Record<string, any> {
|
|
|
194
194
|
if (raw !== null && raw !== undefined) Object.assign(normalized, projectKiller(raw));
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
if (normalized.type === 'killed') {
|
|
198
|
+
for (const field of ['killer_role', 'killer_faction'] as const) {
|
|
199
|
+
if (!Object.hasOwn(normalized, field)) continue;
|
|
200
|
+
if (typeof normalized[field] !== 'string' || normalized[field].length === 0) {
|
|
201
|
+
throw new TypeError(`GameSync Event.${field} must be a non-empty string`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
197
206
|
for (const field of PLAYER_REF_ARRAY_FIELDS) {
|
|
198
207
|
if (!Object.hasOwn(normalized, field)) continue;
|
|
199
208
|
normalized[field] = playerRefArray(normalized[field], `GameSync Event.${field}`);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type RoleDisplayLocale = 'en' | 'zh-CN';
|
|
2
|
+
|
|
3
|
+
const ROLE_DISPLAY_NAMES: Readonly<Record<string, Readonly<Record<RoleDisplayLocale, string>>>> = Object.freeze({
|
|
4
|
+
generic: { en: 'Generic', 'zh-CN': '通用身份' },
|
|
5
|
+
shrimp_generic: { en: 'Shrimp', 'zh-CN': '普通虾' },
|
|
6
|
+
shrimp_warrior: { en: 'Warrior Shrimp', 'zh-CN': '武士虾' },
|
|
7
|
+
shrimp_pistol: { en: 'Pistol Shrimp', 'zh-CN': '枪虾' },
|
|
8
|
+
shrimp_krill: { en: 'Krill', 'zh-CN': '磷虾' },
|
|
9
|
+
shrimp_pipi: { en: 'Mantis Shrimp', 'zh-CN': '皮皮虾' },
|
|
10
|
+
crab_generic: { en: 'Crab', 'zh-CN': '蟹' },
|
|
11
|
+
crab_assassin: { en: 'Assassin Crab', 'zh-CN': '刺客蟹' },
|
|
12
|
+
crab_honest: { en: 'Honest Crab', 'zh-CN': '诚实蟹' },
|
|
13
|
+
crab_spy: { en: 'Spy Crab', 'zh-CN': '间谍蟹' },
|
|
14
|
+
neutral_paradise_fish: { en: 'Paradise Fish', 'zh-CN': '天堂鱼' },
|
|
15
|
+
neutral_jellyfish: { en: 'Jellyfish', 'zh-CN': '水母' },
|
|
16
|
+
neutral_octopus: { en: 'Octopus', 'zh-CN': '章鱼' },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function roleDisplayName(value: unknown, locale: RoleDisplayLocale): string | undefined {
|
|
20
|
+
if (typeof value !== 'string' || value.length === 0) return undefined;
|
|
21
|
+
return ROLE_DISPLAY_NAMES[value]?.[locale] ?? value;
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type AgentAbilityId = 'kill'
|
|
1
|
+
export type AgentAbilityId = 'kill';
|
|
2
2
|
|
|
3
3
|
export interface AgentAbilityState extends Record<string, unknown> {
|
|
4
4
|
id: AgentAbilityId;
|
|
@@ -65,25 +65,5 @@ export function projectAgentAbilities(summary: Record<string, any>): AgentAbilit
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
const sabotage = summary.crab_sabotage
|
|
69
|
-
&& typeof summary.crab_sabotage === 'object'
|
|
70
|
-
&& !Array.isArray(summary.crab_sabotage)
|
|
71
|
-
? summary.crab_sabotage as Record<string, any>
|
|
72
|
-
: null;
|
|
73
|
-
const sabotageStatus = nonEmptyString(sabotage?.status);
|
|
74
|
-
if (sabotageStatus) {
|
|
75
|
-
const cooldown = finiteNumber(sabotage?.cooldown_remaining_secs);
|
|
76
|
-
abilities.push({
|
|
77
|
-
id: 'trigger_alarm',
|
|
78
|
-
name: '触发警报',
|
|
79
|
-
ready: actionablePhase && alive && sabotageStatus === 'ready',
|
|
80
|
-
...(cooldown === undefined
|
|
81
|
-
? {}
|
|
82
|
-
: { cooldown_remaining_secs: Math.max(0, cooldown) }),
|
|
83
|
-
remaining_uses: null,
|
|
84
|
-
status: sabotageStatus,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
68
|
return abilities.length > 0 ? abilities : undefined;
|
|
89
69
|
}
|
|
@@ -91,14 +91,19 @@ import {
|
|
|
91
91
|
import { BEHAVIOR_PLUGIN_API_VERSION, resolveClawclawResourceMetadata } from '../../sdk/behavior-plugin/index.js';
|
|
92
92
|
import { TRIGGER_PLUGIN_API_VERSION } from '../../sdk/trigger-plugin/index.js';
|
|
93
93
|
import {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
} from '../../lib/behavior-export.js';
|
|
97
|
-
import { syncOfficialPerceptions } from '../../lib/perception-export.js';
|
|
94
|
+
listClawclawBehaviorSources,
|
|
95
|
+
} from './plugins/behavior/behavior-source.js';
|
|
98
96
|
import {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
} from '../../lib/
|
|
97
|
+
readLocalAgentWorkspaceSnapshot,
|
|
98
|
+
resolveLocalAgentWorkspaceSnapshot,
|
|
99
|
+
} from '../../lib/agent-workspace-sync.js';
|
|
100
|
+
import {
|
|
101
|
+
listAgentWorkspaceBehaviorSources,
|
|
102
|
+
listAgentWorkspacePerceptionSources,
|
|
103
|
+
mergeAgentWorkspaceBehaviorSources,
|
|
104
|
+
mergeAgentWorkspacePerceptionSources,
|
|
105
|
+
} from '../../lib/agent-workspace-runtime.js';
|
|
106
|
+
import { listClawclawTriggerSources } from './plugins/trigger/trigger-source.js';
|
|
102
107
|
import {
|
|
103
108
|
type ClawclawTriggerRegistration,
|
|
104
109
|
type ResolvedClawclawTriggerSource,
|
|
@@ -113,6 +118,13 @@ import {
|
|
|
113
118
|
import {
|
|
114
119
|
type ClawclawOwnerNotificationHost,
|
|
115
120
|
} from './notifications.js';
|
|
121
|
+
import { listClawclawPerceptionSourcesInDirectory } from './plugins/perception/perception-source.js';
|
|
122
|
+
import {
|
|
123
|
+
ensureAccountUserDataLayout,
|
|
124
|
+
getUserDataAccountBehaviorsDir,
|
|
125
|
+
getUserDataAccountPerceptionsDir,
|
|
126
|
+
getUserDataAccountTriggersDir,
|
|
127
|
+
} from '../../lib/user-data.js';
|
|
116
128
|
|
|
117
129
|
export interface ClawclawOwnerOptions {
|
|
118
130
|
profile: AuthProfile;
|
|
@@ -710,19 +722,28 @@ export async function runClawclawOwner(
|
|
|
710
722
|
rawWsMessageSink: rawWsLog,
|
|
711
723
|
});
|
|
712
724
|
const workspaceDir = getWorkspaceDir();
|
|
713
|
-
|
|
714
|
-
await syncOfficialPerceptions({ workspaceDir });
|
|
715
|
-
await syncOfficialTriggers({ workspaceDir });
|
|
725
|
+
ensureAccountUserDataLayout(workspaceDir, options.profile);
|
|
716
726
|
const perceptionConfig = readWorkspacePerceptionConfig();
|
|
717
|
-
const gameplayConfig = readGameplayConfig(workspaceDir);
|
|
727
|
+
const gameplayConfig = readGameplayConfig(workspaceDir, options.profile);
|
|
728
|
+
const storedAgentWorkspace = readLocalAgentWorkspaceSnapshot(workspaceDir, options.profile);
|
|
729
|
+
const agentWorkspace = storedAgentWorkspace
|
|
730
|
+
? resolveLocalAgentWorkspaceSnapshot(workspaceDir, options.profile, storedAgentWorkspace)
|
|
731
|
+
: undefined;
|
|
718
732
|
const configurationWarning: ConfigurationWarning = (code, details) => {
|
|
719
733
|
telemetry?.log('warn', `runtime.configuration.${code}`, details, {
|
|
720
734
|
component: 'runtime.behavior',
|
|
721
735
|
});
|
|
722
736
|
};
|
|
723
737
|
const disabledBehaviors = new Set(gameplayConfig.disabled_behaviors);
|
|
724
|
-
const
|
|
725
|
-
|
|
738
|
+
const agentBehaviorSources = agentWorkspace
|
|
739
|
+
? listAgentWorkspaceBehaviorSources(workspaceDir, options.profile, agentWorkspace)
|
|
740
|
+
: [];
|
|
741
|
+
const behaviorSources = mergeAgentWorkspaceBehaviorSources(
|
|
742
|
+
listClawclawBehaviorSources(
|
|
743
|
+
getUserDataAccountBehaviorsDir(workspaceDir, options.profile),
|
|
744
|
+
).filter((source) => !disabledBehaviors.has(source.id)),
|
|
745
|
+
agentBehaviorSources,
|
|
746
|
+
);
|
|
726
747
|
const behaviorSourceById = new Map(behaviorSources.map((source) => [source.id, source]));
|
|
727
748
|
const behaviorCatalog = new ClawclawBehaviorCatalog(behaviorSources);
|
|
728
749
|
const behaviorEventTypes = [...new Set(
|
|
@@ -735,16 +756,37 @@ export async function runClawclawOwner(
|
|
|
735
756
|
behaviorCatalog,
|
|
736
757
|
configurationWarning,
|
|
737
758
|
);
|
|
738
|
-
const triggerSources =
|
|
759
|
+
const triggerSources = listClawclawTriggerSources(
|
|
760
|
+
getUserDataAccountTriggersDir(workspaceDir, options.profile),
|
|
761
|
+
);
|
|
739
762
|
const triggers = triggerRegistrations(
|
|
740
763
|
triggerSources,
|
|
741
764
|
gameplayConfig,
|
|
742
765
|
behaviorCatalog,
|
|
743
766
|
configurationWarning,
|
|
744
767
|
);
|
|
768
|
+
const disabledPerceptions = new Set(gameplayConfig.disabled_perception_modules);
|
|
769
|
+
const agentPerceptionSources = agentWorkspace
|
|
770
|
+
? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace)
|
|
771
|
+
: [];
|
|
772
|
+
const localPerceptionSources = listClawclawPerceptionSourcesInDirectory(
|
|
773
|
+
getUserDataAccountPerceptionsDir(workspaceDir, options.profile),
|
|
774
|
+
).filter((source) => !disabledPerceptions.has(source.id));
|
|
775
|
+
const perceptionSources = mergeAgentWorkspacePerceptionSources(
|
|
776
|
+
localPerceptionSources,
|
|
777
|
+
agentPerceptionSources,
|
|
778
|
+
);
|
|
779
|
+
const perceptionModules = [
|
|
780
|
+
...localPerceptionSources.map(({ id }) => id),
|
|
781
|
+
...agentPerceptionSources.map(({ id }) => id),
|
|
782
|
+
].filter((id, index, values) => values.indexOf(id) === index);
|
|
745
783
|
const assembly = assembleClawclawPlugins(client, {
|
|
746
784
|
epochPlugins: options.epochPlugins,
|
|
747
|
-
perception:
|
|
785
|
+
perception: {
|
|
786
|
+
...perceptionConfig.perception,
|
|
787
|
+
modules: perceptionModules,
|
|
788
|
+
moduleSources: perceptionSources,
|
|
789
|
+
},
|
|
748
790
|
behaviorCatalog,
|
|
749
791
|
fallbackBehaviors,
|
|
750
792
|
behaviorEventTypes,
|
|
@@ -1225,7 +1267,7 @@ export async function runClawclawOwner(
|
|
|
1225
1267
|
if (!ownerScopeIsCurrent(runtime!, expected)) {
|
|
1226
1268
|
return { ok: false, type: 'behavior_fallback', error: 'stale_runtime_scope' };
|
|
1227
1269
|
}
|
|
1228
|
-
const latest = readGameplayConfig(workspaceDir);
|
|
1270
|
+
const latest = readGameplayConfig(workspaceDir, options.profile);
|
|
1229
1271
|
if (readyRoleForScope(runtime!, expected) === role) {
|
|
1230
1272
|
await assembly.behavior.noteAgentActivity();
|
|
1231
1273
|
}
|
|
@@ -1252,7 +1294,7 @@ export async function runClawclawOwner(
|
|
|
1252
1294
|
if (!ownerScopeIsCurrent(runtime!, expected)) {
|
|
1253
1295
|
return { ok: false, type: 'behavior_idle', error: 'stale_runtime_scope' };
|
|
1254
1296
|
}
|
|
1255
|
-
const latest = readGameplayConfig(workspaceDir);
|
|
1297
|
+
const latest = readGameplayConfig(workspaceDir, options.profile);
|
|
1256
1298
|
await assembly.behavior.setIdleMs(latest.idle_ms);
|
|
1257
1299
|
return { ok: true, type: 'behavior_idle', idle_ms: latest.idle_ms };
|
|
1258
1300
|
}
|
|
@@ -1264,8 +1306,10 @@ export async function runClawclawOwner(
|
|
|
1264
1306
|
if (!ownerScopeIsCurrent(runtime!, expected)) {
|
|
1265
1307
|
return { ok: false, type: 'trigger_configure', error: 'stale_runtime_scope' };
|
|
1266
1308
|
}
|
|
1267
|
-
const latest = readGameplayConfig(workspaceDir);
|
|
1268
|
-
const currentTriggerSources =
|
|
1309
|
+
const latest = readGameplayConfig(workspaceDir, options.profile);
|
|
1310
|
+
const currentTriggerSources = listClawclawTriggerSources(
|
|
1311
|
+
getUserDataAccountTriggersDir(workspaceDir, options.profile),
|
|
1312
|
+
);
|
|
1269
1313
|
if (!currentTriggerSources.some((source) => source.id === request.trigger)) {
|
|
1270
1314
|
return { ok: false, type: 'trigger_configure', error: 'trigger_source_unavailable' };
|
|
1271
1315
|
}
|
|
@@ -45,7 +45,6 @@ export function describeClawclawActionControl(
|
|
|
45
45
|
case 'task':
|
|
46
46
|
case 'kill':
|
|
47
47
|
case 'report':
|
|
48
|
-
case 'trigger_alarm':
|
|
49
48
|
domains = ['physical'];
|
|
50
49
|
break;
|
|
51
50
|
case 'speech':
|
|
@@ -370,6 +369,14 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
|
|
|
370
369
|
const staleAtStart = this.automationSafetyRejection(request, scope, actionId, caller, context);
|
|
371
370
|
if (staleAtStart) return staleAtStart;
|
|
372
371
|
const action = { ...request.action };
|
|
372
|
+
if (action.action === 'trigger_alarm') {
|
|
373
|
+
return actionResult(scope, actionId, 'failure', undefined, {
|
|
374
|
+
error: {
|
|
375
|
+
code: 'TRIGGER_ALARM_REMOVED_USE_TASK',
|
|
376
|
+
message: 'Crab sabotage emergencies now start when an assigned sabotage task completes.',
|
|
377
|
+
},
|
|
378
|
+
}, { source: 'local', actionOutcome: 'not_submitted' });
|
|
379
|
+
}
|
|
373
380
|
const route = request.route === 'auto'
|
|
374
381
|
? (this.stage === 'room' && action.action === 'speech' ? 'room_chat' : 'game')
|
|
375
382
|
: request.route ?? 'game';
|
|
@@ -5,7 +5,6 @@ const ACTION_FIELDS: Readonly<Record<string, readonly string[]>> = Object.freeze
|
|
|
5
5
|
task: ['action', 'task_name', 'thinking_content'],
|
|
6
6
|
report: ['action', 'thinking_content'],
|
|
7
7
|
think: ['action', 'thinking_content'],
|
|
8
|
-
trigger_alarm: ['action', 'thinking_content'],
|
|
9
8
|
});
|
|
10
9
|
|
|
11
10
|
const ERRORS: Readonly<{
|
|
@@ -142,13 +142,19 @@ export class BehaviorActivationManager {
|
|
|
142
142
|
return this.idleMs;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
bindFallback(
|
|
145
|
+
bindFallback(
|
|
146
|
+
binding: BehaviorFallbackBinding | undefined,
|
|
147
|
+
now: number,
|
|
148
|
+
startImmediately = false,
|
|
149
|
+
): readonly BehaviorActivationTransition[] {
|
|
146
150
|
this.fallback = binding
|
|
147
151
|
? Object.freeze({ behaviorId: binding.behaviorId, input: cloneInput(binding.input) })
|
|
148
152
|
: undefined;
|
|
149
153
|
this.idleGeneration += 1;
|
|
150
154
|
this.fallbackStartedGeneration = -1;
|
|
151
|
-
if (!this.short && !this.reflex && !this.long)
|
|
155
|
+
if (!this.short && !this.reflex && !this.long) {
|
|
156
|
+
this.longEligibleAt = startImmediately ? now : now + this.idleMs;
|
|
157
|
+
}
|
|
152
158
|
return this.advance(now);
|
|
153
159
|
}
|
|
154
160
|
|
|
@@ -1156,7 +1156,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
|
|
|
1156
1156
|
await this.applyTransitions(this.manager.bindFallback({
|
|
1157
1157
|
behaviorId: configured.behaviorId,
|
|
1158
1158
|
input: prepared.input,
|
|
1159
|
-
}, now));
|
|
1159
|
+
}, now, true));
|
|
1160
1160
|
} catch (error) {
|
|
1161
1161
|
this.fallbackPrepared = undefined;
|
|
1162
1162
|
this.fallbackPreparedUsed = false;
|
|
@@ -1165,7 +1165,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
|
|
|
1165
1165
|
role,
|
|
1166
1166
|
behavior_id: configured.behaviorId,
|
|
1167
1167
|
error_code: errorCode(error, 'BEHAVIOR_FALLBACK_INVALID'),
|
|
1168
|
-
}, '
|
|
1168
|
+
}, 'warn');
|
|
1169
1169
|
}
|
|
1170
1170
|
}
|
|
1171
1171
|
|