Skip to content

Commit c23a9ba

Browse files
committed
refactor(core): move the replay divergence implementation into src/core
replay-divergence.ts mixed the wire vocabulary every zone reads with the sanitizing, bounding and reporting implementation only root zones call. The ten value consumers are all root (daemon replay, the session replay coordinator, the daemon client lifecycle, the replay-test reporter, the command error projection, and the MCP tool error), so the implementation moves to src/core/replay-divergence.ts and carries its test unchanged. The types stay in contracts and keep the @agent-device/contracts/divergence subpath, which packages/ad-replay and packages/selectors type-import. ReplayVarScrubEntry follows the implementation: it is the sanitizer's own parameter shape, not part of the divergence wire report. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SdXHhx9NkfH1PT4XjYe7tE
1 parent 44d9b10 commit c23a9ba

15 files changed

Lines changed: 531 additions & 541 deletions
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
export {
2-
REPLAY_DIVERGENCE_DEFAULT_REF_LIMIT,
3-
REPLAY_DIVERGENCE_DIGEST_REF_LIMIT,
4-
REPLAY_DIVERGENCE_LEVEL_BYTE_LIMITS,
5-
REPLAY_DIVERGENCE_SUGGESTION_LIMIT,
6-
applyReplayDivergenceLevelCaps,
7-
boundReplayDivergence,
8-
createReplayDivergenceSanitizer,
9-
formatReplayDivergenceReport,
10-
measureReplayDivergenceBytes,
11-
readReplayDivergenceResume,
12-
sanitizeReplayDivergenceField,
13-
scrubReplayVarValues,
14-
truncateUtf8Field,
15-
} from '../replay-divergence.ts';
161
export type {
172
ReplayDivergence,
183
ReplayDivergenceCause,
@@ -30,5 +15,4 @@ export type {
3015
ReplayDivergenceTargetCandidate,
3116
ReplayDivergenceTargetIdentity,
3217
ReplayRepairHint,
33-
ReplayVarScrubEntry,
3418
} from '../replay-divergence.ts';

packages/contracts/src/replay-divergence.ts

Lines changed: 0 additions & 510 deletions
Large diffs are not rendered by default.

src/cli/replay-test/reporters/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../progress.ts';
77
import { formatDurationSeconds } from '../duration-format.ts';
88
import { colorize, supportsColor } from '../../../commands/output/color.ts';
9-
import { formatReplayDivergenceReport } from '@agent-device/contracts/divergence';
9+
import { formatReplayDivergenceReport } from '../../../core/replay-divergence.ts';
1010
import type {
1111
ReplayTestReporter,
1212
ReplayTestReporterContext,

src/commands/output/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type ErrorCandidateView,
66
type NormalizedError,
77
} from '@agent-device/kernel/errors';
8-
import { formatReplayDivergenceReport } from '@agent-device/contracts/divergence';
8+
import { formatReplayDivergenceReport } from '../../core/replay-divergence.ts';
99

1010
export function printHumanError(
1111
err: AppError | NormalizedError,

packages/contracts/src/replay-divergence.test.ts renamed to src/core/replay-divergence.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
REPLAY_DIVERGENCE_LEVEL_BYTE_LIMITS,
1212
REPLAY_DIVERGENCE_SUGGESTION_LIMIT,
1313
truncateUtf8Field,
14-
type ReplayDivergence,
1514
} from './replay-divergence.ts';
15+
import type { ReplayDivergence } from '@agent-device/contracts/divergence';
1616

1717
function buildDivergence(overrides: Partial<ReplayDivergence> = {}): ReplayDivergence {
1818
return {

src/core/replay-divergence.ts

Lines changed: 513 additions & 0 deletions
Large diffs are not rendered by default.

src/daemon/client/daemon-client-lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import net from 'node:net';
33
import os from 'node:os';
44
import path from 'node:path';
55
import { AppError, normalizeError } from '@agent-device/kernel/errors';
6-
import { readReplayDivergenceResume } from '@agent-device/contracts/divergence';
6+
import { readReplayDivergenceResume } from '../../core/replay-divergence.ts';
77
import type { DaemonRequest, DaemonResponse } from '../daemon-request.ts';
88
import {
99
runCmdDetachedMonitored,

src/daemon/replay/internal/__tests__/session-replay-runtime-failure.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { runReplayForTest } from '../../__tests__/replay-command-fixture.ts';
1414
import { SessionStore } from '../../../session-store.ts';
1515
import type { DaemonResponse } from '../../../daemon-request.ts';
1616
import { makeIosSession } from '../../../../__tests__/test-utils/session-factories.ts';
17-
import { formatReplayDivergenceReport } from '@agent-device/contracts/divergence';
17+
import { formatReplayDivergenceReport } from '../../../../core/replay-divergence.ts';
1818
import { maestroScriptSourceBundleFor } from '../../../../__tests__/test-utils/replay-script-source.ts';
1919
import {
2020
captureSnapshotThroughLegacyDispatchFixture,

src/daemon/replay/internal/session-replay-divergence-publication.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import type { ResponseLevel } from '@agent-device/kernel/contracts';
44
import { redactDiagnosticData } from '@agent-device/kernel/redaction';
5-
import { boundReplayDivergence, type ReplayDivergence } from '@agent-device/contracts/divergence';
5+
import { type ReplayDivergence } from '@agent-device/contracts/divergence';
6+
import { boundReplayDivergence } from '../../../core/replay-divergence.ts';
67
import {
78
bindInternalObservationAuthority,
89
type InternalObservationEvidence,

src/daemon/replay/internal/session-replay-divergence.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ import type { ReplayReportAction } from './session-replay-report-action.ts';
2828
import { rankAndDedupeReplaySuggestions } from './session-replay-suggestion-ranking.ts';
2929
import type { SessionState } from '../../session-state.ts';
3030
import {
31-
REPLAY_DIVERGENCE_SUGGESTION_LIMIT,
32-
createReplayDivergenceSanitizer,
3331
type ReplayDivergence,
3432
type ReplayDivergenceScreen,
3533
type ReplayDivergenceScreenRef,
3634
type ReplayDivergenceSuggestion,
3735
type ReplayDivergenceSuggestionBasis,
38-
type ReplayVarScrubEntry,
3936
} from '@agent-device/contracts/divergence';
37+
import {
38+
REPLAY_DIVERGENCE_SUGGESTION_LIMIT,
39+
createReplayDivergenceSanitizer,
40+
type ReplayVarScrubEntry,
41+
} from '../../../core/replay-divergence.ts';
4042

4143
export type DivergenceFieldSanitizer = (value: string, limit?: number) => string;
4244

0 commit comments

Comments
 (0)