diff --git a/packages/ad-replay/package.json b/packages/ad-replay/package.json index 48ff8c1fb6..2b3bcdadb5 100644 --- a/packages/ad-replay/package.json +++ b/packages/ad-replay/package.json @@ -15,10 +15,6 @@ ".": { "types": "./src/index.ts", "default": "./src/index.ts" - }, - "./divergence": { - "types": "./src/replay-divergence.ts", - "default": "./src/replay-divergence.ts" } } } diff --git a/packages/ad-replay/src/index.ts b/packages/ad-replay/src/index.ts index 2f533795f9..0e7bdf31a6 100644 --- a/packages/ad-replay/src/index.ts +++ b/packages/ad-replay/src/index.ts @@ -1,104 +1,3 @@ -/** - * The `ad-replay` package façade (#1478 P5 stage D — narrowed; report-action/ - * suggestion-ranking/vars/identity-vocabulary further narrowed by the P5 - * review pass; plan-digest/resume and `classifyTargetBindingMatch` further - * narrowed by the #1555 review pass, "complete the binding façade instead of - * documenting deviations"; the target-verification policy functions further - * narrowed by the #1555 review's R3 pass, "target verification must happen - * INSIDE the engine"). `scripts/layering/package-boundaries.test.ts` asserts - * this file's exact export list — see "the real tree parses, declares, and - * passes R11" — so a stray export (including one this parser cannot - * enumerate a name for, like `export *`) fails that gate, not just a comment - * mismatch. - * - * The binding design (issue comment 5156017698) is two value entrypoints — - * `inspectAdReplay` + `runAdReplay` — plus the neutral vocabulary their - * signatures are built from, exported by name (#1555 structural-quality - * review, "typed façade replaces the zero-type rule"): a package a root - * consumer must integrate against through hand-derived `Parameters<...>`/ - * `ReturnType<...>` gymnastics in a SINGLE allowed root module - * (`src/daemon/ad-replay-facade-types.ts`, since deleted) is a shim tax, not - * an isolation win — every derived name still had to be re-exported from that - * one file for every other root module to use, and every daemon-side type - * that shadowed an engine type by hand (`TargetVerificationEntry`, - * `TargetClassificationOutcome`, `TargetBindingFailureEvidence`, - * `ReplayVerifiedTargetGuard`, plus a `toDaemonEvidence` copy translator - * between mutable and readonly array shapes) was a duplicate definition that - * could silently drift from the type it mirrored. `packages/maestro`'s - * façade (`facade-execution.ts`/`facade-runtime-port.ts`/…) is the precedent: - * a package boundary is enforced by an exact, gate-pinned export LIST, not by - * exporting zero types. The gate below now pins values AND types together, - * so a stray widening — a type accidentally exported, or one accidentally - * dropped that a root file was still deriving by hand — fails loudly either - * way. - * - * `inspectAdReplay` is the read-only `.ad` manifest reader — the plan-digest - * hash (`plan-digest.ts`, `computeReplayPlanDigest`) and the `--from`/ - * `--plan-digest` resume-point math (`resume.ts`, `resolveReplayEntryIndex`) - * are internal-only; the manifest carries the digest as `planDigest` and the - * resume math as a `resolveEntryIndex` closure instead, so - * `session-replay-runtime-plan.ts`'s `prepareReplayPlan` and - * `request-router-repair-expired.test.ts` read them off the manifest rather - * than importing the underlying functions. `AdReplayManifest` is its return - * type and `AdReplayVarSources` is `runAdReplay`'s `${VAR}` scope-input - * shape — both named here since `session-replay-runtime-plan.ts` threads them - * by name across its own helper signatures. - * - * `runAdReplay` is the `.ad` step loop; `AdReplayStepRuntime` is the runtime - * capability bag the daemon adapter - * (`session-replay-runtime-engine-adapter.ts`) implements to thread it, - * including selector resolution through the direct `@agent-device/selectors` - * package engine. Selector parsing and matching stay behind that package's - * string-only façade; no adapter value crosses this boundary. - * - * `./internal/target-verification.ts`'s four policy functions - * (`planPostResolutionTargetVerification`, `planPreDispatchTargetVerification`, - * `deriveReplayTargetGuardMismatchEvidence`, `deriveWaitLandmarkMismatchEvidence`) - * stay engine-private — they are called only from `./internal/verify-dispatch.ts`'s - * `verifyAndDispatchStep`, never the daemon — but the TYPED evidence shapes - * they consume (`AdReplayGuardMismatchEvidence`, `AdReplayLandmarkMismatchEvidence`) - * and the classification/guard/binding-evidence/verification-routing shapes - * `verifyAndDispatchStep` exchanges with the daemon's `AdReplayStepRuntime` - * implementation (`AdReplayVerificationEntry`, `AdReplayTargetClassification`, - * `AdReplayTargetObservation`, `AdReplayTargetBindingEvidence`, `AdReplayDispatchGuard`, - * `AdReplayDispatchOutcome`) ARE named here: the - * daemon builds/reads real values of these shapes directly now (routing in - * `session-replay-target-verification.ts`, wire-narrowing in - * `session-replay-runtime-engine-adapter.ts`) rather than re-declaring a - * structurally-identical twin per module. - * - * `${VAR}` scope/planning: the engine builds the `${VAR}` scope (via - * `@agent-device/ad-script`) from the request's `varSources` and resolves - * each action exactly once per step, handing the daemon's `dispatchStep`/ - * `beginTargetVerification` capabilities the RESOLVED action — never a raw - * action plus a scope for the daemon to interpolate itself (#1555 review P1, - * "move variable semantics/planning behind the replay entrypoint"). The - * `${VAR}`-scrub values a divergence report redacts (`AdReplayScrubValue`) - * are threaded the same direction, as an explicit argument on each - * build*Failure/handleActionFailure capability, computed ONCE per run from - * the engine's own live scope — never recomputed daemon-side from a second - * scope object, and never re-collected per call site. - */ - +/** Native inspection and execution implement the shared contracts-owned ports. */ export { inspectAdReplay } from './internal/inspect.ts'; -export type { AdReplayManifest } from './internal/inspect.ts'; - export { runAdReplay } from './internal/step-loop.ts'; - -export type { - AdReplayDispatchGuard, - AdReplayDispatchOutcome, - AdReplayScrubValue, - AdReplayStepFailure, - AdReplayStepRuntime, - AdReplayTargetBindingEvidence, - AdReplayTargetClassification, - AdReplayTargetObservation, - AdReplayVarSources, - AdReplayVerificationEntry, -} from './internal/runtime-port-types.ts'; - -export type { - AdReplayGuardMismatchEvidence, - AdReplayLandmarkMismatchEvidence, -} from './internal/target-verification.ts'; diff --git a/packages/ad-replay/src/internal/__tests__/resume.test.ts b/packages/ad-replay/src/internal/__tests__/resume.test.ts index 9d6a682785..ffc8341bbd 100644 --- a/packages/ad-replay/src/internal/__tests__/resume.test.ts +++ b/packages/ad-replay/src/internal/__tests__/resume.test.ts @@ -1,10 +1,10 @@ +import type { + AdReplayEntryIndexParams, + PendingRecordAndHeal, +} from '@agent-device/contracts/ad-replay-execution'; import assert from 'node:assert/strict'; import { test } from 'vitest'; -import { - resolveReplayEntryIndex, - type AdReplayEntryIndexParams, - type PendingRecordAndHeal, -} from '../resume.ts'; +import { resolveReplayEntryIndex } from '../resume.ts'; /** * #1555 structural-quality review ("package-local tests... resume.ts and diff --git a/packages/ad-replay/src/internal/__tests__/step-loop.test.ts b/packages/ad-replay/src/internal/__tests__/step-loop.test.ts index aa5d1e394c..6e004f0b64 100644 --- a/packages/ad-replay/src/internal/__tests__/step-loop.test.ts +++ b/packages/ad-replay/src/internal/__tests__/step-loop.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { test } from 'vitest'; import { runAdReplay } from '../step-loop.ts'; -import type { AdReplayStepRuntime } from '../runtime-port-types.ts'; +import type { AdReplayStepRuntime } from '@agent-device/contracts/ad-replay-execution'; import type { SessionAction } from '@agent-device/contracts/session'; import type { TargetAnnotationV1 } from '@agent-device/contracts/replay'; diff --git a/packages/ad-replay/src/internal/__tests__/target-verification.test.ts b/packages/ad-replay/src/internal/__tests__/target-verification.test.ts index 9a4775b63f..344fda8a90 100644 --- a/packages/ad-replay/src/internal/__tests__/target-verification.test.ts +++ b/packages/ad-replay/src/internal/__tests__/target-verification.test.ts @@ -1,3 +1,7 @@ +import type { + AdReplayGuardMismatchEvidence, + AdReplayLandmarkMismatchEvidence, +} from '@agent-device/contracts/ad-replay-execution'; import assert from 'node:assert/strict'; import { test } from 'vitest'; import type { TargetAnnotationV1 } from '@agent-device/contracts/replay'; @@ -6,8 +10,6 @@ import { deriveWaitLandmarkMismatchEvidence, planPostResolutionTargetVerification, planPreDispatchTargetVerification, - type AdReplayGuardMismatchEvidence, - type AdReplayLandmarkMismatchEvidence, } from '../target-verification.ts'; /** diff --git a/packages/ad-replay/src/internal/inspect.ts b/packages/ad-replay/src/internal/inspect.ts index f86baa7685..2bd38ddabc 100644 --- a/packages/ad-replay/src/internal/inspect.ts +++ b/packages/ad-replay/src/internal/inspect.ts @@ -1,13 +1,11 @@ import { AppError } from '@agent-device/kernel/errors'; -import type { SessionAction } from '@agent-device/contracts/session'; import { parseReplayScriptDetailed, readReplayScriptMetadata, resolveDeclaredScriptPlatform, - type ReplayScriptMetadata, } from '@agent-device/ad-script'; import { computeReplayPlanDigest } from './plan-digest.ts'; -import { resolveReplayEntryIndex, type PendingRecordAndHeal } from './resume.ts'; +import { resolveReplayEntryIndex } from './resume.ts'; /** * #1478 P5 stage C2b: the read-only `.ad` inspection façade. Moved out of @@ -29,23 +27,10 @@ import { resolveReplayEntryIndex, type PendingRecordAndHeal } from './resume.ts' * new top-level façade export — they are plain data/a closure hanging off * the manifest object `inspectAdReplay` already returns. */ -export type AdReplayManifest = Readonly<{ - actions: SessionAction[]; - actionLines: number[]; - metadata: ReplayScriptMetadata; - /** SHA-256 digest of the canonical plan (`digestFlags` binds the same platform/target the replay invokes with). */ - planDigest: string; - /** The `--from`/`--plan-digest` resume-point math, closed over this manifest's own `actions`/`planDigest`. */ - resolveEntryIndex(params: { - from: number | undefined; - digest: string | undefined; - pendingRecordAndHeal: PendingRecordAndHeal | undefined; - sessionActionsLength: number; - }): { ok: true; value: number } | { ok: false; message: string }; -}>; - -/** The request-level `--platform`/`--target` override the plan digest binds (raw flags, before any metadata merge). */ -export type AdReplayDigestFlags = Readonly<{ platform?: string; target?: string }>; +import type { + AdReplayManifest, + AdReplayDigestFlags, +} from '@agent-device/contracts/ad-replay-execution'; /** * Parses one `.ad` script's TEXT and returns its actions/line table, header diff --git a/packages/ad-replay/src/internal/resume.ts b/packages/ad-replay/src/internal/resume.ts index 9e2dcb7789..dfff7f96db 100644 --- a/packages/ad-replay/src/internal/resume.ts +++ b/packages/ad-replay/src/internal/resume.ts @@ -17,27 +17,11 @@ * notes for why that reordering was judged out of scope here. */ -/** - * The session-side state that gates an EMPTY-TAIL resume (`--from actionCount - * + 1`). Stamped for `record-and-heal`, and per #1262 also for - * `caution`/`manual`'s record-and-heal-shaped alternate repair (their own - * unshifted `resume.from` is unaffected by this watermark). - */ -export type PendingRecordAndHeal = Readonly<{ - expectedFrom: number; - actionsCountAtDivergence: number; -}>; - -export type AdReplayEntryIndexParams = Readonly<{ - from: number | undefined; - digest: string | undefined; - pendingRecordAndHeal: PendingRecordAndHeal | undefined; - sessionActionsLength: number; -}>; - -export type AdReplayEntryIndexResult = - | Readonly<{ readonly ok: true; readonly value: number }> - | Readonly<{ readonly ok: false; readonly message: string }>; +import type { + PendingRecordAndHeal, + AdReplayEntryIndexParams, + AdReplayEntryIndexResult, +} from '@agent-device/contracts/ad-replay-execution'; /** * Resolves `--from`/`--plan-digest` into a 0-based loop entry index before diff --git a/packages/ad-replay/src/internal/step-loop.ts b/packages/ad-replay/src/internal/step-loop.ts index 619a20583c..6820039e5d 100644 --- a/packages/ad-replay/src/internal/step-loop.ts +++ b/packages/ad-replay/src/internal/step-loop.ts @@ -11,7 +11,7 @@ import type { AdReplayRunOutcome, AdReplayRunRequest, AdReplayStepRuntime, -} from './runtime-port-types.ts'; +} from '@agent-device/contracts/ad-replay-execution'; /** * #1478 P5 stage C2b: the `.ad` step-loop ENGINE policy, split out of @@ -19,7 +19,7 @@ import type { * `resolveReplayStepResponse` / `buildReplayActionFailure`. Everything that * touches a real device, a snapshot, `SessionStore`, or the P4b repair * coordinator is daemon authority and stays behind the narrow - * `AdReplayStepRuntime` capabilities (`./runtime-port-types.ts`) — this + * `AdReplayStepRuntime` capabilities (`@agent-device/contracts/ad-replay-execution`) — this * module only decides which action to run next, when to skip one, and when * to stop. * @@ -28,7 +28,7 @@ import type { * vocabulary and the verify-then-dispatch orchestrator — both extracted out, * following `packages/maestro`'s own three-way split * (`runtime-port-types.ts` for the vocabulary, its engine files for the - * orchestration logic). `./runtime-port-types.ts` now owns every + * orchestration logic). `@agent-device/contracts/ad-replay-execution` now owns every * `AdReplayStepRuntime`-adjacent type; `./verify-dispatch.ts` owns * `verifyAndDispatchStep` and its two dispatch helpers. This file is left * with exactly the loop (`runAdReplay`) and the terminal-close/executable- diff --git a/packages/ad-replay/src/internal/target-verification.ts b/packages/ad-replay/src/internal/target-verification.ts index 0d3264e4fa..e431c573ce 100644 --- a/packages/ad-replay/src/internal/target-verification.ts +++ b/packages/ad-replay/src/internal/target-verification.ts @@ -44,7 +44,7 @@ * not engine policy. This module now only reads already-typed values. */ -import type { TargetAncestryEntry, TargetAnnotationV1 } from '@agent-device/contracts/replay'; +import type { TargetAnnotationV1 } from '@agent-device/contracts/replay'; import { firstAncestryMismatch, identityFieldMismatches, @@ -52,37 +52,11 @@ import { } from '@agent-device/ad-script'; import { readSelectorExpression } from '@agent-device/selectors'; -/** - * The verified/observed member's structural position within its capture - * (document order + sibling) — moved here (from `./step-loop.ts`, which - * still uses it for `AdReplayVerifiedTargetGuard`) so both this module's - * typed evidence shapes and the step loop can reference ONE definition - * without a cycle: this module has no dependency on `./step-loop.ts`, but - * `./step-loop.ts` already depends on this one. - */ -export type AdReplayTargetStructuralDenotation = Readonly<{ - documentOrder: number; - sibling: number; -}>; - -/** - * The guard-mismatch refusal's typed evidence, already narrowed by the - * daemon adapter from the wire response's `details` bag — the engine never - * sees the untyped bag itself. - */ -export type AdReplayGuardMismatchEvidence = Readonly<{ - targetRole?: 'source' | 'destination'; - observed: LocalIdentity | undefined; - expectedStructural: AdReplayTargetStructuralDenotation | undefined; - observedStructural: AdReplayTargetStructuralDenotation | undefined; -}>; - -/** The wait-landmark-mismatch refusal's typed evidence — same translate-before-crossing rule. */ -export type AdReplayLandmarkMismatchEvidence = Readonly<{ - matchCount: number | undefined; - observed: LocalIdentity | undefined; - observedAncestry: readonly TargetAncestryEntry[]; -}>; +import type { + AdReplayTargetStructuralDenotation, + AdReplayGuardMismatchEvidence, + AdReplayLandmarkMismatchEvidence, +} from '@agent-device/contracts/ad-replay-execution'; // --------------------------------------------------------------------------- // Pre-capture verification gating (`verifyReplayActionTarget`'s two branches). diff --git a/packages/ad-replay/src/internal/verify-dispatch.ts b/packages/ad-replay/src/internal/verify-dispatch.ts index e82303bc5d..5c9b017ec7 100644 --- a/packages/ad-replay/src/internal/verify-dispatch.ts +++ b/packages/ad-replay/src/internal/verify-dispatch.ts @@ -13,7 +13,7 @@ import type { AdReplayStepRuntime, AdReplayTargetObservation, AdReplayVerifiedTargetGuard, -} from './runtime-port-types.ts'; +} from '@agent-device/contracts/ad-replay-execution'; /** * #1478 P5 stage C2b (split out of `step-loop.ts` by the #1555 structural- diff --git a/packages/ad-script/src/index.ts b/packages/ad-script/src/index.ts index da5ccaedb8..a3df8be6bc 100644 --- a/packages/ad-script/src/index.ts +++ b/packages/ad-script/src/index.ts @@ -1,5 +1,5 @@ export { parseReplayScriptDetailed, readReplayScriptMetadata } from './internal/script.ts'; -export type { ReplayScriptMetadata } from './internal/script.ts'; +export type { ReplayScriptMetadata } from '@agent-device/contracts/replay-script-data'; export { resolveDeclaredScriptPlatform } from './internal/open-script.ts'; diff --git a/packages/ad-script/src/internal/replay-input.ts b/packages/ad-script/src/internal/replay-input.ts index 5de1fe4b8a..3b9cefcaea 100644 --- a/packages/ad-script/src/internal/replay-input.ts +++ b/packages/ad-script/src/internal/replay-input.ts @@ -1,3 +1,4 @@ +import type { ReplayScriptMetadata } from '@agent-device/contracts/replay-script-data'; import type { CommandFlags } from '@agent-device/contracts/command'; import { AppError } from '@agent-device/kernel/errors'; import { isReplayBackendId, unsupportedReplayBackendMessage } from './format.ts'; @@ -5,7 +6,6 @@ import { parseReplayScriptDetailed, readReplayScriptMetadata, type ParsedReplayScript, - type ReplayScriptMetadata, } from './script.ts'; export type ParsedReplayInput = ParsedReplayScript & { diff --git a/packages/ad-script/src/internal/script.ts b/packages/ad-script/src/internal/script.ts index 758f3c2a22..191b4439ce 100644 --- a/packages/ad-script/src/internal/script.ts +++ b/packages/ad-script/src/internal/script.ts @@ -1,3 +1,4 @@ +import type { ReplayScriptMetadata } from '@agent-device/contracts/replay-script-data'; import { AppError } from '@agent-device/kernel/errors'; import { recordingQualityInputToExportQuality } from '@agent-device/contracts/recording'; import { @@ -45,14 +46,6 @@ export const REPLAY_METADATA_PLATFORMS = new Set( ); const REPLAY_METADATA_TARGETS = new Set(['mobile', 'tv', 'desktop']); -export type ReplayScriptMetadata = { - platform?: ReplayScriptPlatform; - target?: DeviceTarget; - timeoutMs?: number; - retries?: number; - env?: Record; -}; - export type ParsedReplayScript = { actions: SessionAction[]; actionLines: number[]; diff --git a/packages/ad-script/src/internal/vars.ts b/packages/ad-script/src/internal/vars.ts index f02aaab980..e557d37f73 100644 --- a/packages/ad-script/src/internal/vars.ts +++ b/packages/ad-script/src/internal/vars.ts @@ -13,12 +13,7 @@ export type ReplayVarScope = { expandedBuiltinNames?: Set; }; -export type ReplayVarSources = { - builtins?: Record; - fileEnv?: Record; - shellEnv?: Record; - cliEnv?: Record; -}; +import type { ReplayVarSources } from '@agent-device/contracts/replay-script-data'; const SHELL_PREFIX = 'AD_VAR_'; diff --git a/packages/command-output/package.json b/packages/command-output/package.json index 96333df650..caff572370 100644 --- a/packages/command-output/package.json +++ b/packages/command-output/package.json @@ -6,7 +6,6 @@ "type": "module", "description": "Shared CLI and MCP command presentation: per-family output formatters, warning routing, color, human error lines, and result serialization. Takes terminal facts as explicit input and performs no process I/O.", "dependencies": { - "@agent-device/ad-replay": "workspace:*", "@agent-device/capture-kit": "workspace:*", "@agent-device/command-registry": "workspace:*", "@agent-device/command-surface": "workspace:*", diff --git a/packages/command-output/src/output/error.ts b/packages/command-output/src/output/error.ts index 6df70954d7..da3fc2f23b 100644 --- a/packages/command-output/src/output/error.ts +++ b/packages/command-output/src/output/error.ts @@ -8,7 +8,7 @@ import { type NormalizedError, } from '@agent-device/kernel/errors'; import { readResponseWarnings } from '@agent-device/kernel/success-text'; -import { formatReplayDivergenceReport } from '@agent-device/ad-replay/divergence'; +import { formatReplayDivergenceReport } from '@agent-device/contracts/replay-divergence-data'; import { collapseWarningText } from '../output-common.ts'; /** diff --git a/packages/command-output/tsconfig.json b/packages/command-output/tsconfig.json index fa6bf31bf0..36cd559426 100644 --- a/packages/command-output/tsconfig.json +++ b/packages/command-output/tsconfig.json @@ -13,7 +13,6 @@ // declared beside them; a package program that reaches registry.ts needs the declaration too. "include": ["src", "../command-registry/src/global.d.ts"], "references": [ - { "path": "../ad-replay" }, { "path": "../capture-kit" }, { "path": "../command-registry" }, { "path": "../command-surface" }, diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 15207e4d4d..6033aaf160 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -555,6 +555,22 @@ "./wait": { "types": "./src/wait.ts", "default": "./src/wait.ts" + }, + "./replay-divergence-data": { + "types": "./src/replay-divergence-data.ts", + "default": "./src/replay-divergence-data.ts" + }, + "./replay-script-data": { + "types": "./src/replay-script-data.ts", + "default": "./src/replay-script-data.ts" + }, + "./ad-replay-execution": { + "types": "./src/ad-replay-execution.ts", + "default": "./src/ad-replay-execution.ts" + }, + "./replay-test-execution": { + "types": "./src/replay-test-execution.ts", + "default": "./src/replay-test-execution.ts" } }, "devDependencies": { diff --git a/packages/ad-replay/src/internal/runtime-port-types.ts b/packages/contracts/src/ad-replay-execution.ts similarity index 85% rename from packages/ad-replay/src/internal/runtime-port-types.ts rename to packages/contracts/src/ad-replay-execution.ts index 5a34a33034..5c04a31395 100644 --- a/packages/ad-replay/src/internal/runtime-port-types.ts +++ b/packages/contracts/src/ad-replay-execution.ts @@ -4,12 +4,12 @@ import type { Platform, PublicPlatform } from '@agent-device/kernel/device'; import type { SnapshotNode } from '@agent-device/kernel/snapshot'; import type { TargetAnnotationV1 } from '@agent-device/contracts/replay'; import type { ReplayDivergenceTargetBindingKind } from '@agent-device/contracts/divergence'; -import type { buildReplayVarScope, LocalIdentity } from '@agent-device/ad-script'; import type { - AdReplayGuardMismatchEvidence, - AdReplayLandmarkMismatchEvidence, - AdReplayTargetStructuralDenotation, -} from './target-verification.ts'; + LocalIdentity, + NodeStructuralDenotation, + TargetAncestryEntry, +} from './target-annotation.ts'; +import type { ReplayVarSources, ReplayScriptMetadata } from './replay-script-data.ts'; /** * #1478 P5 stage C2b (split out of `step-loop.ts` by the #1555 structural- @@ -23,14 +23,8 @@ import type { * full boundary rationale. */ -/** - * `${VAR}` scope inputs — plain data (builtins/file/shell/cli env) the - * daemon reads from the request/process and passes in; `runAdReplay` builds - * the scope from this. Derived structurally off `buildReplayVarScope` - * (`@agent-device/ad-script` does not export its own `ReplayVarSources` type - * by name) rather than duplicating the shape. - */ -export type AdReplayVarSources = Parameters[0]; +/** Host-provided variable sources; the engine resolves each action once. */ +export type AdReplayVarSources = ReplayVarSources; /** * A `${VAR}` value eligible for divergence-report redaction — the engine's @@ -373,3 +367,60 @@ export type AdReplayRunOutcome = readonly stepIndex: number; readonly failure: AdReplayStepFailure; }>; + +/** The verified member's shared structural position, read-only across the execution boundary. */ +export type AdReplayTargetStructuralDenotation = Readonly; + +/** + * The guard-mismatch refusal's typed evidence, already narrowed by the + * daemon adapter from the wire response's `details` bag — the engine never + * sees the untyped bag itself. + */ +export type AdReplayGuardMismatchEvidence = Readonly<{ + targetRole?: 'source' | 'destination'; + observed: LocalIdentity | undefined; + expectedStructural: AdReplayTargetStructuralDenotation | undefined; + observedStructural: AdReplayTargetStructuralDenotation | undefined; +}>; + +/** The wait-landmark-mismatch refusal's typed evidence — same translate-before-crossing rule. */ +export type AdReplayLandmarkMismatchEvidence = Readonly<{ + matchCount: number | undefined; + observed: LocalIdentity | undefined; + observedAncestry: readonly TargetAncestryEntry[]; +}>; + +export type AdReplayManifest = Readonly<{ + actions: SessionAction[]; + actionLines: number[]; + metadata: ReplayScriptMetadata; + /** SHA-256 digest of the canonical plan (`digestFlags` binds the same platform/target the replay invokes with). */ + planDigest: string; + /** The `--from`/`--plan-digest` resume-point math, closed over this manifest's own `actions`/`planDigest`. */ + resolveEntryIndex(params: AdReplayEntryIndexParams): AdReplayEntryIndexResult; +}>; + +/** The request-level `--platform`/`--target` override the plan digest binds (raw flags, before any metadata merge). */ +export type AdReplayDigestFlags = Readonly<{ platform?: string; target?: string }>; + +/** + * The session-side state that gates an EMPTY-TAIL resume (`--from actionCount + * + 1`). Stamped for `record-and-heal`, and per #1262 also for + * `caution`/`manual`'s record-and-heal-shaped alternate repair (their own + * unshifted `resume.from` is unaffected by this watermark). + */ +export type PendingRecordAndHeal = Readonly<{ + expectedFrom: number; + actionsCountAtDivergence: number; +}>; + +export type AdReplayEntryIndexParams = Readonly<{ + from: number | undefined; + digest: string | undefined; + pendingRecordAndHeal: PendingRecordAndHeal | undefined; + sessionActionsLength: number; +}>; + +export type AdReplayEntryIndexResult = + | Readonly<{ readonly ok: true; readonly value: number }> + | Readonly<{ readonly ok: false; readonly message: string }>; diff --git a/packages/ad-replay/src/replay-divergence.test.ts b/packages/contracts/src/replay-divergence-data.test.ts similarity index 98% rename from packages/ad-replay/src/replay-divergence.test.ts rename to packages/contracts/src/replay-divergence-data.test.ts index af85a73569..8b1d7d48a1 100644 --- a/packages/ad-replay/src/replay-divergence.test.ts +++ b/packages/contracts/src/replay-divergence-data.test.ts @@ -11,7 +11,7 @@ import { REPLAY_DIVERGENCE_LEVEL_BYTE_LIMITS, REPLAY_DIVERGENCE_SUGGESTION_LIMIT, truncateUtf8Field, -} from './replay-divergence.ts'; +} from './replay-divergence-data.ts'; import type { ReplayDivergence } from '@agent-device/contracts/divergence'; function buildDivergence(overrides: Partial = {}): ReplayDivergence { @@ -240,7 +240,7 @@ test('sanitizeReplayDivergenceField redacts sensitive content even when no trunc // --- Text report carries the repair data (bounded refs + unavailable hint) --- test('formatReplayDivergenceReport lists a bounded ref/role/label subset for an available screen', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -273,7 +273,7 @@ test('formatReplayDivergenceReport lists a bounded ref/role/label subset for an }); test('formatReplayDivergenceReport carries the unavailable-screen hint', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -296,7 +296,7 @@ test('formatReplayDivergenceReport carries the unavailable-screen hint', async ( }); test('scrubReplayVarValues replaces every occurrence with a named marker, longest value first', async () => { - const { scrubReplayVarValues } = await import('./replay-divergence.ts'); + const { scrubReplayVarValues } = await import('./replay-divergence-data.ts'); const entries = [ { name: 'LONG', value: 'abc-def' }, { name: 'SHORT', value: 'abc' }, @@ -415,7 +415,7 @@ test('boundReplayDivergence keeps targetBinding on the minimal overflow fallback }); test('formatReplayDivergenceReport renders matchCount, mismatches, and candidates for a target-binding divergence', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -443,7 +443,7 @@ test('formatReplayDivergenceReport renders matchCount, mismatches, and candidate }); test('formatReplayDivergenceReport lists candidates for an identity-unverifiable target-binding divergence', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -478,7 +478,7 @@ test('formatReplayDivergenceReport lists candidates for an identity-unverifiable // refused — it surfaces `resume.reason` instead. --- test('formatReplayDivergenceReport embeds the concrete resume command for an allowed record-and-heal divergence', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -503,7 +503,7 @@ test('formatReplayDivergenceReport embeds the concrete resume command for an all }); test('formatReplayDivergenceReport never renders a --from command when resume is NOT allowed, surfacing the reason instead', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -533,7 +533,7 @@ test('formatReplayDivergenceReport never renders a --from command when resume is }); test('formatReplayDivergenceReport falls back to a generic non-resumable sentence when resume carries no reason', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -562,7 +562,7 @@ test('formatReplayDivergenceReport falls back to a generic non-resumable sentenc // NEVER re-derives resumability, so text and structured wire never disagree. --- test('formatReplayDivergenceReport embeds BOTH concrete resume commands for a caution divergence whose wire carries alternateFrom', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -595,7 +595,7 @@ test('formatReplayDivergenceReport embeds BOTH concrete resume commands for a ca }); test('formatReplayDivergenceReport embeds BOTH concrete resume commands for a manual divergence whose wire carries alternateFrom', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -623,7 +623,7 @@ test('formatReplayDivergenceReport embeds BOTH concrete resume commands for a ma }); test('formatReplayDivergenceReport renders ONLY the state-fix command for a caution divergence WITHOUT alternateFrom (the diverged step is not skip-safe)', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); // resume.allowed is true (resuming AT N is fine), but the diverged step N // is a runScript/control-flow action, so `--from N + 1` would be refused — // the daemon omits alternateFrom, and the text must NOT offer `--from N + 1`. @@ -655,7 +655,7 @@ test('formatReplayDivergenceReport renders ONLY the state-fix command for a caut }); test('formatReplayDivergenceReport renders neither caution command when resume is NOT allowed', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -696,7 +696,7 @@ const REPAIR_DIAGNOSTICS_CLAUSE_PATTERN = /Read-only inspection while armed \(snapshot -i, get attrs, find, is\) is excluded from the healed script by default — no --no-record needed\. If the step you are repairing is itself a read, add --record to that command so it lands in the heal\./; test('formatReplayDivergenceReport appends the diagnostics default-exclusion clause for record-and-heal when repairSessionHeld is true', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -719,7 +719,7 @@ test('formatReplayDivergenceReport appends the diagnostics default-exclusion cla }); test('formatReplayDivergenceReport OMITS the diagnostics clause for record-and-heal when repairSessionHeld is absent (plain, non-repair divergence)', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -742,7 +742,7 @@ test('formatReplayDivergenceReport OMITS the diagnostics clause for record-and-h }); test('formatReplayDivergenceReport appends the diagnostics clause for state-repair when armed, distinct from the existing app-state --no-record clause', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -766,7 +766,7 @@ test('formatReplayDivergenceReport appends the diagnostics clause for state-repa }); test('formatReplayDivergenceReport OMITS the diagnostics clause for state-repair when repairSessionHeld is absent', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -787,7 +787,7 @@ test('formatReplayDivergenceReport OMITS the diagnostics clause for state-repair }); test('formatReplayDivergenceReport appends the diagnostics clause for caution when armed, alongside the dual-path resume commands', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -817,7 +817,7 @@ test('formatReplayDivergenceReport appends the diagnostics clause for caution wh }); test('formatReplayDivergenceReport OMITS the diagnostics clause for caution when repairSessionHeld is absent', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, @@ -837,7 +837,7 @@ test('formatReplayDivergenceReport OMITS the diagnostics clause for caution when }); test('formatReplayDivergenceReport appends the diagnostics clause for manual when armed, even when resume is NOT allowed', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); // `repairSessionHeld` reports the daemon KEPT THE SESSION LIVE, independent // of `resume.allowed` (plan-resumability) — the diagnostics clause must // still render here: the agent may still inspect the (held) session while @@ -869,7 +869,7 @@ test('formatReplayDivergenceReport appends the diagnostics clause for manual whe }); test('formatReplayDivergenceReport OMITS the diagnostics clause for manual when repairSessionHeld is absent', async () => { - const { formatReplayDivergenceReport } = await import('./replay-divergence.ts'); + const { formatReplayDivergenceReport } = await import('./replay-divergence-data.ts'); const report = formatReplayDivergenceReport({ divergence: { version: 1, diff --git a/packages/ad-replay/src/replay-divergence.ts b/packages/contracts/src/replay-divergence-data.ts similarity index 100% rename from packages/ad-replay/src/replay-divergence.ts rename to packages/contracts/src/replay-divergence-data.ts diff --git a/packages/contracts/src/replay-script-data.ts b/packages/contracts/src/replay-script-data.ts new file mode 100644 index 0000000000..7bd76bfd51 --- /dev/null +++ b/packages/contracts/src/replay-script-data.ts @@ -0,0 +1,16 @@ +import type { DeviceTarget, PlatformSelector } from '@agent-device/kernel/device'; + +export type ReplayScriptMetadata = { + platform?: Exclude; + target?: DeviceTarget; + timeoutMs?: number; + retries?: number; + env?: Record; +}; + +export type ReplayVarSources = { + builtins?: Record; + fileEnv?: Record; + shellEnv?: Record; + cliEnv?: Record; +}; diff --git a/packages/replay-test/src/internal/session-test-types.ts b/packages/contracts/src/replay-test-execution.ts similarity index 91% rename from packages/replay-test/src/internal/session-test-types.ts rename to packages/contracts/src/replay-test-execution.ts index a7dfe1ca44..7495c8105a 100644 --- a/packages/replay-test/src/internal/session-test-types.ts +++ b/packages/contracts/src/replay-test-execution.ts @@ -5,11 +5,6 @@ import type { ReplayTestSuiteProgressEvent, } from '@agent-device/contracts/progress'; import type { DeviceTarget, PlatformSelector } from '@agent-device/kernel/device'; -import type { - ReplayTestResolveShardTargets, - ReplayTestShardContext, - ReplayTestShardMode, -} from './session-test-sharding.ts'; /** * The device vocabulary a scheduler may name, sourced from the neutral kernel rather than @@ -276,20 +271,35 @@ export type ReplayTestExecutionDependencies = Omit< 'discoverSources' | 'resolveShardTargets' >; -/** Neutral failure outcome helper; keeps timeout/unknown construction in one place. */ -export function replayTestAttemptFailure(params: { - error: ReplayTestAttemptError; - artifactPaths?: readonly string[]; - warnings?: readonly string[]; - infrastructure?: boolean; - snapshotDiagnostics?: SnapshotDiagnosticsSummary; -}): ReplayTestAttemptFailed { - return { - status: 'failed', - error: params.error, - artifactPaths: params.artifactPaths ?? [], - warnings: params.warnings ?? [], - infrastructure: params.infrastructure ?? false, - ...(params.snapshotDiagnostics ? { snapshotDiagnostics: params.snapshotDiagnostics } : {}), - }; -} +export type ReplayTestShardMode = 'all' | 'split'; + +/** + * The device a shard runs against, in neutral vocabulary. + * + * The scheduler reads `id`/`name` for session labels and progress metadata. `platform` and + * `target` are here because the host needs them to bind a nested request, and both are already + * neutral kernel types — so `DeviceInfo` itself never crosses into scheduling. + */ +export type ReplayTestShardTarget = Readonly<{ + id: string; + name: string; + platform: ReplayTestPlatform; + target?: ReplayTestTarget; +}>; + +export type ReplayTestShardContext = { + shardIndex: number; + shardCount: number; + device: ReplayTestShardTarget; +}; + +/** + * Resolves the devices a sharded run will use (#1478 P3b). + * + * Enumerating inventory, applying allowlists and simulator set paths, and rejecting a run with + * too few devices are all host concerns. The scheduler decides how many shards there are and + * which entries go to each; it never enumerates hardware. + */ +export type ReplayTestResolveShardTargets = ( + shardCount: number, +) => Promise; diff --git a/packages/daemon-client/package.json b/packages/daemon-client/package.json index 8d0fa16303..8821b515e1 100644 --- a/packages/daemon-client/package.json +++ b/packages/daemon-client/package.json @@ -5,7 +5,6 @@ "type": "module", "description": "The client side of the daemon wire: transport and JSON-RPC framing, request cancellation and progress, local daemon launch, ensure, attach and stop, and remote daemon health. Internal workspace package bundled into the published agent-device artifact.", "dependencies": { - "@agent-device/ad-replay": "workspace:*", "@agent-device/command-registry": "workspace:*", "@agent-device/contracts": "workspace:*", "@agent-device/daemon-contracts": "workspace:*", diff --git a/packages/daemon-client/src/daemon-client-lifecycle.ts b/packages/daemon-client/src/daemon-client-lifecycle.ts index b68845aafd..c499b0187a 100644 --- a/packages/daemon-client/src/daemon-client-lifecycle.ts +++ b/packages/daemon-client/src/daemon-client-lifecycle.ts @@ -8,7 +8,7 @@ import type { DaemonResponse } from '@agent-device/kernel/contracts'; import net from 'node:net'; import { AppError, normalizeError, type NormalizedError } from '@agent-device/kernel/errors'; import type { EnvMap, HostEnvironment } from '@agent-device/kernel/source-value'; -import { readReplayDivergenceResume } from '@agent-device/ad-replay/divergence'; +import { readReplayDivergenceResume } from '@agent-device/contracts/replay-divergence-data'; import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; import { createOwnedReplayStateDir, diff --git a/packages/daemon-client/tsconfig.json b/packages/daemon-client/tsconfig.json index 0cbd24bfa4..361fd7043f 100644 --- a/packages/daemon-client/tsconfig.json +++ b/packages/daemon-client/tsconfig.json @@ -11,7 +11,6 @@ }, "include": ["src"], "references": [ - { "path": "../ad-replay" }, { "path": "../command-registry" }, { "path": "../contracts" }, { "path": "../daemon-contracts" }, diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 09a1aa211a..5351051cc2 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -5,7 +5,6 @@ "type": "module", "description": "The agent-device daemon server: request routing, sessions, leases, device claims, snapshot and interaction handling. Internal workspace package bundled into the published agent-device artifact (#3352 daemon extraction).", "dependencies": { - "@agent-device/ad-replay": "workspace:*", "@agent-device/ad-script": "workspace:*", "@agent-device/capture-kit": "workspace:*", "@agent-device/command-registry": "workspace:*", @@ -31,7 +30,8 @@ "oxc-parser": "^0.146.0", "vitest": "5.0.4", "yaml": "^2.9.0", - "@agent-device/maestro": "workspace:*" + "@agent-device/maestro": "workspace:*", + "@agent-device/ad-replay": "workspace:*" }, "exports": { ".": { diff --git a/packages/daemon/src/sessions/__tests__/replay-runtime/replay-command-fixture.ts b/packages/daemon/src/sessions/__tests__/replay-runtime/replay-command-fixture.ts index ed4b2c94c8..215db348a3 100644 --- a/packages/daemon/src/sessions/__tests__/replay-runtime/replay-command-fixture.ts +++ b/packages/daemon/src/sessions/__tests__/replay-runtime/replay-command-fixture.ts @@ -1,5 +1,5 @@ import type { DaemonResponse } from '@agent-device/kernel/contracts'; -import type { ReplayTestAttemptStepSink } from '@agent-device/replay-test'; +import type { ReplayTestAttemptStepSink } from '@agent-device/contracts/replay-test-execution'; import type { DaemonInvokeFn, DaemonRequest } from '../../../core/daemon-request.ts'; import type { SessionStore } from '../../../core/session-store.ts'; import { diff --git a/packages/daemon/src/sessions/__tests__/replay-runtime/session-replay-runtime-failure.test.ts b/packages/daemon/src/sessions/__tests__/replay-runtime/session-replay-runtime-failure.test.ts index 1c1bd76a76..45ae051d07 100644 --- a/packages/daemon/src/sessions/__tests__/replay-runtime/session-replay-runtime-failure.test.ts +++ b/packages/daemon/src/sessions/__tests__/replay-runtime/session-replay-runtime-failure.test.ts @@ -15,7 +15,7 @@ import path from 'node:path'; import { runReplayForTest } from './replay-command-fixture.ts'; import { SessionStore } from '../../../core/session-store.ts'; import { makeIosSession } from '../../../__tests__/support/session-factories.ts'; -import { formatReplayDivergenceReport } from '@agent-device/ad-replay/divergence'; +import { formatReplayDivergenceReport } from '@agent-device/contracts/replay-divergence-data'; import { maestroScriptSourceBundleFor } from '../../../__tests__/support/replay-script-source-fixture.ts'; import { captureSnapshotThroughLegacyDispatchFixture, diff --git a/packages/daemon/src/sessions/session-replay-coordinator.ts b/packages/daemon/src/sessions/session-replay-coordinator.ts index b6a47ad730..bc0c40b563 100644 --- a/packages/daemon/src/sessions/session-replay-coordinator.ts +++ b/packages/daemon/src/sessions/session-replay-coordinator.ts @@ -1,7 +1,7 @@ import type { DaemonResponse } from '@agent-device/kernel/contracts'; import type { SessionAction } from '@agent-device/contracts/session'; import type { ReplayDivergenceResume, ReplayRepairHint } from '@agent-device/contracts/divergence'; -import { readReplayDivergenceResume } from '@agent-device/ad-replay/divergence'; +import { readReplayDivergenceResume } from '@agent-device/contracts/replay-divergence-data'; import type { SessionRuntimeHints, SessionState } from '../core/session-state.ts'; import { armRepairStep, diff --git a/packages/replay-port/src/daemon-port/replay-backend-failure.ts b/packages/replay-port/src/daemon-port/replay-backend-failure.ts index d632c3f12c..bc2b64faf7 100644 --- a/packages/replay-port/src/daemon-port/replay-backend-failure.ts +++ b/packages/replay-port/src/daemon-port/replay-backend-failure.ts @@ -4,7 +4,7 @@ import { REPLAY_DIVERGENCE_SUGGESTION_LIMIT, createReplayDivergenceSanitizer, type ReplayVarScrubEntry, -} from '@agent-device/ad-replay/divergence'; +} from '@agent-device/contracts/replay-divergence-data'; import { getRequestSignal } from '@agent-device/host-kit/request'; import type { DaemonResponse } from '@agent-device/kernel/contracts'; import { computeReplayRepairHint } from './repair-hint.ts'; diff --git a/packages/replay-port/src/daemon-port/session-replay-dispatch-narrowing.ts b/packages/replay-port/src/daemon-port/session-replay-dispatch-narrowing.ts index a6f7dacd1e..6fd1bfc2dd 100644 --- a/packages/replay-port/src/daemon-port/session-replay-dispatch-narrowing.ts +++ b/packages/replay-port/src/daemon-port/session-replay-dispatch-narrowing.ts @@ -5,7 +5,7 @@ import type { AdReplayGuardMismatchEvidence, AdReplayLandmarkMismatchEvidence, AdReplayStepFailure, -} from '@agent-device/ad-replay'; +} from '@agent-device/contracts/ad-replay-execution'; import type { LocalIdentity } from '@agent-device/ad-script'; import type { TargetAncestryEntry } from '@agent-device/contracts/replay'; import { diff --git a/packages/replay-port/src/daemon-port/session-replay-divergence-publication.ts b/packages/replay-port/src/daemon-port/session-replay-divergence-publication.ts index 5953ee9526..6e38ee8238 100644 --- a/packages/replay-port/src/daemon-port/session-replay-divergence-publication.ts +++ b/packages/replay-port/src/daemon-port/session-replay-divergence-publication.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import type { ResponseLevel } from '@agent-device/kernel/contracts'; import { redactDiagnosticData } from '@agent-device/kernel/redaction'; import { type ReplayDivergence } from '@agent-device/contracts/divergence'; -import { boundReplayDivergence } from '@agent-device/ad-replay/divergence'; +import { boundReplayDivergence } from '@agent-device/contracts/replay-divergence-data'; import type { ReplayObservationEvidence } from '@agent-device/contracts/replay'; import type { ReplaySessionObservation, diff --git a/packages/replay-port/src/daemon-port/session-replay-divergence.ts b/packages/replay-port/src/daemon-port/session-replay-divergence.ts index e4bfd9db79..7ea894e76c 100644 --- a/packages/replay-port/src/daemon-port/session-replay-divergence.ts +++ b/packages/replay-port/src/daemon-port/session-replay-divergence.ts @@ -47,7 +47,7 @@ import { REPLAY_DIVERGENCE_SUGGESTION_LIMIT, createReplayDivergenceSanitizer, type ReplayVarScrubEntry, -} from '@agent-device/ad-replay/divergence'; +} from '@agent-device/contracts/replay-divergence-data'; export type DivergenceFieldSanitizer = (value: string, limit?: number) => string; diff --git a/packages/replay-port/src/daemon-port/session-replay-resume.ts b/packages/replay-port/src/daemon-port/session-replay-resume.ts index 824545ce2d..45f78098e1 100644 --- a/packages/replay-port/src/daemon-port/session-replay-resume.ts +++ b/packages/replay-port/src/daemon-port/session-replay-resume.ts @@ -42,7 +42,7 @@ export function buildAndPersistReplayDivergenceResume(params: { * `failedIndex` would re-diverge on the step the agent already performed). * Every other repair hint (including a plain `action-failure`) resumes AT * `failedIndex` unchanged. This must agree with the text guidance rendered by - * `formatReplayDivergenceReport` (`packages/ad-replay/src/replay-divergence.ts`) — both are + * `formatReplayDivergenceReport` (`packages/contracts/src/replay-divergence-data.ts`) — both are * derived from the same computed `from` value. * * `failedIndex` is always a valid 1-based index into `actions` (both call diff --git a/packages/replay-port/src/daemon-port/session-replay-runtime-engine-adapter.ts b/packages/replay-port/src/daemon-port/session-replay-runtime-engine-adapter.ts index ab8719ed49..414884f367 100644 --- a/packages/replay-port/src/daemon-port/session-replay-runtime-engine-adapter.ts +++ b/packages/replay-port/src/daemon-port/session-replay-runtime-engine-adapter.ts @@ -20,7 +20,10 @@ import type { SnapshotTimingSample } from '@agent-device/contracts/capture'; import { withReplayFailureDiagnostics } from './session-replay-runtime-failure.ts'; import { invokeReplayAction } from './session-replay-action-runtime.ts'; -import type { AdReplayStepFailure, AdReplayStepRuntime } from '@agent-device/ad-replay'; +import type { + AdReplayStepFailure, + AdReplayStepRuntime, +} from '@agent-device/contracts/ad-replay-execution'; import { collectReplayActionArtifactPaths } from '@agent-device/replay-port/session-replay-runtime-artifacts'; import { applyReplayDispatchGuard, @@ -39,7 +42,7 @@ import { resolveTargetVerificationEntry, type TargetBindingDivergenceContext, } from './session-replay-target-verification.ts'; -import type { ReplayTestAttemptStepSink } from '@agent-device/replay-test'; +import type { ReplayTestAttemptStepSink } from '@agent-device/contracts/replay-test-execution'; /** * #1555 P5 (decomposition): the daemon's `AdReplayStepRuntime` adapter — extracted verbatim out diff --git a/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts b/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts index db5f5f56ca..a86b31904d 100644 --- a/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts +++ b/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts @@ -1,7 +1,10 @@ import type { SessionAction } from '@agent-device/contracts/session'; import { ANDROID_SHELL_TEXT_UNSUPPORTED_REASON } from '@agent-device/contracts/input-validation'; import { BOUNDED_COMPOSITE_RESOURCE_UNSUPPORTED_REASON } from '@agent-device/kernel/errors'; -import { scrubReplayVarValues, type ReplayVarScrubEntry } from '@agent-device/ad-replay/divergence'; +import { + scrubReplayVarValues, + type ReplayVarScrubEntry, +} from '@agent-device/contracts/replay-divergence-data'; import { formatDivergenceActionLabel } from '@agent-device/ad-script'; import type { SnapshotDiagnosticsSummary } from '@agent-device/contracts/capture'; import { buildDisplayPositionals } from '@agent-device/session-journal/session-event-action'; diff --git a/packages/replay-port/src/daemon-port/session-replay-runtime-failure.ts b/packages/replay-port/src/daemon-port/session-replay-runtime-failure.ts index eb9d0d225e..4280b5ac22 100644 --- a/packages/replay-port/src/daemon-port/session-replay-runtime-failure.ts +++ b/packages/replay-port/src/daemon-port/session-replay-runtime-failure.ts @@ -1,5 +1,5 @@ import type { SessionAction } from '@agent-device/contracts/session'; -import type { AdReplayScrubValue } from '@agent-device/ad-replay'; +import type { AdReplayScrubValue } from '@agent-device/contracts/ad-replay-execution'; import { summarizeSnapshotTimingSamples, type SnapshotDiagnosticsSummary, diff --git a/packages/replay-port/src/daemon-port/session-replay-runtime-plan.ts b/packages/replay-port/src/daemon-port/session-replay-runtime-plan.ts index 59b0ec51d1..2cb6ad48a6 100644 --- a/packages/replay-port/src/daemon-port/session-replay-runtime-plan.ts +++ b/packages/replay-port/src/daemon-port/session-replay-runtime-plan.ts @@ -1,3 +1,4 @@ +import { inspectAdReplay } from '@agent-device/ad-replay'; import type { SessionAction } from '@agent-device/contracts/session'; import type { ReplayDispatchOptions } from '@agent-device/contracts/replay'; import type { CommandFlags, DaemonWireRequest } from '@agent-device/contracts/command'; @@ -9,11 +10,10 @@ import type { ReplaySessionStore, } from '@agent-device/contracts/replay-backend'; import { buildReplayScriptPlatformFlags } from '@agent-device/replay-port/replay-script-selection'; -import { - inspectAdReplay, - type AdReplayManifest, - type AdReplayVarSources, -} from '@agent-device/ad-replay'; +import type { + AdReplayManifest, + AdReplayVarSources, +} from '@agent-device/contracts/ad-replay-execution'; import { collectReplayShellEnv, isReplayBackendId, diff --git a/packages/replay-port/src/daemon-port/session-replay-target-verification.ts b/packages/replay-port/src/daemon-port/session-replay-target-verification.ts index 6cc42477d0..11db4ab668 100644 --- a/packages/replay-port/src/daemon-port/session-replay-target-verification.ts +++ b/packages/replay-port/src/daemon-port/session-replay-target-verification.ts @@ -16,14 +16,14 @@ import type { AdReplayTargetBindingEvidence, AdReplayTargetClassification, AdReplayVerificationEntry, -} from '@agent-device/ad-replay'; +} from '@agent-device/contracts/ad-replay-execution'; import { type ReplayDivergence, type ReplayDivergenceTargetBindingKind, type ReplayDivergenceTargetCandidate, type ReplayDivergenceTargetIdentity, } from '@agent-device/contracts/divergence'; -import { createReplayDivergenceSanitizer } from '@agent-device/ad-replay/divergence'; +import { createReplayDivergenceSanitizer } from '@agent-device/contracts/replay-divergence-data'; import { REPLAY_TARGET_GUARD_MISMATCH_REASON, WAIT_LANDMARK_MISMATCH_REASON, diff --git a/packages/replay-port/src/daemon-port/session-test-outcome.ts b/packages/replay-port/src/daemon-port/session-test-outcome.ts index 088616de5c..85828ef4ba 100644 --- a/packages/replay-port/src/daemon-port/session-test-outcome.ts +++ b/packages/replay-port/src/daemon-port/session-test-outcome.ts @@ -2,7 +2,10 @@ import { readSnapshotDiagnosticsSummary } from '@agent-device/contracts/capture' import { readResponseWarnings } from '@agent-device/kernel/success-text'; import { BOUNDED_COMPOSITE_RESOURCE_UNSUPPORTED_REASON } from '@agent-device/kernel/errors'; import { isReplayInfrastructureFailure } from './session-test-infrastructure.ts'; -import type { ReplayTestAttemptFailed, ReplayTestAttemptOutcome } from '@agent-device/replay-test'; +import type { + ReplayTestAttemptFailed, + ReplayTestAttemptOutcome, +} from '@agent-device/contracts/replay-test-execution'; import { type DaemonResponse } from '@agent-device/kernel/contracts'; /** diff --git a/packages/replay-port/src/daemon-port/session-test-shard-devices.ts b/packages/replay-port/src/daemon-port/session-test-shard-devices.ts index 7c588571a4..dedec38bc4 100644 --- a/packages/replay-port/src/daemon-port/session-test-shard-devices.ts +++ b/packages/replay-port/src/daemon-port/session-test-shard-devices.ts @@ -15,7 +15,7 @@ import type { ReplayTestResolveShardTargets, ReplayTestShardContext, ReplayTestShardTarget, -} from '@agent-device/replay-test'; +} from '@agent-device/contracts/replay-test-execution'; /** * The daemon adapter's shard-device binding (#1478 P3b). diff --git a/packages/replay-port/src/daemon-port/session-test-source-discovery.ts b/packages/replay-port/src/daemon-port/session-test-source-discovery.ts index 6ef93fe530..66a55a1fee 100644 --- a/packages/replay-port/src/daemon-port/session-test-source-discovery.ts +++ b/packages/replay-port/src/daemon-port/session-test-source-discovery.ts @@ -9,7 +9,7 @@ import type { ReplayTestDiscoverSources, ReplayTestManifest, ReplayTestSource, -} from '@agent-device/replay-test'; +} from '@agent-device/contracts/replay-test-execution'; import type { ReplayBackend } from '@agent-device/contracts/replay-backend'; import { getReplayBackend } from './replay-backend-registry.ts'; diff --git a/packages/replay-port/src/daemon-port/test-command.ts b/packages/replay-port/src/daemon-port/test-command.ts index 3a4f01747c..28488f8951 100644 --- a/packages/replay-port/src/daemon-port/test-command.ts +++ b/packages/replay-port/src/daemon-port/test-command.ts @@ -1,3 +1,4 @@ +import { runReplayTestSuite } from '@agent-device/replay-test'; /** Runs the replay-test scheduler and its nested replay attempts. */ import { randomUUID } from 'node:crypto'; @@ -13,13 +14,12 @@ import { REPLAY_SCRIPT_SOURCE_REQUIRED_MESSAGE } from '@agent-device/replay-port import type { ReplayScriptMetadata } from '@agent-device/ad-script'; import { expandSessionPath } from '@agent-device/host-kit/session-paths'; import type { ReplayCommand, ReplayTestCommand } from '@agent-device/replay-port/command-types'; -import { - runReplayTestSuite, - type ReplayTestAttemptOutcome, - type ReplayTestBindAttemptCancellation, - type ReplayTestShardContext, - type ReplayTestSuiteRequest, -} from '@agent-device/replay-test'; +import type { + ReplayTestAttemptOutcome, + ReplayTestBindAttemptCancellation, + ReplayTestShardContext, + ReplayTestSuiteRequest, +} from '@agent-device/contracts/replay-test-execution'; import { runReplayCommand } from './native-command.ts'; import { collectReplayActionArtifactPaths } from '@agent-device/replay-port/session-replay-runtime-artifacts'; import { diff --git a/packages/replay-test/src/index.ts b/packages/replay-test/src/index.ts index c4f469f001..ae868639e8 100644 --- a/packages/replay-test/src/index.ts +++ b/packages/replay-test/src/index.ts @@ -1,35 +1,2 @@ -/** - * The replay-test package façade (#1478 P3). - * - * One function plus the values crossing its seam. Everything else — scheduling, retries, - * sharding distribution, attempt identity, timeout policy, finalization/cleanup ordering, and - * result aggregation — is private to `internal/`. - * - * The scheduler is format-agnostic: it imports neither engine, and a source reaches it only as - * a `ReplayTestManifest`. Host authority arrives as narrow capabilities on the runtime-dependency - * half of `runReplayTestSuite`'s parameter; none of them hands over a daemon request, a session - * store, mutable session state, or an engine. - * - * The parameter and result types themselves are not named here. The single caller builds the - * bag inline and TypeScript infers both, so re-exporting the names would add surface no consumer - * asks for; a consumer that needs to name one earns it back through the R11 pin. - */ +/** Suite scheduling consumes shared contracts and explicit host capabilities. */ export { runReplayTestSuite } from './internal/session-test.ts'; - -export type { - ReplayTestAttemptFailed, - ReplayTestAttemptOutcome, - ReplayTestAttemptStepSink, - ReplayTestBindAttemptCancellation, - ReplayTestDiscoverSources, - ReplayTestManifest, - ReplayTestSource, - ReplayTestSuiteRequest, -} from './internal/session-test-types.ts'; - -export type { - ReplayTestResolveShardTargets, - ReplayTestShardContext, - ReplayTestShardMode, - ReplayTestShardTarget, -} from './internal/session-test-sharding.ts'; diff --git a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts index ef16fc0b92..9be8ddb2cc 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-artifacts.test.ts @@ -9,7 +9,7 @@ import { prepareReplayTestAttemptArtifacts, resolveReplayTestArtifactsDir, } from '../session-test-artifacts.ts'; -import type { ReplayTestAttemptOutcome } from '../session-test-types.ts'; +import type { ReplayTestAttemptOutcome } from '@agent-device/contracts/replay-test-execution'; import { mkdtempForTestSync } from '../../tmp-dir.fixtures.ts'; test('resolveReplayTestArtifactsDir falls back to the default root when artifactsDir is omitted', () => { diff --git a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts index e42b3788a5..a584c7b8cc 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-attempt.test.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { expect, test } from 'vitest'; import { runReplayTestCase } from '../session-test-attempt.ts'; import type { ReplayTestRunEntry } from '../session-test-discovery.ts'; -import type { ReplayTestAttemptOutcome } from '../session-test-types.ts'; +import type { ReplayTestAttemptOutcome } from '@agent-device/contracts/replay-test-execution'; import type { ReplaySuiteTestFailed } from '@agent-device/contracts/replay'; import { mkdtempForTestSync } from '../../tmp-dir.fixtures.ts'; diff --git a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts index 2f620df7d5..a7cb8e8344 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-discovery.test.ts @@ -8,7 +8,10 @@ import { } from '../session-test-discovery.ts'; import { trimEdgeDashes } from '@agent-device/kernel/collections'; import { buildReplayTestArtifactSlug } from '../session-test-artifacts.ts'; -import type { ReplayTestManifest, ReplayTestSource } from '../session-test-types.ts'; +import type { + ReplayTestManifest, + ReplayTestSource, +} from '@agent-device/contracts/replay-test-execution'; // Scheduler-owned discovery policy (#1478 P3b): which sources a --platform filter runs, which // it skips and with what message, and rejecting a suite that matched nothing. Inspection is the diff --git a/packages/replay-test/src/internal/__tests__/session-test-runtime.test.ts b/packages/replay-test/src/internal/__tests__/session-test-runtime.test.ts index fa1f8ec1d3..f19cb89c77 100644 --- a/packages/replay-test/src/internal/__tests__/session-test-runtime.test.ts +++ b/packages/replay-test/src/internal/__tests__/session-test-runtime.test.ts @@ -5,7 +5,7 @@ import { afterEach, expect, test, vi } from 'vitest'; import { runReplayTestAttempt } from '../session-test-runtime.ts'; -import type { ReplayTestAttemptOutcome } from '../session-test-types.ts'; +import type { ReplayTestAttemptOutcome } from '@agent-device/contracts/replay-test-execution'; import { mkdtempForTestSync } from '../../tmp-dir.fixtures.ts'; // What the scheduler owes its host around cancellation (#1478 P3b): cancel exactly once when diff --git a/packages/replay-test/src/internal/session-test-artifacts.ts b/packages/replay-test/src/internal/session-test-artifacts.ts index aa052def70..a900fea499 100644 --- a/packages/replay-test/src/internal/session-test-artifacts.ts +++ b/packages/replay-test/src/internal/session-test-artifacts.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; import { trimEdgeDashes } from '@agent-device/kernel/collections'; -import type { ReplayTestAttemptOutcome } from '@agent-device/replay-test'; +import type { ReplayTestAttemptOutcome } from '@agent-device/contracts/replay-test-execution'; /** * `test`'s default artifacts root when `--artifacts-dir` is not given. `packages/remote/src/daemon-artifacts.ts` diff --git a/packages/replay-test/src/internal/session-test-attempt-failure.ts b/packages/replay-test/src/internal/session-test-attempt-failure.ts new file mode 100644 index 0000000000..fd102161a1 --- /dev/null +++ b/packages/replay-test/src/internal/session-test-attempt-failure.ts @@ -0,0 +1,23 @@ +import type { + ReplayTestAttemptError, + ReplayTestAttemptFailed, +} from '@agent-device/contracts/replay-test-execution'; +import type { SnapshotDiagnosticsSummary } from '@agent-device/contracts/capture'; + +/** Neutral failure outcome helper; keeps timeout/unknown construction in one place. */ +export function replayTestAttemptFailure(params: { + error: ReplayTestAttemptError; + artifactPaths?: readonly string[]; + warnings?: readonly string[]; + infrastructure?: boolean; + snapshotDiagnostics?: SnapshotDiagnosticsSummary; +}): ReplayTestAttemptFailed { + return { + status: 'failed', + error: params.error, + artifactPaths: params.artifactPaths ?? [], + warnings: params.warnings ?? [], + infrastructure: params.infrastructure ?? false, + ...(params.snapshotDiagnostics ? { snapshotDiagnostics: params.snapshotDiagnostics } : {}), + }; +} diff --git a/packages/replay-test/src/internal/session-test-attempt.ts b/packages/replay-test/src/internal/session-test-attempt.ts index 11101da418..c40821acca 100644 --- a/packages/replay-test/src/internal/session-test-attempt.ts +++ b/packages/replay-test/src/internal/session-test-attempt.ts @@ -13,10 +13,10 @@ import { } from './session-test-discovery.ts'; import { runReplayTestAttempt } from './session-test-runtime.ts'; import type { + ReplayTestShardContext, ReplayTestAttemptOutcome, ReplayTestExecutionDependencies, -} from './session-test-types.ts'; -import type { ReplayTestShardContext } from './session-test-sharding.ts'; +} from '@agent-device/contracts/replay-test-execution'; type ReplayTestCaseResult = Extract; type ReplayTestAttemptFailure = NonNullable< diff --git a/packages/replay-test/src/internal/session-test-discovery.ts b/packages/replay-test/src/internal/session-test-discovery.ts index 57e77bd7b5..33b857f431 100644 --- a/packages/replay-test/src/internal/session-test-discovery.ts +++ b/packages/replay-test/src/internal/session-test-discovery.ts @@ -6,7 +6,7 @@ import type { ReplayTestDiscoverSources, ReplayTestManifest, ReplayTestPlatform, -} from './session-test-types.ts'; +} from '@agent-device/contracts/replay-test-execution'; const MAX_REPLAY_TEST_RETRIES = 3; diff --git a/packages/replay-test/src/internal/session-test-runtime.ts b/packages/replay-test/src/internal/session-test-runtime.ts index ecdf22b2fa..0c8c50ab2d 100644 --- a/packages/replay-test/src/internal/session-test-runtime.ts +++ b/packages/replay-test/src/internal/session-test-runtime.ts @@ -1,9 +1,9 @@ +import { replayTestAttemptFailure } from './session-test-attempt-failure.ts'; import fs from 'node:fs'; import path from 'node:path'; import { setTimeout as sleep } from 'node:timers/promises'; import { normalizeError } from '@agent-device/kernel/errors'; import { - replayTestAttemptFailure, type ReplayTestAttemptFailed, type ReplayTestAttemptOutcome, type ReplayTestAttemptStepSink, @@ -12,7 +12,7 @@ import { type ReplayTestRunReplayParams, type ReplayTestTarget, type ReplayTestRuntimeDependencies, -} from './session-test-types.ts'; +} from '@agent-device/contracts/replay-test-execution'; const REPLAY_TIMEOUT_CLEANUP_GRACE_MS = 2_000; const REPLAY_TEST_TIMEOUT_HINT = diff --git a/packages/replay-test/src/internal/session-test-sharding.ts b/packages/replay-test/src/internal/session-test-sharding.ts index 6cb81ff6cd..79be86b323 100644 --- a/packages/replay-test/src/internal/session-test-sharding.ts +++ b/packages/replay-test/src/internal/session-test-sharding.ts @@ -1,37 +1,8 @@ -import type { ReplayTestPlatform, ReplayTestTarget } from './session-test-types.ts'; - -export type ReplayTestShardMode = 'all' | 'split'; - -/** - * The device a shard runs against, in neutral vocabulary. - * - * The scheduler reads `id`/`name` for session labels and progress metadata. `platform` and - * `target` are here because the host needs them to bind a nested request, and both are already - * neutral kernel types — so `DeviceInfo` itself never crosses into scheduling. - */ -export type ReplayTestShardTarget = Readonly<{ - id: string; - name: string; - platform: ReplayTestPlatform; - target?: ReplayTestTarget; -}>; - -export type ReplayTestShardContext = { - shardIndex: number; - shardCount: number; - device: ReplayTestShardTarget; -}; - -/** - * Resolves the devices a sharded run will use (#1478 P3b). - * - * Enumerating inventory, applying allowlists and simulator set paths, and rejecting a run with - * too few devices are all host concerns. The scheduler decides how many shards there are and - * which entries go to each; it never enumerates hardware. - */ -export type ReplayTestResolveShardTargets = ( - shardCount: number, -) => Promise; +import type { + ReplayTestShardContext, + ReplayTestShardMode, + ReplayTestResolveShardTargets, +} from '@agent-device/contracts/replay-test-execution'; export type ReplayTestShardPlan = { mode: ReplayTestShardMode; diff --git a/packages/replay-test/src/internal/session-test.ts b/packages/replay-test/src/internal/session-test.ts index 410ed3c37d..c8e7160443 100644 --- a/packages/replay-test/src/internal/session-test.ts +++ b/packages/replay-test/src/internal/session-test.ts @@ -14,6 +14,8 @@ import { } from './session-test-discovery.ts'; import { runReplayTestCase, type ReplayTestCaseReport } from './session-test-attempt.ts'; import type { + ReplayTestResolveShardTargets, + ReplayTestShardContext, ReplayTestEmitProgress, ReplayTestIsCanceled, ReplayTestExecutionDependencies, @@ -21,13 +23,8 @@ import type { ReplayTestSuiteOutcome, ReplayTestSuiteRequest, ReplayTestDiscoverSources, -} from './session-test-types.ts'; -import { - buildReplayTestShardPlan, - type ReplayTestResolveShardTargets, - type ReplayTestShardContext, - type ReplayTestShardPlan, -} from './session-test-sharding.ts'; +} from '@agent-device/contracts/replay-test-execution'; +import { buildReplayTestShardPlan, type ReplayTestShardPlan } from './session-test-sharding.ts'; import { mergeSnapshotDiagnostics } from '@agent-device/contracts/capture'; type ReplayTestEntry = ReturnType[number]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 331f2ad435..146ca9b87e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -373,13 +373,10 @@ importers: version: link:../test-kit vitest: specifier: 5.0.4 - version: 5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1)) + version: 5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1)) packages/command-output: dependencies: - '@agent-device/ad-replay': - specifier: workspace:* - version: link:../ad-replay '@agent-device/capture-kit': specifier: workspace:* version: link:../capture-kit @@ -488,7 +485,7 @@ importers: version: link:../test-kit vitest: specifier: 5.0.4 - version: 5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1)) + version: 5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1)) packages/contracts: dependencies: @@ -502,9 +499,6 @@ importers: packages/daemon: dependencies: - '@agent-device/ad-replay': - specifier: workspace:* - version: link:../ad-replay '@agent-device/ad-script': specifier: workspace:* version: link:../ad-script @@ -551,6 +545,9 @@ importers: specifier: workspace:* version: link:../session-journal devDependencies: + '@agent-device/ad-replay': + specifier: workspace:* + version: link:../ad-replay '@agent-device/apple-runner': specifier: workspace:* version: link:../apple-runner @@ -581,9 +578,6 @@ importers: packages/daemon-client: dependencies: - '@agent-device/ad-replay': - specifier: workspace:* - version: link:../ad-replay '@agent-device/command-registry': specifier: workspace:* version: link:../command-registry @@ -5650,23 +5644,17 @@ packages: resolution: {integrity: sha512-9K2k72s4n7rV9s4bX0MyjbX9iBribvKZbBJKuEmTCZfeWJXs6Yh7bGpY4eoc7UufAjvpheBqwyZCOIPBvxCv0A==} peerDependencies: '@volar/language-service': ~2.4.0 - typescript: '*' peerDependenciesMeta: '@volar/language-service': optional: true - typescript: - optional: true volar-service-typescript@0.0.71: resolution: {integrity: sha512-yTtM/BVT6hoyEYnDtaCyAtNhdNeS/mhTTABlBOdw3NNiRBUin3IznFJpgfjer4c6RYopiPjjQjc9VFhxVl1mLw==} peerDependencies: '@volar/language-service': ~2.4.0 - typescript: '*' peerDependenciesMeta: '@volar/language-service': optional: true - typescript: - optional: true volar-service-yaml@0.0.71: resolution: {integrity: sha512-qYGWGuVpUTnZGu5P/CR4KLK4aIR8RrcVnmfZ2eRcj9q/I8VZCoC5yy9FtEvfNvnDp4MU17yhdJcvpQPIqhJS2Q==} @@ -5976,8 +5964,8 @@ snapshots: volar-service-emmet: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)) volar-service-html: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)) volar-service-prettier: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3))(prettier@3.9.10) - volar-service-typescript: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3))(typescript@5.9.3) - volar-service-typescript-twoslash-queries: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3))(typescript@5.9.3) + volar-service-typescript: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)) + volar-service-typescript-twoslash-queries: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)) volar-service-yaml: 0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)) vscode-html-languageservice: 5.6.2 vscode-uri: 3.2.0 @@ -7489,14 +7477,14 @@ snapshots: optionalDependencies: vite: 8.3.5(@types/node@22.20.1)(yaml@2.9.0) - '@vitest/mocker@5.0.4(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1))': + '@vitest/mocker@5.0.4(vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1))': dependencies: '@jridgewell/trace-mapping': 0.3.31 '@vitest/spy': 5.0.4 estree-walker: 3.0.3 magic-string: 1.4.3 optionalDependencies: - vite: 8.3.5(@types/node@22.20.1)(yaml@2.9.1) + vite: 8.3.5(@types/node@26.2.0)(yaml@2.9.1) '@vitest/spy@5.0.4': {} @@ -10107,6 +10095,18 @@ snapshots: fsevents: 2.3.3 yaml: 2.9.1 + vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1): + dependencies: + lightningcss: 1.33.0 + picomatch: 4.0.7 + postcss: 8.5.23 + rolldown: 1.2.15 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.2.0 + fsevents: 2.3.3 + yaml: 2.9.1 + vitefu@1.1.3(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1)): optionalDependencies: vite: 8.3.5(@types/node@22.20.1)(yaml@2.9.1) @@ -10133,10 +10133,10 @@ snapshots: transitivePeerDependencies: - msw - vitest@5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1)): + vitest@5.0.4(@types/node@22.20.1)(@vitest/coverage-v8@5.0.4)(vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1)): dependencies: '@types/chai': 5.2.3 - '@vitest/mocker': 5.0.4(vite@8.3.5(@types/node@22.20.1)(yaml@2.9.1)) + '@vitest/mocker': 5.0.4(vite@8.3.5(@types/node@26.2.0)(yaml@2.9.1)) chai: 6.3.0 es-module-lexer: 2.3.2 expect-type: 1.4.0 @@ -10147,7 +10147,7 @@ snapshots: tinybench: 6.2.2 tinyexec: 1.3.1 tinyglobby: 0.2.17 - vite: 8.3.5(@types/node@22.20.1)(yaml@2.9.1) + vite: 8.3.5(@types/node@26.2.0)(yaml@2.9.1) why-is-node-running: 3.2.1 optionalDependencies: '@types/node': 22.20.1 @@ -10187,14 +10187,13 @@ snapshots: '@volar/language-service': 2.4.30(typescript@5.9.3) prettier: 3.9.10 - volar-service-typescript-twoslash-queries@0.0.71(@volar/language-service@2.4.30(typescript@5.9.3))(typescript@5.9.3): + volar-service-typescript-twoslash-queries@0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)): dependencies: vscode-uri: 3.2.0 optionalDependencies: '@volar/language-service': 2.4.30(typescript@5.9.3) - typescript: 5.9.3 - volar-service-typescript@0.0.71(@volar/language-service@2.4.30(typescript@5.9.3))(typescript@5.9.3): + volar-service-typescript@0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)): dependencies: path-browserify: 1.0.1 semver: 7.8.5 @@ -10204,7 +10203,6 @@ snapshots: vscode-uri: 3.2.0 optionalDependencies: '@volar/language-service': 2.4.30(typescript@5.9.3) - typescript: 5.9.3 volar-service-yaml@0.0.71(@volar/language-service@2.4.30(typescript@5.9.3)): dependencies: diff --git a/scripts/layering/contracts-exports.snapshot.json b/scripts/layering/contracts-exports.snapshot.json index 368cb971b4..8481c3e0ac 100644 --- a/scripts/layering/contracts-exports.snapshot.json +++ b/scripts/layering/contracts-exports.snapshot.json @@ -1,4 +1,5 @@ [ + "@agent-device/contracts/ad-replay-execution", "@agent-device/contracts/alert-contract", "@agent-device/contracts/alert-runtime", "@agent-device/contracts/android-clipboard-support", @@ -103,6 +104,9 @@ "@agent-device/contracts/remote", "@agent-device/contracts/replay", "@agent-device/contracts/replay-backend", + "@agent-device/contracts/replay-divergence-data", + "@agent-device/contracts/replay-script-data", + "@agent-device/contracts/replay-test-execution", "@agent-device/contracts/runner-lease-context", "@agent-device/contracts/runtime-contract", "@agent-device/contracts/runtime-contract-error", diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index eace49cc44..66368a2faa 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -702,58 +702,19 @@ test('the real tree parses, declares, and passes R11', () => { ]); const adReplayPackage = packages.find((pkg) => pkg.name === '@agent-device/ad-replay'); assert.ok(adReplayPackage, 'ad-replay package must exist'); - // Locks the export surface: `.` (the engine) and `./divergence` (the - // divergence report/sanitization vocabulary, off the engine entry so CLI/MCP - // surfaces don't load the step loop). Any other subpath widens this key - // list and fails the assertion. - assert.deepEqual( - [...adReplayPackage.exportTargets.keys()], - ['@agent-device/ad-replay', '@agent-device/ad-replay/divergence'], - ); + assert.deepEqual([...adReplayPackage.exportTargets.keys()], ['@agent-device/ad-replay']); assert.deepEqual([...adReplayPackage.workspaceDependencies].sort(), [ '@agent-device/ad-script', '@agent-device/contracts', '@agent-device/kernel', '@agent-device/selectors', ]); - // #1555 review P1 ("add the reviewer-required exact exported-symbol - // gate"; second pass, "enforce the accepted two-entrypoint facade"; the - // structural-quality review, "typed façade replaces the zero-type rule"): - // the exports-subpath assertion above only proves the package exposes one - // `.` entry point — it says nothing about what that entry point actually - // NAMES. This pins the exact symbol list `packages/ad-replay/src/index.ts` - // exports: the binding design's two VALUE entrypoints, `inspectAdReplay` - // and `runAdReplay` (never a third value), plus the neutral vocabulary - // their signatures are built from, named explicitly instead of every root - // consumer hand-deriving `Parameters<...>`/`ReturnType<...>` off them (the - // shim `src/daemon/ad-replay-facade-types.ts` used to centralize — since - // deleted). `formatReplaySuccessMessage` (presentation, not engine policy) - // stays out on purpose — it sits daemon-side beside its one caller. A - // stray export — intentional or not, including a form `readNamedExports` - // cannot enumerate a name for (`export *`, `export default` — see the - // rejection tests below) — must edit this list too, not just slip through - // the exports-subpath check. + // The engine exports two value entrypoints. Shared port vocabulary belongs to contracts. assert.deepEqual( readNamedExports( fs.readFileSync(path.join(repoRoot, 'packages/ad-replay/src/index.ts'), 'utf8'), ), - [ - 'AdReplayDispatchGuard', - 'AdReplayDispatchOutcome', - 'AdReplayGuardMismatchEvidence', - 'AdReplayLandmarkMismatchEvidence', - 'AdReplayManifest', - 'AdReplayScrubValue', - 'AdReplayStepFailure', - 'AdReplayStepRuntime', - 'AdReplayTargetBindingEvidence', - 'AdReplayTargetClassification', - 'AdReplayTargetObservation', - 'AdReplayVarSources', - 'AdReplayVerificationEntry', - 'inspectAdReplay', - 'runAdReplay', - ], + ['inspectAdReplay', 'runAdReplay'], ); const selectorsPackage = packages.find((pkg) => pkg.name === '@agent-device/selectors'); assert.ok(selectorsPackage, 'selectors package must exist'); diff --git a/src/cli/replay-test/reporters/default.ts b/src/cli/replay-test/reporters/default.ts index d2b0d00fe3..b0550013b8 100644 --- a/src/cli/replay-test/reporters/default.ts +++ b/src/cli/replay-test/reporters/default.ts @@ -6,7 +6,7 @@ import { } from '../progress.ts'; import { formatDurationSeconds } from '../duration-format.ts'; import { colorize, supportsColor } from '@agent-device/command-output'; -import { formatReplayDivergenceReport } from '@agent-device/ad-replay/divergence'; +import { formatReplayDivergenceReport } from '@agent-device/contracts/replay-divergence-data'; import type { ReplayTestReporter, ReplayTestReporterContext,