Implement the following plan: Plan: Fix Issue #37 — typetext autocorrect interference…
- User
Implement the following plan:
Plan: Fix Issue #37 — type_text autocorrect interference
Context
GitHub Issue #37:
type_text가 CGEvent로 문자별 키보드 이벤트를 보내면 iOS 시뮬레이터의 autocorrect/autocomplete가 텍스트를 손상시킴."Hello Baepsae!"입력 시"Aǎ"같은 결과가 나옴.해결 방법:
method파라미터를 추가하여 두 가지 입력 방식 제공:"paste": NSPasteboard + Cmd+V로 클립보드 붙여넣기 (autocorrect 우회)"keyboard": 기존 문자별 입력 (IndigoHID/CGEvent)"auto"(기본값): 시뮬레이터→paste, macOS앱→keyboard
Changes
1. TS Layer —
src/tools/ui.tsTypeParams 타입 (line ~45):
method필드 추가typescripttype TypeParams = { text?: string; stdinText?: string; file?: string; method?: "auto" | "paste" | "keyboard"; };typeSchema (line ~113):
methodZod 스키마 추가typescriptconst typeSchema = { text: z.string().optional().describe("Text argument"), stdinText: z.string().optional().describe("Text piped to stdin mode"), file: z.string().optional().describe("Path for file input"), method: z.enum(["auto", "paste", "keyboard"]).optional().describe( "Input method: 'paste' uses clipboard to avoid iOS autocorrect, 'keyboard' types character-by-character. Default 'auto' (paste for simulators, keyboard for macOS apps)." ), };buildTypeArgs (line ~251):
--method인자 전달typescriptif (params.method !== undefined) { args.push("--method", params.method); }tool description (line ~350): 설명 업데이트하여 method 파라미터 언급
2. Native Layer —
native/Sources/Commands/UICommands.swifthandleType (line ~309): paste 방식 분기 추가
Assistant
Issue #37 수정을 시작하겠습니다. 먼저 관련 파일들을 읽어보겠습니다.
Assistant
★ Insight ─────────────────────────────────────handleType(UICommands.swift:309)는resolveInputBackend를 통해 IndigoHID(시뮬레이터) 또는 CGEvent(macOS앱)을 선택합니다. 이 두 방식 모두 문자별 키보드 이벤트를 보내기 때문에 iOS의 autocorrect/autocomplete가 간섭합니다.- 해결 방법: NSPasteboard로 텍스트를 복사하고 Cmd+V로 붙여넣으면 autocorrect를 완전히 우회할 수 있습니다.
─────────────────────────────────────────────────
이제
sendKeyCombo와 클립보드 패턴을 확인하겠습니다.Assistant
sendKeyCombo함수와 unit test 패턴을 확인했습니다. 이제 unit test 파일의 끝과 real test 파일의 관련 부분도 확인하겠습니다.Assistant
이제 unit test 파일의 끝 부분을 확인해서 새 테스트를 어디에 추가할지 정하겠습니다.
Assistant
모든 필요한 컨텍스트를 확인했습니다. 이제 3개의 레이어(TS, Swift, Tests)를 병렬로 수정하겠습니다.
★ Insight ─────────────────────────────────────- iOS 시뮬레이터에서
CGEvent기반 문자별 입력은 macOS가 키 이벤트를 iOS 시뮬레이터에 전달할 때 autocorrect/autocomplete 엔진이 개입하여 텍스트를 왜곡합니다. NSPasteboard+Cmd+V방식은 이미 완성된 텍스트를 클립보드 경유로 직접 붙여넣으므로, iOS의 입력 보정 로직을 완전히 우회합니다.auto기본값으로 시뮬레이터에서는 paste, macOS 앱에서는 keyboard를 선택하는 것은 기존 동작의 하위 호환성을 유지하면서 시뮬레이터 사용자의 주요 문제를 자동 해결합니다.─────────────────────────────────────────────────
1. TS Layer 수정
- iOS 시뮬레이터에서
Assistant
2. Swift Native Layer 수정
Assistant
3. 테스트 추가
Assistant
이제 real test에 paste/keyboard 방식 테스트를 추가합니다.
Assistant
4. 빌드 및 테스트
Assistant
빌드 성공. 이제 테스트를 실행합니다.
Assistant
Contract tests 16개 모두 통과. 이제 unit tests를 실행합니다.
Assistant
모든 테스트 통과 — contract 16개 + unit 89개 (기존 86 + 신규 3개).
★ Insight ─────────────────────────────────────- Unit test 패턴: 이 프로젝트의 unit test는 MCP SDK 클라이언트를 통해 tool을 호출하고, dry-run 모드(시뮬레이터 없이)에서 네이티브 바이너리의 커맨드라인 인자가 올바르게 구성되는지 stdout 출력으로 검증합니다.
assert.match(text, /--method/)같은 패턴 매칭이 핵심입니다. pasteText설계: 클립보드 저장→교체→Cmd+V→0.15초 대기→복원 순서가 중요합니다. 대기 없이 즉시 복원하면 paste 이벤트가 아직 처리되기 전에 클립보드가 원복되어 원본 텍스트가 붙여넣어질 수 있습니다.─────────────────────────────────────────────────
변경 요약
파일 변경 내용 src/tools/ui.tsTypeParams에method필드 추가,typeSchema에 Zod 스키마 추가,buildTypeArgs에서--method인자 전달, tool description 업데이트native/Sources/Commands/UICommands.swifthandleType에서--method옵션 파싱 및 paste/keyboard 분기 로직,pasteText()함수 추가 (NSPasteboard + Cmd+V + 클립보드 복원)tests/unit.test.mjsmethod=paste,method=keyboard, method 미지정 시 3개 테스트 추가- Unit test 패턴: 이 프로젝트의 unit test는 MCP SDK 클라이언트를 통해 tool을 호출하고, dry-run 모드(시뮬레이터 없이)에서 네이티브 바이너리의 커맨드라인 인자가 올바르게 구성되는지 stdout 출력으로 검증합니다.
- User
commit and push
Assistant
커밋 및 푸시 완료.
6d2d5b7—feat: add method parameter to type_text for clipboard-based input (#37)