-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-project.sh
More file actions
executable file
Β·234 lines (198 loc) Β· 7.97 KB
/
setup-project.sh
File metadata and controls
executable file
Β·234 lines (198 loc) Β· 7.97 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
#!/bin/bash
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Copilot Hive β Project Setup Agent
# Uses GitHub Copilot CLI to discover competitors and generate
# project-specific context for all agents.
#
# Usage: setup-project.sh <project-id>
# Called by the dashboard after creating a project config.
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
HIVE_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECTS_DIR="${HIVE_DIR}/projects"
COPILOT="${COPILOT:-/usr/local/bin/copilot}"
PROJECT_ID="${1:?Usage: setup-project.sh <project-id>}"
PROJECT_DIR_PATH="${PROJECTS_DIR}/${PROJECT_ID}"
PROJECT_FILE="${PROJECT_DIR_PATH}/project.json"
SETUP_LOG="${PROJECT_DIR_PATH}/setup.log"
if [ ! -f "$PROJECT_FILE" ]; then
echo "ERROR: Project config not found: $PROJECT_FILE" >&2
exit 1
fi
# Update setup status
update_setup_status() {
local status="$1" step="$2"
python3 -c "
import json
with open('${PROJECT_FILE}') as f: data = json.load(f)
data['setup_status'] = '$status'
data['setup_step'] = '$step'
with open('${PROJECT_FILE}', 'w') as f: json.dump(data, f, indent=2)
" 2>/dev/null
}
# Reset status for re-runs
python3 -c "
import json
try:
with open('${PROJECT_FILE}') as f: data = json.load(f)
data['setup_step'] = 'Initializing'
with open('${PROJECT_FILE}', 'w') as f: json.dump(data, f, indent=2)
except: pass
" 2>/dev/null
update_setup_status "running" "Starting setup"
echo "$(date) β Setup started for project: $PROJECT_ID" > "$SETUP_LOG"
# Read project description
PROJECT_DESC=$(python3 -c "
import json
with open('${PROJECT_FILE}') as f: data = json.load(f)
print(data.get('description', ''))
" 2>/dev/null)
SOURCE_PATH=$(python3 -c "
import json
with open('${PROJECT_FILE}') as f: data = json.load(f)
print(data.get('path', ''))
" 2>/dev/null)
GITHUB_REPO=$(python3 -c "
import json
with open('${PROJECT_FILE}') as f: data = json.load(f)
print(data.get('github_repo', ''))
" 2>/dev/null)
# ββ Step 1: Clone/verify project source ββββββββββββββββββββββββββββββ
update_setup_status "running" "Preparing project source"
if [ -n "$GITHUB_REPO" ] && [ ! -d "$SOURCE_PATH" ]; then
echo "$(date) β Cloning $GITHUB_REPO to $SOURCE_PATH" >> "$SETUP_LOG"
git clone "https://github.com/${GITHUB_REPO}.git" "$SOURCE_PATH" >> "$SETUP_LOG" 2>&1
if [ $? -ne 0 ]; then
update_setup_status "failed" "Git clone failed"
echo "$(date) β ERROR: Clone failed" >> "$SETUP_LOG"
exit 1
fi
elif [ ! -d "$SOURCE_PATH" ]; then
echo "$(date) β WARNING: Source path does not exist: $SOURCE_PATH" >> "$SETUP_LOG"
mkdir -p "$SOURCE_PATH"
fi
# Pull latest if repo already exists
if [ -n "$GITHUB_REPO" ] && [ -d "$SOURCE_PATH/.git" ]; then
echo "$(date) β Pulling latest from $GITHUB_REPO" >> "$SETUP_LOG"
git -C "$SOURCE_PATH" pull origin main >> "$SETUP_LOG" 2>&1 || true
fi
# ββ Step 2: Use Copilot CLI to analyze project and discover competitors ββ
update_setup_status "running" "Analyzing project with Copilot CLI"
CONTEXT_FILE="${PROJECT_DIR_PATH}/context.json"
SETUP_IDEAS_DIR="${PROJECT_DIR_PATH}/ideas"
mkdir -p "$SETUP_IDEAS_DIR"
SETUP_PROMPT="You are a project analyst for the Copilot Hive autonomous agent swarm. Your job is to analyze a software project and discover its competitive landscape so that our AI agents can provide project-specific insights.
PROJECT DESCRIPTION (from the owner):
${PROJECT_DESC}
PROJECT SOURCE CODE: ${SOURCE_PATH}
YOUR TASKS:
1. READ the project source code to understand:
- What does it do? (product type, core features)
- What tech stack does it use? (languages, frameworks, databases)
- Who is the target market? (developers, enterprises, consumers, etc.)
- What industry/category is it in?
2. DISCOVER COMPETITORS:
- Based on what the project does, search the web for similar products/services
- Find 5-10 direct competitors with their URLs
- For each competitor, note: name, URL, key features, pricing model, unique selling points
- Look at their legal pages (terms, privacy, etc.) and note the URLs
3. IDENTIFY RELEVANT COMPLIANCE FRAMEWORKS:
- Based on the project's industry and what data it handles
- Which compliance standards are relevant? (GDPR, SOC2, HIPAA, PCI-DSS, etc.)
4. WRITE the analysis to: ${CONTEXT_FILE}
Use this EXACT JSON format:
\`\`\`json
{
\"project_analysis\": {
\"product_type\": \"what kind of product this is\",
\"tech_stack\": \"languages, frameworks, databases found\",
\"target_market\": \"who uses this\",
\"industry\": \"the industry category\",
\"core_features\": [\"feature1\", \"feature2\", ...]
},
\"competitors\": [
{
\"name\": \"Competitor Name\",
\"url\": \"https://competitor.com\",
\"features\": \"key features they offer\",
\"notes\": \"pricing, unique selling points\"
}
],
\"legal_sites\": [
{
\"name\": \"Competitor Name\",
\"url\": \"https://competitor.com\",
\"pages\": [\"terms\", \"privacy\", \"acceptable-use\"]
}
],
\"compliance_frameworks\": [
{
\"name\": \"GDPR\",
\"relevant\": true,
\"reason\": \"why this framework applies\"
}
]
}
\`\`\`
RULES:
- Only write to ${CONTEXT_FILE} β do NOT modify any project source code
- Be thorough in competitor discovery β the agents depend on this data
- Include real, working URLs that you've verified with curl
- If you can't find competitors, explain why and suggest search terms"
echo "$(date) β Running Copilot CLI for competitor discovery..." >> "$SETUP_LOG"
cd "$SETUP_IDEAS_DIR"
"$COPILOT" --prompt "$SETUP_PROMPT" --yolo \
--add-dir "$SOURCE_PATH" \
--allow-all-urls \
--deny-tool 'shell(git push)' \
--deny-tool 'shell(git commit)' \
--deny-tool 'shell(git add)' \
--deny-tool 'shell(rm:*)' \
>> "$SETUP_LOG" 2>&1
COPILOT_EXIT=$?
echo "$(date) β Copilot CLI finished (exit: $COPILOT_EXIT)" >> "$SETUP_LOG"
# ββ Step 3: Merge discovered data back into project.json βββββββββββββ
update_setup_status "running" "Merging discovered data"
if [ -f "$CONTEXT_FILE" ]; then
python3 -c "
import json
# Load project config
with open('${PROJECT_FILE}') as f:
project = json.load(f)
# Load context (discovered by Copilot)
try:
with open('${CONTEXT_FILE}') as f:
context = json.load(f)
except Exception as e:
print(f'Warning: Could not parse context.json: {e}')
context = {}
# Merge competitors
if 'competitors' in context:
project['competitors'] = context['competitors']
# Merge legal sites
if 'legal_sites' in context:
project['legal_sites'] = context['legal_sites']
# Merge analysis
if 'project_analysis' in context:
analysis = context['project_analysis']
if analysis.get('tech_stack'):
project['tech_stack'] = analysis['tech_stack']
if analysis.get('target_market'):
project['target_market'] = analysis['target_market']
if analysis.get('industry'):
project['industry'] = analysis['industry']
if analysis.get('product_type'):
project['product_type'] = analysis['product_type']
# Merge compliance
if 'compliance_frameworks' in context:
project['compliance_frameworks'] = context['compliance_frameworks']
project['setup_status'] = 'complete'
project['setup_step'] = 'Done'
with open('${PROJECT_FILE}', 'w') as f:
json.dump(project, f, indent=2)
print('Project config updated with discovered data')
" >> "$SETUP_LOG" 2>&1
else
echo "$(date) β WARNING: No context.json generated by Copilot" >> "$SETUP_LOG"
update_setup_status "complete" "Done (no competitor data discovered)"
fi
echo "$(date) β Setup complete for project: $PROJECT_ID" >> "$SETUP_LOG"