Skip to content

refactor: eliminate Instance.state() — convert 16 modules#20

Merged
e6qu merged 1 commit intodevfrom
refactor/effectify-trivial
Mar 18, 2026
Merged

refactor: eliminate Instance.state() — convert 16 modules#20
e6qu merged 1 commit intodevfrom
refactor/effectify-trivial

Conversation

@e6qu
Copy link
Copy Markdown
Owner

@e6qu e6qu commented Mar 18, 2026

Summary

  • Convert all 16 Instance.state() modules to module-level Map<directory, state> with registerDisposer() for lifecycle cleanup
  • Delete State module (src/project/state.ts) and remove state() method from Instance
  • Delete Scheduler module (src/scheduler/index.ts) — replaced by inline setInterval in bootstrap
  • Register 4 new Effect services in instances.ts: EnvService, BusService, SessionStatusService, InstructionService
  • 11 modules use registerDisposer directly (Config, TuiConfig, Plugin, ToolRegistry, Provider, Agent, Command, Prompt, PTY, LSP, MCP) — can't be in instances.ts due to circular import constraints

Modules converted (by stage)

Stage Modules
1 — Trivial Env, SessionStatus, Instruction
2 — Bus + Scheduler Bus (converted), Scheduler (deleted)
3 — Config Config, TuiConfig
4 — Plugin + Registry Plugin, ToolRegistry
5 — Provider + Agent Provider, Agent
6 — Command + Prompt Command, Prompt
7 — Lifecycle PTY, LSP, MCP
8 — Cleanup Remove Instance.state(), delete State module

Test plan

  • bun typecheck — 0 errors across all 13 packages
  • bun test — 1423 tests pass, 0 failures
  • grep -rn 'Instance\.state(' packages/opencode/src/ — 0 results
  • Dispose logic preserved for lifecycle services (PTY kills processes, LSP shuts down clients, MCP kills descendants)

…evel state maps

Replace all Instance.state() usage with module-level Map<directory, state> plus
registerDisposer() for cleanup. Delete State module, Scheduler module (replaced
by inline timer in bootstrap), and their tests.

Services registered in instances.ts (simple, no circular deps):
EnvService, BusService, SessionStatusService, InstructionService

Services using registerDisposer (complex import graphs):
Config, TuiConfig, Plugin, ToolRegistry, Provider, Agent, Command,
Prompt, PTY, LSP, MCP

Verification: 0 errors (bun typecheck), 1423 tests pass, 0 Instance.state() remaining.
@e6qu e6qu merged commit 5d284f0 into dev Mar 18, 2026
1 check passed
@e6qu e6qu deleted the refactor/effectify-trivial branch March 18, 2026 08:11
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