refactor(contracts): consolidate per-domain defineUse wrappers into one neutral defineUse - #1741
Conversation
…ne neutral defineUse
ADR 0019 §9: use declarations share one neutral defineUse; per-domain
currying wrappers around runtimeUse<PlatformRuntimeOperations>() add a
module per domain for no information. network-runtime-plan.ts,
logs-runtime-plan.ts, screen-recording-runtime-plan.ts, and
app-log-resource-recovery.ts each re-derived their own curried alias
(defineNetworkUse, appLogUse, defineScreenRecordingUse, and an inline
instantiation) from the same generic factory with the same type
parameter.
Export defineUse = runtimeUse<PlatformRuntimeOperations>() once from
platform-runtime.ts (where runtimeUse lives) and re-export it from the
platform facade. Every runtime-use declaration (networkDumpUse,
networkAdmissionUse, the app-log uses, the screen-recording uses, and
appLogRecoveryUse) now builds through that single export; the
per-domain wrappers are deleted.
Type-level only: no required/preferred keys changed, and no use
declaration was added, removed, or altered. Existing deepEqual
assertions in network-runtime-plan.test.ts, logs-runtime-plan.test.ts,
and screen-recording-runtime-plan.test.ts already pin every produced
use object's exact {required, preferred} shape, so they double as the
before/after regression proof that this refactor is behavior-neutral.
Part of #1739 (wave 0).
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
|
Exact-head review at P2: Otherwise the consolidation is behavior-neutral: every required/preferred literal is unchanged and the produced frozen use-object shapes remain identical. The iOS red check is the known unrelated simulator flake ( |
|
Fixed the P2: 🤖 Addressed by Claude Code |
Review: defining defineUse in platform-runtime.ts required importing the concrete PlatformRuntimeOperations catalog into the generic runtimeUse primitive module, while platform-runtime-operations.ts already imports generic runtime types from platform-runtime.ts. That's an avoidable reverse type dependency — the lower generic primitive depended on its concrete aggregate catalog. The unchanged SCC file count didn't prove this harmless; it counts cycle members, not newly introduced back-edges. Move defineUse = runtimeUse<PlatformRuntimeOperations>() into platform-runtime-operations.ts, alongside PlatformRuntimeOperations. platform-runtime.ts no longer imports the concrete catalog. Re-export defineUse through the platform facade from its new source module; every call site keeps importing it from @agent-device/contracts/platform unchanged, and the three contracts-internal call sites now import it directly from platform-runtime-operations.ts. Validation: tsc (full workspace + examples/sdk), check:layering (136/136, type-cycle count unchanged at 46), and check:affected --run (473 files / 3939 tests) all clean at the new head.
|
Reviewed exact head |
|
What changed
packages/contractshad four separate call sites re-deriving their own curriedalias of
runtimeUse<PlatformRuntimeOperations>()with no distinguishinginformation between them:
network-runtime-plan.ts:defineNetworkUselogs-runtime-plan.ts:appLogUsescreen-recording-runtime-plan.ts:defineScreenRecordingUsesrc/daemon/app-log-resource-recovery.ts: an inlineruntimeUse<PlatformRuntimeOperations>()({...})instantiationPer ADR 0019 §9: "Use declarations share one neutral
defineUse; per-domaincurrying wrappers add a module per domain for no information."
This PR exports one neutral
defineUse = runtimeUse<PlatformRuntimeOperations>()from
packages/contracts/src/platform-runtime.ts(the module whereruntimeUsealready lives) and re-exports it from the
@agent-device/contracts/platformfacade. Every runtime-use declaration in the four call sites above
(
networkDumpUse,networkAdmissionUse, the app-log usesappLogInspectUse/appLogDoctorUse/appLogStartUse/appLogAdmissionUse, thescreen-recording uses
screenRecordingStartUse/screenRecordingRecoveryUse/screenRecordingAdmissionUse, andappLogRecoveryUse) now builds through thatsingle
defineUseexport. The per-domain wrapper consts are deleted.runtimeUseitself is untouched and stays exported — it's still the genericprimitive exercised directly by
platform-runtime.test.tsagainst anunrelated test
Operationstype.Why this is behavior-neutral
This is a type-level refactor only:
defineUseis exactlyruntimeUse<PlatformRuntimeOperations>()— the samefunction the deleted wrappers each produced, with the same
Operationstypeparameter. Every call site keeps its exact
required/preferredargumentlist unchanged, so every produced
RuntimeUseobject is identical.changed.
deepEqualassertions innetwork-runtime-plan.test.ts,logs-runtime-plan.test.ts, andscreen-recording-runtime-plan.test.tsalready pin every produced use object's exact
{required, preferred}shape(e.g.
assert.deepEqual(networkDumpUse, { required: ['networkDump'], preferred: [] })).These pass unchanged after the refactor, so they double as the before/after
regression proof that the produced objects didn't change.
Validation
pnpm exec tsc -b packages/kernel packages/contracts— cleanpnpm typecheck(full workspace + examples/sdk) — cleanpnpm check:layering— 136/136 structural tests pass; type-cycle countunchanged at 46 (under the 47 baseline), confirming the new type-only
platform-runtime.ts→platform-runtime-operations.tsimport edgeintroduces no regression
pnpm check:affected --run— 473 test files / 3939 tests passed, plusformat, lint, layering, build/declarations, coverage-changed,
integration-progress, replay-compat, and daemon-wire-compat checks
Part of #1739 (wave 0).