Skip to content

Conversation

@ammario
Copy link
Member

@ammario ammario commented Oct 5, 2025

Problem

When retrying/resuming after stream interruption, the component wasn't passing provider options (specifically for Anthropic's 1M context window). This caused retries to fall back to the default 200k token limit, triggering "prompt too long" errors.

Additionally, the logic for building was duplicated between and , creating a maintenance burden and risk of divergence.

Solution

1. Created hook

  • Single source of truth for constructing
  • Reads all user preferences: , , ,
  • Returns complete options object with provider settings
  • Uses which has listener mode → changes propagate automatically to all components

2. Simplified IPC signature

  • Changed: resumeStream(workspaceId, model, options?)resumeStream(workspaceId, options)
  • Model is now part of the options object (not a separate parameter)
  • Eliminates redundancy

3. Updated components

  • ChatInput: Uses hook instead of inline options construction
  • RetryBarrier: Uses same hook, removed model prop, removed duplicated code
  • AIView: No longer passes model prop to RetryBarrier

Benefits

Guaranteed parity - Physically impossible for retry/resume to use different options than send
Current preferences - Retry always uses user's latest settings, not historical ones
Less code - Eliminated ~30 lines of duplication
Simpler props - RetryBarrier interface is cleaner
Easy maintenance - Changes to option logic happen in one place
Type-safe - All passing type checks

Testing

  • ✅ TypeScript compilation passes
  • User can now change 1M context toggle, thinking level, or model while RetryBarrier is showing, and retry will use the new settings
  • Fixes "prompt too long" errors when using 1M context with Anthropic models

Generated with cmux

@ammario ammario force-pushed the refactor-utils-organization branch from ed26bbf to a92be13 Compare October 5, 2025 21:34
ammario added 12 commits October 5, 2025 16:46
- Move asyncMutex.ts and mutexMap.ts to utils/concurrency/
- No functional changes, just organizational improvement

_Generated with `cmux`_
- Move workspaceValidation.ts and test to utils/validation/
- Tests remain co-located with implementation

_Generated with `cmux`_
- Move keybinds.ts, modeUtils.ts and tests to utils/ui/
- Update modeUtils.ts imports for new location

_Generated with `cmux`_
- Move cacheStrategy.ts and providerOptions.ts to utils/ai/
- Groups AI model configuration and optimization strategies

_Generated with `cmux`_
- Move messageUtils, modelMessageTransform, StreamingMessageAggregator to utils/messages/
- Keep all tests co-located with implementations
- Groups message transformation and aggregation logic

_Generated with `cmux`_
- Move toolDefinitions, toolPolicy, tools to utils/tools/
- Keep all tests co-located
- Groups tool definitions, policies, and instantiation logic

_Generated with `cmux`_
- Move tokenizer, tokenStatsCalculator, TokenStatsWorker, modelStats to utils/tokens/
- Move models.json to tokens/ directory
- Update tokenizer.ts import to reference tools/toolDefinitions
- Keep all tests co-located
- Groups token counting, statistics, and model metadata

_Generated with `cmux`_
- Update imports in 21 files across components, services, and types
- All imports now point to domain-specific subdirectories:
  - concurrency/ (asyncMutex, mutexMap)
  - validation/ (workspaceValidation)
  - ui/ (keybinds, modeUtils)
  - ai/ (cacheStrategy, providerOptions)
  - messages/ (messageUtils, modelMessageTransform, StreamingMessageAggregator)
  - tools/ (toolDefinitions, toolPolicy, tools)
  - tokens/ (tokenizer, tokenStatsCalculator, TokenStatsWorker, modelStats)
- No functional changes, only import path updates

_Generated with `cmux`_
- Add @/* path alias to tsconfig.json and vite.config.ts
- Convert all relative imports (../, ../../) to absolute imports (@/)
- Update tsconfig.main.json to include necessary directories
- Exclude web worker files from main process type checking

Benefits:
- No more import path hell with ../../../
- Clearer, more maintainable imports
- Easier refactoring and file moves
- Consistent import style across codebase

_Generated with `cmux`_
_Generated with `cmux`_
The resolve.alias config was lost during a git checkout. Re-adding it so
Vite/Rollup can resolve @/ imports during build.

_Generated with `cmux`_
The added includes caused dist/main.js to output as dist/src/main.js,
breaking electron-builder. The original config only includes main.ts
and constants, which TypeScript then follows to include dependencies.

_Generated with `cmux`_
@ammario ammario force-pushed the refactor-utils-organization branch from b5a94be to d1020e3 Compare October 5, 2025 21:46
Remove PROPOSAL file and JS compilation artifacts that shouldn't be in the PR.

_Generated with `cmux`_
@ammario ammario merged commit 8bed8c9 into main Oct 5, 2025
6 checks passed
@ammario ammario deleted the refactor-utils-organization branch October 5, 2025 21:53
ammario added a commit that referenced this pull request Oct 5, 2025
## Summary

Converts all relative imports (`../`, `../../`, etc.) to absolute
imports using the `@/` alias across the entire codebase.

## Changes

Systematically converted imports for all major directories:
- `../types/` → `@/types/`
- `../utils/` → `@/utils/`
- `../services/` → `@/services/`
- `../components/` → `@/components/`
- `../contexts/` → `@/contexts/`
- `../constants/` → `@/constants/`
- `../hooks/` → `@/hooks/`
- `../styles/` → `@/styles/`

**Files affected:** 22 files
**Net change:** 0 lines (86 insertions, 86 deletions - pure refactor)

## Benefits

- **No more import path hell**: Say goodbye to `../../../types/message`
- **Easier refactoring**: Moving files doesn't break dozens of import
statements
- **Consistency**: All imports follow the same `@/` pattern
- **Clarity**: Import paths are clearer and easier to understand
- **Maintainability**: New developers can find imports more easily

## Example

**Before:**
```typescript
import type { CmuxMessage } from "../../../types/message";
import { StreamManager } from "../../services/streamManager";
import { keybinds } from "../utils/keybinds";
```

**After:**
```typescript
import type { CmuxMessage } from "@/types/message";
import { StreamManager } from "@/services/streamManager";
import { keybinds } from "@/utils/keybinds";
```

## Testing

- ✅ `bun typecheck` passes
- ✅ All imports resolve correctly
- No functional changes, only import path updates

## Notes

This builds on PR #33 which:
- Reorganized utils/ into domain-specific subdirectories
- Added the @/ path alias configuration

_Generated with `cmux`_
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