coding-agent-adapters 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # coding-agent-adapters
2
+
3
+ CLI adapters for AI coding agents. Works with [pty-manager](https://www.npmjs.com/package/pty-manager) to spawn and manage coding agents like Claude Code, Gemini CLI, OpenAI Codex, and Aider.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install coding-agent-adapters pty-manager
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { PTYManager, AdapterRegistry } from 'pty-manager';
15
+ import { ClaudeAdapter, GeminiAdapter, AiderAdapter } from 'coding-agent-adapters';
16
+
17
+ // Create adapter registry and register the adapters you need
18
+ const registry = new AdapterRegistry();
19
+ registry.register(new ClaudeAdapter());
20
+ registry.register(new GeminiAdapter());
21
+ registry.register(new AiderAdapter());
22
+
23
+ // Create PTY manager with the registry
24
+ const manager = new PTYManager({ adapters: registry });
25
+
26
+ // Spawn a Claude Code session
27
+ const session = await manager.spawn({
28
+ name: 'code-assistant',
29
+ type: 'claude',
30
+ workdir: '/path/to/project',
31
+ adapterConfig: {
32
+ anthropicKey: process.env.ANTHROPIC_API_KEY,
33
+ },
34
+ });
35
+
36
+ // Listen for output
37
+ session.on('output', (data) => console.log(data));
38
+
39
+ // Send a task
40
+ session.send('Help me refactor this function to use async/await');
41
+ ```
42
+
43
+ ## Available Adapters
44
+
45
+ | Adapter | CLI | Type | Install Command |
46
+ |---------|-----|------|-----------------|
47
+ | `ClaudeAdapter` | Claude Code | `claude` | `npm install -g @anthropic-ai/claude-code` |
48
+ | `GeminiAdapter` | Gemini CLI | `gemini` | `npm install -g @anthropics/gemini-cli` |
49
+ | `CodexAdapter` | OpenAI Codex | `codex` | `npm install -g @openai/codex` |
50
+ | `AiderAdapter` | Aider | `aider` | `pip install aider-chat` |
51
+
52
+ ## Preflight Check
53
+
54
+ Before spawning agents, check if the required CLIs are installed:
55
+
56
+ ```typescript
57
+ import { checkAdapters, checkAllAdapters, printMissingAdapters } from 'coding-agent-adapters';
58
+
59
+ // Check specific adapters
60
+ const results = await checkAdapters(['claude', 'aider']);
61
+ for (const result of results) {
62
+ if (result.installed) {
63
+ console.log(`✓ ${result.adapter} v${result.version}`);
64
+ } else {
65
+ console.log(`✗ ${result.adapter} - Install: ${result.installCommand}`);
66
+ }
67
+ }
68
+
69
+ // Check all adapters
70
+ const allResults = await checkAllAdapters();
71
+
72
+ // Print formatted installation instructions for missing tools
73
+ await printMissingAdapters(['claude', 'gemini']);
74
+ ```
75
+
76
+ Each adapter also provides installation info:
77
+
78
+ ```typescript
79
+ import { ClaudeAdapter } from 'coding-agent-adapters';
80
+
81
+ const claude = new ClaudeAdapter();
82
+ console.log(claude.installation);
83
+ // {
84
+ // command: 'npm install -g @anthropic-ai/claude-code',
85
+ // alternatives: ['npx @anthropic-ai/claude-code', 'brew install claude-code'],
86
+ // docsUrl: 'https://docs.anthropic.com/en/docs/claude-code',
87
+ // minVersion: '1.0.0'
88
+ // }
89
+
90
+ // Get formatted instructions
91
+ console.log(claude.getInstallInstructions());
92
+ ```
93
+
94
+ ## Passing Credentials
95
+
96
+ You can pass API keys either via environment variables or through `adapterConfig`:
97
+
98
+ ```typescript
99
+ // Via environment variables (recommended for production)
100
+ process.env.ANTHROPIC_API_KEY = 'sk-ant-...';
101
+
102
+ const session = await manager.spawn({
103
+ name: 'claude-agent',
104
+ type: 'claude',
105
+ workdir: '/project',
106
+ });
107
+
108
+ // Via adapterConfig (useful for multi-tenant scenarios)
109
+ const session = await manager.spawn({
110
+ name: 'claude-agent',
111
+ type: 'claude',
112
+ workdir: '/project',
113
+ adapterConfig: {
114
+ anthropicKey: 'sk-ant-...',
115
+ },
116
+ });
117
+ ```
118
+
119
+ ## Adapter Features
120
+
121
+ ### Auto-Response Rules
122
+
123
+ Each adapter includes auto-response rules for common prompts (updates, telemetry, etc.):
124
+
125
+ ```typescript
126
+ const claude = new ClaudeAdapter();
127
+ console.log(claude.autoResponseRules);
128
+ // [
129
+ // { pattern: /update available.*\[y\/n\]/i, response: 'n', ... },
130
+ // { pattern: /telemetry.*\[y\/n\]/i, response: 'n', ... },
131
+ // ...
132
+ // ]
133
+ ```
134
+
135
+ ### Blocking Prompt Detection
136
+
137
+ Adapters detect blocking prompts that require user intervention:
138
+
139
+ ```typescript
140
+ session.on('blocking_prompt', (promptInfo, autoResponded) => {
141
+ if (!autoResponded) {
142
+ console.log(`User action required: ${promptInfo.type}`);
143
+ console.log(promptInfo.instructions);
144
+ }
145
+ });
146
+ ```
147
+
148
+ ### Login Detection
149
+
150
+ Adapters detect when authentication is required:
151
+
152
+ ```typescript
153
+ session.on('login_required', (instructions, url) => {
154
+ console.log('Authentication required:', instructions);
155
+ if (url) {
156
+ console.log('Open:', url);
157
+ }
158
+ });
159
+ ```
160
+
161
+ ## Creating Custom Adapters
162
+
163
+ Extend `BaseCodingAdapter` to create adapters for other coding CLIs:
164
+
165
+ ```typescript
166
+ import { BaseCodingAdapter } from 'coding-agent-adapters';
167
+ import type { SpawnConfig, ParsedOutput, LoginDetection } from 'pty-manager';
168
+
169
+ export class CursorAdapter extends BaseCodingAdapter {
170
+ readonly adapterType = 'cursor';
171
+ readonly displayName = 'Cursor';
172
+
173
+ getCommand(): string {
174
+ return 'cursor';
175
+ }
176
+
177
+ getArgs(config: SpawnConfig): string[] {
178
+ return ['--cli'];
179
+ }
180
+
181
+ getEnv(config: SpawnConfig): Record<string, string> {
182
+ return {};
183
+ }
184
+
185
+ detectLogin(output: string): LoginDetection {
186
+ // Implement login detection
187
+ return { required: false };
188
+ }
189
+
190
+ detectReady(output: string): boolean {
191
+ return output.includes('Cursor ready');
192
+ }
193
+
194
+ parseOutput(output: string): ParsedOutput | null {
195
+ // Implement output parsing
196
+ return null;
197
+ }
198
+
199
+ getPromptPattern(): RegExp {
200
+ return /cursor>\s*$/;
201
+ }
202
+ }
203
+ ```
204
+
205
+ ## Convenience Functions
206
+
207
+ ```typescript
208
+ import { createAllAdapters, createAdapter, ADAPTER_TYPES } from 'coding-agent-adapters';
209
+
210
+ // Create all adapters at once
211
+ const allAdapters = createAllAdapters();
212
+
213
+ // Create a specific adapter
214
+ const claude = createAdapter('claude');
215
+
216
+ // Available adapter types
217
+ console.log(Object.keys(ADAPTER_TYPES)); // ['claude', 'gemini', 'codex', 'aider']
218
+ ```
219
+
220
+ ## License
221
+
222
+ MIT