-
Notifications
You must be signed in to change notification settings - Fork 0
feat(darwinkit): add interactive CLI tool for DarwinKit #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
75acc64
refactor(macos): use Neighbor type from darwinkit, remove local defin…
genesiscz d6ae2c5
docs: add DarwinKit CLI tool design and implementation plan
genesiscz cc9d855
feat(macos): add auth util wrappers
genesiscz 2802eec
feat(macos): add icloud util wrappers
genesiscz 0e3edb4
feat(macos): add system util wrapper
genesiscz 6068d30
feat(darwinkit): add output formatter
genesiscz 7826e16
feat(darwinkit): add command registry
genesiscz 6d72ba3
feat(darwinkit): add interactive mode
genesiscz 1322995
feat(darwinkit): add CLI entry point with interactive + commander modes
genesiscz fb638d2
fix(darwinkit): resolve TS warnings in interactive.ts and index.ts
genesiscz f045862
fix(darwinkit): address PR #104 review feedback
genesiscz 302228a
fix(darwinkit): fix string[] comma splitting and --format flag
genesiscz 4f5e11e
fix(darwinkit): address PR #104 review feedback (round 2)
genesiscz cc5de05
fix: resolve pre-existing biome lint errors blocking CI
genesiscz 0d4d3f0
fix(darwinkit): check Swift exit code in vision test + fix biome-igno…
genesiscz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # DarwinKit CLI Tool — Design Document | ||
|
|
||
| ## Goal | ||
|
|
||
| Create an interactive CLI tool (`tools darwinkit`) that exposes the full DarwinKit API surface (NLP, Vision, TTS, Auth, iCloud, System) through both an interactive clack menu and flat CLI subcommands. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| @genesiscz/darwinkit (package) | ||
| ↓ | ||
| src/utils/macos/*.ts (util wrappers — thin layer over package) | ||
| ↓ | ||
| src/darwinkit/lib/commands.ts (registry map — single source of truth) | ||
| ↓ | ||
| src/darwinkit/index.ts (entry — interactive or CLI mode) | ||
| ``` | ||
|
|
||
| The CLI tool never imports from `@genesiscz/darwinkit` directly — it only calls `src/utils/macos/` utils. Phase 1 expands utils to cover iCloud/auth/system (currently missing), Phase 2 builds the CLI. | ||
|
|
||
| ## Phase 1: Expand Utils | ||
|
|
||
| ### New files in `src/utils/macos/`: | ||
|
|
||
| **`auth.ts`** — Biometric authentication | ||
| - `checkBiometry()` → returns `{ available, biometry_type }` | ||
| - `authenticate(reason?)` → returns `{ success }` | ||
|
|
||
| **`system.ts`** — System capabilities | ||
| - `getCapabilities()` → returns `{ version, os, arch, methods }` | ||
|
|
||
| **`icloud.ts`** — iCloud Drive operations | ||
| - `icloudStatus()` → returns `{ available, container_url }` | ||
| - `icloudRead(path)` → returns `{ content }` | ||
| - `icloudWrite(path, content)` → returns `{ ok }` | ||
| - `icloudWriteBytes(path, data)` → returns `{ ok }` | ||
| - `icloudDelete(path)` → returns `{ ok }` | ||
| - `icloudMove(source, destination)` → returns `{ ok }` | ||
| - `icloudCopy(source, destination)` → returns `{ ok }` | ||
| - `icloudList(path)` → returns `ICloudDirEntry[]` | ||
| - `icloudMkdir(path)` → returns `{ ok }` | ||
| - `icloudStartMonitoring()` / `icloudStopMonitoring()` | ||
|
|
||
| Update `index.ts` exports and `types.ts` re-exports for new package types. | ||
|
|
||
| ## Phase 2: CLI Tool | ||
|
|
||
| ### Command Registry (`src/darwinkit/lib/commands.ts`) | ||
|
|
||
| Single source of truth — drives interactive menu, CLI dispatch, help generation, and param validation. | ||
|
|
||
| ```typescript | ||
| interface ParamDef { | ||
| name: string; | ||
| type: "string" | "number" | "boolean" | "string[]"; | ||
| required: boolean; | ||
| description: string; | ||
| default?: unknown; | ||
| } | ||
|
|
||
| interface CommandDef { | ||
| name: string; // "detect-language" (CLI subcommand) | ||
| group: string; // "nlp" (interactive menu grouping) | ||
| description: string; // shown in help + interactive | ||
| params: ParamDef[]; // drives --help, validation, interactive prompts | ||
| run: (args: Record<string, unknown>) => Promise<unknown>; | ||
| } | ||
| ``` | ||
|
|
||
| ### Groups & Commands (~35 total) | ||
|
|
||
| **nlp** (11): detect-language, sentiment, tag, entities, lemmatize, keywords, embed, distance, similar, relevance, neighbors | ||
| **vision** (1): ocr | ||
| **text-analysis** (6): rank, batch-sentiment, group-by-language, batch-entities, deduplicate, cluster | ||
| **classification** (3): classify, classify-batch, group-by-category | ||
| **tts** (2): speak, list-voices | ||
| **auth** (2): check-biometry, authenticate | ||
| **icloud** (10): status, read, write, write-bytes, delete, move, copy, list, mkdir, monitor | ||
| **system** (1): capabilities | ||
|
|
||
| ### Output Formatting (`src/darwinkit/lib/format.ts`) | ||
|
|
||
| `--format json|pretty|raw` | ||
|
|
||
| - **json**: `JSON.stringify(result, null, 2)` — for piping | ||
| - **pretty**: Colored human-readable (tables for arrays, key-value for objects) | ||
| - **raw**: Just the value (string result → string, arrays → newline-separated) | ||
| - **Default**: pretty if TTY, json if piped | ||
|
|
||
| ### Interactive Flow (`src/darwinkit/lib/interactive.ts`) | ||
|
|
||
| Progressive prompting with clack: | ||
|
|
||
| 1. `tools darwinkit` (TTY) → DarwinKit logo → group select → command select → param prompts → execute | ||
| 2. `tools darwinkit` (non-TTY) → full help listing | ||
| 3. `tools darwinkit <cmd>` (TTY, missing params) → shows usage line first → clack prompts for missing params | ||
| 4. `tools darwinkit <cmd> --all-params` → just execute, no prompting | ||
|
|
||
| ### File Structure | ||
|
|
||
| ``` | ||
| src/darwinkit/ | ||
| ├── index.ts # entry: interactive vs CLI dispatch | ||
| ├── lib/ | ||
| │ ├── commands.ts # registry map (single source of truth) | ||
| │ ├── format.ts # json/pretty/raw formatter | ||
| │ └── interactive.ts # clack prompts for interactive mode | ||
| ``` | ||
|
|
||
| ### Example Usage | ||
|
|
||
| ```bash | ||
| # Interactive | ||
| tools darwinkit | ||
|
|
||
| # CLI - flat subcommands | ||
| tools darwinkit detect-language "Bonjour le monde" | ||
| tools darwinkit sentiment "I love this product" | ||
| tools darwinkit ocr ~/screenshot.png --languages en-US,cs | ||
| tools darwinkit speak "Hello world" --voice Samantha --rate 200 | ||
| tools darwinkit icloud-list /Documents | ||
| tools darwinkit classify "fix null pointer" --categories "bug fix,feature,refactor" | ||
|
|
||
| # Output control | ||
| tools darwinkit sentiment "Great!" --format json | ||
| tools darwinkit sentiment "Great!" --format raw # just: 0.95 | ||
|
|
||
| # Piped | ||
| echo "Hello world" | tools darwinkit detect-language --format json | jq .language | ||
|
|
||
| # Help | ||
| tools darwinkit --help | ||
| tools darwinkit ocr --help | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The piped example advertises stdin support that the CLI does not implement.
detect-languagestill requires the positionaltextargument. In the current implementation, this invocation prints subcommand help instead of consuming piped stdin, so the example will fail as written.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents