Skip to content

Commit 8d280a2

Browse files
thymikeeclaude
andauthored
refactor(request): move the device-inventory context out of core (#1993)
`device-inventory-context.ts` is an AsyncLocalStorage holder: it imports only `node:async_hooks`, kernel errors, and contracts types, and nothing from `core`. `daemon-modularity.ts` already describes `src/request/` as "request-global daemon plumbing (progress sinks, cancellation, AsyncLocalStorage)", and `request/progress.ts` is the same shape — a `withX`/accessor pair over one store. Living in `core` (rank 2) made the platform-runtime composition root reach up to rank 2 for `listLocalDeviceInventory`. Injecting the lookup would not have fixed that: the only caller, `platform-runtime-operation-host.ts`, is in the same zone, so the edge would move rather than disappear. Relocating the module does remove it, and every other consumer — daemon (rank 4) and `core/dispatch-resolve.ts` (rank 2) — now reaches down instead of sideways or up. Pure rename; the module body is unchanged and 14 import specifiers are retargeted. R17's `DEVICES_INVENTORY_IMPORT_SOURCES` pin follows the module: the rule still asserts the devices handler imports the neutral gateway, does not shadow it, and calls it. This clears the last composition-root upward value edge that was not deliberate. Confirmed with `pnpm depgraph`: those edges drop from 3 to 2, and the two that remain are the documented ones — `provider-limrun-runtime.ts` (an in-file comment marks it a deliberate static seam) and `runtime.ts -> commands/index.ts` (`bindCommands` is the aggregate binder). Cycle, back-edge and R6 counts unchanged. Claude-Session: https://claude.ai/code/session_01WWLBCBDBpdR8z1aCmDerXS Co-authored-by: Claude <[email protected]>
1 parent 777ded9 commit 8d280a2

13 files changed

Lines changed: 16 additions & 15 deletions

‎scripts/layering/runtime-command-cutover-extensions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type AstNode = Record<string, unknown>;
1515

1616
const DEVICES_HANDLER_FILE = 'src/daemon/handlers/session-inventory.ts';
1717
const DEVICES_INVENTORY_IMPORT_SOURCES = new Set([
18-
'../../core/device-inventory-context.ts',
18+
'../../request/device-inventory-context.ts',
1919
'../../core/dispatch-resolve.ts',
2020
]);
2121
const DEVICES_GATEWAY_BINDING = 'listDeviceInventory';

‎src/__tests__/test-utils/device-inventory-gateways.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from '@agent-device/contracts/platform';
1313
import { createPlatformModuleRegistry } from '@agent-device/contracts/platform-module';
1414
import type { DeviceInfo, Platform } from '@agent-device/kernel/device';
15-
import { withDeviceInventoryContext } from '../../core/device-inventory-context.ts';
15+
import { withDeviceInventoryContext } from '../../request/device-inventory-context.ts';
1616
import { createComposedDeviceInventoryGateways } from '../../platform-runtime-device-inventory.ts';
1717

1818
type TestDeviceInventoryOptions = Readonly<{

‎src/core/dispatch-resolve.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
listLocalDeviceInventory,
2323
readDeviceInventory,
2424
shouldPropagateDeviceInventoryProbeError,
25-
} from './device-inventory-context.ts';
25+
} from '../request/device-inventory-context.ts';
2626
export type ResolveDeviceFlags = Pick<
2727
CliFlags,
2828
| 'platform'

‎src/daemon/handlers/__tests__/session-inventory-appleos.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { test, expect, vi, beforeEach } from 'vitest';
33
// The `devices` handler resolves its inventory through listDeviceInventory; mocking it
44
// lets us drive the additive `appleOs` projection off the shared device fixtures without
55
// touching real local discovery.
6-
vi.mock('../../../core/device-inventory-context.ts', async (importOriginal) => {
7-
const actual = await importOriginal<typeof import('../../../core/device-inventory-context.ts')>();
6+
vi.mock('../../../request/device-inventory-context.ts', async (importOriginal) => {
7+
const actual =
8+
await importOriginal<typeof import('../../../request/device-inventory-context.ts')>();
89
return { ...actual, listDeviceInventory: vi.fn(async () => []) };
910
});
1011

1112
import { handleSessionInventoryCommands } from '../session-inventory.ts';
12-
import { listDeviceInventory } from '../../../core/device-inventory-context.ts';
13+
import { listDeviceInventory } from '../../../request/device-inventory-context.ts';
1314
import { makeSessionStore } from '../../../__tests__/test-utils/store-factory.ts';
1415
import type { DaemonRequest, DaemonResponse } from '../../types.ts';
1516
import type { AppleOS, DeviceInfo } from '@agent-device/kernel/device';

‎src/daemon/handlers/session-doctor-device.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { buildDeviceInventoryRequestFromFlags } from '../../core/dispatch-resolve.ts';
2-
import { listDeviceInventory } from '../../core/device-inventory-context.ts';
2+
import { listDeviceInventory } from '../../request/device-inventory-context.ts';
33
import {
44
countDeviceInventoryByGroup,
55
LOCAL_DEVICE_INVENTORY_PLATFORM_SELECTORS,

‎src/daemon/handlers/session-doctor-toolchain.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { DoctorCheck } from '@agent-device/contracts/observability';
88
import {
99
listLocalDeviceInventory,
1010
shouldPropagateDeviceInventoryProbeError,
11-
} from '../../core/device-inventory-context.ts';
11+
} from '../../request/device-inventory-context.ts';
1212

1313
const TOOLCHAIN_TIMEOUT_MS = 3_000;
1414
type AndroidLicenseState = 'accepted' | 'missing' | 'unknown';

‎src/daemon/handlers/session-inventory.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isCommandSupportedOnDevice, listCapabilityCommands } from '../../core/capabilities.ts';
2-
import { listDeviceInventory } from '../../core/device-inventory-context.ts';
2+
import { listDeviceInventory } from '../../request/device-inventory-context.ts';
33
import { assertResolvedAppsFilter } from '@agent-device/contracts/device';
44
import { AppError, asAppError } from '@agent-device/kernel/errors';
55
import {

‎src/daemon/handlers/session-test-shard-devices.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CommandFlags } from '@agent-device/contracts/command';
22
import type { DeviceInventoryRequest } from '@agent-device/contracts/device';
3-
import { listDeviceInventory } from '../../core/device-inventory-context.ts';
3+
import { listDeviceInventory } from '../../request/device-inventory-context.ts';
44
import {
55
resolveAndroidSerialAllowlist,
66
resolveIosSimulatorDeviceSetPath,

‎src/daemon/ios-app-session-hint.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { beforeEach, expect, test, vi } from 'vitest';
44
const listBootedIosSimulators = vi.hoisted(() => vi.fn());
55
const detectSoleRunningIosSimulatorApp = vi.hoisted(() => vi.fn());
66

7-
vi.mock('../core/device-inventory-context.ts', async (importOriginal) => ({
8-
...(await importOriginal<typeof import('../core/device-inventory-context.ts')>()),
7+
vi.mock('../request/device-inventory-context.ts', async (importOriginal) => ({
8+
...(await importOriginal<typeof import('../request/device-inventory-context.ts')>()),
99
listLocalDeviceInventory: listBootedIosSimulators,
1010
}));
1111
vi.mock('../platforms/apple/core/app-resolution.ts', () => ({ detectSoleRunningIosSimulatorApp }));

‎src/daemon/request-router.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { withResolveTargetDeviceCacheScope } from '../core/dispatch-resolve.ts';
2-
import { withDeviceInventoryContext } from '../core/device-inventory-context.ts';
2+
import { withDeviceInventoryContext } from '../request/device-inventory-context.ts';
33
import type { LeaseLifecycleProvider } from '@agent-device/contracts/device';
44
import type {
55
ComposedDeviceInventoryGateways,

0 commit comments

Comments
 (0)