Skip to content

refactor(screens): extract viewedTask selector from god module REPL.tsx (audit 1.1.1) - #172

Merged
dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-viewedtask
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit-1.1.1-repl-split-viewedtask

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Context

Third surgical extraction in the REPL.tsx god-module split (audit §1.1.1, task #170). src/screens/REPL.tsx is a 7096-LOC god module (render tree + keybindings + task lists + compaction + tool permissions + session management in one file). The multi-session split strategy: survey → rank by closure-dependency count → extract the fewest-depend pure-helper / leaf cohesive subsystem first (safe, byte-identical, independently mergeable).

Follows PR #168 (3 leaf components + median(), −285 LOC) and PR #171 (2 spinner-state derives → utils/spinnerState.ts, −70 LOC).

Change

The three viewed-task derives move from inline in REPL.tsx to a pure-function selector module — same pattern as PR #171 (pure-helper class, deps as args, no React, no side effects):

  • src/tasks/viewedTaskSelector.ts (NEW, 36 LOC):

    • getViewedTask(tasks, viewingAgentTaskId) — raw record lookup by id
    • getViewedTeammateTask(viewedTask) — teammate-only narrowed (drives inProgressToolUseIDs access)
    • getViewedAgentTask(viewedTask, viewedTeammateTask) — teammate OR local_agent, drives downstream boolean checks (displayedMessages, placeholderText, hidePill, isBriefOnly, …)
  • src/screens/REPL.tsx: the 6-line inline block replaced by 3 thin const call wrappers (identical names viewedTask / viewedTeammateTask / viewedAgentTask → identical downstream usage). Pure relocation + import wiring, byte-identical behavior. Removed now-unused isInProcessTeammateTask guard import (sole call site moved out). Kept InProcessTeammateTaskState type (still used at panel helper :4580) and isLocalAgentTask (two other call sites :796/:805/:4583).

  • src/__tests__/tasks/viewedTaskSelector.test.ts (NEW, 10 tests) — selector narrowing branches: teammate preference, local_agent fallback, undefined/non-agent cases.

LOC

LOC win on the god module is small here, but the cohesion win is real — the selector logic (teammate-vs-local narrowing) is now reusable + unit-testable in isolation, and REPL's render function sheds one more inline derivation cluster.

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 714 pass (+10 new), 0 fail
  • bun run lint — net-zero vs 4601-error baseline (new file clean)
  • bun run build:dev — 3757 modules, passes

Byte-identical

Pure relocation + import wiring. The three const bindings keep identical names and downstream usage; only the derivation moves out. Removed import (isInProcessTeammateTask) had its single call site moved to the selector. Existing 704 tests cover the REPL render paths that consume viewedAgentTask.

Task #170 stays in_progress — full 4-6wk split continues in follow-up PRs.

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

…sx (audit 1.1.1)

Third surgical extraction in the REPL.tsx god-module split (audit §1.1.1).
The three viewed-task derives (viewedTask / viewedTeammateTask / viewedAgentTask)
move from inline in REPL.tsx to a pure-function selector module:
src/tasks/viewedTaskSelector.ts. No React, no side effects — deps as args.

- getViewedTask: raw record lookup by id
- getViewedTeammateTask: teammate-only narrowed (in_progress_teammate)
- getViewedAgentTask: teammate OR local_agent — drives downstream boolean checks

REPL keeps the three const bindings as thin call wrappers (identical names,
identical downstream usage) — pure relocation + import wiring, byte-identical
behavior. Removed now-unused isInProcessTeammateTask guard import from REPL
(sole call site moved out); kept InProcessTeammateTaskState type (still used
at the panel helper) and isLocalAgentTask (two other call sites).

REPL.tsx 6741 → 6732 LOC (-9). viewedTaskSelector.ts +36 LOC (new).
Cohesion win: selector logic now reusable + unit-testable in isolation.

Gates: typecheck 0 / 714 tests pass (+10 new) / lint net-zero vs 4601 baseline
/ build:dev 3757 modules.

Follows PR #168 (leaf components, -285) + PR #171 (spinner derives, -70) in
the multi-session split. Task #170 stays in_progress — full 4-6wk split
continues in follow-up PRs.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit dab850f into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit-1.1.1-repl-split-viewedtask branch August 28, 2026 06:34
dahai80 added a commit that referenced this pull request Aug 28, 2026
…State (audit 1.1.1) (#176) (#177)

Sixth surgical extraction for audit §1.1.1 god-module split.
Bundle 3 chained pure derives out of REPL.tsx (was 5748-5769):
  - usesSyncMessages (showStreamingText||!isLoading)
  - displayedMessages (agent view|sync|deferred, ref-preserving)
  - placeholderText (input-baseline gate)

src/utils/messageDisplayState.ts NEW — deriveUsesSyncMessages +
deriveDisplayedMessages + derivePlaceholderText + aggregate
deriveMessageDisplayState. No React, no hooks, deps as args.
Returns ORIGINAL array refs (no spread copy) — preserves ref-identity
for Messages memo + length checks downstream. Byte-identical to inline.

REPL keeps useDeferredValue(messages) + userInputBaselineRef ref;
calls deriveMessageDisplayState once, destructures to SAME const names
→ downstream reads unchanged.

Picked 7-dep bundle over survey #1 getFocusedInputDialog (90 LOC but 23
deps) — strategy = fewest-dep pure-helper = lowest byte-identical risk
(per proven PR #174/#175 pattern).

Tests: messageDisplayState.test.ts 19 tests — usesSyncMessages 3 arms,
displayedMessages ref-identity + agent-override + empty-array,
placeholderText baseline gate + agent suppress, aggregate 7 cases
including ref-identity assertion (not a copy).

REPL.tsx 6709 → 6696 (−13). Cumulative off 7096:
  #168(−285)+#171(−70)+#172(−9)+#174(−17)+#175(−6)+#176(−13) = −400 LOC.

Gates: typecheck 0 / 769 tests (+19) / lint net-zero 4601 / build:dev 3764.

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