@artyfacts/claude 1.0.0 → 1.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 CHANGED
@@ -1,134 +1,215 @@
1
1
  # @artyfacts/claude
2
2
 
3
- Run AI agents locally using Claude Code, orchestrated by Artyfacts.
3
+ Claude adapter for Artyfacts - Execute tasks using the Anthropic Claude API.
4
4
 
5
- ## Quick Start
5
+ ## Installation
6
6
 
7
7
  ```bash
8
+ npm install @artyfacts/claude
9
+ # or
8
10
  npx @artyfacts/claude
9
11
  ```
10
12
 
11
- That's it. The CLI will:
12
- 1. Open your browser to log in (first time only)
13
- 2. Check Claude Code is installed
14
- 3. Start polling for tasks from artyfacts.dev
15
- 4. Execute tasks locally with Claude Code
16
-
17
- ## Prerequisites
18
-
19
- **Claude Code** must be installed:
13
+ ## Quick Start
20
14
 
21
15
  ```bash
22
- npm install -g @anthropic-ai/claude-code
23
- claude login
16
+ # 1. Set your Anthropic API key
17
+ export ANTHROPIC_API_KEY=sk-ant-...
18
+
19
+ # 2. Start listening for tasks
20
+ npx @artyfacts/claude
24
21
  ```
25
22
 
26
- ## How It Works
23
+ ## CLI Commands
27
24
 
28
- ```
29
- artyfacts.dev Your Machine
30
- ───────────── ────────────
31
- Create goal
32
- Create tasks ──────────> npx @artyfacts/claude
33
-
34
- ├─ Polls for tasks
35
- ├─ Claims task
36
- ├─ Runs: claude -p "task..."
37
- ├─ Reports completion
38
-
39
- Task complete! <────────── Next task...
40
- ```
25
+ ### Run (default)
41
26
 
42
- ## Commands
27
+ Start listening for and executing tasks:
43
28
 
44
29
  ```bash
45
- # Start the adapter (default)
46
30
  npx @artyfacts/claude
31
+ npx @artyfacts/claude run
47
32
 
48
- # Check status
49
- npx @artyfacts/claude status
33
+ # Options
34
+ npx @artyfacts/claude run --model claude-sonnet-4-20250514 # Use different model
35
+ npx @artyfacts/claude run --dry-run # Print tasks without executing
36
+ ```
50
37
 
51
- # Log in manually
52
- npx @artyfacts/claude login
38
+ ### Login
53
39
 
54
- # Log out
55
- npx @artyfacts/claude logout
40
+ Authenticate with Artyfacts:
56
41
 
57
- # Show current user
58
- npx @artyfacts/claude whoami
42
+ ```bash
43
+ npx @artyfacts/claude login # Device auth flow
44
+ npx @artyfacts/claude login --manual # Enter credentials manually
59
45
  ```
60
46
 
61
- ## Options
47
+ ### Status
62
48
 
63
- ```bash
64
- npx @artyfacts/claude [options]
49
+ Check authentication and connection status:
65
50
 
66
- -i, --interval <sec> Poll interval in seconds (default: 30)
67
- -c, --concurrent <n> Max concurrent tasks (default: 1)
68
- -m, --model <model> Claude model: sonnet, opus (default: sonnet)
69
- -d, --cwd <dir> Working directory
51
+ ```bash
52
+ npx @artyfacts/claude status
70
53
  ```
71
54
 
72
- ## Example Session
55
+ ### Logout
56
+
57
+ Clear stored credentials:
73
58
 
59
+ ```bash
60
+ npx @artyfacts/claude logout
74
61
  ```
62
+
63
+ ## User Experience
64
+
65
+ ```bash
75
66
  $ npx @artyfacts/claude
67
+ 🔗 Connecting to Artyfacts...
68
+ ✅ Claude API connected (model: claude-sonnet-4-20250514)
69
+ ✅ Connected as engineering-agent
70
+ 👂 Listening for tasks...
71
+
72
+ [Task received] Break down initiative into subtasks
73
+ → Executing with Claude...
74
+ → ✅ Completed! Created 4 subtasks.
75
+ (1234 in / 567 out tokens)
76
+
77
+ ^C
78
+ 👋 Disconnecting...
79
+ ```
76
80
 
77
- 🚀 Artyfacts + Claude Code
81
+ ## Programmatic Usage
78
82
 
79
- 🔗 Opening browser to log in...
83
+ ```typescript
84
+ import {
85
+ ClaudeExecutor,
86
+ ArtyfactsListener,
87
+ getCredentials
88
+ } from '@artyfacts/claude';
89
+
90
+ // Get credentials (runs device auth if needed)
91
+ const credentials = await getCredentials();
92
+
93
+ // Create executor
94
+ const executor = new ClaudeExecutor({
95
+ apiKey: process.env.ANTHROPIC_API_KEY!,
96
+ model: 'claude-sonnet-4-20250514',
97
+ });
80
98
 
81
- https://artyfacts.dev/auth/device?code=ABCD-1234
99
+ // Create listener
100
+ const listener = new ArtyfactsListener({
101
+ apiKey: credentials.apiKey,
102
+ agentId: credentials.agentId,
103
+ });
82
104
 
83
- Your code: ABCD-1234
105
+ // Handle task assignments
106
+ listener.on('task_assigned', async (event) => {
107
+ const result = await executor.execute({
108
+ taskId: event.data.taskId,
109
+ heading: event.data.heading,
110
+ content: event.data.content,
111
+ artifactId: event.data.artifactId,
112
+ });
113
+
114
+ if (result.success) {
115
+ console.log('Task completed:', result.summary);
116
+ } else {
117
+ console.error('Task failed:', result.error);
118
+ }
119
+ });
84
120
 
85
- Waiting for authorization...
121
+ // Start listening
122
+ listener.connect();
86
123
 
87
- Logged in as gracie@example.com
124
+ // Cleanup
125
+ process.on('SIGINT', () => {
126
+ listener.disconnect();
127
+ process.exit(0);
128
+ });
129
+ ```
88
130
 
89
- Checking Claude Code...
90
- ✓ Claude Code 2.1.22
131
+ ## Configuration
91
132
 
92
- Started
93
- Polling every 30s
94
- Model: sonnet
133
+ ### Credentials
95
134
 
96
- Waiting for tasks from artyfacts.dev...
97
- Create goals and tasks at https://artyfacts.dev
135
+ Credentials are stored in `~/.artyfacts/credentials.json`:
98
136
 
99
- ▶ Research competitor pricing
100
- From: Q2 Growth Strategy
101
- Running with Claude...
102
- Completed
103
- Duration: 45.2s
137
+ ```json
138
+ {
139
+ "apiKey": "af_xxx",
140
+ "agentId": "engineering-agent",
141
+ "agentName": "Engineering Agent"
142
+ }
104
143
  ```
105
144
 
106
- ## Programmatic Usage
145
+ ### Environment Variables
107
146
 
108
- ```typescript
109
- import { ClaudeAdapter, DeviceAuth } from '@artyfacts/claude';
147
+ - `ANTHROPIC_API_KEY` - Your Anthropic API key (required)
148
+ - `ARTYFACTS_API_KEY` - Alternative to device auth
149
+ - `ARTYFACTS_AGENT_ID` - Agent ID when using API key directly
110
150
 
111
- const auth = new DeviceAuth();
151
+ ## API Reference
112
152
 
113
- // Ensure logged in
114
- if (!auth.hasCredentials()) {
115
- await auth.login();
116
- }
153
+ ### ClaudeExecutor
117
154
 
118
- const adapter = new ClaudeAdapter({
119
- apiKey: auth.getAccessToken()!,
155
+ Execute tasks using Claude API:
156
+
157
+ ```typescript
158
+ const executor = new ClaudeExecutor({
159
+ apiKey: string; // Anthropic API key
160
+ model?: string; // Model (default: claude-sonnet-4-20250514)
161
+ maxTokens?: number; // Max response tokens (default: 4096)
162
+ systemPromptPrefix?: string; // Prepend to system prompt
120
163
  });
121
164
 
122
- adapter.on('task:completed', (task) => {
123
- console.log(`Done: ${task.heading}`);
165
+ const result = await executor.execute({
166
+ taskId: string;
167
+ heading: string;
168
+ content: string;
169
+ artifactId: string;
170
+ artifactTitle?: string;
171
+ priority?: number;
172
+ context?: Record<string, unknown>;
124
173
  });
174
+ // Returns: { success, output, summary, error?, usage? }
175
+ ```
125
176
 
126
- await adapter.start();
177
+ ### ArtyfactsListener
178
+
179
+ Listen for SSE events from Artyfacts:
180
+
181
+ ```typescript
182
+ const listener = new ArtyfactsListener({
183
+ apiKey: string;
184
+ agentId: string;
185
+ baseUrl?: string; // API base URL
186
+ onStateChange?: (state) => void;
187
+ onError?: (error) => void;
188
+ });
189
+
190
+ // Subscribe to events
191
+ listener.on('task_assigned', (event) => { ... });
192
+ listener.on('blocker_resolved', (event) => { ... });
193
+ listener.subscribe((event) => { ... }); // All events
194
+
195
+ // Connection management
196
+ listener.connect();
197
+ listener.disconnect();
198
+ listener.reconnect();
127
199
  ```
128
200
 
129
- ## Credentials
201
+ ### Authentication
130
202
 
131
- Stored in `~/.artyfacts/credentials.json` with 600 permissions (user read/write only).
203
+ ```typescript
204
+ import {
205
+ getCredentials, // Get or run device auth
206
+ loadCredentials, // Load from disk
207
+ saveCredentials, // Save to disk
208
+ clearCredentials, // Delete from disk
209
+ runDeviceAuth, // Manual device auth
210
+ promptForApiKey, // Manual input
211
+ } from '@artyfacts/claude';
212
+ ```
132
213
 
133
214
  ## License
134
215
 
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI entry point for @artyfacts/claude
5
+ *
6
+ * This file bootstraps the TypeScript CLI.
7
+ * After build, it loads the compiled version from dist/.
8
+ */
9
+
10
+ const path = require('path');
11
+ const fs = require('fs');
12
+
13
+ // Check if we're running from source or dist
14
+ const distCli = path.join(__dirname, '..', 'dist', 'cli.js');
15
+ const srcCli = path.join(__dirname, '..', 'src', 'cli.ts');
16
+
17
+ if (fs.existsSync(distCli)) {
18
+ // Run compiled version
19
+ require(distCli);
20
+ } else if (fs.existsSync(srcCli)) {
21
+ // Development: run with ts-node or tsx
22
+ try {
23
+ require('tsx/cjs');
24
+ require(srcCli);
25
+ } catch {
26
+ try {
27
+ require('ts-node/register');
28
+ require(srcCli);
29
+ } catch {
30
+ console.error('Error: Package not built. Run `npm run build` first.');
31
+ console.error('Or install tsx/ts-node for development: npm install -D tsx');
32
+ process.exit(1);
33
+ }
34
+ }
35
+ } else {
36
+ console.error('Error: CLI source not found. Package may be corrupted.');
37
+ process.exit(1);
38
+ }