wraptc 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wraptc might be problematic. Click here for more details.

package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial release with automated CI/CD pipeline
12
+ - GitHub Actions workflow for publishing to npm
13
+ - Semantic release configuration
14
+ - Support for three packages: core, cli, and mcp-server
15
+
16
+ [Unreleased]: https://github.com/briansunter/wraptc/compare/v0.1.0...HEAD
package/README.md ADDED
@@ -0,0 +1,516 @@
1
+ # wraptc
2
+
3
+ A unified CLI wrapper for multiple coding AI agents (Gemini CLI, OpenCode, Qwen Code, Codex CLI) with intelligent routing, credit tracking, and automatic fallback.
4
+
5
+ ## Features
6
+
7
+ - **Multi-Provider Support**: Works with Gemini CLI, OpenCode, Qwen Code CLI, Codex CLI, and custom providers
8
+ - **Intelligent Routing**: Automatic provider selection based on priority, availability, and credit limits
9
+ - **Credit Tracking**: Per-provider usage tracking and automatic fallback when limits are reached
10
+ - **Error Threshold Blacklisting**: Automatic provider blacklisting after consecutive failures (configurable per provider)
11
+ - **Tokens Saved Tracking**: Estimates Claude tokens saved by delegating tasks to free-tier providers
12
+ - **Streaming Support**: Real-time streaming of responses in JSON or text format
13
+ - **Unified API**: Single, consistent JSON-first interface across all providers
14
+ - **MCP Server**: Exposes functionality as an MCP server for Claude Desktop and other MCP clients
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ # Clone and build
20
+ git clone https://github.com/briansunter/wraptc.git
21
+ cd wraptc
22
+ bun install
23
+ bun run build
24
+
25
+ # Install globally
26
+ npm link
27
+ # or
28
+ bun link
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ### Basic Usage
34
+
35
+ ```bash
36
+ # Simple request using best available provider
37
+ wraptc ask -p "Write a TypeScript function that reverses a string"
38
+
39
+ # Specify a provider
40
+ wraptc ask -p "Explain this code" --provider gemini
41
+
42
+ # Include file context
43
+ wraptc ask -p "Refactor this module" -f src/utils.ts -f src/main.ts
44
+
45
+ # Stream response
46
+ wraptc ask -p "Create unit tests" --stream --output jsonl
47
+ ```
48
+
49
+ ### Output Formats
50
+
51
+ **JSON (default)**:
52
+
53
+ ```json
54
+ {
55
+ "provider": "qwen-code",
56
+ "text": "function reverseString(str: string): string {\n return str.split('').reverse().join('');\n}",
57
+ "usage": {
58
+ "inputTokens": 45,
59
+ "outputTokens": 23
60
+ },
61
+ "meta": {
62
+ "elapsedMs": 1250
63
+ }
64
+ }
65
+ ```
66
+
67
+ **Text**:
68
+
69
+ ```bash
70
+ wraptc ask -p "Write a function" --output text
71
+ ```
72
+
73
+ ## Configuration
74
+
75
+ wraptc uses a layered configuration system:
76
+
77
+ 1. Built-in defaults
78
+ 2. System config: `/etc/wraptc/config.json`
79
+ 3. User config: `~/.config/wraptc/config.json`
80
+ 4. Project config: `./.config/wraptc/config.json`
81
+ 5. Environment variables: `WTC_*`
82
+ 6. CLI flags
83
+
84
+ ### Example Configuration
85
+
86
+ Create `~/.config/wraptc/config.json`:
87
+
88
+ ```json
89
+ {
90
+ "routing": {
91
+ "defaultOrder": ["gemini", "opencode", "qwen-code", "codex"],
92
+ "perModeOverride": {
93
+ "test": ["codex", "gemini"],
94
+ "explain": ["gemini", "qwen-code"]
95
+ }
96
+ },
97
+ "providers": {
98
+ "gemini": {
99
+ "binary": "gemini",
100
+ "args": [],
101
+ "jsonMode": "flag",
102
+ "jsonFlag": "--output-format",
103
+ "streamingMode": "jsonl",
104
+ "capabilities": ["generate", "edit", "explain", "test"]
105
+ },
106
+ "opencode": {
107
+ "binary": "opencode",
108
+ "args": [],
109
+ "jsonMode": "flag",
110
+ "jsonFlag": "-f",
111
+ "streamingMode": "none",
112
+ "capabilities": ["generate", "edit", "explain", "test", "refactor"]
113
+ },
114
+ "qwen-code": {
115
+ "binary": "qwen",
116
+ "args": [],
117
+ "jsonMode": "flag",
118
+ "jsonFlag": "--json",
119
+ "streamingMode": "jsonl",
120
+ "capabilities": ["generate", "edit", "explain", "test"]
121
+ },
122
+ "codex": {
123
+ "binary": "cdx",
124
+ "args": [],
125
+ "jsonMode": "none",
126
+ "streamingMode": "line",
127
+ "capabilities": ["generate", "edit", "test"]
128
+ }
129
+ },
130
+ "credits": {
131
+ "providers": {
132
+ "gemini": {
133
+ "dailyRequestLimit": 1000,
134
+ "resetHourUtc": 0
135
+ },
136
+ "opencode": {
137
+ "dailyRequestLimit": 1000,
138
+ "resetHourUtc": 0
139
+ },
140
+ "qwen-code": {
141
+ "dailyRequestLimit": 2000,
142
+ "resetHourUtc": 0
143
+ },
144
+ "codex": {
145
+ "plan": "chatgpt_plus"
146
+ }
147
+ }
148
+ }
149
+ }
150
+ ```
151
+
152
+ ### Adding Custom Providers
153
+
154
+ You can add new providers via configuration:
155
+
156
+ ```json
157
+ {
158
+ "providers": {
159
+ "my-custom-llm": {
160
+ "binary": "my-llm-cli",
161
+ "argsTemplate": ["--model", "gpt-4", "--prompt", "{{prompt}}"],
162
+ "streamingMode": "line",
163
+ "capabilities": ["generate", "explain"]
164
+ }
165
+ },
166
+ "routing": {
167
+ "defaultOrder": ["my-custom-llm", "qwen-code", "gemini"]
168
+ }
169
+ }
170
+ ```
171
+
172
+ ### Environment Variables
173
+
174
+ Override config with environment variables:
175
+
176
+ ```bash
177
+ WRAPTC_ROUTING__DEFAULT_ORDER='["gemini","codex"]' wraptc ask -p "Hello"
178
+ WRAPTC_REQUEST__PROVIDER="gemini" wraptc ask -p "Hello"
179
+ ```
180
+
181
+ ## CLI Commands
182
+
183
+ ### `wraptc ask`
184
+
185
+ Send a coding request to the best available provider.
186
+
187
+ ```bash
188
+ wraptc ask -p "Your prompt" [options]
189
+
190
+ Options:
191
+ -p, --prompt <prompt> The prompt to send
192
+ --provider <provider> Override provider selection
193
+ --mode <mode> Request mode: generate, edit, explain, test
194
+ --language <language> Language hint
195
+ -f, --file <files...> Include file context
196
+ --temperature <temp> Temperature (0-2)
197
+ --stream Enable streaming
198
+ --output <format> Output format: json, jsonl, text
199
+ --dry-run Show which provider would be used
200
+ --config <path> Config file path
201
+ ```
202
+
203
+ ### `wraptc providers`
204
+
205
+ List all available providers and their status.
206
+
207
+ ```bash
208
+ wraptc providers
209
+ ```
210
+
211
+ ### `wraptc reset`
212
+
213
+ Reset provider state (counters, error tracking).
214
+
215
+ ```bash
216
+ wraptc reset --provider qwen-code # Reset specific provider
217
+ wraptc reset --all # Reset all providers
218
+ ```
219
+
220
+ ### `ultrathink`
221
+
222
+ Alias for enhanced reasoning mode.
223
+
224
+ ```bash
225
+ ultrathink -p "Explain this complex algorithm in detail"
226
+ ```
227
+
228
+ ## MCP Server
229
+
230
+ The MCP server exposes wraptc functionality to MCP clients.
231
+
232
+ ### Running the MCP Server
233
+
234
+ ```bash
235
+ # Directly
236
+ bun run packages/mcp-server/src/server.ts
237
+
238
+ # With config
239
+ WTC_CONFIG=/path/to/config.json bun run packages/mcp-server/src/server.ts
240
+ ```
241
+
242
+ ### MCP Tools
243
+
244
+ #### `run_coding_task`
245
+
246
+ Execute a coding task using the best available provider.
247
+
248
+ **Parameters:**
249
+
250
+ - `prompt` (string, required): The coding task prompt
251
+ - `mode` (string, optional): generate, edit, explain, or test
252
+ - `language` (string, optional): Language hint
253
+ - `files` (array of strings, optional): File paths for context
254
+ - `provider` (string, optional): Specific provider to use
255
+
256
+ **Response:**
257
+
258
+ ```json
259
+ {
260
+ "provider": "qwen-code",
261
+ "text": "Generated code...",
262
+ "usage": { "inputTokens": 100, "outputTokens": 50 }
263
+ }
264
+ ```
265
+
266
+ #### `get_providers`
267
+
268
+ List all available providers and their current status.
269
+
270
+ **Response:**
271
+
272
+ ```json
273
+ [
274
+ {
275
+ "id": "qwen-code",
276
+ "displayName": "Qwen Code CLI",
277
+ "requestsToday": 42,
278
+ "outOfCreditsUntil": null
279
+ }
280
+ ]
281
+ ```
282
+
283
+ #### `dry_run`
284
+
285
+ Show which provider would be used for a request without executing it.
286
+
287
+ **Parameters:**
288
+
289
+ - `prompt` (string, required)
290
+ - `mode` (string, optional)
291
+ - `provider` (string, optional)
292
+
293
+ ## Architecture
294
+
295
+ ### Core Components
296
+
297
+ 1. **Provider Abstraction** (`packages/core/src/providers/`)
298
+ - `Provider` interface for unified provider API
299
+ - Adapters for Gemini, Qwen Code, Codex, and custom providers
300
+ - Streaming and non-streaming support
301
+
302
+ 2. **Router** (`packages/core/src/router.ts`)
303
+ - Provider selection based on priority and availability
304
+ - Automatic fallback on errors or credit exhaustion
305
+ - Per-mode routing overrides
306
+
307
+ 3. **State Manager** (`packages/core/src/state.ts`)
308
+ - Per-provider usage tracking
309
+ - Credit limit enforcement
310
+ - Error history and cooldown management
311
+
312
+ 4. **Config Loader** (`packages/core/src/config.ts`)
313
+ - Multi-source configuration merging
314
+ - Environment variable support
315
+ - Validation with Zod
316
+
317
+ 5. **CLI** (`packages/cli/src/index.ts`)
318
+ - Commander-based CLI with multiple commands
319
+ - Support for streaming and multiple output formats
320
+
321
+ 6. **MCP Server** (`packages/mcp-server/src/server.ts`)
322
+ - MCP protocol implementation
323
+ - Tool-based interface for MCP clients
324
+
325
+ ## Error Handling
326
+
327
+ The wrapper classifies errors into categories:
328
+
329
+ - `OUT_OF_CREDITS`: Provider has exhausted quota
330
+ - `RATE_LIMIT`: Provider is rate limited
331
+ - `TRANSIENT`: Temporary error, retryable
332
+ - `BAD_REQUEST`: Invalid request, don't retry
333
+ - `INTERNAL`: Provider internal error
334
+
335
+ When a provider fails, the router automatically tries the next available provider in the priority list.
336
+
337
+ ## State File
338
+
339
+ State is persisted to `~/.config/wraptc/state.json`:
340
+
341
+ ```json
342
+ {
343
+ "version": "1.0.0",
344
+ "providers": {
345
+ "qwen-code": {
346
+ "lastUsedAt": "2025-01-20T10:30:00Z",
347
+ "requestsToday": 42,
348
+ "lastReset": "2025-01-20T00:00:00Z",
349
+ "outOfCreditsUntil": null,
350
+ "lastErrors": []
351
+ }
352
+ }
353
+ }
354
+ ```
355
+
356
+ ## Development
357
+
358
+ ```bash
359
+ # Install dependencies
360
+ bun install
361
+
362
+ # Build all packages
363
+ bun run build
364
+
365
+ # Development mode with watch
366
+ bun run dev
367
+
368
+ # Run tests
369
+ bun test
370
+
371
+ # Lint
372
+ bun run lint
373
+
374
+ # Type check
375
+ bun run typecheck
376
+ ```
377
+
378
+ ## Examples
379
+
380
+ ### Generate Code
381
+
382
+ ```bash
383
+ wraptc ask -p "Write a Python function to parse CSV data" --language python
384
+ ```
385
+
386
+ ### Explain Code
387
+
388
+ ```bash
389
+ wraptc ask -p "Explain this function" -f src/complex.ts --mode explain
390
+ ```
391
+
392
+ ### Edit with Context
393
+
394
+ ```bash
395
+ wraptc ask -p "Refactor to use async/await" -f src/api.ts --mode edit
396
+ ```
397
+
398
+ ### Test Generation
399
+
400
+ ```bash
401
+ wraptc ask -p "Create unit tests" -f src/utils.ts --mode test
402
+ ```
403
+
404
+ ### Stream Response
405
+
406
+ ```bash
407
+ wraptc ask -p "Write a long document" --stream --output jsonl
408
+ ```
409
+
410
+ ### Check Provider Status
411
+
412
+ ```bash
413
+ wraptc providers
414
+ ```
415
+
416
+ ## Troubleshooting
417
+
418
+ ### Provider Not Found
419
+
420
+ Ensure the CLI tool is installed and in your PATH:
421
+
422
+ ```bash
423
+ which gemini # Should show path
424
+ gemini --help # Should work
425
+ ```
426
+
427
+ ### Credit Limit Issues
428
+
429
+ Check provider status:
430
+
431
+ ```bash
432
+ wraptc providers
433
+ ```
434
+
435
+ Reset if needed:
436
+
437
+ ```bash
438
+ wraptc reset --provider qwen-code
439
+ ```
440
+
441
+ ### Configuration Issues
442
+
443
+ Validate your config:
444
+
445
+ ```bash
446
+ # The tool validates on startup and will show errors
447
+ wraptc ask -p "test" --dry-run
448
+ ```
449
+
450
+ ### Debug Mode
451
+
452
+ Enable debug logging:
453
+
454
+ ```bash
455
+ DEBUG=1 wraptc ask -p "Hello"
456
+ ```
457
+
458
+ ## MCP Server
459
+
460
+ wraptc includes an MCP (Model Context Protocol) server for integration with Claude Desktop and other MCP-compatible tools.
461
+
462
+ ### Starting the MCP Server
463
+
464
+ ```bash
465
+ # Using the --mcp flag
466
+ wraptc --mcp
467
+
468
+ # Or using the mcp command
469
+ wraptc mcp
470
+ ```
471
+
472
+ ### MCP Tools
473
+
474
+ The MCP server exposes the following tools:
475
+
476
+ - **run_coding_task**: Execute a coding task using the best available provider
477
+ - **get_providers**: List all available providers and their current status
478
+ - **dry_run**: Show which provider would be used for a request without executing it
479
+
480
+ ### Claude Desktop Integration
481
+
482
+ Add to your Claude Desktop configuration (`claude_desktop_config.json`):
483
+
484
+ ```json
485
+ {
486
+ "mcpServers": {
487
+ "wraptc": {
488
+ "command": "wraptc",
489
+ "args": ["--mcp"]
490
+ }
491
+ }
492
+ }
493
+ ```
494
+
495
+ ## Publishing
496
+
497
+ This project uses **Bitwarden Secrets Manager (BWS)** for secure npm token management in CI/CD. See [docs/PUBLISHING_CHECKLIST.md](docs/PUBLISHING_CHECKLIST.md) for setup instructions and [docs/PUBLISHING.md](docs/PUBLISHING.md) for detailed documentation.
498
+
499
+ **Why BWS?**
500
+ - No npm tokens stored in GitHub Secrets
501
+ - On-demand secret retrieval with audit logs
502
+ - Centralized secret management
503
+ - Works with Bun (unlike OIDC)
504
+ - Single location for token rotation
505
+
506
+ **Quick setup:**
507
+ 1. Create BWS project: `bws project create "npm-publishing"`
508
+ 2. Store npm token in BWS: `bws secret create NPM_TOKEN "<token>" <project-id>`
509
+ 3. Add `BWS_ACCESS_TOKEN` and `BWS_NPM_TOKEN_ID` to GitHub Secrets
510
+ 4. Push to `master` branch with conventional commits
511
+ 5. GitHub Actions fetches token from BWS and publishes!
512
+
513
+ ## License
514
+
515
+ MIT
516
+ # Test
package/bin/wraptc ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createRequire } from 'module';
4
+ const require = createRequire(import.meta.url);
5
+
6
+ const args = process.argv.slice(2);
7
+
8
+ // Check if --mcp flag is present or first command is 'mcp'
9
+ if (args.includes('--mcp') || args[0] === 'mcp') {
10
+ // Run MCP server
11
+ await import('../dist/mcp/server.js');
12
+ } else {
13
+ // Run CLI
14
+ await import('../dist/cli/index.js');
15
+ }