blob: 5a1693ee87a98b5ce727aedc1482bd25d449fece (
plain) (
blame)
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
|
#!/bin/bash
# Makima Supervisor Helper Script
# Usage: ./supervisor.sh <command> [args...]
API_URL="${MAKIMA_API_URL:-http://localhost:8080}"
API_KEY="${MAKIMA_API_KEY}"
TASK_ID="${MAKIMA_TASK_ID}"
CONTRACT_ID="${MAKIMA_CONTRACT_ID}"
if [ -z "$API_KEY" ]; then
echo "Error: MAKIMA_API_KEY not set" >&2
exit 1
fi
if [ -z "$CONTRACT_ID" ]; then
echo "Error: MAKIMA_CONTRACT_ID not set" >&2
exit 1
fi
# Helper function to make API calls and check for errors
api_call() {
local method="$1"
local url="$2"
local data="$3"
local response
local http_code
if [ -n "$data" ]; then
response=$(curl -s -w "\n%{http_code}" -X "$method" \
-H "X-Makima-Tool-Key: $API_KEY" \
-H "Content-Type: application/json" \
-d "$data" \
"$url")
else
response=$(curl -s -w "\n%{http_code}" -X "$method" \
-H "X-Makima-Tool-Key: $API_KEY" \
"$url")
fi
# Extract HTTP code (last line) and body (everything else)
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
# Check for curl errors or non-2xx status
if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then
echo "Error: API request failed with HTTP $http_code" >&2
echo "URL: $url" >&2
echo "Response: $body" >&2
echo "$body"
return 1
fi
echo "$body"
return 0
}
case "$1" in
tasks)
# Get all tasks in this contract's tree
api_call GET "$API_URL/api/v1/mesh/supervisor/contracts/$CONTRACT_ID/tasks"
;;
tree)
# Get full task tree structure
api_call GET "$API_URL/api/v1/mesh/supervisor/contracts/$CONTRACT_ID/tree"
;;
spawn)
# Create a new task (fire and forget)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 spawn \"<name>\" \"<plan>\" [--parent <task_id>] [--checkpoint <sha>]" >&2
exit 1
fi
NAME="$2"
PLAN="$3"
PARENT_ID=""
CHECKPOINT_SHA=""
shift 3
while [ $# -gt 0 ]; do
case "$1" in
--parent)
PARENT_ID="$2"
shift 2
;;
--checkpoint)
CHECKPOINT_SHA="$2"
shift 2
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
# Escape for JSON: backslashes first, then quotes, then newlines
NAME_ESCAPED=$(printf '%s' "$NAME" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
PLAN_ESCAPED=$(printf '%s' "$PLAN" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
# Build JSON body
JSON_BODY="{\"name\":\"$NAME_ESCAPED\",\"plan\":\"$PLAN_ESCAPED\",\"contractId\":\"$CONTRACT_ID\""
if [ -n "$PARENT_ID" ]; then
JSON_BODY="$JSON_BODY,\"parentTaskId\":\"$PARENT_ID\""
fi
if [ -n "$CHECKPOINT_SHA" ]; then
JSON_BODY="$JSON_BODY,\"checkpointSha\":\"$CHECKPOINT_SHA\""
fi
JSON_BODY="$JSON_BODY}"
echo "Creating task: $NAME..." >&2
api_call POST "$API_URL/api/v1/mesh/supervisor/tasks" "$JSON_BODY"
;;
wait)
# Wait for a task to complete
if [ -z "$2" ]; then
echo "Usage: $0 wait <task_id> [timeout_seconds]" >&2
exit 1
fi
WAIT_TASK_ID="$2"
TIMEOUT="${3:-300}"
echo "Waiting for task $WAIT_TASK_ID (timeout: ${TIMEOUT}s)..." >&2
api_call POST "$API_URL/api/v1/mesh/supervisor/tasks/$WAIT_TASK_ID/wait" "{\"timeoutSeconds\":$TIMEOUT}"
;;
read-file)
# Read a file from any task's worktree
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 read-file <task_id> <file_path>" >&2
exit 1
fi
READ_TASK_ID="$2"
FILE_PATH="$3"
FILE_PATH_ESCAPED=$(echo "$FILE_PATH" | sed 's/"/\\"/g')
api_call POST "$API_URL/api/v1/mesh/supervisor/tasks/$READ_TASK_ID/read-file" "{\"filePath\":\"$FILE_PATH_ESCAPED\"}"
;;
checkpoint)
# Create a git checkpoint
if [ -z "$2" ]; then
echo "Usage: $0 checkpoint \"<message>\"" >&2
exit 1
fi
MESSAGE_ESCAPED=$(printf '%s' "$2" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
api_call POST "$API_URL/api/v1/mesh/tasks/$TASK_ID/checkpoint" "{\"message\":\"$MESSAGE_ESCAPED\"}"
;;
checkpoints)
# List checkpoints for a task
CHECK_TASK_ID="${2:-$TASK_ID}"
api_call GET "$API_URL/api/v1/mesh/tasks/$CHECK_TASK_ID/checkpoints"
;;
status)
# Get contract status
api_call GET "$API_URL/api/v1/contracts/$CONTRACT_ID/daemon/status"
;;
branch)
# Create a new branch
if [ -z "$2" ]; then
echo "Usage: $0 branch <branch_name> [--from <task_id|sha>]" >&2
exit 1
fi
BRANCH_NAME="$2"
FROM_REF=""
shift 2
while [ $# -gt 0 ]; do
case "$1" in
--from)
FROM_REF="$2"
shift 2
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
JSON_BODY="{\"branchName\":\"$BRANCH_NAME\""
if [ -n "$FROM_REF" ]; then
JSON_BODY="$JSON_BODY,\"fromRef\":\"$FROM_REF\""
fi
JSON_BODY="$JSON_BODY}"
echo "Creating branch: $BRANCH_NAME..." >&2
api_call POST "$API_URL/api/v1/mesh/supervisor/branches" "$JSON_BODY"
;;
merge)
# Merge a task's changes to a branch
if [ -z "$2" ]; then
echo "Usage: $0 merge <task_id> [--to <branch>] [--squash]" >&2
exit 1
fi
MERGE_TASK_ID="$2"
TARGET_BRANCH=""
SQUASH="false"
shift 2
while [ $# -gt 0 ]; do
case "$1" in
--to)
TARGET_BRANCH="$2"
shift 2
;;
--squash)
SQUASH="true"
shift
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
JSON_BODY="{\"squash\":$SQUASH"
if [ -n "$TARGET_BRANCH" ]; then
JSON_BODY="$JSON_BODY,\"targetBranch\":\"$TARGET_BRANCH\""
fi
JSON_BODY="$JSON_BODY}"
echo "Merging task $MERGE_TASK_ID..." >&2
api_call POST "$API_URL/api/v1/mesh/supervisor/tasks/$MERGE_TASK_ID/merge" "$JSON_BODY"
;;
pr)
# Create a pull request
if [ -z "$2" ]; then
echo "Usage: $0 pr <task_id> --title \"Title\" [--body \"Body\"] [--base main]" >&2
exit 1
fi
PR_TASK_ID="$2"
PR_TITLE=""
PR_BODY=""
PR_BASE="main"
shift 2
while [ $# -gt 0 ]; do
case "$1" in
--title)
PR_TITLE="$2"
shift 2
;;
--body)
PR_BODY="$2"
shift 2
;;
--base)
PR_BASE="$2"
shift 2
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done
if [ -z "$PR_TITLE" ]; then
echo "Error: --title is required" >&2
exit 1
fi
TITLE_ESCAPED=$(printf '%s' "$PR_TITLE" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
BODY_ESCAPED=$(printf '%s' "$PR_BODY" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
JSON_BODY="{\"taskId\":\"$PR_TASK_ID\",\"title\":\"$TITLE_ESCAPED\",\"body\":\"$BODY_ESCAPED\",\"baseBranch\":\"$PR_BASE\"}"
echo "Creating PR for task $PR_TASK_ID..." >&2
api_call POST "$API_URL/api/v1/mesh/supervisor/pr" "$JSON_BODY"
;;
diff)
# Get diff for a task
if [ -z "$2" ]; then
echo "Usage: $0 diff <task_id>" >&2
exit 1
fi
DIFF_TASK_ID="$2"
api_call GET "$API_URL/api/v1/mesh/supervisor/tasks/$DIFF_TASK_ID/diff"
;;
*)
echo "Makima Supervisor Helper"
echo ""
echo "Usage: $0 <command> [args...]"
echo ""
echo "Task Management:"
echo " tasks List all tasks in contract tree"
echo " tree Get full task tree structure"
echo " spawn \"<name>\" \"<plan>\" Create and start a new task"
echo " --parent <task_id> Parent task to branch from"
echo " --checkpoint <sha> Checkpoint to start from"
echo " wait <task_id> [timeout] Wait for task completion"
echo " read-file <task_id> <path> Read file from task's worktree"
echo ""
echo "Git Operations:"
echo " branch <name> [--from <ref>] Create a new branch"
echo " merge <task_id> [--to <branch>] Merge task changes"
echo " --squash Squash commits on merge"
echo " pr <task_id> --title \"Title\" Create a pull request"
echo " --body \"Body\" PR description"
echo " --base <branch> Target branch (default: main)"
echo " diff <task_id> View task's diff"
echo ""
echo "Checkpoints:"
echo " checkpoint \"<message>\" Create git checkpoint"
echo " checkpoints [task_id] List task checkpoints"
echo ""
echo "Contract:"
echo " status Get contract status"
echo ""
echo "Examples:"
echo " $0 tasks"
echo " $0 spawn \"Implement auth\" \"Add user authentication system\""
echo " $0 wait abc12345 600"
echo " $0 merge abc12345 --to main --squash"
echo " $0 pr abc12345 --title \"Add auth\" --base main"
;;
esac
|