#!/bin/bash # agent-ops/bin/init-agent-ops.sh # 프로젝트에 agent-ops 스캐폴드를 초기화하는 스크립트 set -e SCRIPT_DIR=$(realpath "$(dirname "$0")") SOURCE_DIR=$(realpath "$SCRIPT_DIR/..") source "$SCRIPT_DIR/entry-files.sh" if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi TARGET_DIR=$(realpath "$1") TASK_ARCHIVE_IGNORE_PATTERN="agent-task/archive/**" ROADMAP_ARCHIVE_IGNORE_PATTERN="agent-ops/roadmap/archive/**" append_unique_line() { local file="$1" local line="$2" touch "$file" if ! grep -qxF "$line" "$file"; then printf "%s\n" "$line" >> "$file" fi } create_project_agent_ops_dirs() { local agent_ops_dir="$1" mkdir -p "$agent_ops_dir/rules/project/domain" mkdir -p "$agent_ops_dir/rules/private" mkdir -p "$agent_ops_dir/skills/project" } copy_common_agent_ops() { local source_dir="$1" local target_agent_ops_dir="$2" mkdir -p "$target_agent_ops_dir/rules" mkdir -p "$target_agent_ops_dir/skills" cp "$source_dir/.version" "$target_agent_ops_dir/" rm -rf "$target_agent_ops_dir/bin" rm -rf "$target_agent_ops_dir/rules/common" rm -rf "$target_agent_ops_dir/skills/common" cp -r "$source_dir/bin" "$target_agent_ops_dir/" cp -r "$source_dir/rules/common" "$target_agent_ops_dir/rules/" cp -r "$source_dir/skills/common" "$target_agent_ops_dir/skills/" } ensure_common_rules_file() { local source_dir="$1" local target_agent_ops_dir="$2" local source_rules="$source_dir/rules/common/rules.md" local target_rules="$target_agent_ops_dir/rules/common/rules.md" if [ ! -f "$source_rules" ]; then echo "Error: common rules file not found: $source_rules" >&2 exit 1 fi mkdir -p "$(dirname "$target_rules")" cp "$source_rules" "$target_rules" } echo "Initializing agent-ops in: $TARGET_DIR" echo "Source agent-ops: $SOURCE_DIR" # 1. 대상 폴더 생성 (프로젝트 전용 폴더는 내용 복사 없이 폴더만 생성) create_project_agent_ops_dirs "$TARGET_DIR/agent-ops" # 2. 공통 요소 복사 (프로젝트 전용 설정은 제외) copy_common_agent_ops "$SOURCE_DIR" "$TARGET_DIR/agent-ops" # 3. 에이전트 진입 파일 생성 (common/rules.md 복사) COMMON_RULES="$SOURCE_DIR/rules/common/rules.md" apply_agent_ops_entry_files "$COMMON_RULES" "$TARGET_DIR" ensure_common_rules_file "$SOURCE_DIR" "$TARGET_DIR/agent-ops" # 4. AI ignore / permission 설정 append_unique_line "$TARGET_DIR/.geminiignore" "$TASK_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.geminiignore" "$ROADMAP_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.aiexclude" "$TASK_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.aiexclude" "$ROADMAP_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.cursorignore" "$TASK_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.cursorignore" "$ROADMAP_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.clineignore" "$TASK_ARCHIVE_IGNORE_PATTERN" append_unique_line "$TARGET_DIR/.clineignore" "$ROADMAP_ARCHIVE_IGNORE_PATTERN" mkdir -p "$TARGET_DIR/.claude" if [ ! -f "$TARGET_DIR/.claude/settings.json" ]; then cat > "$TARGET_DIR/.claude/settings.json" <<'EOF' { "$schema": "https://json.schemastore.org/claude-code-settings.json", "permissions": { "deny": [ "Read(./agent-task/archive/**)", "Read(./agent-ops/roadmap/archive/**)" ] } } EOF elif ! grep -q "agent-task/archive" "$TARGET_DIR/.claude/settings.json" || ! grep -q "agent-ops/roadmap/archive" "$TARGET_DIR/.claude/settings.json"; then echo "Note: .claude/settings.json exists; add Read(./agent-task/archive/**) and Read(./agent-ops/roadmap/archive/**) manually." fi if [ ! -f "$TARGET_DIR/opencode.json" ]; then cat > "$TARGET_DIR/opencode.json" <<'EOF' { "$schema": "https://opencode.ai/config.json", "permission": { "read": { "agent-task/archive/**": "deny", "agent-ops/roadmap/archive/**": "deny" }, "glob": { "agent-task/archive/**": "deny", "agent-ops/roadmap/archive/**": "deny" } }, "watcher": { "ignore": [ "agent-task/archive/**", "agent-ops/roadmap/archive/**" ] } } EOF elif ! grep -q "agent-task/archive" "$TARGET_DIR/opencode.json" || ! grep -q "agent-ops/roadmap/archive" "$TARGET_DIR/opencode.json"; then echo "Note: opencode.json exists; add agent-task/archive/** and agent-ops/roadmap/archive/** read/glob deny and watcher ignore manually." fi # 5. .gitignore 설정 TOUCH_GITIGNORE="$TARGET_DIR/.gitignore" touch "$TOUCH_GITIGNORE" if ! grep -q "agent-ops/rules/private/" "$TOUCH_GITIGNORE"; then echo "" >> "$TOUCH_GITIGNORE" echo "# Agent-Ops Private Rules" >> "$TOUCH_GITIGNORE" echo "agent-ops/rules/private/" >> "$TOUCH_GITIGNORE" fi echo "Successfully initialized agent-ops in $TARGET_DIR" echo "Note: agent-ops/rules/project and agent-ops/skills/project are initialized as empty."