forked from lancekrogers/claude-code-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
452 lines (398 loc) · 15.3 KB
/
Taskfile.yml
File metadata and controls
452 lines (398 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# Claude Code Go SDK - Build Pipeline (Task)
# https://taskfile.dev
#
# Alternative: Use `make <command>` if you prefer Makefiles (see Makefile)
version: "3"
vars:
PROJECT_NAME: Claude Code Go SDK
BIN_DIR: ./bin
COVERAGE_DIR: ./coverage
tasks:
default:
desc: "Run complete build and test pipeline"
aliases: [all]
cmds:
- task: banner
- task: clean
- task: deps
- task: build-all
- task: test-all
- task: coverage
- task: summary
banner:
desc: "Display project banner"
silent: true
cmds:
- echo "╔══════════════════════════════════════════════════════════════╗"
- echo "║ {{.PROJECT_NAME}} ║"
- echo "║ Build Pipeline ║"
- echo "╚══════════════════════════════════════════════════════════════╝"
- echo ""
clean:
desc: "Clean build artifacts and test cache"
cmds:
- rm -rf {{.BIN_DIR}}
- rm -rf {{.COVERAGE_DIR}}
- rm -rf it_works/
- go clean -cache -testcache
- mkdir -p {{.BIN_DIR}} {{.COVERAGE_DIR}}
deps:
desc: "Download and verify dependencies"
cmds:
- echo "📦 Checking dependencies..."
- go mod download
- go mod verify
- go mod tidy
- echo "✅ Dependencies verified"
build-all:
desc: "Build all components"
cmds:
- task: build-lib
- task: build-examples
build-lib:
desc: "Build the core library"
cmds:
- echo "🔨 Building core library..."
- go build ./pkg/claude
- echo "✅ Core library built successfully"
examples:
desc: "Build all example programs (alias)"
aliases: [build-examples]
cmds:
- task: build-examples
build-examples:
desc: "Build example programs"
cmds:
- echo "🔨 Building examples..."
- mkdir -p {{.BIN_DIR}}
- go build -o {{.BIN_DIR}}/basic-example ./examples/basic || echo "❌ Basic example build failed"
- go build -o {{.BIN_DIR}}/advanced-example ./examples/advanced || echo "❌ Advanced example build failed"
- go build -o {{.BIN_DIR}}/testing-example ./examples/testing || echo "❌ Testing example build failed"
- task: build-demo-streaming
- task: build-demo-basic
- task: build-dangerous-example
- echo "✅ Example builds completed"
# Individual example build targets for development
build-basic:
desc: "Build basic example only"
cmds:
- echo "🔨 Building basic example..."
- mkdir -p {{.BIN_DIR}}
- go build -o {{.BIN_DIR}}/basic-example ./examples/basic
- echo "✅ Basic example built at {{.BIN_DIR}}/basic-example"
build-advanced:
desc: "Build advanced example only"
cmds:
- echo "🔨 Building advanced example..."
- mkdir -p {{.BIN_DIR}}
- go build -o {{.BIN_DIR}}/advanced-example ./examples/advanced
- echo "✅ Advanced example built at {{.BIN_DIR}}/advanced-example"
build-testing:
desc: "Build testing example only"
cmds:
- echo "🔨 Building testing example..."
- mkdir -p {{.BIN_DIR}}
- go build -o {{.BIN_DIR}}/testing-example ./examples/testing
- echo "✅ Testing example built at {{.BIN_DIR}}/testing-example"
build-demo:
desc: "Build the interactive demo (streaming)"
deps: [build-demo-streaming]
build-demo-streaming:
desc: "Build the streaming demo"
cmds:
- echo "🔨 Building streaming demo..."
- mkdir -p {{.BIN_DIR}}
- |
cd examples/demo/streaming
go mod tidy
go build -o ../../../{{.BIN_DIR}}/demo ./cmd/demo
- echo "✅ Streaming demo built successfully"
build-demo-basic:
desc: "Build the basic demo"
cmds:
- echo "🔨 Building basic demo..."
- mkdir -p {{.BIN_DIR}}
- |
cd examples/demo/basic
go mod tidy
go build -o ../../../{{.BIN_DIR}}/demo-basic ./cmd/demo
- echo "✅ Basic demo built successfully"
build-dangerous-example:
desc: "Build dangerous usage example"
cmds:
- echo "🔨 Building dangerous example..."
- mkdir -p {{.BIN_DIR}}
- |
cd examples/dangerous_usage
go mod tidy
go build -o ../../{{.BIN_DIR}}/dangerous-example .
- echo "✅ Dangerous example built successfully"
test-all:
desc: "Run all tests"
cmds:
- task: test-lib
test-lib:
desc: "Test the core library"
cmds:
- echo "🧪 Testing core library..."
- go test -v ./pkg/claude || echo "❌ Core library tests failed"
- echo "✅ Core library tests completed (check for errors above)"
test-dangerous:
desc: "Test dangerous package (security-sensitive features)"
cmds:
- echo "🚨 Testing dangerous package..."
- go test -v ./pkg/claude/dangerous || echo "❌ Dangerous package tests failed"
- echo "✅ Dangerous package tests completed (check for errors above)"
demo:
desc: "Run the interactive Claude Code Go SDK demo (streaming)"
deps: [build-demo-streaming]
cmds:
- echo "🚀 Claude Code Go SDK Demo (Streaming)"
- echo "====================================="
- |
# Check Go version
if ! command -v go &> /dev/null; then
echo "❌ Error: Go is not installed or not in PATH"
exit 1
fi
go_version=$(go version | awk '{print $3}' | sed 's/go//')
major_version=$(echo $go_version | cut -d. -f1)
minor_version=$(echo $go_version | cut -d. -f2)
if [[ $major_version -lt 1 ]] || [[ $major_version -eq 1 && $minor_version -lt 20 ]]; then
echo "❌ Error: Go ≥1.20 is required (found: $go_version)"
exit 1
fi
echo "✔️ Go version: $go_version"
- |
# Check for claude CLI
if ! claude_path=$(command -v claude 2>/dev/null); then
echo "❌ Error: claude CLI not found in PATH"
echo " Please install from: https://docs.anthropic.com/en/docs/claude-code/getting-started"
exit 1
fi
echo "✔️ Found claude CLI: $claude_path"
- echo ""
- echo "🎯 Starting streaming demo with real-time tool display..."
- echo " Type your responses and press Enter"
- echo " Type 'exit', 'quit', 'bye', or press Enter on empty line to exit"
- echo ""
- "{{.BIN_DIR}}/demo"
demo-streaming:
desc: "Run the streaming demo"
deps: [build-demo-streaming]
cmds:
- task: demo
demo-basic:
desc: "Run the basic demo"
deps: [build-demo-basic]
cmds:
- echo "🚀 Claude Code Go SDK Demo (Basic)"
- echo "================================"
- |
# Check Go version
if ! command -v go &> /dev/null; then
echo "❌ Error: Go is not installed or not in PATH"
exit 1
fi
go_version=$(go version | awk '{print $3}' | sed 's/go//')
major_version=$(echo $go_version | cut -d. -f1)
minor_version=$(echo $go_version | cut -d. -f2)
if [[ $major_version -lt 1 ]] || [[ $major_version -eq 1 && $minor_version -lt 20 ]]; then
echo "❌ Error: Go ≥1.20 is required (found: $go_version)"
exit 1
fi
echo "✔️ Go version: $go_version"
- |
# Check for claude CLI
if ! claude_path=$(command -v claude 2>/dev/null); then
echo "❌ Error: claude CLI not found in PATH"
echo " Please install from: https://docs.anthropic.com/en/docs/claude-code/getting-started"
exit 1
fi
echo "✔️ Found claude CLI: $claude_path"
- echo ""
- echo "🎯 Starting basic demo with simple JSON output..."
- echo " Type your responses and press Enter"
- echo " Type 'exit', 'quit', 'bye', or press Enter on empty line to exit"
- echo ""
- "{{.BIN_DIR}}/demo-basic"
run-dangerous:
desc: "Run dangerous features example (development only)"
deps: [build-dangerous-example]
cmds:
- echo "🚨 Running Dangerous Features Example"
- echo "====================================="
- |
# Check required environment variables
if [ "$CLAUDE_ENABLE_DANGEROUS" != "i-accept-all-risks" ]; then
echo "❌ Error: CLAUDE_ENABLE_DANGEROUS must be set to 'i-accept-all-risks'"
echo " export CLAUDE_ENABLE_DANGEROUS=\"i-accept-all-risks\""
exit 1
fi
# Check not in production
if [ "$NODE_ENV" = "production" ] || [ "$GO_ENV" = "production" ] || [ "$ENVIRONMENT" = "production" ]; then
echo "❌ Error: Cannot run dangerous example in production environment"
exit 1
fi
echo "✔️ Security requirements met"
- echo ""
- "{{.BIN_DIR}}/dangerous-example"
coverage:
desc: "Generate test coverage report"
cmds:
- echo "📊 Generating coverage report..."
- mkdir -p {{.COVERAGE_DIR}}
- go test -coverprofile={{.COVERAGE_DIR}}/coverage.out ./pkg/... || echo "❌ Coverage generation failed"
- go tool cover -func={{.COVERAGE_DIR}}/coverage.out || echo "❌ Coverage summary failed"
- go tool cover -html={{.COVERAGE_DIR}}/coverage.out -o {{.COVERAGE_DIR}}/coverage.html || echo "❌ HTML coverage report failed"
- echo "✅ Coverage generation completed"
- echo "📄 View HTML report at {{.COVERAGE_DIR}}/coverage.html"
summary:
desc: "Display final summary"
silent: true
cmds:
- echo ""
- echo "╔══════════════════════════════════════════════════════════════╗"
- echo "║ PIPELINE SUMMARY ║"
- echo "╚══════════════════════════════════════════════════════════════╝"
- echo ""
- echo "🎉 Build and test pipeline completed!"
- echo ""
- echo "📁 SDK Library:"
- echo " • pkg/claude/ - Go SDK ready for import"
- echo ""
- echo "📁 Example Binaries:"
- echo " • {{.BIN_DIR}}/basic-example - Basic usage examples"
- echo " • {{.BIN_DIR}}/advanced-example - Advanced MCP examples"
- echo " • {{.BIN_DIR}}/testing-example - Testing utilities"
- echo ""
- echo "📊 Reports:"
- echo " • Coverage at {{.COVERAGE_DIR}}/coverage.html"
- echo ""
- echo "🚀 Usage:"
- echo " • import \"github.com/lancekrogers/claude-code-go/pkg/claude\""
- echo " • See examples/ for usage patterns"
- echo ""
test:
desc: "Run tests with verbose output"
cmds:
- go test -v ./...
test-coverage:
desc: "Run tests with coverage and open HTML report"
cmds:
- mkdir -p {{.COVERAGE_DIR}}
- go test -coverprofile={{.COVERAGE_DIR}}/coverage.out ./pkg/...
- go tool cover -html={{.COVERAGE_DIR}}/coverage.out -o {{.COVERAGE_DIR}}/coverage.html
- echo "Coverage report at {{.COVERAGE_DIR}}/coverage.html"
lint:
desc: "Run linting tools"
cmds:
- go fmt ./...
- go vet ./...
fix:
desc: "Fix common issues"
cmds:
- go fmt ./...
- go mod tidy
- echo "✅ Common issues fixed"
docs:
desc: "Generate and serve documentation"
cmds:
- echo "📚 Starting documentation server..."
- echo "Visit http://localhost:6060/pkg/github.com/lancekrogers/claude-code-go/"
- godoc -http=:6060
# Integration Testing Tasks
test-integration:
desc: "🧪 Run integration tests with mock server"
cmds:
- task: start-mock-server-bg
- sleep 2
- INTEGRATION_TESTS=1 USE_MOCK_SERVER=1 go test -tags=integration ./test/integration -v
- task: stop-mock-server
test-integration-real:
desc: "🧪 Run integration tests with real Claude Code CLI"
cmds:
- echo "⚠️ This will use real Claude Code CLI and may consume credits"
- echo "Claude will handle authentication automatically if needed"
- INTEGRATION_TESTS=1 go test -tags=integration ./test/integration -v
# Mock Server Tasks
start-mock-server:
desc: "🚀 Start mock Claude server"
cmds:
- echo "🚀 Starting mock Claude server on port 8080..."
- go run test/mockserver/main.go
start-mock-server-bg:
desc: "🚀 Start mock Claude server in background"
cmds:
- echo "🚀 Starting mock Claude server in background..."
- go run test/mockserver/main.go &
- echo $! > /tmp/mock-server.pid
stop-mock-server:
desc: "🛑 Stop mock Claude server"
cmds:
- |
if [ -f /tmp/mock-server.pid ]; then
kill $(cat /tmp/mock-server.pid) 2>/dev/null || true
rm -f /tmp/mock-server.pid
echo "🛑 Mock server stopped"
fi
test-mock-server:
desc: "🧪 Test mock server functionality"
cmds:
- echo "🧪 Testing mock server..."
- curl -X POST http://localhost:8080/claude -d '-p "Hello world"' -s
- echo ""
- curl -X POST http://localhost:8080/claude -d '-p "Hello" --output-format json' -s | jq .
- echo "✅ Mock server tests completed"
# Benchmark and Performance Testing
test-bench:
desc: "📊 Run benchmark tests"
cmds:
- echo "📊 Running benchmark tests..."
- go test -bench=. ./pkg/claude -benchmem
- echo "✅ Benchmark tests completed"
test-race:
desc: "🏃 Run tests with race detection"
cmds:
- echo "🏃 Running tests with race detection..."
- go test -race ./...
- echo "✅ Race detection tests completed"
test-memory:
desc: "🧠 Run memory profiling tests"
cmds:
- echo "🧠 Running memory profiling tests..."
- go test -memprofile=mem.prof ./pkg/claude
- go tool pprof mem.prof
- echo "✅ Memory profiling completed"
# Local Development Testing
test-local:
desc: "🏠 Run local development tests"
cmds:
- echo "🏠 Running local development test suite..."
- task: test
- task: test-integration
- echo "✅ All local tests completed"
# Comprehensive Testing
test-full:
desc: "🎯 Run comprehensive test suite"
cmds:
- echo "🎯 Running comprehensive test suite..."
- task: test
- task: test-race
- task: test-integration
- task: test-bench
- echo "✅ Comprehensive testing completed"
# Setup Testing Environment
setup-test-env:
desc: "⚙️ Setup testing environment"
cmds:
- echo "⚙️ Setting up testing environment..."
- |
echo "export CLAUDE_CODE_PATH=claude" >> .env.test
echo "export TEST_TIMEOUT=30s" >> .env.test
echo "export MOCK_SERVER_PORT=8080" >> .env.test
echo "export USE_MOCK_SERVER=1" >> .env.test
echo "# Set USE_MOCK_SERVER=0 to use real Claude CLI" >> .env.test
- echo "✅ Test environment setup complete"
- echo "📝 Edit .env.test to configure your testing environment"
- echo "💡 Claude Code CLI will handle authentication automatically when needed"