From 25803cca62f0e455f4f18f33124aa3827411349c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 10 Oct 2026 22:50:15 +0200 Subject: [PATCH 1/2] refactor(move): relocate daemon-only and shared core modules to their owners The daemon stops importing src/core except at the composition root: - core/dispatch-context.ts -> src/daemon/dispatch-context.ts: its only importer is src/daemon/context.ts, so the daemon owns it. - core/interaction-response-data-transform.ts -> src/daemon/interaction/ internal/: only the daemon touch-response route imports it. - core/doctor-output.ts -> packages/host-kit/src/doctor-lines.ts: status-marker presentation shared by the daemon doctor handlers (static) and the CLI (dynamic); host-kit is the lowest package both can import, so it sits beside the markers it formats. - core/deploy-result-target.ts -> packages/contracts: the pure public-app-target precedence both the daemon deployment handlers and the CLI/MCP serializers render as "Installed: ". - core/interaction-outcome.ts -> packages/host-kit: the error-attached resolved-target side channel has an attach (commands) and a read (daemon) side; R18 keeps the mutable WeakMap lifecycle out of contracts, and host-kit owns the request-scoped mechanics seam. - core/status-markers.ts -> packages/host-kit: CLI/daemon shared presentation marker formatting; host-kit is the lowest package both can import. Tests move 1:1 with their sources; all consumers updated directly with no re-export shims. --- docs/agents/cli-flags.md | 2 +- .../contracts/src}/deploy-result-target.test.ts | 0 {src/core => packages/contracts/src}/deploy-result-target.ts | 0 .../doctor-output.ts => packages/host-kit/src/doctor-lines.ts | 0 {src/core => packages/host-kit/src}/interaction-outcome.ts | 0 {src/core => packages/host-kit/src}/status-markers.ts | 0 src/cli/replay-test/progress.ts | 2 +- src/commands/interaction/runtime/interactions.ts | 2 +- src/commands/management/output.ts | 2 +- src/commands/output/result-serialization.ts | 2 +- src/daemon/__tests__/snapshot-runtime-fixture.ts | 2 +- src/daemon/context.ts | 2 +- src/{core => daemon}/dispatch-context.ts | 0 src/daemon/handlers/session-app-deployment.ts | 2 +- src/daemon/handlers/session-app-source-deployment.ts | 2 +- src/daemon/handlers/session-doctor-output.ts | 2 +- .../__tests__/interaction-response-data-transform.test.ts | 0 .../internal}/interaction-response-data-transform.ts | 0 src/daemon/interaction/internal/interaction-touch-response.ts | 2 +- src/daemon/interaction/internal/interaction-touch-runtime.ts | 2 +- 20 files changed, 12 insertions(+), 12 deletions(-) rename {src/core => packages/contracts/src}/deploy-result-target.test.ts (100%) rename {src/core => packages/contracts/src}/deploy-result-target.ts (100%) rename src/core/doctor-output.ts => packages/host-kit/src/doctor-lines.ts (100%) rename {src/core => packages/host-kit/src}/interaction-outcome.ts (100%) rename {src/core => packages/host-kit/src}/status-markers.ts (100%) rename src/{core => daemon}/dispatch-context.ts (100%) rename src/{core => daemon/interaction/internal}/__tests__/interaction-response-data-transform.test.ts (100%) rename src/{core => daemon/interaction/internal}/interaction-response-data-transform.ts (100%) diff --git a/docs/agents/cli-flags.md b/docs/agents/cli-flags.md index 0291f5531c..b06eb28d27 100644 --- a/docs/agents/cli-flags.md +++ b/docs/agents/cli-flags.md @@ -28,7 +28,7 @@ Thread a flag only through the layers that consume it: interface exposes it. 6. `src/client/client-normalizers.ts`: update daemon flag normalization only when the request still needs a public-to-internal translation. -7. `src/daemon/context.ts` and `src/core/dispatch-context.ts`: add the field only when it flows into +7. `src/daemon/context.ts` and `src/daemon/dispatch-context.ts`: add the field only when it flows into platform dispatch. 8. Handler/platform modules: thread the option only after the command surface, grammar, and projection prove it belongs there. diff --git a/src/core/deploy-result-target.test.ts b/packages/contracts/src/deploy-result-target.test.ts similarity index 100% rename from src/core/deploy-result-target.test.ts rename to packages/contracts/src/deploy-result-target.test.ts diff --git a/src/core/deploy-result-target.ts b/packages/contracts/src/deploy-result-target.ts similarity index 100% rename from src/core/deploy-result-target.ts rename to packages/contracts/src/deploy-result-target.ts diff --git a/src/core/doctor-output.ts b/packages/host-kit/src/doctor-lines.ts similarity index 100% rename from src/core/doctor-output.ts rename to packages/host-kit/src/doctor-lines.ts diff --git a/src/core/interaction-outcome.ts b/packages/host-kit/src/interaction-outcome.ts similarity index 100% rename from src/core/interaction-outcome.ts rename to packages/host-kit/src/interaction-outcome.ts diff --git a/src/core/status-markers.ts b/packages/host-kit/src/status-markers.ts similarity index 100% rename from src/core/status-markers.ts rename to packages/host-kit/src/status-markers.ts diff --git a/src/cli/replay-test/progress.ts b/src/cli/replay-test/progress.ts index fa81d83836..9ef7ebde37 100644 --- a/src/cli/replay-test/progress.ts +++ b/src/cli/replay-test/progress.ts @@ -6,7 +6,7 @@ import type { ReplayTestResult, ReplayTestStep, } from './reporters/types.ts'; -import { formatCliStatusMarker } from '../../core/status-markers.ts'; +import { formatCliStatusMarker } from '@agent-device/host-kit/status-markers'; import { formatDurationSeconds } from './duration-format.ts'; import { colorize, supportsColor } from '../../commands/output/color.ts'; diff --git a/src/commands/interaction/runtime/interactions.ts b/src/commands/interaction/runtime/interactions.ts index 890cc7e603..270cee3231 100644 --- a/src/commands/interaction/runtime/interactions.ts +++ b/src/commands/interaction/runtime/interactions.ts @@ -11,7 +11,7 @@ import { SELECTOR_PIPELINE_POLICIES } from '@agent-device/selectors/selector-pip import type { Point } from '@agent-device/kernel/snapshot'; import type { AgentDeviceRuntime, CommandContext } from '../../../runtime-contract.ts'; import { isFillableType } from '@agent-device/contracts/snapshot'; -import { attachResolvedInteractionTarget } from '../../../core/interaction-outcome.ts'; +import { attachResolvedInteractionTarget } from '@agent-device/host-kit/interaction-outcome'; import { toBackendContext } from '../../runtime-common.ts'; import { toBackendResult, type RuntimeCommand } from '../../runtime-types.ts'; import { diff --git a/src/commands/management/output.ts b/src/commands/management/output.ts index 19086385f4..331a4302e0 100644 --- a/src/commands/management/output.ts +++ b/src/commands/management/output.ts @@ -187,7 +187,7 @@ export async function doctorCliOutput( progress?: CommandProgressState, ): Promise { const { formatDoctorCheckDetailLines, formatDoctorCheckSummaryLine } = - await import('../../core/doctor-output.ts'); + await import('@agent-device/host-kit/doctor-lines'); const data = result as Record; const status = typeof data.status === 'string' ? data.status : 'unknown'; const lines = [`Doctor: ${status}`]; diff --git a/src/commands/output/result-serialization.ts b/src/commands/output/result-serialization.ts index 1429fda47d..cff68bad33 100644 --- a/src/commands/output/result-serialization.ts +++ b/src/commands/output/result-serialization.ts @@ -15,7 +15,7 @@ import { successText, withSuccessText } from '@agent-device/kernel/success-text' import { resolveDeployResultTarget, resolveInstallFromSourceResultTarget, -} from '../../core/deploy-result-target.ts'; +} from '@agent-device/contracts/deploy-result-target'; function serializeSessionDevice( device: AgentDeviceSessionDevice, diff --git a/src/daemon/__tests__/snapshot-runtime-fixture.ts b/src/daemon/__tests__/snapshot-runtime-fixture.ts index a24690d839..8e99ba5884 100644 --- a/src/daemon/__tests__/snapshot-runtime-fixture.ts +++ b/src/daemon/__tests__/snapshot-runtime-fixture.ts @@ -35,7 +35,7 @@ import { } from '@agent-device/kernel/device'; import { applePlugin } from '@agent-device/platform-apple'; import { textSizeSettingPayload } from '@agent-device/contracts/settings'; -import { type DispatchContext } from '../../core/dispatch-context.ts'; +import { type DispatchContext } from '../dispatch-context.ts'; import { getRequestSignal } from '@agent-device/host-kit/request'; import { isActiveProviderDevice } from '../provider-device-admission.ts'; import type { BindDeviceRuntime, InspectDeviceRuntimeFacts } from '../request-runtime-binding.ts'; diff --git a/src/daemon/context.ts b/src/daemon/context.ts index 18a2ca53ef..782fce235e 100644 --- a/src/daemon/context.ts +++ b/src/daemon/context.ts @@ -1,5 +1,5 @@ import type { CommandFlags } from '@agent-device/contracts/command'; -import { dispatchContextFlags, type DispatchContext } from '../core/dispatch-context.ts'; +import { dispatchContextFlags, type DispatchContext } from './dispatch-context.ts'; import { resolveClickButton } from '@agent-device/contracts/click-button'; import { screenshotFlagsFromOptions, diff --git a/src/core/dispatch-context.ts b/src/daemon/dispatch-context.ts similarity index 100% rename from src/core/dispatch-context.ts rename to src/daemon/dispatch-context.ts diff --git a/src/daemon/handlers/session-app-deployment.ts b/src/daemon/handlers/session-app-deployment.ts index 51e8d79efc..d1ae923904 100644 --- a/src/daemon/handlers/session-app-deployment.ts +++ b/src/daemon/handlers/session-app-deployment.ts @@ -14,7 +14,7 @@ import type { SessionStore } from '../session-store.ts'; import type { DaemonRequest, DaemonResponse } from '../daemon-request.ts'; import type { SessionRef, SessionState } from '../session-state.ts'; import { resolvePayloadInput } from '../payload-input.ts'; -import { resolveDeployResultTarget } from '../../core/deploy-result-target.ts'; +import { resolveDeployResultTarget } from '@agent-device/contracts/deploy-result-target'; import { withSuccessText } from '@agent-device/kernel/success-text'; import { recordSessionAction } from '../session-action-recorder.ts'; import { diff --git a/src/daemon/handlers/session-app-source-deployment.ts b/src/daemon/handlers/session-app-source-deployment.ts index 013c0bf27a..2507643d83 100644 --- a/src/daemon/handlers/session-app-source-deployment.ts +++ b/src/daemon/handlers/session-app-source-deployment.ts @@ -21,7 +21,7 @@ import type { BindDeviceRuntime, InspectDeviceRuntimeFacts } from '../request-ru import { SessionStore } from '../session-store.ts'; import type { DaemonRequest, DaemonResponse } from '../daemon-request.ts'; import type { SessionState } from '../session-state.ts'; -import { resolveInstallFromSourceResultTarget } from '../../core/deploy-result-target.ts'; +import { resolveInstallFromSourceResultTarget } from '@agent-device/contracts/deploy-result-target'; import { withSuccessText } from '@agent-device/kernel/success-text'; import { recordSessionAction } from '../session-action-recorder.ts'; import { resolveCommandDevice } from '../session-device-resolution.ts'; diff --git a/src/daemon/handlers/session-doctor-output.ts b/src/daemon/handlers/session-doctor-output.ts index d616af5af4..0ac3f02c12 100644 --- a/src/daemon/handlers/session-doctor-output.ts +++ b/src/daemon/handlers/session-doctor-output.ts @@ -2,7 +2,7 @@ import { emitRequestProgress } from '@agent-device/host-kit/request'; import { formatDoctorCheckDetailLines, formatDoctorCheckSummaryLine, -} from '../../core/doctor-output.ts'; +} from '@agent-device/host-kit/doctor-lines'; import type { DoctorCheck, DoctorStatus } from '@agent-device/contracts/observability'; export function summarizeDoctorStatus(checks: DoctorCheck[]): 'pass' | 'warn' | 'fail' { diff --git a/src/core/__tests__/interaction-response-data-transform.test.ts b/src/daemon/interaction/internal/__tests__/interaction-response-data-transform.test.ts similarity index 100% rename from src/core/__tests__/interaction-response-data-transform.test.ts rename to src/daemon/interaction/internal/__tests__/interaction-response-data-transform.test.ts diff --git a/src/core/interaction-response-data-transform.ts b/src/daemon/interaction/internal/interaction-response-data-transform.ts similarity index 100% rename from src/core/interaction-response-data-transform.ts rename to src/daemon/interaction/internal/interaction-response-data-transform.ts diff --git a/src/daemon/interaction/internal/interaction-touch-response.ts b/src/daemon/interaction/internal/interaction-touch-response.ts index 74fed83a21..741da1b325 100644 --- a/src/daemon/interaction/internal/interaction-touch-response.ts +++ b/src/daemon/interaction/internal/interaction-touch-response.ts @@ -14,7 +14,7 @@ import { stripInternalInteractionDiagnostics, transformInteractionResponseData, type InteractionResponseDataTransformCommand, -} from '../../../core/interaction-response-data-transform.ts'; +} from './interaction-response-data-transform.ts'; import { issueSettleRefs } from '../../session-snapshot.ts'; import type { RecordedTargetCapture } from '@agent-device/selectors/target-evidence'; import type { CaptureSnapshotForSession, InteractionRouteInput } from './types.ts'; diff --git a/src/daemon/interaction/internal/interaction-touch-runtime.ts b/src/daemon/interaction/internal/interaction-touch-runtime.ts index 502fa9aa64..028163a399 100644 --- a/src/daemon/interaction/internal/interaction-touch-runtime.ts +++ b/src/daemon/interaction/internal/interaction-touch-runtime.ts @@ -9,7 +9,7 @@ import type { import type { GestureReferenceFrame } from '@agent-device/contracts/scroll-gesture'; import type { SnapshotState } from '@agent-device/kernel/snapshot'; import { asAppError, normalizeError } from '@agent-device/kernel/errors'; -import { readResolvedInteractionTarget } from '../../../core/interaction-outcome.ts'; +import { readResolvedInteractionTarget } from '@agent-device/host-kit/interaction-outcome'; import { publishAmbiguousMatchCandidateRefs } from '../../session-snapshot.ts'; import { isSessionRecording } from '../../session-script-publication-capability.ts'; import type { DaemonResponse } from '../../daemon-request.ts'; From 586a7142436564ddc98b55cd76413b3e4296bf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 10 Oct 2026 22:50:15 +0200 Subject: [PATCH 2/2] chore(gates): retarget export maps, snapshots, and pins for the core moves - packages/contracts exports ./deploy-result-target; contracts exports snapshot regenerated. - packages/host-kit exports ./doctor-lines, ./interaction-outcome and ./status-markers; R11 host-kit export pin extended. - R18 planted-ban message names @agent-device/host-kit/interaction-outcome as the WeakMap lifecycle owner instead of the retired src/core home. --- packages/contracts/package.json | 4 ++++ packages/host-kit/package.json | 12 ++++++++++++ scripts/layering/contracts-exports.snapshot.json | 1 + .../layering/contracts-implementation-policy.test.ts | 2 +- scripts/layering/contracts-implementation-policy.ts | 2 +- scripts/layering/package-boundaries.test.ts | 3 +++ 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 8f321131f2..e3e124afc2 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -156,6 +156,10 @@ "types": "./src/daemon-http.ts", "default": "./src/daemon-http.ts" }, + "./deploy-result-target": { + "types": "./src/deploy-result-target.ts", + "default": "./src/deploy-result-target.ts" + }, "./device": { "types": "./src/facades/device.ts", "default": "./src/facades/device.ts" diff --git a/packages/host-kit/package.json b/packages/host-kit/package.json index cc448ab6a6..72a6b4f4db 100644 --- a/packages/host-kit/package.json +++ b/packages/host-kit/package.json @@ -40,6 +40,10 @@ "types": "./src/diagnostics.ts", "default": "./src/diagnostics.ts" }, + "./doctor-lines": { + "types": "./src/doctor-lines.ts", + "default": "./src/doctor-lines.ts" + }, "./file": { "types": "./src/file.ts", "default": "./src/file.ts" @@ -48,6 +52,10 @@ "types": "./src/host-file.ts", "default": "./src/host-file.ts" }, + "./interaction-outcome": { + "types": "./src/interaction-outcome.ts", + "default": "./src/interaction-outcome.ts" + }, "./process": { "types": "./src/process.ts", "default": "./src/process.ts" @@ -72,6 +80,10 @@ "types": "./src/session-paths.ts", "default": "./src/session-paths.ts" }, + "./status-markers": { + "types": "./src/status-markers.ts", + "default": "./src/status-markers.ts" + }, "./transport": { "types": "./src/transport.ts", "default": "./src/transport.ts" diff --git a/scripts/layering/contracts-exports.snapshot.json b/scripts/layering/contracts-exports.snapshot.json index c8a8f860cd..267d240055 100644 --- a/scripts/layering/contracts-exports.snapshot.json +++ b/scripts/layering/contracts-exports.snapshot.json @@ -36,6 +36,7 @@ "@agent-device/contracts/command", "@agent-device/contracts/command-platform-execution", "@agent-device/contracts/daemon-http", + "@agent-device/contracts/deploy-result-target", "@agent-device/contracts/device", "@agent-device/contracts/device-boot", "@agent-device/contracts/device-readiness-runtime", diff --git a/scripts/layering/contracts-implementation-policy.test.ts b/scripts/layering/contracts-implementation-policy.test.ts index d6764ebb80..5c9f08713b 100644 --- a/scripts/layering/contracts-implementation-policy.test.ts +++ b/scripts/layering/contracts-implementation-policy.test.ts @@ -78,7 +78,7 @@ test('network traffic vocabulary cannot grow parser implementation inside contra test('contracts rejects mutable interaction-outcome lifecycle', () => { assert.match( messages('const targets = new WeakMap();', 'packages/contracts/src/interaction-outcome.ts')[0]!, - /src\/core/, + /host-kit\/interaction-outcome/, ); }); diff --git a/scripts/layering/contracts-implementation-policy.ts b/scripts/layering/contracts-implementation-policy.ts index 41cb4f72c0..6e6e88a2e8 100644 --- a/scripts/layering/contracts-implementation-policy.ts +++ b/scripts/layering/contracts-implementation-policy.ts @@ -47,7 +47,7 @@ export function contractsImplementationAuthorityViolations( violation( file.path, 1, - 'contracts may not own mutable interaction-outcome lifecycle; that WeakMap identity map belongs in src/core', + 'contracts may not own mutable interaction-outcome lifecycle; that WeakMap identity map lives in @agent-device/host-kit/interaction-outcome', ), ); } diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index 68e25c7ef9..838d35a64e 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -558,14 +558,17 @@ test('the real tree parses, declares, and passes R11', () => { '@agent-device/host-kit/code-signature-cache', '@agent-device/host-kit/command', '@agent-device/host-kit/diagnostics', + '@agent-device/host-kit/doctor-lines', '@agent-device/host-kit/file', '@agent-device/host-kit/host-file', + '@agent-device/host-kit/interaction-outcome', '@agent-device/host-kit/process', '@agent-device/host-kit/project-runtime', '@agent-device/host-kit/request', '@agent-device/host-kit/retry', '@agent-device/host-kit/runtime-transport-hints', '@agent-device/host-kit/session-paths', + '@agent-device/host-kit/status-markers', '@agent-device/host-kit/transport', '@agent-device/host-kit/version', ]);