작동 방식
-p, --print
)를 사용해.
스크립트에서 파일 수정
--print
와 --force
를 함께 써:
Copy
Ask AI
# 프린트 모드에서 파일 수정 활성화
cursor-agent -p --force "Refactor this code to use modern ES6+ syntax"
# --force가 없으면 변경 사항은 제안만 되고 적용되지는 않아
cursor-agent -p "이 파일에 JSDoc 주석을 추가해 줘" # 파일은 수정하지 않아
# 실제 파일 수정을 포함한 배치 처리
find src/ -name "*.js" | while read file; do
cursor-agent -p --force "$file에 포괄적인 JSDoc 주석을 추가해 줘"
done
--force
플래그를 사용하면 에이전트가 확인 없이 파일을 직접 변경할 수 있어설정
Copy
Ask AI
# Cursor CLI 설치
curl https://cursor.com/install -fsS | bash
# 스크립트용 API 키 설정
export CURSOR_API_KEY=your_api_key_here
cursor-agent -p "이 코드를 분석해 줘"
예시 스크립트
코드베이스 검색
--output-format text
를 써:
Copy
Ask AI
#!/bin/bash
# 간단한 코드베이스 질문
cursor-agent -p --output-format text "이 코드베이스는 무엇을 하나?"
자동 코드 리뷰
--output-format json
을 사용해:
Copy
Ask AI
#!/bin/bash
# simple-code-review.sh - 기본 코드 리뷰 스크립트
echo "코드 리뷰를 시작하는 중..."
# 최근 변경사항 리뷰
cursor-agent -p --force --output-format text \
"최근 코드 변경사항을 검토하고 다음 항목에 대해 피드백을 제공해줘:
- 코드 품질과 가독성
- 잠재적 버그 또는 이슈
- 보안 고려 사항
- 모범 사례 준수 여부
개선을 위한 구체적인 제안을 제시하고 review.txt에 작성해줘"
if [ $? -eq 0 ]; then
echo "✅ 코드 리뷰를 성공적으로 완료"
else
echo "❌ 코드 리뷰 실패"
exit 1
fi
실시간 진행 상황 추적
--output-format stream-json
을(를) 사용해:
Copy
Ask AI
#!/bin/bash
# stream-progress.sh - 실시간 진행 상황 추적
echo "🚀 스트림 처리 시작..."
# 실시간 진행 상황 추적
accumulated_text=""
tool_count=0
start_time=$(date +%s)
cursor-agent -p --force --output-format stream-json \
"이 프로젝트 구조를 분석하고 analysis.txt에 요약 보고서를 만들어줘" | \
while IFS= read -r line; do
type=$(echo "$line" | jq -r '.type // empty')
subtype=$(echo "$line" | jq -r '.subtype // empty')
case "$type" in
"system")
if [ "$subtype" = "init" ]; then
model=$(echo "$line" | jq -r '.model // "unknown"')
echo "🤖 사용 모델: $model"
fi
;;
"assistant")
# 스트리밍 텍스트 델타 누적
content=$(echo "$line" | jq -r '.message.content[0].text // empty')
accumulated_text="$accumulated_text$content"
# 실시간 진행 상황 표시
printf "\r📝 생성 중: %d자" ${#accumulated_text}
;;
"tool_call")
if [ "$subtype" = "started" ]; then
tool_count=$((tool_count + 1))
# 도구 정보 추출
if echo "$line" | jq -e '.tool_call.writeToolCall' > /dev/null 2>&1; then
path=$(echo "$line" | jq -r '.tool_call.writeToolCall.args.path // "unknown"')
echo -e "\n🔧 도구 #$tool_count: $path 생성"
elif echo "$line" | jq -e '.tool_call.readToolCall' > /dev/null 2>&1; then
path=$(echo "$line" | jq -r '.tool_call.readToolCall.args.path // "unknown"')
echo -e "\n📖 도구 #$tool_count: $path 읽는 중"
fi
elif [ "$subtype" = "completed" ]; then
# 도구 결과 추출 및 표시
if echo "$line" | jq -e '.tool_call.writeToolCall.result.success' > /dev/null 2>&1; then
lines=$(echo "$line" | jq -r '.tool_call.writeToolCall.result.success.linesCreated // 0')
size=$(echo "$line" | jq -r '.tool_call.writeToolCall.result.success.fileSize // 0')
echo " ✅ $lines줄 생성됨 ($size바이트)"
elif echo "$line" | jq -e '.tool_call.readToolCall.result.success' > /dev/null 2>&1; then
lines=$(echo "$line" | jq -r '.tool_call.readToolCall.result.success.totalLines // 0')
echo " ✅ $lines줄 읽음"
fi
fi
;;
"result")
duration=$(echo "$line" | jq -r '.duration_ms // 0')
end_time=$(date +%s)
total_time=$((end_time - start_time))
echo -e "\n\n🎯 완료: ${duration}ms 소요 (${total_time}s 총"
echo "📊 최종 통계: 도구 $tool_count개, 총 ${#accumulated_text}자 생성"
;;
esac
done