@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,583 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, readFile, readdir, writeFile } from 'fs/promises';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { ObservabilityRedactor } from './redaction.js';
|
|
6
|
-
import { BufferedObservabilityReporter } from './reporter.js';
|
|
7
|
-
import { TelemetryRecorder } from './recorder.js';
|
|
8
|
-
import { CompositeObservabilitySink, JsonlObservabilitySink } from './sinks.js';
|
|
9
|
-
import type { ObservabilityRecord, ObservabilitySink } from './types.js';
|
|
10
|
-
import {
|
|
11
|
-
observabilityInputEnabled,
|
|
12
|
-
observabilityLevel,
|
|
13
|
-
observabilityRetention,
|
|
14
|
-
resolveOwnerObservabilityLevel,
|
|
15
|
-
createOwnerTelemetryRecorder,
|
|
16
|
-
observabilityLogPath,
|
|
17
|
-
} from './factory.js';
|
|
18
|
-
import { Runtime } from '../framework/runtime.js';
|
|
19
|
-
import { behaviorControllerSpec } from '../framework/capability-registry.js';
|
|
20
|
-
import { EventCatalog, MemoryEventRepository } from '../framework/events/index.js';
|
|
21
|
-
import { MemoryStateHistoryRepository } from '../framework/state/index.js';
|
|
22
|
-
|
|
23
|
-
class MemorySink implements ObservabilitySink {
|
|
24
|
-
readonly id = 'memory';
|
|
25
|
-
readonly records: ObservabilityRecord[] = [];
|
|
26
|
-
async write(records: readonly ObservabilityRecord[]): Promise<void> {
|
|
27
|
-
this.records.push(...records);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('observability', () => {
|
|
32
|
-
it('uses error-only local defaults and keeps non-redundant development diagnostics full-only', () => {
|
|
33
|
-
expect(observabilityLevel({ level: 'errors', allow_upload: false }, {})).toBe('errors');
|
|
34
|
-
expect(observabilityLevel(
|
|
35
|
-
{ level: 'errors', allow_upload: false },
|
|
36
|
-
{ CLAWCLAW_OBSERVABILITY_LEVEL: 'full' },
|
|
37
|
-
)).toBe('full');
|
|
38
|
-
expect(observabilityLevel(
|
|
39
|
-
{ level: 'errors', allow_upload: true },
|
|
40
|
-
{ CLAWCLAW_OBSERVABILITY_LEVEL: 'errors' },
|
|
41
|
-
)).toBe('telemetry');
|
|
42
|
-
expect(resolveOwnerObservabilityLevel({
|
|
43
|
-
diagnosticsConfig: { level: 'full', allow_upload: false },
|
|
44
|
-
env: {},
|
|
45
|
-
})).toBe('full');
|
|
46
|
-
expect(observabilityLevel(
|
|
47
|
-
{ level: 'errors', allow_upload: false },
|
|
48
|
-
{ CLAWCLAW_OBSERVABILITY_MODE: 'off' },
|
|
49
|
-
)).toBe('errors');
|
|
50
|
-
expect(observabilityInputEnabled('errors', {
|
|
51
|
-
kind: 'log',
|
|
52
|
-
severity: 'debug',
|
|
53
|
-
name: 'runtime.plugin.invocation_completed',
|
|
54
|
-
})).toBe(false);
|
|
55
|
-
expect(observabilityInputEnabled('errors', {
|
|
56
|
-
kind: 'log',
|
|
57
|
-
severity: 'warn',
|
|
58
|
-
name: 'runtime.plugin.invocation_failed',
|
|
59
|
-
})).toBe(false);
|
|
60
|
-
expect(observabilityInputEnabled('errors', {
|
|
61
|
-
kind: 'error',
|
|
62
|
-
severity: 'error',
|
|
63
|
-
name: 'runtime.plugin.invocation_failed',
|
|
64
|
-
})).toBe(true);
|
|
65
|
-
expect(observabilityInputEnabled('errors', {
|
|
66
|
-
kind: 'log',
|
|
67
|
-
severity: 'info',
|
|
68
|
-
name: 'runtime.owner.started',
|
|
69
|
-
})).toBe(true);
|
|
70
|
-
expect(observabilityInputEnabled('errors', {
|
|
71
|
-
kind: 'log',
|
|
72
|
-
severity: 'info',
|
|
73
|
-
name: 'runtime.mailbox.monitor_batch_split',
|
|
74
|
-
})).toBe(true);
|
|
75
|
-
expect(observabilityInputEnabled('errors', {
|
|
76
|
-
kind: 'log',
|
|
77
|
-
severity: 'info',
|
|
78
|
-
name: 'runtime.action.completed',
|
|
79
|
-
})).toBe(false);
|
|
80
|
-
expect(observabilityInputEnabled('telemetry', {
|
|
81
|
-
kind: 'log',
|
|
82
|
-
severity: 'info',
|
|
83
|
-
name: 'runtime.action.completed',
|
|
84
|
-
})).toBe(true);
|
|
85
|
-
expect(observabilityInputEnabled('full', {
|
|
86
|
-
kind: 'log',
|
|
87
|
-
severity: 'debug',
|
|
88
|
-
name: 'runtime.input.accepted',
|
|
89
|
-
})).toBe(false);
|
|
90
|
-
expect(observabilityInputEnabled('full', {
|
|
91
|
-
kind: 'log',
|
|
92
|
-
severity: 'debug',
|
|
93
|
-
name: 'runtime.plugin.timing_window',
|
|
94
|
-
})).toBe(true);
|
|
95
|
-
expect(observabilityInputEnabled('full', {
|
|
96
|
-
kind: 'log',
|
|
97
|
-
severity: 'debug',
|
|
98
|
-
name: 'runtime.view.ready',
|
|
99
|
-
})).toBe(false);
|
|
100
|
-
expect(observabilityInputEnabled('full', {
|
|
101
|
-
kind: 'log',
|
|
102
|
-
severity: 'debug',
|
|
103
|
-
name: 'perception.module.timing_window',
|
|
104
|
-
})).toBe(true);
|
|
105
|
-
expect(observabilityInputEnabled('full', {
|
|
106
|
-
kind: 'error',
|
|
107
|
-
severity: 'error',
|
|
108
|
-
name: 'runtime.plugin.invocation_failed',
|
|
109
|
-
})).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('falls back to local error logging when diagnostics.json is invalid', async () => {
|
|
113
|
-
const workspace = await mkdtemp(join(tmpdir(), 'ccl-observability-config-'));
|
|
114
|
-
const runtimeState = join(workspace, 'runtime-state');
|
|
115
|
-
await mkdir(join(workspace, 'user-data'), { recursive: true });
|
|
116
|
-
await writeFile(join(workspace, 'user-data', 'diagnostics.json'), '{broken', 'utf8');
|
|
117
|
-
const recorder = createOwnerTelemetryRecorder({
|
|
118
|
-
apiKey: 'test-secret',
|
|
119
|
-
runtimeAccountId: 'acct_0123456789abcdef0123456789abcdef',
|
|
120
|
-
}, {
|
|
121
|
-
workspaceDir: workspace,
|
|
122
|
-
runtimeStateDir: runtimeState,
|
|
123
|
-
flushIntervalMs: 0,
|
|
124
|
-
});
|
|
125
|
-
recorder.log('info', 'runtime.action.completed');
|
|
126
|
-
recorder.error('runtime.test.failed', new Error('expected failure'));
|
|
127
|
-
await recorder.close();
|
|
128
|
-
|
|
129
|
-
const lines = (await readFile(observabilityLogPath(runtimeState), 'utf8'))
|
|
130
|
-
.trim().split(/\r?\n/).map((line) => JSON.parse(line));
|
|
131
|
-
expect(lines.map((line) => line.name)).toEqual([
|
|
132
|
-
'observability.config.invalid',
|
|
133
|
-
'runtime.test.failed',
|
|
134
|
-
]);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('bounds environment-configured local log retention', () => {
|
|
138
|
-
expect(observabilityRetention({})).toEqual({
|
|
139
|
-
maxFileBytes: 10 * 1024 * 1024,
|
|
140
|
-
retainedFiles: 5,
|
|
141
|
-
});
|
|
142
|
-
expect(observabilityRetention({
|
|
143
|
-
CLAWCLAW_OBSERVABILITY_MAX_FILE_MIB: '2',
|
|
144
|
-
CLAWCLAW_OBSERVABILITY_RETAINED_FILES: '3',
|
|
145
|
-
})).toEqual({
|
|
146
|
-
maxFileBytes: 2 * 1024 * 1024,
|
|
147
|
-
retainedFiles: 3,
|
|
148
|
-
});
|
|
149
|
-
expect(observabilityRetention({
|
|
150
|
-
CLAWCLAW_OBSERVABILITY_MAX_FILE_MIB: '0',
|
|
151
|
-
CLAWCLAW_OBSERVABILITY_RETAINED_FILES: '100',
|
|
152
|
-
})).toEqual({
|
|
153
|
-
maxFileBytes: 10 * 1024 * 1024,
|
|
154
|
-
retainedFiles: 5,
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('redacts credentials, private text, raw payloads, identities, paths and URL queries before write', async () => {
|
|
159
|
-
const sink = new MemorySink();
|
|
160
|
-
const reporter = new BufferedObservabilityReporter(sink, { flushIntervalMs: 0 });
|
|
161
|
-
const recorder = new TelemetryRecorder({
|
|
162
|
-
process: { role: 'owner', pid: 42 },
|
|
163
|
-
reporter,
|
|
164
|
-
redactor: new ObservabilityRedactor({ hashSalt: 'test' }),
|
|
165
|
-
now: () => new Date('2026-07-15T00:00:00.000Z'),
|
|
166
|
-
idFactory: () => 'obs_1',
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
recorder.log('info', 'http.request.finished', {
|
|
170
|
-
api_key: 'secret-key',
|
|
171
|
-
'x-api-key': 'header-secret',
|
|
172
|
-
workerToken: 'worker-secret',
|
|
173
|
-
speech: 'say this aloud',
|
|
174
|
-
thinkingContent: 'private chain of thought',
|
|
175
|
-
promptText: 'private prompt',
|
|
176
|
-
raw_payload: { state: { players: ['all'] } },
|
|
177
|
-
player_name: 'Alice',
|
|
178
|
-
file_path: 'C:\\Users\\Alice\\secret.mp3',
|
|
179
|
-
file_size: 123,
|
|
180
|
-
url: 'https://example.test/download/abc?token=secret#fragment',
|
|
181
|
-
wsUrl: 'wss://game.example.test/stream?token=short-secret&room=827391',
|
|
182
|
-
note: 'failed at C:\\Users\\Alice\\workspace with Bearer abcdefghijklmnopqrstuvwxyz123456',
|
|
183
|
-
stack: 'Error: failed at C:\\Users\\Alice\\OneDrive - Private Org\\project\\file.ts:1:1',
|
|
184
|
-
});
|
|
185
|
-
await recorder.flush();
|
|
186
|
-
|
|
187
|
-
expect(sink.records).toHaveLength(1);
|
|
188
|
-
const attributes = sink.records[0]!.attributes as any;
|
|
189
|
-
expect(attributes.api_key).toBe('[REDACTED]');
|
|
190
|
-
expect(attributes['x-api-key']).toBe('[REDACTED]');
|
|
191
|
-
expect(attributes.workerToken).toBe('[REDACTED]');
|
|
192
|
-
expect(attributes.speech).toMatchObject({ redacted: true, kind: 'private_text', length: 14 });
|
|
193
|
-
expect(attributes.thinkingContent).toMatchObject({ redacted: true, kind: 'private_text' });
|
|
194
|
-
expect(attributes.promptText).toMatchObject({ redacted: true, kind: 'private_text' });
|
|
195
|
-
expect(attributes.raw_payload).toMatchObject({ redacted: true, kind: 'raw_payload' });
|
|
196
|
-
expect(attributes.player_name).toMatch(/^hash:/);
|
|
197
|
-
expect(attributes.file_path).toMatchObject({ redacted: true, kind: 'local_path', extension: '.mp3' });
|
|
198
|
-
expect(attributes.file_size).toBe(123);
|
|
199
|
-
expect(attributes.url).toBe('https://example.test/download/abc');
|
|
200
|
-
expect(attributes.wsUrl).toBe('wss://game.example.test/stream');
|
|
201
|
-
expect(attributes.note).not.toContain('Alice');
|
|
202
|
-
expect(attributes.note).not.toContain('abcdefghijklmnopqrstuvwxyz');
|
|
203
|
-
expect(attributes.stack).toBe('Error: failed at [LOCAL_PATH]');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('isolates a throwing sampler and synchronous composite sink hooks', async () => {
|
|
207
|
-
const sampledSink = new MemorySink();
|
|
208
|
-
const sampledReporter = new BufferedObservabilityReporter(sampledSink, { flushIntervalMs: 0 });
|
|
209
|
-
const sampled = new TelemetryRecorder({
|
|
210
|
-
process: { role: 'owner', pid: 1 },
|
|
211
|
-
reporter: sampledReporter,
|
|
212
|
-
sampler: () => { throw new Error('sampler failed'); },
|
|
213
|
-
});
|
|
214
|
-
expect(() => sampled.log('info', 'runtime.test')).not.toThrow();
|
|
215
|
-
expect(sampled.log('info', 'runtime.test')).toBeNull();
|
|
216
|
-
|
|
217
|
-
const durable = new MemorySink();
|
|
218
|
-
const failing: ObservabilitySink = {
|
|
219
|
-
id: 'sync-failure',
|
|
220
|
-
write: (() => { throw new Error('sink failed'); }) as any,
|
|
221
|
-
close: (() => { throw new Error('close failed'); }) as any,
|
|
222
|
-
};
|
|
223
|
-
const composite = new CompositeObservabilitySink([failing, durable], {
|
|
224
|
-
onSinkError: () => { throw new Error('hook failed'); },
|
|
225
|
-
});
|
|
226
|
-
const reporter = new BufferedObservabilityReporter(composite, { flushIntervalMs: 0 });
|
|
227
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
228
|
-
recorder.log('info', 'runtime.test');
|
|
229
|
-
await expect(recorder.close()).resolves.toBeUndefined();
|
|
230
|
-
expect(durable.records).toHaveLength(1);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('provides a bounded close helper for owner shutdown', async () => {
|
|
234
|
-
const never = new Promise<void>(() => {});
|
|
235
|
-
const recorder = new TelemetryRecorder({
|
|
236
|
-
process: { role: 'owner', pid: 1 },
|
|
237
|
-
reporter: {
|
|
238
|
-
enqueue: () => true,
|
|
239
|
-
flush: async () => never,
|
|
240
|
-
close: async () => never,
|
|
241
|
-
stats: () => ({ accepted: 0, dropped: 0, flushed: 0, failedBatches: 0, queued: 0 }),
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
await expect(recorder.closeWithin(10)).resolves.toBe(false);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('bounds its buffer and reports drops without recursively logging them', async () => {
|
|
248
|
-
let release!: () => void;
|
|
249
|
-
const blocked = new Promise<void>((resolve) => { release = resolve; });
|
|
250
|
-
const sink: ObservabilitySink = { id: 'blocked', write: vi.fn(async () => blocked) };
|
|
251
|
-
const reporter = new BufferedObservabilityReporter(sink, {
|
|
252
|
-
maxQueueRecords: 2,
|
|
253
|
-
batchSize: 10,
|
|
254
|
-
flushIntervalMs: 0,
|
|
255
|
-
});
|
|
256
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
257
|
-
recorder.log('info', 'one');
|
|
258
|
-
recorder.log('info', 'two');
|
|
259
|
-
expect(recorder.log('info', 'three')).toBeNull();
|
|
260
|
-
expect(reporter.stats()).toMatchObject({ accepted: 2, dropped: 1, queued: 2 });
|
|
261
|
-
release();
|
|
262
|
-
await recorder.flush();
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('evicts lower-priority records for warnings, errors and critical lifecycle records', async () => {
|
|
266
|
-
const sink = new MemorySink();
|
|
267
|
-
const reporter = new BufferedObservabilityReporter(sink, {
|
|
268
|
-
maxQueueRecords: 3,
|
|
269
|
-
batchSize: 10,
|
|
270
|
-
flushIntervalMs: 0,
|
|
271
|
-
});
|
|
272
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
273
|
-
|
|
274
|
-
recorder.log('debug', 'runtime.tick');
|
|
275
|
-
recorder.log('info', 'runtime.connected');
|
|
276
|
-
recorder.log('debug', 'runtime.ping');
|
|
277
|
-
expect(recorder.log('warn', 'runtime.connection.disconnected')).not.toBeNull();
|
|
278
|
-
expect(recorder.log('info', 'runtime.owner.stopped')).not.toBeNull();
|
|
279
|
-
expect(recorder.log('info', 'runtime.ordinary')).toBeNull();
|
|
280
|
-
|
|
281
|
-
expect(reporter.stats()).toMatchObject({ accepted: 5, dropped: 3, queued: 3 });
|
|
282
|
-
await recorder.flush();
|
|
283
|
-
expect(sink.records.map((record) => record.name)).toEqual([
|
|
284
|
-
'runtime.connected',
|
|
285
|
-
'runtime.connection.disconnected',
|
|
286
|
-
'runtime.owner.stopped',
|
|
287
|
-
]);
|
|
288
|
-
expect(reporter.stats()).toMatchObject({ flushed: 3, queued: 0 });
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('keeps failed critical records ahead of low-priority records accepted in flight', async () => {
|
|
292
|
-
let signalStarted!: () => void;
|
|
293
|
-
let releaseFailure!: () => void;
|
|
294
|
-
const started = new Promise<void>((resolve) => { signalStarted = resolve; });
|
|
295
|
-
const failureGate = new Promise<void>((resolve) => { releaseFailure = resolve; });
|
|
296
|
-
const persisted: ObservabilityRecord[] = [];
|
|
297
|
-
let firstWrite = true;
|
|
298
|
-
const sink: ObservabilitySink = {
|
|
299
|
-
id: 'fail-once',
|
|
300
|
-
async write(records) {
|
|
301
|
-
if (firstWrite) {
|
|
302
|
-
firstWrite = false;
|
|
303
|
-
signalStarted();
|
|
304
|
-
await failureGate;
|
|
305
|
-
throw new Error('temporary sink failure');
|
|
306
|
-
}
|
|
307
|
-
persisted.push(...records);
|
|
308
|
-
},
|
|
309
|
-
};
|
|
310
|
-
const reporter = new BufferedObservabilityReporter(sink, {
|
|
311
|
-
maxQueueRecords: 2,
|
|
312
|
-
batchSize: 10,
|
|
313
|
-
flushIntervalMs: 0,
|
|
314
|
-
});
|
|
315
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
316
|
-
recorder.log('warn', 'runtime.connection.disconnected');
|
|
317
|
-
recorder.error('runtime.action.failed', new Error('denied'));
|
|
318
|
-
const firstFlush = recorder.flush();
|
|
319
|
-
await started;
|
|
320
|
-
recorder.log('debug', 'runtime.tick');
|
|
321
|
-
recorder.log('info', 'runtime.ordinary');
|
|
322
|
-
releaseFailure();
|
|
323
|
-
|
|
324
|
-
await expect(firstFlush).rejects.toThrow('temporary sink failure');
|
|
325
|
-
expect(reporter.stats()).toMatchObject({ accepted: 4, dropped: 2, queued: 2, failedBatches: 1 });
|
|
326
|
-
await recorder.flush();
|
|
327
|
-
expect(persisted.map((record) => record.name)).toEqual([
|
|
328
|
-
'runtime.connection.disconnected',
|
|
329
|
-
'runtime.action.failed',
|
|
330
|
-
]);
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('writes compact JSONL and rotates a bounded number of local files', async () => {
|
|
334
|
-
const dir = await mkdtemp(join(tmpdir(), 'ccl-observability-'));
|
|
335
|
-
const path = join(dir, 'runtime.jsonl');
|
|
336
|
-
const sink = new JsonlObservabilitySink(path, { maxFileBytes: 64 * 1024, retainedFiles: 2 });
|
|
337
|
-
const reporter = new BufferedObservabilityReporter(sink, { batchSize: 1, flushIntervalMs: 0 });
|
|
338
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
339
|
-
recorder.metric('runtime.uptime', 1, { unit: 'ms' });
|
|
340
|
-
await recorder.close();
|
|
341
|
-
|
|
342
|
-
const line = (await readFile(path, 'utf8')).trim();
|
|
343
|
-
expect(JSON.parse(line)).toMatchObject({ schema: 'ccl.observability.v1', kind: 'metric' });
|
|
344
|
-
|
|
345
|
-
const rotatingPath = join(dir, 'rotating.jsonl');
|
|
346
|
-
const rotating = new JsonlObservabilitySink(rotatingPath, { maxFileBytes: 64 * 1024, retainedFiles: 2 });
|
|
347
|
-
const oversized = {
|
|
348
|
-
...JSON.parse(line),
|
|
349
|
-
recordId: 'oversized-1',
|
|
350
|
-
attributes: { bounded_test_data: 'x'.repeat(70 * 1024) },
|
|
351
|
-
} as ObservabilityRecord;
|
|
352
|
-
await rotating.write([oversized]);
|
|
353
|
-
await rotating.write([{ ...oversized, recordId: 'oversized-2' }]);
|
|
354
|
-
await rotating.close();
|
|
355
|
-
expect(await readFile(`${rotatingPath}.1`, 'utf8')).toContain('oversized-1');
|
|
356
|
-
expect(await readFile(rotatingPath, 'utf8')).toContain('oversized-2');
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it('removes numbered history beyond the configured retention on first write', async () => {
|
|
360
|
-
const dir = await mkdtemp(join(tmpdir(), 'ccl-observability-prune-'));
|
|
361
|
-
const path = join(dir, 'runtime.jsonl');
|
|
362
|
-
await writeFile(`${path}.1`, 'retained\n');
|
|
363
|
-
await writeFile(`${path}.3`, 'expired\n');
|
|
364
|
-
await writeFile(`${path}.note`, 'unmanaged\n');
|
|
365
|
-
const sink = new JsonlObservabilitySink(path, { retainedFiles: 1 });
|
|
366
|
-
|
|
367
|
-
await sink.write([{
|
|
368
|
-
schema: 'ccl.observability.v1',
|
|
369
|
-
recordId: 'retention-1',
|
|
370
|
-
timestamp: '2026-07-15T00:00:00.000Z',
|
|
371
|
-
kind: 'log',
|
|
372
|
-
name: 'runtime.retention',
|
|
373
|
-
severity: 'info',
|
|
374
|
-
component: 'runtime',
|
|
375
|
-
process: { role: 'owner', pid: 1 },
|
|
376
|
-
attributes: {},
|
|
377
|
-
}]);
|
|
378
|
-
await sink.close();
|
|
379
|
-
|
|
380
|
-
expect(await readdir(dir)).toEqual(expect.arrayContaining([
|
|
381
|
-
'runtime.jsonl',
|
|
382
|
-
'runtime.jsonl.1',
|
|
383
|
-
'runtime.jsonl.note',
|
|
384
|
-
]));
|
|
385
|
-
expect(await readdir(dir)).not.toContain('runtime.jsonl.3');
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it('aborts a write when rotating the active file fails', async () => {
|
|
389
|
-
const dir = await mkdtemp(join(tmpdir(), 'ccl-observability-rotate-failure-'));
|
|
390
|
-
const path = join(dir, 'runtime.jsonl');
|
|
391
|
-
class FailingActiveRenameSink extends JsonlObservabilitySink {
|
|
392
|
-
failActiveRename = false;
|
|
393
|
-
protected override renameFile(source: string, destination: string): Promise<void> {
|
|
394
|
-
if (this.failActiveRename && source === this.filePath) {
|
|
395
|
-
return Promise.reject(Object.assign(new Error('active log is locked'), { code: 'EACCES' }));
|
|
396
|
-
}
|
|
397
|
-
return super.renameFile(source, destination);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
const sink = new FailingActiveRenameSink(path, { maxFileBytes: 64 * 1024, retainedFiles: 2 });
|
|
401
|
-
const oversized = {
|
|
402
|
-
schema: 'ccl.observability.v1',
|
|
403
|
-
recordId: 'oversized-1',
|
|
404
|
-
timestamp: '2026-07-15T00:00:00.000Z',
|
|
405
|
-
kind: 'log',
|
|
406
|
-
name: 'runtime.large',
|
|
407
|
-
severity: 'info',
|
|
408
|
-
component: 'runtime',
|
|
409
|
-
process: { role: 'owner', pid: 1 },
|
|
410
|
-
attributes: { bounded_test_data: 'x'.repeat(70 * 1024) },
|
|
411
|
-
} as ObservabilityRecord;
|
|
412
|
-
await sink.write([oversized]);
|
|
413
|
-
sink.failActiveRename = true;
|
|
414
|
-
|
|
415
|
-
await expect(sink.write([{ ...oversized, recordId: 'must-not-append' }])).rejects.toThrow(
|
|
416
|
-
'active log is locked',
|
|
417
|
-
);
|
|
418
|
-
const active = await readFile(path, 'utf8');
|
|
419
|
-
expect(active).toContain('oversized-1');
|
|
420
|
-
expect(active).not.toContain('must-not-append');
|
|
421
|
-
await sink.close();
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('records owner action outcomes without copying action or response payloads', async () => {
|
|
425
|
-
const sink = new MemorySink();
|
|
426
|
-
const reporter = new BufferedObservabilityReporter(sink, { flushIntervalMs: 0 });
|
|
427
|
-
const recorder = new TelemetryRecorder({ process: { role: 'owner', pid: 1 }, reporter });
|
|
428
|
-
const runtime = new Runtime({
|
|
429
|
-
adapterId: 'test-game',
|
|
430
|
-
accountId: 'account-secret',
|
|
431
|
-
eventCatalog: new EventCatalog([]),
|
|
432
|
-
eventRepository: new MemoryEventRepository(),
|
|
433
|
-
stateHistoryRepository: new MemoryStateHistoryRepository(),
|
|
434
|
-
initialSegment: { kind: 'game', identity: 'game-1' },
|
|
435
|
-
observability: recorder,
|
|
436
|
-
});
|
|
437
|
-
runtime.actions.register({
|
|
438
|
-
capability: 'test.action',
|
|
439
|
-
async perform(action: any, scope) {
|
|
440
|
-
if (action.businessReject) {
|
|
441
|
-
return {
|
|
442
|
-
scope,
|
|
443
|
-
actionId: 'action-3',
|
|
444
|
-
status: 'failure' as const,
|
|
445
|
-
source: 'backend' as const,
|
|
446
|
-
actionOutcome: 'confirmed' as const,
|
|
447
|
-
error: {
|
|
448
|
-
error: {
|
|
449
|
-
code: 'COOLDOWN_ACTIVE',
|
|
450
|
-
message: 'backend rejected a normal gameplay attempt',
|
|
451
|
-
},
|
|
452
|
-
http_status: 409,
|
|
453
|
-
},
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
if (action.serverFailure) {
|
|
457
|
-
return {
|
|
458
|
-
scope,
|
|
459
|
-
actionId: 'action-4',
|
|
460
|
-
status: 'failure' as const,
|
|
461
|
-
source: 'backend' as const,
|
|
462
|
-
actionOutcome: 'confirmed' as const,
|
|
463
|
-
error: {
|
|
464
|
-
error: {
|
|
465
|
-
code: 'HTTP_500',
|
|
466
|
-
message: 'private server response',
|
|
467
|
-
},
|
|
468
|
-
http_status: 500,
|
|
469
|
-
},
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
if (action.fail) {
|
|
473
|
-
return {
|
|
474
|
-
scope,
|
|
475
|
-
actionId: 'action-2',
|
|
476
|
-
status: 'failure' as const,
|
|
477
|
-
error: {
|
|
478
|
-
code: 'denied',
|
|
479
|
-
message: 'request rejected abcdefghijklmnopqrstuvwxyz123456',
|
|
480
|
-
response_body: { state: 'must-not-be-logged' },
|
|
481
|
-
},
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
scope,
|
|
486
|
-
actionId: 'action-1',
|
|
487
|
-
status: 'success' as const,
|
|
488
|
-
value: { private_response: 'must-not-be-logged' },
|
|
489
|
-
};
|
|
490
|
-
},
|
|
491
|
-
});
|
|
492
|
-
const scope = runtime.publicScope();
|
|
493
|
-
const behavior = {
|
|
494
|
-
kind: 'behavior' as const,
|
|
495
|
-
activationId: 'worker-1',
|
|
496
|
-
layer: 'long' as const,
|
|
497
|
-
activationGeneration: 1,
|
|
498
|
-
};
|
|
499
|
-
runtime.actions.controls.registerController(behaviorControllerSpec(behavior, {
|
|
500
|
-
scope: runtime.scope(),
|
|
501
|
-
domains: ['*'],
|
|
502
|
-
lifecycle: 'persistent',
|
|
503
|
-
ready: true,
|
|
504
|
-
}));
|
|
505
|
-
await runtime.performAction(
|
|
506
|
-
'test.action',
|
|
507
|
-
{ speech: 'must-not-be-logged' },
|
|
508
|
-
{ sessionId: scope.sessionId, segmentId: scope.segmentId },
|
|
509
|
-
behavior,
|
|
510
|
-
);
|
|
511
|
-
await runtime.performAction(
|
|
512
|
-
'test.action',
|
|
513
|
-
{ fail: true },
|
|
514
|
-
{ sessionId: scope.sessionId, segmentId: scope.segmentId },
|
|
515
|
-
{ kind: 'agent' },
|
|
516
|
-
);
|
|
517
|
-
await runtime.performAction(
|
|
518
|
-
'test.action',
|
|
519
|
-
{ businessReject: true },
|
|
520
|
-
{ sessionId: scope.sessionId, segmentId: scope.segmentId },
|
|
521
|
-
{ kind: 'agent' },
|
|
522
|
-
);
|
|
523
|
-
await runtime.performAction(
|
|
524
|
-
'test.action',
|
|
525
|
-
{ serverFailure: true },
|
|
526
|
-
{ sessionId: scope.sessionId, segmentId: scope.segmentId },
|
|
527
|
-
{ kind: 'agent' },
|
|
528
|
-
);
|
|
529
|
-
await recorder.flush();
|
|
530
|
-
|
|
531
|
-
const actionRecord = sink.records.find((record) => record.name === 'runtime.action.completed');
|
|
532
|
-
expect(actionRecord).toMatchObject({
|
|
533
|
-
correlation: {
|
|
534
|
-
actionId: 'action-1',
|
|
535
|
-
behaviorActivationId: 'worker-1',
|
|
536
|
-
behaviorActivationGeneration: 1,
|
|
537
|
-
},
|
|
538
|
-
attributes: { capability: 'test.action', caller_kind: 'behavior', status: 'success' },
|
|
539
|
-
});
|
|
540
|
-
expect(JSON.stringify(actionRecord)).not.toContain('must-not-be-logged');
|
|
541
|
-
expect(JSON.stringify(sink.records)).not.toContain('account-secret');
|
|
542
|
-
const failureRecord = sink.records.find((record) => (
|
|
543
|
-
record.name === 'runtime.action.failed' && record.correlation?.actionId === 'action-2'
|
|
544
|
-
));
|
|
545
|
-
expect(failureRecord).toMatchObject({
|
|
546
|
-
kind: 'error',
|
|
547
|
-
error: { code: 'denied' },
|
|
548
|
-
correlation: { actionId: 'action-2' },
|
|
549
|
-
});
|
|
550
|
-
expect(JSON.stringify(failureRecord)).not.toContain('abcdefghijklmnopqrstuvwxyz');
|
|
551
|
-
const rejectedRecord = sink.records.find((record) => (
|
|
552
|
-
record.name === 'runtime.action.failed' && record.correlation?.actionId === 'action-3'
|
|
553
|
-
));
|
|
554
|
-
expect(rejectedRecord).toMatchObject({
|
|
555
|
-
kind: 'log',
|
|
556
|
-
severity: 'warn',
|
|
557
|
-
attributes: {
|
|
558
|
-
action_source: 'backend',
|
|
559
|
-
action_outcome: 'confirmed',
|
|
560
|
-
error_code: 'COOLDOWN_ACTIVE',
|
|
561
|
-
http_status: 409,
|
|
562
|
-
},
|
|
563
|
-
});
|
|
564
|
-
expect(JSON.stringify(rejectedRecord)).not.toContain('normal gameplay attempt');
|
|
565
|
-
const serverFailureRecord = sink.records.find((record) => (
|
|
566
|
-
record.name === 'runtime.action.failed' && record.correlation?.actionId === 'action-4'
|
|
567
|
-
));
|
|
568
|
-
expect(serverFailureRecord).toMatchObject({
|
|
569
|
-
kind: 'error',
|
|
570
|
-
severity: 'error',
|
|
571
|
-
error: { code: 'HTTP_500' },
|
|
572
|
-
attributes: {
|
|
573
|
-
action_source: 'backend',
|
|
574
|
-
action_outcome: 'confirmed',
|
|
575
|
-
error_code: 'HTTP_500',
|
|
576
|
-
http_status: 500,
|
|
577
|
-
},
|
|
578
|
-
});
|
|
579
|
-
expect(JSON.stringify(serverFailureRecord)).not.toContain('private server response');
|
|
580
|
-
await runtime.close();
|
|
581
|
-
await recorder.close();
|
|
582
|
-
});
|
|
583
|
-
});
|