autopilot-code 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "enabled": true,
3
3
  "repo": "bakkensoftware/autopilot",
4
- "agent": "opencode",
4
+ "agent": "opencode-server",
5
5
  "autoMerge": true,
6
6
  "mergeMethod": "squash",
7
7
  "allowedMergeUsers": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autopilot-code",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "private": false,
5
5
  "description": "Repo-issue–driven autopilot runner",
6
6
  "license": "MIT",
@@ -183,11 +183,63 @@ class GitHubStateManager:
183
183
  except (json.JSONDecodeError, KeyError, TypeError):
184
184
  return None
185
185
 
186
+ def _create_label(self, label_name: str) -> bool:
187
+ """
188
+ Create a label in the GitHub repository.
189
+
190
+ Returns True if created or already exists, False on failure.
191
+ """
192
+ # Define standard labels with colors and descriptions
193
+ label_defs = {
194
+ "autopilot:todo": {"color": "7057ff", "description": "Ready to be picked up by autopilot"},
195
+ "autopilot:in-progress": {"color": "0075ca", "description": "Claimed by autopilot"},
196
+ "autopilot:blocked": {"color": "d93f0b", "description": "Needs human input or missing heartbeat"},
197
+ "autopilot:done": {"color": "3fb950", "description": "Completed"},
198
+ "autopilot:backlog": {"color": "d4c5f9", "description": "Captured, not ready"},
199
+ "autopilot:planning": {"color": "5319e7", "description": "Creating implementation plan"},
200
+ "autopilot:implementing": {"color": "1f883d", "description": "Writing code"},
201
+ "autopilot:pr-created": {"color": "fbca04", "description": "Pull request created"},
202
+ "autopilot:waiting-checks": {"color": "0e8a16", "description": "Waiting for CI checks"},
203
+ "autopilot:fixing-checks": {"color": "cfd3d7", "description": "Fixing failing CI checks"},
204
+ "autopilot:merging": {"color": "bfd4f2", "description": "Merging pull request"},
205
+ }
206
+
207
+ if label_name not in label_defs:
208
+ print(f"Warning: Unknown label '{label_name}', skipping auto-creation", flush=True)
209
+ return False
210
+
211
+ label_info = label_defs[label_name]
212
+
213
+ try:
214
+ self._run_gh([
215
+ "api",
216
+ "--method",
217
+ "POST",
218
+ "-H",
219
+ "Accept: application/vnd.github+json",
220
+ f"repos/{self.repo}/labels",
221
+ "-f",
222
+ f"name={label_name}",
223
+ "-f",
224
+ f"color={label_info['color']}",
225
+ "-f",
226
+ f"description={label_info['description']}",
227
+ ])
228
+ print(f"✅ Auto-created missing label: {label_name}", flush=True)
229
+ return True
230
+ except RuntimeError as e:
231
+ # Label might already exist, which is fine
232
+ if "already exists" in str(e).lower() or "Label already exists" in str(e):
233
+ return True
234
+ print(f"⚠️ Failed to auto-create label '{label_name}': {e}", flush=True)
235
+ return False
236
+
186
237
  def _set_step_label(self, issue_number: int, step: IssueStep) -> None:
187
238
  """
188
- Update the autopilot step label.
239
+ Update autopilot step label.
189
240
 
190
241
  Removes any existing autopilot:* step labels and adds the new one.
242
+ Auto-creates missing labels if needed.
191
243
  """
192
244
  result = self._run_gh(
193
245
  [
@@ -220,17 +272,48 @@ class GitHubStateManager:
220
272
  )
221
273
 
222
274
  if step in STEP_LABELS:
223
- self._run_gh(
224
- [
225
- "issue",
226
- "edit",
227
- str(issue_number),
228
- "--repo",
229
- self.repo,
230
- "--add-label",
231
- STEP_LABELS[step],
232
- ]
233
- )
275
+ new_label = STEP_LABELS[step]
276
+ try:
277
+ self._run_gh(
278
+ [
279
+ "issue",
280
+ "edit",
281
+ str(issue_number),
282
+ "--repo",
283
+ self.repo,
284
+ "--add-label",
285
+ new_label,
286
+ ]
287
+ )
288
+ except RuntimeError as e:
289
+ # Check if it's a "label not found" error
290
+ error_msg = str(e)
291
+ if "not found" in error_msg.lower() or "label" in error_msg.lower():
292
+ print(f"⚠️ Label '{new_label}' not found in repo '{self.repo}'", flush=True)
293
+ print(f"🔧 Attempting to auto-create label...", flush=True)
294
+
295
+ if self._create_label(new_label):
296
+ # Retry adding the label
297
+ self._run_gh(
298
+ [
299
+ "issue",
300
+ "edit",
301
+ str(issue_number),
302
+ "--repo",
303
+ self.repo,
304
+ "--add-label",
305
+ new_label,
306
+ ]
307
+ )
308
+ else:
309
+ # Auto-creation failed, provide helpful error
310
+ raise RuntimeError(
311
+ f"Required label '{new_label}' does not exist in repository '{self.repo}'. "
312
+ f"Please run: autopilot setup-labels --repo {self.repo}"
313
+ ) from e
314
+ else:
315
+ # Some other error, re-raise
316
+ raise
234
317
 
235
318
  def _run_gh(self, args: list[str]) -> str:
236
319
  """Run a gh CLI command and return stdout."""