2.0 KiB
2.0 KiB
Smartrequest Refactoring Plan
Command to reread CLAUDE.md: cat /home/philkunz/.claude/CLAUDE.md
Objective
Refactor smartrequest to use native fetch-like API with a streamlined core that supports unix sockets and keep-alive.
Architecture Overview
- Rename
legacy/
tocore/
and remove "smartrequest." prefix from filenames - Create a modern Response class similar to fetch API
- Use core as foundation for modern API, not as legacy adapter
- Maintain unix socket and keep-alive support
Task Checklist
- Reread /home/philkunz/.claude/CLAUDE.md
- Create ts/core directory structure with request.ts, types.ts, and plugins.ts
- Migrate core request logic from legacy to core/request.ts
- Create modern Response class with fetch-like API
- Update modern API to use new core module
- Create legacy adapter for backward compatibility
- Update exports in ts/index.ts
- Run tests and fix any issues
- Clean up old legacy files
Implementation Details
Core Module Structure
ts/core/
├── request.ts # Core HTTP/HTTPS request logic with unix socket support
├── types.ts # Core interfaces and types
├── plugins.ts # Dependencies (http, https, agentkeepalive, etc.)
└── response.ts # Modern Response class
Response Class API
The new Response class will provide fetch-like methods:
json()
: Promise - Parse response as JSONtext()
: Promise - Get response as textarrayBuffer()
: Promise - Get response as ArrayBufferstream()
: ReadableStream - Get response as streamok
: boolean - Status is 2xxstatus
: number - HTTP status codestatusText
: string - HTTP status textheaders
: Headers - Response headers
Migration Strategy
- Move core request logic without breaking changes
- Create Response wrapper that provides modern API
- Update SmartRequestClient to use new core
- Add legacy adapter for backward compatibility
- Ensure all tests pass throughout migration