Repository navigation
refactor: de-duplicate exported type names within each package - #4757
Conversation
11 same-name exported type collisions existed within single packages. The big one: packages/contracts exported PointTarget/RefTarget/ SelectorTarget/ElementTarget/InteractionTarget from both client-target.ts (public, never-exclusive client props) and interaction.ts (internal, kind-discriminated), with 45 importers split between them. Rename the internal sets, never the public ones: - contracts/interaction.ts: InteractionSelectorTarget, InteractionRefTarget, InteractionElementTarget, InteractionPointTarget, InteractionRequestTarget (client-target.ts untouched) - command-runtime: selector-wait.ts SelectorWaitSnapshotOptions - daemon: session-open-execution.ts OpenRuntimeHintClearOperation - maestro: MaestroRuntimePlatform, MaestroSnapshotTargetQuery, MaestroInputTargetResolution - platform-apple: adapter.ts SimulatorBridgeSnapshotSource Rename-only; importers updated. One name now means one type inside a package, so an importer can no longer silently pick the wrong same-named type.
New zero-baseline rule: no two modules of one package may export the same name in the type namespace. Re-exports resolve transitively, so a barrel re-exporting one declaration is the same symbol, and aliases across package boundaries stay legal at layer seams. Registered in LAYERING_RULE_IDS/LAYERING_RULES (the object-key trick makes a missing rule a type error) with a unit test beside the rule module. Verified to report exactly the 11 collisions fixed in the previous commit at origin/main and zero at this head.
Size Report
Startup median (7 runs, lower is better):
|
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
scripts/layering/unique-exported-type-names.ts:176 |
R87 star-export path keeps origin-keyed composite keys as export names for downstream consumers |
scripts/layering/unique-exported-type-names.ts:219 |
R87 treats every non-packages/ path as one "src (root package)" |
Reviewed with this repository's own Sentinel configuration (7b6500cd2da2).
💬 Talking to Sentinel
In a finding's thread, reply with:
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 14da66c. The verdict and the full list are in the summary comment.
| for (const [name, nameOrigins] of origins) { | ||
| const site = sites.get(name)!; | ||
| if (nameOrigins.size === 1) { | ||
| out.set(name, site); | ||
| } else { | ||
| // A star-star conflict keeps several origins on one name; report each origin once. | ||
| // Identifiers cannot contain '@', so the composite key is unambiguous. | ||
| for (const origin of nameOrigins) out.set(`${name}@${origin}`, { ...site, origin }); | ||
| } | ||
| } | ||
| return out; |
There was a problem hiding this comment.
🟡 Minor · R87 star-export path keeps origin-keyed composite keys as export names for downstream consumers
one.ts declares Opts, two.ts declares Opts, star.ts does export * from './one.ts'; export * from './two.ts', and barrel.ts does export type { Opts } from './star.ts' — star.ts exports Opts@one.ts and Opts@two.ts as names, the barrel's typeExportOf lookup of plain Opts misses and records origin=star.ts as its single origin, yielding zero violations for a genuine intra-package collision. The composite-key encoding at line 183 is decoded only in the final grouping loop (line 198), not by consumers of the returned map.
Suggested change
Return a structured per-name origin list from exportsOf instead of encoding multiple origins into the map key, or have typeExportOf/export-star consumers recognize the name@origin form and carry all origins forward. Add a test with a conflicted star module re-exported by a barrel in the same package.
Details
persona: senior-developer
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
| }); | ||
| } | ||
| } | ||
| } | ||
| return violations; |
There was a problem hiding this comment.
🟡 Minor · R87 treats every non-packages/ path as one "src (root package)"
Two same-named exported types in different non-packages/ directories (e.g. one in scripts/, one in test/) are reported as a collision inside src (root package). packageOf maps every path not matching ^packages/([^/]+)/ to that single bucket, so all tooling-tree types share one namespace.
Suggested change
Decide and encode which directories form the root package for R87 (e.g. only src/, or each top-level folder separately) and cover the scripts//test/ case in the test file.
Details
persona: javascript
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.
|
The code at 14da66c is ready, CI is green (18 checks, none failing), and there are no conflicts. Nothing blocks merge. Not blocking, and you can take or leave these: the JSDoc at unique-exported-type-names.ts:40 describes the inner Two open inline threads do not apply, so please resolve them. The first (#4757 (comment), barrel hides collision) does not hold: the loop at unique-exported-type-names.ts:193-203 runs |
…odes Main defines R87 as unique-exported-type-names (#4757), so the promise-race ratchet takes R88 in the rule, its test, the check.ts comments and the success line. The count now parses each source with the shared layering parser and counts Promise.race CallExpression nodes, so comments, strings and spacing cannot move the count; the header's LOC figures are corrected. Conflict with main in check.ts resolved keeping both rules. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…odes Main defines R87 as unique-exported-type-names (#4757), so the promise-race ratchet takes R88 in the rule, its test, the check.ts comments and the success line. The count now parses each source with the shared layering parser and counts Promise.race CallExpression nodes, so comments, strings and spacing cannot move the count; the header's LOC figures are corrected. Conflict with main in check.ts resolved keeping both rules. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…ace ratchet (#4766) * feat(host-kit): add settleWithin deadline settle to the retry module Adds settleWithin(work, timeoutMs) beside Deadline/sleep/pollUntilSettled and exports it through the existing ./retry subpath. The typed outcome is { kind: 'settled', value } | { kind: 'deadline' }; the deadline timer is cleared on every settle path, and the doc comment states it does not cancel the work (a late rejection stays observed, a rejection that beats the deadline propagates). * refactor(daemon): settle deadline races through host-kit settleWithin Removes the daemon-local settleWithinBudget and migrates every hand-rolled deadline race in the daemon to settleWithin: closeDaemonServers and session teardown in server-shutdown, the request drain and platform-owner/plugin closes in daemon-runtime, the lease-release drain in provider-lease-expiry, and the idle-expiry settle budget in daemon-session-idle-expiry (dropping its bespoke budgetElapsedAfter timer). Races that are not deadlines (the abort race in artifact-tracking, TTL/retry timers) are untouched. * chore(gates): ratchet Promise.race counts per package (R87) New layering rule promise-race-ratchet (R87): Promise.race( occurrences per package over production sources must not grow past the merge-base with origin/main, measured by the shared merge-base ratchet machinery. Deadline races belong to settleWithin in @agent-device/host-kit/retry, which clears its own timer on every settle path; non-deadline races are out of scope for the count. Registered in LAYERING_RULES with a unit test. * fix(host-kit): settleWithin keepAlive:false unrefs the deadline timer A deadline awaited by a background sweep must not hold the event loop: the removed budgetElapsedAfter() unref'd its timer on purpose. settleWithin now takes { keepAlive: false } to unref the deadline timer, and expireIdleSession passes it (a hung idle expiry could otherwise keep a daemon with closed servers alive for up to the 46s teardown budget). The default stays ref'd for shutdown callers, where an unref'd timer could let the process exit mid-report. Host-kit test covers the unref'd case and the ref'd default. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> * refactor(daemon): drop dead abort controller and shutdown locals retryPending() takes no signal, so the AbortController in the lease drain only cancelled the old sleep; pass retryPending directly. Awaiting emitDaemonDiagnostic inside the owner-shutdown catch drops the ownerFailed/ownerFailure locals. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> * chore(gates): renumber race ratchet to R88 and count CallExpression nodes Main defines R87 as unique-exported-type-names (#4757), so the promise-race ratchet takes R88 in the rule, its test, the check.ts comments and the success line. The count now parses each source with the shared layering parser and counts Promise.race CallExpression nodes, so comments, strings and spacing cannot move the count; the header's LOC figures are corrected. Conflict with main in check.ts resolved keeping both rules. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai> * fix(daemon): drain reports its result when a release fails inside the budget settleWithin rejects a work rejection that arrives while the deadline has not yet been reported, so a pending release failing inside the drain window threw out of drain instead of returning its report. The drain bounds shutdown; a failed release is a pending release, so the report stands. settleWithin's doc now states the spent-budget ordering explicitly: a rejection after the deadline is swallowed, and a caller that must see the work's own failure awaits the work. --------- Co-authored-by: Mistral Vibe <vibe@mistral.ai>
Summary
Behavior: 11 same-name exported type collisions existed within single packages; each internal declaration is renamed, never the public one. BEFORE:
packages/contractsexportedPointTarget/RefTarget/SelectorTarget/ElementTarget/InteractionTargetfrom bothclient-target.ts(public) andinteraction.ts(internal, fan-in 50), plus one collision each in command-runtime, daemon, platform-apple, and three in maestro. AFTER: the internal sets get distinct names (contracts:Interaction*-prefixed target types; the other six similarly suffixed); all importers updated.client-target.tsand the public subpath surface are untouched (R83 snapshot unchanged).Reason: one name must mean one type inside a package, so an importer can no longer silently pick the wrong same-named type.
38 files touched (35 rename + 3 gate); gross diff 726 lines (<1,000), rename-only modulo import re-wrapping.
Impact. SIZE: rename-only in packages; net +476 lines is the R87 rule + test in the gates commit. PERF: none (type-only). COLLOCATION: one name = one concept per package, now enforced by R87.
Validation
Tested SHA:
14da66c8d6(head).pnpm check:affected --run --head 14da66c8d6passed format, lint, typecheck, layering, fallow, build, package, integration-node, vitest-related and other gates (exit=0), then hit this sandbox's 300s command cap during the fullunitsuite, so CI's serialized gate validates the pushed head per docs/agents/testing.md. No localexactCommitreceipt; unresolved risk.Local evidence at head:
check:layeringOK incl. R87 (10/10 rule tests); R87 reports the 11 collisions at merge-basee766e8890f, zero at head. Unit shards pass: contracts+command-runtime 1457 tests, daemon 4549, maestro+platform-apple 2256 (+2 load flakes passing in isolation).depgraph:test,lint,typecheck,check:production-exports,check:packagegreen;formatapplied. Blast radius:depgraph affected packages/contracts/src/interaction.ts= fan-in 50, all type-only. CI runs the full gate; device/native lanes out of scope per task.