Skip to content

refactor(providers): split provider contract types so onWriteUnavailable can drop its cast [stacked on #10065] - #10434

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/pty-provider-types-split
Jul 30, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/pty-provider-types-split

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Stacked hardening follow-up to #10065. Do not land this first — see merge order below.

Why

src/main/providers/types.ts was 291 effective lines against the repo's 300-line max-lines cap (skipBlankLines/skipComments). That 9-line headroom is why #10065 could not declare onWriteUnavailable on IPtyProvider and had to reach for a structural cast at the pty.ts call site instead:

const writeUnavailableSource = localProvider as {
  onWriteUnavailable?: (callback: (payload: { id: string }) => void) => () => void
}

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.ts along its three existing domain seams (they were already // ─── PTY Provider ───-style sections in the file, so the seams are the file's own):

File Contents Effective lines
pty-provider-contract.ts IPtyProvider, PtySpawnOptions, PtyProviderBufferSnapshot 105
git-provider-contract.ts IGitProvider, GitProviderStatusOptions re-export 104
filesystem-provider-contract.ts IFilesystemProvider, FileStat, FileReadResult, FileUploadSession, TerminalArtifactAccessOptions 75
types.ts (barrel) IProviderRegistry + re-exports of everything above 26

Names are the concrete domain concept per AGENTS.md — no helpers/common/misc. No max-lines disable and no ratchet-baseline entry was added (config/max-lines-baseline.txt is untouched); every file is comfortably under the cap on its own.

2. Zero caller churn. types.ts re-exports every symbol it exported before, so all 39 files importing from providers/types are unmodified. Diff is 5 files total.

3. Promoted onWriteUnavailable onto IPtyProvider as an optional member, with the "only respawnable endpoints implement it" rationale moved from the call-site comment onto the declaration — and deleted the cast in src/main/ipc/pty.ts. The daemon adapter's onWriteUnavailable(callback: (payload: { id: string }) => void): () => void is now structurally checked against the contract instead of against a locally re-typed assumption.

Merge order

  1. fix(daemon): respawn on PTY write dropped to a dead daemon socket (STA-2373) #10065 lands first (it owns the STA-2373 fix and the call site this PR edits).
  2. Then retarget this PR to main and 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, including check:max-lines-ratchet.
  • vitest over src/main/providers, src/main/daemon, src/main/ipc/pty-management.test.ts — 1616 passed, 5 skipped, 0 failed.
  • src/main/ipc/pty.test.ts has 7 pre-existing failures in its Windows UTF-8 code page block 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.ts is type re-exports (erased), and the pty.ts edit removes a cast whose runtime value was already localProvider.

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.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/pty-provider-types-split branch from 90da3c3 to c617570 Compare July 26, 2026 22:54
@brennanb2025
brennanb2025 changed the base branch from brennanb2025/sta2373-respawn-deadsock to main July 26, 2026 22:54
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 666f469f-5562-4466-8799-2fd13e10cd40

📥 Commits

Reviewing files that changed from the base of the PR and between 39a200d and 58ec249.

📒 Files selected for processing (5)
  • src/main/ipc/pty.ts
  • src/main/providers/filesystem-provider-contract.ts
  • src/main/providers/git-provider-contract.ts
  • src/main/providers/pty-provider-contract.ts
  • src/main/providers/types.ts

📝 Walkthrough

Walkthrough

Provider 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the refactor and validation, but it omits required template sections like Screenshots, AI Review Report, Security Audit, and Notes. Add the missing template sections, including Screenshots or No visual change, AI Review Report, Security Audit, and Notes, and format Testing as the repo expects.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: splitting provider contract types to remove the onWriteUnavailable cast.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…ider-types-split

# Conflicts:
#	src/main/providers/types.ts
@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

Splits src/main/providers/types.ts (previously near the 300-line max-lines cap) into three per-domain contract files (pty-provider-contract.ts, git-provider-contract.ts, filesystem-provider-contract.ts), turning types.ts into a 26-line re-export barrel that keeps all 39 existing import paths intact. As a direct consequence, onWriteUnavailable is properly promoted onto IPtyProvider and the structural cast in pty.ts is deleted.

  • Type-only refactor: all new content is moved verbatim from types.ts; no interface members are added, removed, or changed except the addition of onWriteUnavailable to IPtyProvider.
  • No caller churn: the barrel re-exports every symbol that types.ts previously declared, so downstream consumers are untouched.
  • Cast elimination: localProvider.onWriteUnavailable?. now resolves against the interface directly, removing the per-call-site redeclaration that could silently drift from the daemon adapter's real signature.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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
Loading

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

@brennanb2025
brennanb2025 merged commit d94ed85 into main Jul 30, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
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