Skip to content

Commit d5f11f6

Browse files
authored
refactor: import package types directly — no internal re-export laundering (#1640)
* refactor: import package types directly instead of re-exporting from internal modules Post-#1636 review feedback: internal src modules were re-exporting package types (export type { X } from '@agent-device/...'), giving one declaration several import paths and hiding its provenance. New rule applied repo-wide: internal modules import directly from the owning package; only published entry surfaces (src/sdk/* entries, client-types, finders, metro composition, remote-config-schema) may re-export. Eleven internal re-exports removed and ~110 import sites redirected to the packages, the big two being CommandFlags (core/dispatch chain, 39 sites) and SessionAction (daemon/types.ts, 19 sites). Two were already dead (RefFrameEffect via daemon-command-registry, DiffSnapshotCommandResult via capture/runtime/snapshot). Entry-surface chains now re-export from the package rather than laundering through a second internal module (client-types/client-metro MetroBridgeScope). Side effect: the R9 type cycle shrinks again, 49 -> 47 (daemon-server 19 -> 17); ceilings lowered to match. * refactor: drop command-schema's CliFlags re-export (#1640 review P2) The one consumer (cli/parser/args.ts, a multi-line import the sweep's single-line scan missed) now imports CliFlags from contracts/command; FlagDefinition/FlagKey stay — they are src-declared types, not package laundering.
1 parent 870d12c commit d5f11f6

116 files changed

Lines changed: 153 additions & 178 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CONTEXT.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ The perfect-shape refactor is complete and merged. Its end-state:
322322
theirs.
323323
- Type-cycle growth (R9). R4 keeps the VALUE import graph acyclic, so every remaining cycle is
324324
created by type-only imports — free at runtime, invisible to R5/R6, and the largest single
325-
obstacle to reading a subsystem in isolation: inside a strongly-connected component of 49 files,
325+
obstacle to reading a subsystem in isolation: inside a strongly-connected component of 47 files,
326326
no file has a self-contained slice. `TYPE_CYCLE_BASELINE`, derived from the zone ceilings in
327327
`scripts/layering/daemon-modularity.ts`, ratchets it for **growth only**, deliberately unlike R6: reducing it
328328
is a real refactor rather than a file move, so a hard equality would turn every unrelated
@@ -334,7 +334,7 @@ The perfect-shape refactor is complete and merged. Its end-state:
334334
#1632 sank `backend.ts`'s two upward type imports — 27 files stranded out of the component at
335335
once.
336336
- Daemon modularity ratchets (R10). The same tooling-only declaration pins R7's writer-owned
337-
field/owner-claim counts, R9's 49 members by zone (`commands` 14, `daemon-server` 19, `core` 10,
337+
field/owner-claim counts, R9's 47 members by zone (`commands` 14, `daemon-server` 17, `core` 10,
338338
`platforms` 2, root 3, `client` 1), and the external production importers of `daemon/types.ts`
339339
(down to 2: the client normalizers and remote artifacts). R7 counts and external importers may
340340
only shrink; no zone may grow inside R9, and replay/Maestro/replay-test engine files remain outside

‎scripts/layering/daemon-modularity.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ test('daemon modularity baseline records the measured R7 ownership pressure', ()
5151
Object.values(SESSION_STATE_FIELD_OWNERS).reduce((sum, owners) => sum + owners.length, 0),
5252
DAEMON_MODULARITY_BASELINE.sessionState.ownerFileClaims,
5353
);
54-
assert.equal(TYPE_CYCLE_BASELINE, 49);
55-
assert.equal(DAEMON_MODULARITY_BASELINE.largestTypeCycle.zoneMembers['daemon-server'], 19);
54+
assert.equal(TYPE_CYCLE_BASELINE, 47);
55+
assert.equal(DAEMON_MODULARITY_BASELINE.largestTypeCycle.zoneMembers['daemon-server'], 17);
5656
assert.equal('daemon' in DAEMON_MODULARITY_BASELINE.largestTypeCycle.zoneMembers, false);
5757
});
5858

‎scripts/layering/daemon-modularity.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const LARGEST_TYPE_CYCLE_ZONE_CEILINGS: Readonly<Record<string, number>> = {
77
client: 1,
88
commands: 14,
99
core: 10,
10-
'daemon-server': 19,
10+
'daemon-server': 17,
1111
platforms: 2,
1212
};
1313

‎src/__tests__/daemon-client-progress.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import type { RequestProgressEvent } from '@agent-device/contracts/progress';
12
import assert from 'node:assert/strict';
23
import { EventEmitter } from 'node:events';
34
import type { Socket } from 'node:net';
45
import { test } from 'vitest';
56
import type { DaemonRequest, DaemonResponse } from '../daemon/types.ts';
6-
import type { RequestProgressEvent } from '../request/progress.ts';
77
import { readDaemonSocketProgressResponse } from '../daemon/client/daemon-client-progress.ts';
88
import { AppError } from '@agent-device/kernel/errors';
99

‎src/agent-device-client.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CommandFlags } from '@agent-device/contracts/command';
12
import {
23
readSerializedSnapshotCaptureAnnotations,
34
readSnapshotDiagnosticsSummary,
@@ -68,7 +69,6 @@ import {
6869
import { systemCommandFamily } from './commands/system/index.ts';
6970
import type { ProjectedNavigationCommandClient } from './commands/system/navigation-projection.ts';
7071
import type { CommandResult } from './core/command-descriptor/command-result.ts';
71-
import type { CommandFlags } from './core/dispatch-context.ts';
7272
import { sendToDaemon } from './daemon/client/daemon-client.ts';
7373
import { resolveDaemonPaths } from './daemon/config.ts';
7474
import { prepareMetroRuntime, reloadMetro } from './metro/client-metro.ts';

‎src/cli-schema/cli-config.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { CliFlags } from '@agent-device/contracts/command';
12
import fs from 'node:fs';
23
import path from 'node:path';
34
import { AppError } from '@agent-device/kernel/errors';
45
import { mergeDefinedFlags } from '../utils/merge-flags.ts';
5-
import { type CliFlags, type FlagKey } from '../commands/cli-grammar/flag-types.ts';
6+
import { type FlagKey } from '../commands/cli-grammar/flag-types.ts';
67
import { expandUserHomePath, resolveUserPath } from '../utils/path-resolution.ts';
78
import {
89
getConfigurableOptionSpecs,

‎src/cli-schema/command-schema.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ import {
77
COMMON_COMMAND_SUPPORTED_FLAG_KEYS,
88
GLOBAL_FLAG_KEYS,
99
} from '../commands/cli-grammar/flag-groups.ts';
10-
import {
11-
type CliFlags,
12-
type FlagDefinition,
13-
type FlagKey,
14-
} from '../commands/cli-grammar/flag-types.ts';
10+
import { type FlagDefinition, type FlagKey } from '../commands/cli-grammar/flag-types.ts';
1511
import { AppError } from '@agent-device/kernel/errors';
1612

17-
export type { CliFlags, FlagDefinition, FlagKey };
13+
export type { FlagDefinition, FlagKey };
1814
export type { CommandSchema };
1915
export { getFlagDefinition, getFlagDefinitions, GLOBAL_FLAG_KEYS };
2016

‎src/cli/commands/connection-runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { MetroBridgeScope } from '@agent-device/contracts/remote';
12
import { resolveDaemonPaths } from '../../daemon/config.ts';
23
import { stopReactDevtoolsCompanion } from '../../client/client-react-devtools-companion.ts';
34
import { stopMetroTunnel } from '../../metro/metro.ts';
@@ -10,7 +11,6 @@ import {
1011
type DeviceInfo,
1112
} from '@agent-device/kernel/device';
1213
import { shouldAgentCdpUseRemoteBridgeUrl } from './agent-cdp.ts';
13-
import type { MetroBridgeScope } from '../../client/client-companion-tunnel-contract.ts';
1414
import {
1515
buildRemoteConnectionDaemonState,
1616
buildRemoteConnectionRequestMetadata,

‎src/cli/parser/args.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CliFlags } from '@agent-device/contracts/command';
12
import { AppError } from '@agent-device/kernel/errors';
23
import { mergeDefinedFlags } from '../../utils/merge-flags.ts';
34
import {
@@ -6,7 +7,6 @@ import {
67
getCommandSchema,
78
getFlagDefinition,
89
getFlagDefinitions,
9-
type CliFlags,
1010
type FlagDefinition,
1111
type FlagKey,
1212
} from '../../cli-schema/command-schema.ts';

‎src/client/client-companion-tunnel-contract.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const ENV_COMPANION_TUNNEL_SESSION = 'AGENT_DEVICE_COMPANION_TUNNEL_SESSI
1919

2020
// The scope SHAPE is declared in contracts/ so zones that only need the shape do not have to
2121
// declare themselves in terms of client/. Re-exported here for this module's existing consumers.
22-
export type { CompanionTunnelScope, MetroBridgeScope } from '@agent-device/contracts/remote';
2322
import type { CompanionTunnelScope } from '@agent-device/contracts/remote';
2423

2524
export class MissingCompanionEnvError extends Error {

0 commit comments

Comments
 (0)