autopilot-code 0.3.0 → 0.4.0
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.
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from dataclasses import dataclass, asdict, field
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IssueStep(Enum):
|
|
9
|
+
"""Discrete steps in the issue resolution workflow."""
|
|
10
|
+
|
|
11
|
+
INIT = "init"
|
|
12
|
+
WORKTREE_READY = "worktree_ready"
|
|
13
|
+
DEPS_INSTALLED = "deps_installed"
|
|
14
|
+
ISSUE_FETCHED = "issue_fetched"
|
|
15
|
+
PLAN_POSTED = "plan_posted"
|
|
16
|
+
IMPLEMENTED = "implemented"
|
|
17
|
+
COMMITTED = "committed"
|
|
18
|
+
PUSHED = "pushed"
|
|
19
|
+
PR_CREATED = "pr_created"
|
|
20
|
+
CONFLICTS_RESOLVING = "conflicts_resolving"
|
|
21
|
+
CONFLICTS_RESOLVED = "conflicts_resolved"
|
|
22
|
+
CHECKS_WAITING = "checks_waiting"
|
|
23
|
+
CHECKS_FIXING = "checks_fixing"
|
|
24
|
+
CHECKS_PASSED = "checks_passed"
|
|
25
|
+
MERGED = "merged"
|
|
26
|
+
DONE = "done"
|
|
27
|
+
FAILED = "failed"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class StateData:
|
|
32
|
+
"""
|
|
33
|
+
Issue state persisted to GitHub as a hidden comment.
|
|
34
|
+
This is the single source of truth for issue progress.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
issue_number: int
|
|
38
|
+
step: IssueStep
|
|
39
|
+
branch: str
|
|
40
|
+
worktree: str
|
|
41
|
+
pr_number: Optional[int] = None
|
|
42
|
+
session_id: Optional[str] = None # Agent session for context continuity
|
|
43
|
+
conflict_attempts: int = 0
|
|
44
|
+
ci_fix_attempts: int = 0
|
|
45
|
+
error_message: Optional[str] = None
|
|
46
|
+
updated_at: str = field(default_factory=lambda: datetime.utcnow().isoformat() + "Z")
|
|
47
|
+
|
|
48
|
+
def to_dict(self) -> dict:
|
|
49
|
+
"""Convert to JSON-serializable dict."""
|
|
50
|
+
d = asdict(self)
|
|
51
|
+
d["step"] = self.step.value
|
|
52
|
+
return d
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def from_dict(cls, data: dict) -> "StateData":
|
|
56
|
+
"""Create from dict (parsed from JSON)."""
|
|
57
|
+
data["step"] = IssueStep(data["step"])
|
|
58
|
+
return cls(**data)
|
|
59
|
+
|
|
60
|
+
def to_comment_body(self, status_message: str) -> str:
|
|
61
|
+
"""Generate GitHub comment with hidden state JSON."""
|
|
62
|
+
state_json = json.dumps(self.to_dict(), indent=2)
|
|
63
|
+
return f"""
|
|
64
|
+
<!-- autopilot-state
|
|
65
|
+
{state_json}
|
|
66
|
+
-->
|
|
67
|
+
|
|
68
|
+
🤖 **Autopilot Status**: {status_message}
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Human-readable status messages for each step
|
|
73
|
+
STEP_STATUS_MESSAGES = {
|
|
74
|
+
IssueStep.INIT: "Starting work on this issue...",
|
|
75
|
+
IssueStep.WORKTREE_READY: "Git worktree created.",
|
|
76
|
+
IssueStep.DEPS_INSTALLED: "Dependencies installed.",
|
|
77
|
+
IssueStep.ISSUE_FETCHED: "Issue details retrieved.",
|
|
78
|
+
IssueStep.PLAN_POSTED: "Implementation plan ready.",
|
|
79
|
+
IssueStep.IMPLEMENTED: "Code changes complete.",
|
|
80
|
+
IssueStep.COMMITTED: "Changes committed.",
|
|
81
|
+
IssueStep.PUSHED: "Branch pushed to remote.",
|
|
82
|
+
IssueStep.PR_CREATED: "Pull request created.",
|
|
83
|
+
IssueStep.CONFLICTS_RESOLVING: "Resolving merge conflicts...",
|
|
84
|
+
IssueStep.CONFLICTS_RESOLVED: "Merge conflicts resolved.",
|
|
85
|
+
IssueStep.CHECKS_WAITING: "Waiting for CI checks to pass...",
|
|
86
|
+
IssueStep.CHECKS_FIXING: "Attempting to fix failing CI checks...",
|
|
87
|
+
IssueStep.CHECKS_PASSED: "All CI checks passed!",
|
|
88
|
+
IssueStep.MERGED: "PR merged successfully!",
|
|
89
|
+
IssueStep.DONE: "Issue complete! 🎉",
|
|
90
|
+
IssueStep.FAILED: "❌ Autopilot encountered an error.",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
# Labels to apply for each step (for human visibility in issue list)
|
|
94
|
+
STEP_LABELS = {
|
|
95
|
+
IssueStep.INIT: "autopilot:starting",
|
|
96
|
+
IssueStep.PLAN_POSTED: "autopilot:planning",
|
|
97
|
+
IssueStep.IMPLEMENTED: "autopilot:implementing",
|
|
98
|
+
IssueStep.PR_CREATED: "autopilot:pr-created",
|
|
99
|
+
IssueStep.CHECKS_WAITING: "autopilot:waiting-checks",
|
|
100
|
+
IssueStep.CHECKS_FIXING: "autopilot:fixing-checks",
|
|
101
|
+
IssueStep.MERGED: "autopilot:merging",
|
|
102
|
+
}
|