mirror of
https://github.com/carey314/mio-plugin-clipper.git
synced 2026-08-09 23:34:32 +00:00
Quick AI actions on clipboard or selected text. Four actions: - 翻译 (中/英/日) - 总结 (3-bullet Chinese) - 改语气 (正式/口语/友好/严谨) - 邮件回复 Powered by DeepSeek with Server-Sent Events streaming for typewriter feedback (~600ms first byte). Two source modes: clipboard (no permission) and selected-text via NSAccessibility (graceful fallback to clipboard + permission banner if denied). Five-state UI machine: idle → input → loading (cancellable) → result → missing-config. Last 20 actions persisted to UserDefaults. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
84 lines
2.9 KiB
Markdown
84 lines
2.9 KiB
Markdown
# 划词侠 — AI Text Actions for MioIsland
|
||
|
||
Quick AI actions on any clipboard or selected text. Translate,
|
||
summarize, rewrite tone, or draft an email reply — all powered by
|
||
DeepSeek with streaming output for instant feedback.
|
||
|
||
## Features
|
||
|
||
- **One-shot actions** — 翻译(中/英/日) / 总结 / 改语气(正式/口语/友好/严谨) / 邮件回复.
|
||
- **Streaming output** — typewriter effect via Server-Sent Events.
|
||
Long replies start showing within ~600ms instead of after the
|
||
full completion lands.
|
||
- **Two text sources** — clipboard (works without permissions) or
|
||
selected text via NSAccessibility (requires the user to grant
|
||
Accessibility permission). Falls back gracefully with a banner
|
||
explaining the System Settings → Privacy step.
|
||
- **History** — last 20 actions persisted in UserDefaults; tap to
|
||
re-copy the result without re-running the model.
|
||
- **Five-state UI** — idle, input, loading (cancellable), result,
|
||
missing-config. Each transition is animated.
|
||
|
||
## Configuration
|
||
|
||
Drop your DeepSeek API key into
|
||
`~/.config/codeisland/clipper-config.json`:
|
||
|
||
```json
|
||
{
|
||
"deepseek_api_key": "sk-...",
|
||
"default_translate_target": "zh"
|
||
}
|
||
```
|
||
|
||
Get a key at https://platform.deepseek.com/ — DeepSeek's pricing is
|
||
roughly **¥0.001/1k tokens for input, ¥0.002/1k for output** (~1/100
|
||
of GPT-4), so a typical 划词侠 session costs less than a fraction of
|
||
a cent.
|
||
|
||
Without the file, the panel shows a friendly missing-config state
|
||
with the file path one click away on the clipboard.
|
||
|
||
## Requirements
|
||
|
||
- macOS 15.0+
|
||
- MioIsland v2.2.0+
|
||
- DeepSeek API key (for actual AI calls; UI works without it)
|
||
- Optional: Accessibility permission (for selected-text source)
|
||
|
||
## Building from source
|
||
|
||
```bash
|
||
./build.sh # produce build/clipper.bundle + build/clipper.zip
|
||
./build.sh install # build + copy to ~/.config/codeisland/plugins/
|
||
```
|
||
|
||
Restart MioIsland (Cmd+Q + reopen) to load the new build.
|
||
|
||
## Structure
|
||
|
||
```
|
||
Sources/
|
||
├── MioPlugin.swift # protocol (verbatim from host)
|
||
├── ClipperPlugin.swift # principal class
|
||
├── ui/
|
||
│ ├── ExpandedView.swift # 380×520 panel, state machine
|
||
│ ├── ActionGrid.swift # 2×2 action buttons + sub-options
|
||
│ ├── SourcePreview.swift # truncated input preview
|
||
│ ├── ResultView.swift # scrollable streaming output
|
||
│ ├── PermissionBanner.swift # AX permission hint
|
||
│ └── Theme.swift # design tokens
|
||
├── data/
|
||
│ ├── DeepSeekClient.swift # actor + URLSession + SSE streaming
|
||
│ ├── TextSource.swift # clipboard / selection providers
|
||
│ └── ClipperConfig.swift # config loader
|
||
└── engine/
|
||
├── ClipperStore.swift # @MainActor state machine + history
|
||
├── HistoryStore.swift # UserDefaults, last 20 actions
|
||
└── ClipperDebugLog.swift # /tmp/clipper-plugin.log
|
||
```
|
||
|
||
## License
|
||
|
||
MIT — see [LICENSE](LICENSE).
|