Skip to content

refactor(layers): enforce service/UI boundary, move react hooks out of src/services (audit 1.1.3) - #202

Merged
dahai80 merged 1 commit into
mainfrom
fix/audit-1-1-3-layer-enforcement
Aug 29, 2026
Merged

dahai80 merged 1 commit into
mainfrom
fix/audit-1-1-3-layer-enforcement

Conversation

@dahai80

@dahai80 dahai80 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Audit §1.1.3 (HIGH) — service/UI bidirectional boundary crossing

Audit finding: service and UI layers crossed bidirectionally, enforced only by convention. Fix = deterministic enforcement via lint rule (Rule 5: code not convention).

Changes

Moved 4 react-importing files out of src/services/ to the UI layer:

File From To Type
claudeAiLimitsHook.ts src/services/ src/hooks/ React hook
compactWarningHook.ts src/services/compact/ src/hooks/ React hook
useManageMCPConnections.ts src/services/mcp/ src/hooks/mcp/ (new dir) React hook
MCPConnectionManager.tsx src/services/mcp/ src/components/mcp/ React component

Updated 10 importer files (path rewrites only, no logic change). Internal imports within moved files updated for new depth.

Enforcement (deterministic, not convention)

  • scripts/layer-lint.ts — wrapper runs biome ci on src/ and filters stdout for only noRestrictedImports diagnostics. Biome 2.5.5 forces noConsole noise even with preset: none, so pure-config isolation is impossible — the wrapper filters by rule name instead.
  • scripts/layer-lint.json — isolated config (does NOT touch the protected biome.json), noRestrictedImports scoped to src/services/** blocking react import.
  • package.json — lint:layers script, integrated into bun run check.
  • Exits 0 on clean layer, exits 1 naming the violating file on react import. Verified via negative test (inject react → FAIL).

Gates

  • typecheck: 0 errors
  • bun test src/__tests__/: 921 pass / 0 fail
  • bun run lint:layers: exit 0 ([layer-lint] OK: no react imports in src/services/**)
  • bun run build:dev: success

Out of scope (follow-up)

Phase B — 91 deep-internal UI→service imports (e.g. UI files importing from src/services/ internals) need a barrel/index migration to enforce the reverse direction cleanly. Filed as follow-up issue.

Co-Authored-By: Claude Fable 5 [email protected]

…f src/services (audit 1.1.3)

Audit finding 1.1.3 (HIGH): service/UI layers crossed bidirectionally,
enforced only by convention. Move 4 react-importing files out of
src/services/ to the proper UI layer and add deterministic lint enforcement.

Moved to UI layer:
- claudeAiLimitsHook.ts -> src/hooks/ (React hook)
- compact/compactWarningHook.ts -> src/hooks/ (React hook)
- mcp/useManageMCPConnections.ts -> src/hooks/mcp/ (React hook)
- mcp/MCPConnectionManager.tsx -> src/components/mcp/ (React component)

Updated 10 importer files (path rewrites only, no logic change).

Enforcement (Rule 5: code not convention):
- scripts/layer-lint.ts: wrapper runs 'biome ci' on src/ and filters
  stdout for only noRestrictedImports diagnostics (biome 2.5.5 forces
  noConsole noise even with preset:none, so a pure-config isolation is
  impossible — wrapper filters by rule name instead).
- scripts/layer-lint.json: isolated config, noRestrictedImports scoped to
  src/services/** blocking 'react' import.
- package.json: 'lint:layers' script, integrated into 'check'.
- Exits 0 on clean layer, exits 1 naming the violating file on react
  import. Verified via negative test (inject react -> FAIL).

Gates: typecheck 0 / 921 pass 0 fail / lint:layers exit 0 / build:dev pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 9dcfdc9 into main Aug 29, 2026
1 check passed
@dahai80
dahai80 deleted the fix/audit-1-1-3-layer-enforcement branch August 29, 2026 15:02
dahai80 added a commit that referenced this pull request Aug 30, 2026
…hase B #203 slice 1)

Phase B of audit 1.1.3 (follow-up to PR #202). PR #202 enforced the
service->UI direction (src/services/** react-free). This slice enforces the
reverse: consumers OUTSIDE src/services/** reach a migrated service subdir
only through its barrel (src/services/<subdir>/index), not a deep file.

Slice #1 ships the enforcement MECHANISM + migrates the single largest clean
subdir (mcp, 83 deep imports, no barrel). The mechanism is allowlist-based
(scripts/layer-lint-reverse.json migratedSubdirs) so it lands without forcing
the other 28 subdirs; future slices append subdirs + migrate them.

Changes:
- NEW src/services/mcp/index.ts: re-export barrel for 13 public mcp files.
  8 internal-only files NOT re-exported (kept private).
- NEW scripts/layer-lint-reverse.ts: custom reverse-boundary scanner.
  noRestrictedImports cannot express 'deep-but-not-barrel' -> regex scanner
  walking src/ minus src/services/**. Enforces only allowlisted subdirs.
- NEW scripts/layer-lint-reverse.json: allowlist config + allowDeepImports
  exemptions for 4 cycle-sensitive files kept at leaf imports.
- MOD package.json: lint:layers:reverse script + chained into lint:layers.
- MOD ~78 consumer files: repoint services/mcp/<deep>.js -> index.js.
- MOD 5 files (config.ts/xaaIdpLogin.ts/utils.ts/channelNotification.ts/
  pluginOnlyPolicy.ts): lazy-require settings accessor to break the eager
  export * cycle (settings -> types -> barrel -> config -> pluginOnlyPolicy
  -> settings re-entry -> isLoadingSettings TDZ). Call-time-neutral.

4 cycle-sensitive settings-cone files kept at leaf imports (exempted via
allowDeepImports): settings/validation.ts, settings/allErrors.ts,
settings/permissionValidation.ts, plugins/schemas.ts. Eager barrel import
there re-enters settings.ts mid-init. allowDeepImports documents the cycle.

Gates: typecheck 0; bun test 973 pass/0 fail; lint errors unchanged
(4600=4600, no new deviations); lint:layers both directions green.
Build:dev succeeds, +1 module (the barrel node; re-exports tree-shake at
symbol level, behavior-preserving; NOT byte-identical since the slice ships
a real barrel + 5 lazy-require blocks).

Real scope 238 deep imports / 29 subdirs (3x issue estimate). Remaining
slices queued: api (34), compact (15), lsp (11). analytics (48) deferred
(needs split-barrel design decision: inert event-log shim vs real growthbook/
metadata impl the barrel intentionally hides).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…ase B #203 slice 2)

Slice 2 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds api subdir to the barrel-enforcement allowlist + migrates its deep
imports to a new public barrel.

- NEW src/services/api/index.ts: re-export barrel for 20 public api files
  (bootstrap/claude/client/dumpPrompts/errors/errorUtils/filesApi/
  firstTokenDate/fusion-mlx-adapter/fusion-mlx-stream/fusion-mlx-types/
  grove/logging/metricsOptOut/overageCreditGrant/promptCacheBreakDetection/
  referral/sessionIngress/usage/withRetry). 4 internal-only files
  (adminRequests/emptyUsage/fusion-mlx-tool-validator/ultrareviewQuota)
  deliberately NOT re-exported — private api internals.
- MOD scripts/layer-lint-reverse.json: migratedSubdirs ["mcp"] -> ["mcp","api"].
  No allowDeepImports additions for api (api subdir has no settings-cone
  cycle — verified: no api file imports settings, so no TDZ risk; no
  lazy-require needed, cleaner than slice 1's mcp).
- MOD ~62 consumer files: repoint services/api/<deep>.js -> services/api/index.js
  across src/__tests__/cli/commands/components/entrypoints/hooks/tools/utils
  + QueryEngine.ts/query.ts/query/deps.ts/main.tsx/interactiveHelpers.tsx.

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3830->3833 modules (+3 = barrel node + 2 previously-tree-shaken internal
files now visible via barrel; re-exports tree-shake at symbol level,
behavior-preserving but NOT byte-identical — honest per Rule 12).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…3 Phase B #203 slice 3)

Slice 3 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds compact subdir to the barrel-enforcement allowlist + migrates its deep
imports to a new public barrel.

- NEW src/services/compact/index.ts: re-export barrel for 10 public compact
  files (compact/autoCompact/microCompact/snipCompact/snipProjection/
  reactiveCompact/postCompactCleanup/compactWarningState/cachedMCConfig/
  sessionMemoryCompact). 7 internal-only files (apiMicrocompact/
  cachedMicrocompact/grouping/hardCompact/prompt/smartCompactV2/
  timeBasedMCConfig) deliberately NOT re-exported — verified 0 external
  consumers each, private compact internals.
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api","compact"].
  No allowDeepImports additions (compact has no settings-cone cycle —
  verified: no compact file imports settings, so no TDZ risk; no lazy-require
  needed, same clean-slice template as api).
- MOD 23 consumer files: repoint services/compact/<deep>.js ->
  services/compact/index.js across src/__tests__/commands/components/hooks/
  utils + QueryEngine.ts/query.ts/query/deps.ts/screens/REPL.tsx/types.

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3833->3836 modules (+3 = barrel node + 2 previously-tree-shaken internal
files now visible via barrel; re-exports tree-shake at symbol level,
behavior-preserving but NOT byte-identical — honest per Rule 12).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…ase B #203 slice 4)

Slice 4 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds lsp subdir to the barrel-enforcement allowlist + migrates its deep
imports to a new public barrel.

- NEW src/services/lsp/index.ts: re-export barrel for 3 public lsp files
  (manager/LSPDiagnosticRegistry/types). 5 internal-only files (config/
  LSPClient/LSPServerInstance/LSPServerManager/passiveFeedback) deliberately
  NOT re-exported — verified 0 external consumers each, private lsp internals.
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api","compact","lsp"].
  No allowDeepImports additions (clean slice: no lsp file imports settings).
- MOD 14 consumer files: repoint services/lsp/<deep>.js -> services/lsp/index.js
  across src/commands/entrypoints/hooks/tools/server/types/utils.

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3836->3838 modules (+2 = barrel node + 1 previously-tree-shaken internal
file now visible via barrel; behavior-preserving but NOT byte-identical).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…hase B #203 slice 5)

Slice 5 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds goal subdir to the barrel-enforcement allowlist + migrates its deep
imports to a new public barrel.

- NEW src/services/goal/index.ts: re-export barrel for both goal files
  (goalState/budgetEnforcer — both are public surface, no internal-only files).
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api","compact","lsp","goal"].
  No allowDeepImports (clean slice).
- MOD 8 consumer files: repoint services/goal/<deep>.js -> services/goal/index.js
  across src/__tests__/commands/tools + QueryEngine.ts.

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3838->3839 modules (+1 = barrel node; behavior-preserving but NOT byte-identical).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…udit 1.1.3 Phase B #203 slice 6)

Slice 6 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds oauth subdir to the barrel-enforcement allowlist. Unlike prior slices,
oauth already had an index.ts — but it only contained the OAuthService class
(no re-exports). This slice appends public re-exports so external consumers
can use the barrel instead of deep files.

- MOD src/services/oauth/index.ts: append `export *` for 4 public files
  (types/client/getOauthProfile/codex-client) after the existing OAuthService
  class. 2 internal-only files (auth-code-listener/crypto) deliberately NOT
  re-exported — verified 0 external consumers each, private oauth internals.
  (The existing `import * as client` local namespace coexists fine with the
  `export *` re-export — TS allows both; typecheck 0 collisions.)
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api","compact","lsp","goal","oauth"].
  No allowDeepImports (clean slice).
- MOD 13 consumer files: repoint services/oauth/<deep>.js (types/client/
  getOauthProfile/codex-client) -> services/oauth/index.js. 3 consumers that
  already imported OAuthService from index.js were left unchanged.

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3839->3840 modules (+1; behavior-preserving but NOT byte-identical).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…ase B #203 slice 7)

Slice 7 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds llm subdir to the barrel-enforcement allowlist + migrates its deep
imports (incl nested capabilities/) to a new public barrel.

- NEW src/services/llm/index.ts: re-export barrel for 13 public llm files
  (ctx/types/streamResume/errors/sseStream/registry/chunkToPart/capability/
  adapter + capabilities/{exec,fs,sandbox,tools}). 4 internal-only files
  (client/httpClient/mlxAdapter/seam) deliberately NOT re-exported — verified
  0 external consumers each, private llm internals.
  The capabilities/ sub-files are re-exported here directly because the
  scanner treats services/llm/capabilities/<x>.js as a deep import into the
  llm subdir (capabilities is not itself a migrated subdir).
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api",
  "compact","lsp","goal","oauth","llm"]. No allowDeepImports (clean slice).
- MOD 18 consumer files: repoint services/llm/<deep>.js -> services/llm/index.js
  (negative-lookahead skips index.js-only importers).

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3840->3845 modules (+5 = barrel node + 4 capabilities + tree-shaken
internals now visible via barrel; behavior-preserving but NOT byte-identical).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
….3 Phase B #203 slice 8)

Slice 8 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds executor subdir to the barrel-enforcement allowlist + migrates its deep
imports to a new public barrel.

- NEW src/services/executor/index.ts: re-export barrel for 4 public executor
  files (executorDriver/turnSnapshot/types/manager). 2 internal-only files
  (ExecutorClient/ExecutorInstance) deliberately NOT re-exported — verified
  0 external consumers each, private executor internals.
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api",
  "compact","lsp","goal","oauth","llm","executor"]. No allowDeepImports (clean slice).
- MOD 11 consumer files: repoint services/executor/<deep>.js ->
  services/executor/index.js (negative-lookahead skips index.js-only importers).

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3845->3847 modules (+2 = barrel node + 1 previously-tree-shaken internal
file; behavior-preserving but NOT byte-identical).

Co-Authored-By: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 30, 2026
…1.1.3 Phase B #203 slice 9)

Slice 9 of #203 Phase B reverse service/UI boundary (follow-up to PR #202).
Adds skillSearch subdir to the barrel-enforcement allowlist + migrates its
deep imports to a new public barrel.

- NEW src/services/skillSearch/index.ts: re-export barrel for all 7
  skillSearch files (featureCheck/prefetch/telemetry/remoteSkillState/
  remoteSkillLoader/localSearch/signals — each has >=1 external consumer).
  NAME COLLISION: `isSkillSearchEnabled` is defined in BOTH featureCheck
  (canonical) and localSearch (local fallback). Resolved via explicit
  re-export — featureCheck's keeps the canonical name (export *), localSearch's
  is aliased to `isSkillSearchEnabledLocal` to avoid TS2308 ambiguity.
  Consumers reach these via module-namespace `require(...) as typeof import(...)`
  casts, so the alias does not break them (they access other localSearch
  symbols like clearSkillIndexCache/searchSkills directly).
- MOD scripts/layer-lint-reverse.json: migratedSubdirs -> ["mcp","api",
  "compact","lsp","goal","oauth","llm","executor","skillSearch"]. No allowDeepImports.
- MOD 5 consumer files: repoint services/skillSearch/<deep>.js ->
  services/skillSearch/index.js (negative-lookahead swaps BOTH the require
  path and the `typeof import(...)` cast path on the same line).

Gates: typecheck 0; bun test src/__tests__/ 973 pass/0 fail; lint errors
unchanged (4600=4600); lint:layers both directions green; build:dev
3847->3847 modules (+0 = all re-exported symbols were already in the bundle
via the require paths; behavior-preserving, byte-module-count-identical
though structurally the barrel node is added/tree-shaken).

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant