Repository navigation
refactor(providers): split provider contract types so onWriteUnavailable can drop its cast [stacked on #10065] - #10434
Conversation
types.ts sat 9 effective lines under the 300 max-lines cap, which forced #10065 to type onWriteUnavailable via a cast at the pty.ts call site. Split into pty-provider-contract.ts, filesystem-provider-contract.ts, and git-provider-contract.ts; types.ts stays a barrel owning IProviderRegistry and re-exporting every prior symbol, so no caller import changes. Largest new file is 105 effective lines. With headroom back, onWriteUnavailable is now declared on IPtyProvider (optional — only respawnable endpoints like the daemon adapter signal it) and the pty.ts cast is gone.
90da3c3 to
c617570
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughProvider types were split into dedicated PTY, filesystem, and Git contract modules. The existing provider types module now re-exports those contracts as a compatibility barrel. The PTY contract includes lifecycle, spawn, streaming, buffering, and optional capability definitions. The filesystem contract adds file operations and related data shapes, while the Git contract defines Git operations. PTY write-unavailability listener registration now uses direct optional chaining while preserving renderer event forwarding. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ider-types-split # Conflicts: # src/main/providers/types.ts
Greptile SummarySplits
Confidence Score: 5/5Safe to merge once #10065 lands first — all changes are type declarations erased at compile time with no runtime effect. The change is entirely type-level: the three new contract files move definitions verbatim from the old monolithic file, the barrel preserves every export name, and the only behavioral edit in pty.ts replaces a structural cast with a direct interface access that the compiler now validates. No logic branches, no new runtime paths, no schema or migration changes. Files Needing Attention: No files require special attention; the barrel in types.ts is the integration point to double-check, and its re-export list matches the original symbol set exactly.
|
| Filename | Overview |
|---|---|
| src/main/providers/pty-provider-contract.ts | New file: extracts IPtyProvider, PtySpawnOptions, PtyProviderBufferSnapshot and their re-exports from types.ts; adds onWriteUnavailable as an optional member on IPtyProvider |
| src/main/providers/git-provider-contract.ts | New file: extracts IGitProvider and re-exports GitProviderStatusOptions from types.ts; no interface changes |
| src/main/providers/filesystem-provider-contract.ts | New file: extracts IFilesystemProvider, FileStat, FileReadResult, FileUploadSession, TerminalArtifactAccessOptions from types.ts; no interface changes |
| src/main/providers/types.ts | Converted to a 26-line barrel that re-exports all symbols previously defined here, keeping all 39 existing import sites unmodified |
| src/main/ipc/pty.ts | Removes the structural cast on localProvider and calls localProvider.onWriteUnavailable directly, now that IPtyProvider carries the declaration |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["providers/types.ts\n(barrel re-exports)"] --> B["pty-provider-contract.ts\nIPtyProvider · PtySpawnOptions\nPtyProviderBufferSnapshot"]
A --> C["git-provider-contract.ts\nIGitProvider\nGitProviderStatusOptions"]
A --> D["filesystem-provider-contract.ts\nIFilesystemProvider · FileStat\nFileReadResult · FileUploadSession\nTerminalArtifactAccessOptions"]
B --> E["pty-provider-events.ts\nPtyBackgroundStreamEvent\nPtyDataEvent · PtyTransientFact"]
B --> F["pty-spawn-result.ts\nPtySpawnResult"]
B --> G["pty-process-info.ts\nPtyProcessInfo"]
C --> H["git-provider-status-options.ts\nGitProviderStatusOptions"]
I["src/main/ipc/pty.ts\nlocalProvider.onWriteUnavailable?.\n(cast removed)"] --> B
J["39 existing importers\nfrom providers/types"] --> A
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile
…i#10434) types.ts sat 9 effective lines under the 300 max-lines cap, which forced stablyai#10065 to type onWriteUnavailable via a cast at the pty.ts call site. Split into pty-provider-contract.ts, filesystem-provider-contract.ts, and git-provider-contract.ts; types.ts stays a barrel owning IProviderRegistry and re-exporting every prior symbol, so no caller import changes. Largest new file is 105 effective lines. With headroom back, onWriteUnavailable is now declared on IPtyProvider (optional — only respawnable endpoints like the daemon adapter signal it) and the pty.ts cast is gone.
Stacked hardening follow-up to #10065. Do not land this first — see merge order below.
Why
src/main/providers/types.tswas 291 effective lines against the repo's 300-linemax-linescap (skipBlankLines/skipComments). That 9-line headroom is why #10065 could not declareonWriteUnavailableonIPtyProviderand had to reach for a structural cast at thepty.tscall site instead:That cast is load-bearing-by-accident: it re-declares the contract at one call site, so the daemon adapter's real signature and the consumer's assumed signature can drift apart silently.
What changed
1. Split
types.tsalong its three existing domain seams (they were already// ─── PTY Provider ───-style sections in the file, so the seams are the file's own):pty-provider-contract.tsIPtyProvider,PtySpawnOptions,PtyProviderBufferSnapshotgit-provider-contract.tsIGitProvider,GitProviderStatusOptionsre-exportfilesystem-provider-contract.tsIFilesystemProvider,FileStat,FileReadResult,FileUploadSession,TerminalArtifactAccessOptionstypes.ts(barrel)IProviderRegistry+ re-exports of everything aboveNames are the concrete domain concept per AGENTS.md — no
helpers/common/misc. Nomax-linesdisable and no ratchet-baseline entry was added (config/max-lines-baseline.txtis untouched); every file is comfortably under the cap on its own.2. Zero caller churn.
types.tsre-exports every symbol it exported before, so all 39 files importing fromproviders/typesare unmodified. Diff is 5 files total.3. Promoted
onWriteUnavailableontoIPtyProvideras an optional member, with the "only respawnable endpoints implement it" rationale moved from the call-site comment onto the declaration — and deleted the cast insrc/main/ipc/pty.ts. The daemon adapter'sonWriteUnavailable(callback: (payload: { id: string }) => void): () => voidis now structurally checked against the contract instead of against a locally re-typed assumption.Merge order
mainand land it. GitHub will retarget automatically on fix(daemon): respawn on PTY write dropped to a dead daemon socket (STA-2373) #10065's merge; the diff should stay clean since nothing else touches these files.Validation
pnpm typecheck— clean (all three tsconfig projects).pnpm lint— clean, includingcheck:max-lines-ratchet.vitestoversrc/main/providers,src/main/daemon,src/main/ipc/pty-management.test.ts— 1616 passed, 5 skipped, 0 failed.src/main/ipc/pty.test.tshas 7 pre-existing failures in itsWindows UTF-8 code pageblock on macOS. Verified identical on the base branch with these changes stashed (7 failed / 336 passed both ways) — not introduced here.Risk
Type-only. No runtime behavior changes: the emitted JS for
types.tsis type re-exports (erased), and thepty.tsedit removes a cast whose runtime value was alreadylocalProvider.