@myclaw163/clawclaw-cli 0.8.12 → 0.8.14

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.
Files changed (68) hide show
  1. package/docs/configuration.md +11 -12
  2. package/docs/custom-modules/README.md +3 -3
  3. package/docs/custom-modules/behavior.md +1 -1
  4. package/docs/custom-modules/perception.md +1 -1
  5. package/docs/custom-modules/trigger.md +1 -1
  6. package/docs/runtime/official-perception-modules.md +1 -1
  7. package/package.json +1 -1
  8. package/scripts/check-skill-command-surface.mjs +1 -0
  9. package/scripts/sync-bundled-skill.mjs +89 -52
  10. package/skills/clawclaw/SKILL.md +10 -6
  11. package/skills/clawclaw/references/BEHAVIORS.md +2 -0
  12. package/skills/clawclaw/references/CHANNELS.md +1 -1
  13. package/skills/clawclaw/references/COMMANDS.md +11 -4
  14. package/skills/clawclaw/references/HUB.md +4 -2
  15. package/skills/clawclaw/references/STREAM.md +4 -2
  16. package/src/cli.ts +2 -0
  17. package/src/commands/behavior.ts +49 -8
  18. package/src/commands/capability.ts +345 -0
  19. package/src/commands/load.ts +195 -8
  20. package/src/commands/perception.ts +21 -7
  21. package/src/commands/persona.ts +6 -0
  22. package/src/commands/trigger.ts +8 -5
  23. package/src/lib/agent-workspace-skills.ts +167 -68
  24. package/src/lib/agent-workspace-sync.ts +20 -31
  25. package/src/lib/capability-cloud-refresh.ts +313 -0
  26. package/src/lib/capability-cloud-sync.ts +315 -0
  27. package/src/lib/capability-discovery.ts +94 -0
  28. package/src/lib/capability-workspace.ts +291 -0
  29. package/src/lib/game-client.ts +12 -4
  30. package/src/lib/hub-client.ts +131 -4
  31. package/src/lib/persona.ts +1 -24
  32. package/src/lib/skill-host.ts +63 -0
  33. package/src/lib/user-data.ts +47 -59
  34. package/src/lib/zip-store.ts +92 -0
  35. package/src/pipeline/event-format.ts +5 -0
  36. package/src/pipeline/event-hints.ts +10 -0
  37. package/src/runtime/clawclaw/agent-event-policy.ts +2 -0
  38. package/src/runtime/clawclaw/behavior-input.ts +5 -0
  39. package/src/runtime/clawclaw/owner.ts +12 -12
  40. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +150 -18
  41. package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +8 -0
  42. package/src/runtime/clawclaw/plugins/behavior/behavior-decision-history.ts +88 -0
  43. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +173 -11
  44. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +6 -0
  45. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +3 -1
  46. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +5 -1
  47. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +5 -5
  48. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +213 -6
  49. package/src/runtime/clawclaw/plugins/source/game-transport.ts +29 -4
  50. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +153 -0
  51. package/src/runtime/clawclaw/plugins/source/types.ts +1 -0
  52. package/src/runtime/clawclaw/runtime.ts +31 -3
  53. package/src/runtime/clawclaw-event-catalog.ts +2 -0
  54. package/src/runtime/framework/events/event-repository.ts +1 -1
  55. package/src/runtime/framework/events/memory-event-repository.ts +59 -1
  56. package/src/runtime/framework/events/sqlite-event-repository.ts +23 -1
  57. package/src/runtime/framework/mailbox/types.ts +2 -0
  58. package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +58 -0
  59. package/src/runtime/framework/persistence/memory-first-persistence.ts +380 -0
  60. package/src/runtime/framework/plugins/contracts.ts +2 -2
  61. package/src/runtime/framework/plugins/runtime-input-journal.ts +173 -17
  62. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +23 -11
  63. package/src/runtime/framework/runtime.ts +57 -4
  64. package/src/runtime/framework/state/history/contracts.ts +9 -1
  65. package/src/runtime/framework/state/history/memory-state-history-repository.ts +49 -7
  66. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +16 -0
  67. package/src/sdk/behavior-plugin/index.ts +5 -24
  68. package/src/sdk/module-input/index.ts +47 -0
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { performance } from 'node:perf_hooks';
2
3
  import type {
3
4
  BehaviorContinuation,
4
5
  BehaviorDecision,
@@ -41,6 +42,7 @@ import {
41
42
  } from './activation-manager.js';
42
43
  import { normalizeClawclawBehaviorAction } from './behavior-action.js';
43
44
  import type { ClawclawBehaviorCatalog } from './behavior-catalog.js';
45
+ import { BehaviorDecisionHistory } from './behavior-decision-history.js';
44
46
  import type { PreparedClawclawBehavior } from './behavior-normalization.js';
45
47
  import { ClawclawBehaviorRunner } from './behavior-runner.js';
46
48
  import type {
@@ -138,6 +140,7 @@ interface ActivationRuntime {
138
140
  lastCommittedBackendTick?: number;
139
141
  lastStatus?: Readonly<BehaviorStatus>;
140
142
  pendingContinuation?: Readonly<BehaviorContinuation>;
143
+ readonly decisionHistory: BehaviorDecisionHistory;
141
144
  committedActionDedupeKeys: Map<string, number>;
142
145
  }
143
146
 
@@ -490,6 +493,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
490
493
  activationId,
491
494
  behaviorId: request.behavior,
492
495
  prepared,
496
+ decisionHistory: new BehaviorDecisionHistory(),
493
497
  committedActionDedupeKeys: new Map(),
494
498
  });
495
499
  const replaced = transitions.find((entry) => entry.type === 'replaced');
@@ -519,33 +523,90 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
519
523
  return { outcome: 'processed', proposal: { ...base, kind: 'inactive' } satisfies BehaviorComputationProposal };
520
524
  }
521
525
  const runtime = this.runtimes.get(current.activationId);
522
- const frame = createBehaviorInput(input, current.input, runtime?.pendingContinuation);
526
+ if (
527
+ runtime
528
+ && runtime.instanceGeneration === current.instanceGeneration
529
+ && isClawclawRuntimeState(input.epoch.state)
530
+ && input.epoch.state.game_snapshot.status === 'fresh'
531
+ ) {
532
+ const tick = Number(
533
+ input.epoch.domainTick
534
+ ?? input.epoch.state.game_snapshot.state.tick
535
+ ?? input.epoch.epochSeq,
536
+ );
537
+ runtime.decisionHistory.begin({
538
+ epochId: input.epoch.epochSeq,
539
+ tick,
540
+ instanceGeneration: current.instanceGeneration,
541
+ });
542
+ const history = runtime.decisionHistory.snapshot();
543
+ context.diagnostic('behavior.decision_history.frame_pending', {
544
+ behavior_id: current.behaviorId,
545
+ activation_id: current.activationId,
546
+ instance_generation: current.instanceGeneration,
547
+ epoch_id: input.epoch.epochSeq,
548
+ tick,
549
+ retained_frame_count: history.length,
550
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
551
+ }, 'debug');
552
+ }
553
+ const frame = createBehaviorInput(
554
+ input,
555
+ current.input,
556
+ runtime?.pendingContinuation,
557
+ runtime?.decisionHistory.snapshot(),
558
+ );
523
559
  if (!frame) {
524
560
  return { outcome: 'processed', proposal: { ...base, kind: 'waiting_for_state' } satisfies BehaviorComputationProposal };
525
561
  }
562
+ const noDecision = (
563
+ kind: BehaviorComputationProposal['kind'],
564
+ reason: string,
565
+ ): RuntimeEpochPluginResult => {
566
+ const resolved = runtime?.decisionHistory.notComputed(frame.epochId, reason);
567
+ if (resolved) {
568
+ const history = runtime!.decisionHistory.snapshot();
569
+ context.diagnostic('behavior.decision_history.frame_resolved', {
570
+ behavior_id: current.behaviorId,
571
+ activation_id: current.activationId,
572
+ instance_generation: current.instanceGeneration,
573
+ epoch_id: frame.epochId,
574
+ tick: resolved.tick,
575
+ status: resolved.status,
576
+ reason,
577
+ action_count: 0,
578
+ retained_frame_count: history.length,
579
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
580
+ }, 'debug');
581
+ }
582
+ return {
583
+ outcome: 'processed',
584
+ proposal: { ...base, kind } satisfies BehaviorComputationProposal,
585
+ };
586
+ };
526
587
  if (frame.gameState.phase === 'game_over') {
527
- return { outcome: 'processed', proposal: { ...base, kind: 'game_over' } satisfies BehaviorComputationProposal };
588
+ return noDecision('game_over', 'game_over');
528
589
  }
529
590
  if (frame.gameState.you?.is_alive === false) {
530
- return { outcome: 'processed', proposal: { ...base, kind: 'player_inactive' } satisfies BehaviorComputationProposal };
591
+ return noDecision('player_inactive', 'player_inactive');
531
592
  }
532
593
  const meetingShort = frame.gameState.phase === 'meeting' && current.layer === 'short';
533
594
  if (frame.gameState.phase !== 'wandering' && !meetingShort) {
534
- return { outcome: 'processed', proposal: { ...base, kind: 'boundary' } satisfies BehaviorComputationProposal };
595
+ return noDecision('boundary', 'phase_boundary');
535
596
  }
536
597
  const control = this.controls.get(current.activationId);
537
598
  if (!runtime?.runner || runtime.instanceGeneration !== current.instanceGeneration) {
538
- return { outcome: 'processed', proposal: { ...base, kind: 'control_held' } satisfies BehaviorComputationProposal };
599
+ return noDecision('control_held', 'runner_unavailable');
539
600
  }
540
601
  if (!control?.isAuthorized()) {
541
- return { outcome: 'processed', proposal: { ...base, kind: 'control_held' } satisfies BehaviorComputationProposal };
602
+ return noDecision('control_held', 'control_held');
542
603
  }
543
604
  const backendTick = Number(frame.gameState.tick ?? frame.epochId);
544
605
  if (
545
606
  runtime.lastCommittedBackendTick !== undefined
546
607
  && backendTick - runtime.lastCommittedBackendTick < runtime.runner.everyTicks
547
608
  ) {
548
- return { outcome: 'processed', proposal: { ...base, kind: 'cadence_skip' } satisfies BehaviorComputationProposal };
609
+ return noDecision('cadence_skip', 'cadence_skip');
549
610
  }
550
611
  const observation = this.observationMemory.capture(frame);
551
612
  if (runtime.runner.execution === 'serial') {
@@ -565,6 +626,22 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
565
626
  context.signal,
566
627
  current.activationId,
567
628
  );
629
+ const resolved = runtime.decisionHistory.complete(frame.epochId, decision.actions);
630
+ if (resolved) {
631
+ const history = runtime.decisionHistory.snapshot();
632
+ context.diagnostic('behavior.decision_history.frame_resolved', {
633
+ behavior_id: current.behaviorId,
634
+ activation_id: current.activationId,
635
+ instance_generation: current.instanceGeneration,
636
+ epoch_id: frame.epochId,
637
+ tick: resolved.tick,
638
+ status: resolved.status,
639
+ action_count: resolved.actions?.length ?? 0,
640
+ action_kinds: (resolved.actions ?? []).map((action) => action.action),
641
+ retained_frame_count: history.length,
642
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
643
+ }, 'debug');
644
+ }
568
645
  return {
569
646
  outcome: 'processed',
570
647
  proposal: {
@@ -576,12 +653,29 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
576
653
  } satisfies BehaviorComputationProposal,
577
654
  };
578
655
  } catch (error) {
656
+ const failure = errorCode(error, 'BEHAVIOR_DECIDE_FAILED');
657
+ const resolved = runtime.decisionHistory.fail(frame.epochId, failure);
658
+ if (resolved) {
659
+ const history = runtime.decisionHistory.snapshot();
660
+ context.diagnostic('behavior.decision_history.frame_resolved', {
661
+ behavior_id: current.behaviorId,
662
+ activation_id: current.activationId,
663
+ instance_generation: current.instanceGeneration,
664
+ epoch_id: frame.epochId,
665
+ tick: resolved.tick,
666
+ status: resolved.status,
667
+ reason: failure,
668
+ action_count: 0,
669
+ retained_frame_count: history.length,
670
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
671
+ }, 'debug');
672
+ }
579
673
  return {
580
674
  outcome: 'processed',
581
675
  proposal: {
582
676
  ...base,
583
677
  kind: 'module_error',
584
- errorCode: errorCode(error, 'BEHAVIOR_DECIDE_FAILED'),
678
+ errorCode: failure,
585
679
  } satisfies BehaviorComputationProposal,
586
680
  };
587
681
  }
@@ -657,6 +751,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
657
751
  activationId,
658
752
  behaviorId,
659
753
  prepared,
754
+ decisionHistory: new BehaviorDecisionHistory(),
660
755
  committedActionDedupeKeys: new Map(),
661
756
  });
662
757
  const transitions = layer === 'long'
@@ -687,11 +782,15 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
687
782
 
688
783
  await this.applyTransitions(this.manager.advance(now));
689
784
  const currentForFrame = this.manager.current();
785
+ const currentFrameRuntime = currentForFrame
786
+ ? this.runtimes.get(currentForFrame.activationId)
787
+ : undefined;
690
788
  const frame = currentForFrame
691
789
  ? createBehaviorInput(
692
790
  input,
693
791
  currentForFrame.input,
694
- this.runtimes.get(currentForFrame.activationId)?.pendingContinuation,
792
+ currentFrameRuntime?.pendingContinuation,
793
+ currentFrameRuntime?.decisionHistory.snapshot(),
695
794
  )
696
795
  : frameForClock;
697
796
  if (frame?.gameState.phase === 'game_over' || computed.kind === 'game_over') {
@@ -727,7 +826,15 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
727
826
  || computed.activationId !== current.activationId
728
827
  || computed.instanceGeneration !== current.instanceGeneration
729
828
  || !this.manager.isCurrent(current.activationId, current.instanceGeneration)
730
- ) return this.output(undefined);
829
+ ) {
830
+ if (computed.activationId) {
831
+ this.runtimes.get(computed.activationId)?.decisionHistory.notComputed(
832
+ input.epoch.epochSeq,
833
+ 'activation_superseded_before_commit',
834
+ );
835
+ }
836
+ return this.output(undefined);
837
+ }
731
838
 
732
839
  if (!frame) return this.output(undefined);
733
840
  const runtime = this.runtimes.get(current.activationId);
@@ -768,13 +875,46 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
768
875
  );
769
876
  } catch (error) {
770
877
  if (errorCode(error) === 'behavior_reflex_preempted') return this.output(undefined);
771
- await this.failCurrent(current, errorCode(error, 'BEHAVIOR_DECIDE_FAILED'), now);
878
+ const failure = errorCode(error, 'BEHAVIOR_DECIDE_FAILED');
879
+ const resolved = runtime.decisionHistory.fail(frame.epochId, failure);
880
+ if (resolved) {
881
+ const history = runtime.decisionHistory.snapshot();
882
+ context.diagnostic('behavior.decision_history.frame_resolved', {
883
+ behavior_id: current.behaviorId,
884
+ activation_id: current.activationId,
885
+ instance_generation: current.instanceGeneration,
886
+ epoch_id: frame.epochId,
887
+ tick: resolved.tick,
888
+ status: resolved.status,
889
+ reason: failure,
890
+ action_count: 0,
891
+ retained_frame_count: history.length,
892
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
893
+ }, 'debug');
894
+ }
895
+ await this.failCurrent(current, failure, now);
772
896
  return this.output(cursor);
773
897
  }
774
898
  }
775
899
  if (!decision || !this.manager.isCurrent(current.activationId, current.instanceGeneration)) {
776
900
  return this.output(undefined);
777
901
  }
902
+ const resolvedDecision = runtime.decisionHistory.complete(frame.epochId, decision.actions);
903
+ if (resolvedDecision) {
904
+ const history = runtime.decisionHistory.snapshot();
905
+ context.diagnostic('behavior.decision_history.frame_resolved', {
906
+ behavior_id: current.behaviorId,
907
+ activation_id: current.activationId,
908
+ instance_generation: current.instanceGeneration,
909
+ epoch_id: frame.epochId,
910
+ tick: resolvedDecision.tick,
911
+ status: resolvedDecision.status,
912
+ action_count: resolvedDecision.actions?.length ?? 0,
913
+ action_kinds: (resolvedDecision.actions ?? []).map((action) => action.action),
914
+ retained_frame_count: history.length,
915
+ pending_frame_count: history.filter((entry) => entry.status === 'pending').length,
916
+ }, 'debug');
917
+ }
778
918
  runtime.lastCommittedBackendTick = backendTick;
779
919
  let output: Readonly<{
780
920
  status?: Readonly<BehaviorStatus>;
@@ -851,13 +991,29 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
851
991
  frame.epochId,
852
992
  safetyGeneration,
853
993
  activation.instanceGeneration,
994
+ frame.gameState.tick,
854
995
  );
996
+ const receiptStartedAt = performance.now();
855
997
  try {
856
998
  const result = await context.capabilities.performAction(
857
999
  CLAWCLAW_ACTION_CAPABILITY,
858
1000
  request,
859
1001
  asActionCaller(control.caller),
860
1002
  );
1003
+ context.diagnostic('behavior.action.receipt', {
1004
+ behavior_id: activation.behaviorId,
1005
+ activation_id: activation.activationId,
1006
+ instance_generation: activation.instanceGeneration,
1007
+ epoch_id: frame.epochId,
1008
+ tick: frame.gameState.tick,
1009
+ action_index: index,
1010
+ action_kind: action.action,
1011
+ action_id: result.actionId,
1012
+ status: result.status,
1013
+ ...(result.source ? { action_source: result.source } : {}),
1014
+ ...(result.actionOutcome ? { action_outcome: result.actionOutcome } : {}),
1015
+ receipt_wait_ms: Math.round((performance.now() - receiptStartedAt) * 1_000) / 1_000,
1016
+ }, result.status === 'failure' ? 'warn' : 'debug');
861
1017
  if (result.actionOutcome !== 'not_submitted') {
862
1018
  runtime.committedActionDedupeKeys.set(dedupeKey, frame.epochId);
863
1019
  while (runtime.committedActionDedupeKeys.size > 2_048) {
@@ -873,6 +1029,10 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
873
1029
  activation_id: activation.activationId,
874
1030
  instance_generation: activation.instanceGeneration,
875
1031
  epoch_id: frame.epochId,
1032
+ tick: frame.gameState.tick,
1033
+ action_index: index,
1034
+ action_kind: action.action,
1035
+ receipt_wait_ms: Math.round((performance.now() - receiptStartedAt) * 1_000) / 1_000,
876
1036
  error_code: errorCode(error, 'BEHAVIOR_ACTION_FAILED'),
877
1037
  }, 'error');
878
1038
  }
@@ -942,6 +1102,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
942
1102
  activationId,
943
1103
  behaviorId: delegated.behaviorId,
944
1104
  prepared: delegated.prepared,
1105
+ decisionHistory: new BehaviorDecisionHistory(),
945
1106
  committedActionDedupeKeys: new Map(),
946
1107
  });
947
1108
  this.delegatedShorts.set(activationId, Object.freeze({
@@ -1103,6 +1264,7 @@ implements RuntimeEpochPlugin<Record<string, any>>, BehaviorReflexActivationDriv
1103
1264
  activationId: activation.activationId,
1104
1265
  behaviorId: activation.behaviorId,
1105
1266
  prepared,
1267
+ decisionHistory: new BehaviorDecisionHistory(),
1106
1268
  committedActionDedupeKeys: new Map(),
1107
1269
  };
1108
1270
  this.runtimes.set(activation.activationId, runtime);
@@ -169,11 +169,15 @@ export class ClawclawBehaviorRunner {
169
169
  activation_id: this.activationId,
170
170
  instance_generation: this.instanceGeneration,
171
171
  epoch_id: input.epochId,
172
+ tick: input.gameState.tick,
172
173
  duration_ms: Math.round(performance.now() - startedAt),
173
174
  read_query_count: queryCount,
174
175
  action_count: decision.actions?.length ?? 0,
176
+ action_kinds: (decision.actions ?? []).map((action) => action.action),
177
+ empty_decision: (decision.actions?.length ?? 0) === 0,
175
178
  event_count: decision.events?.length ?? 0,
176
179
  finished: decision.finish !== undefined,
180
+ execution: this.execution,
177
181
  }, 'debug');
178
182
  return decision;
179
183
  } catch (error) {
@@ -182,9 +186,11 @@ export class ClawclawBehaviorRunner {
182
186
  activation_id: this.activationId,
183
187
  instance_generation: this.instanceGeneration,
184
188
  epoch_id: input.epochId,
189
+ tick: input.gameState.tick,
185
190
  duration_ms: Math.round(performance.now() - startedAt),
186
191
  read_query_count: queryCount,
187
192
  error_code: errorCode(error),
193
+ execution: this.execution,
188
194
  }, signal.aborted ? 'debug' : 'error');
189
195
  throw error;
190
196
  } finally {
@@ -313,7 +313,9 @@ export class ThreadBehaviorExecutor {
313
313
  const request: PendingRequest = {
314
314
  requestId: randomUUID(),
315
315
  operation,
316
- frame: structuredClone(frame),
316
+ // BehaviorInput is already recursively frozen. Keep the Owner snapshot
317
+ // until postMessage performs the one unavoidable Worker-boundary clone.
318
+ frame,
317
319
  ...(observationSnapshot === undefined
318
320
  ? {}
319
321
  : { observationSnapshot: structuredClone(observationSnapshot) }),
@@ -42,7 +42,11 @@ export const DEFAULT_MONITOR_BACKLOG_HINT_WINDOW_ITEM_BUDGET = 4;
42
42
  /** Minimum spacing between directly presented visual telemetry items. */
43
43
  export const DEFAULT_MONITOR_VISUAL_MIN_INTERVAL_MS = 5_000;
44
44
 
45
- const MONITOR_TERMINAL_EVENT_TYPES = new Set(['game_over', 'exile_game_over']);
45
+ const MONITOR_TERMINAL_EVENT_TYPES = new Set([
46
+ 'game_over',
47
+ 'exile_game_over',
48
+ 'game_over_recovered',
49
+ ]);
46
50
  const MONITOR_NOISY_VISUAL_EVENT_TYPES = new Set([
47
51
  'visual.player_moved',
48
52
  'visual.player_motion_changed',
@@ -52,7 +52,7 @@ function roundedElapsed(startedAt: number): number {
52
52
  }
53
53
 
54
54
  function deepFreeze<T>(value: T, seen = new WeakSet<object>()): T {
55
- if (!value || typeof value !== 'object') return value;
55
+ if (!value || typeof value !== 'object' || Object.isFrozen(value)) return value;
56
56
  const object = value as object;
57
57
  if (seen.has(object)) return value;
58
58
  seen.add(object);
@@ -92,10 +92,10 @@ async function analyzeJob(
92
92
  if (typeof analyzer.analyze !== 'function') {
93
93
  throw new Error('perception_analysis_module_not_parallel');
94
94
  }
95
- // Every module/frame job receives its own immutable graph. structuredClone
96
- // at postMessage isolates the Worker from Runtime, but it preserves aliases
97
- // between jobs inside the same batch unless we split them here.
98
- const isolatedInput = deepFreeze(structuredClone(job.input));
95
+ // postMessage already cloned the full batch away from Runtime. Freezing the
96
+ // Worker-owned graph gives every parallel module the same immutable frame
97
+ // without cloning the ten-frame history once again per module.
98
+ const isolatedInput = deepFreeze(job.input);
99
99
  const analysis = structuredClone(await analyzer.analyze(isolatedInput, api));
100
100
  return {
101
101
  moduleId: job.moduleId,