mirror of
https://github.com/johndoe6345789/MetalOS.git
synced 2026-04-24 13:45:02 +00:00
Enhance RoadmapAgent: support listing and viewing phases with parsing logic
- Parse ROADMAP.md dynamically to list phases and view specific phase details - Fix path resolution to top-level docs/ROADMAP.md Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -3,39 +3,81 @@
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
def parse_roadmap(path):
|
||||
lines = path.read_text().splitlines(keepends=True)
|
||||
phases = []
|
||||
for i, line in enumerate(lines):
|
||||
m = re.match(r"^### Phase\s+(\d+):\s*(.+)", line)
|
||||
if m:
|
||||
phases.append((m.group(1), m.group(2).strip(), i))
|
||||
return lines, phases
|
||||
|
||||
|
||||
def list_phases(phases):
|
||||
print("Available Phases:")
|
||||
for num, title, _ in phases:
|
||||
print(f"Phase {num}: {title}")
|
||||
|
||||
|
||||
def view_phase(lines, phases, phase_num):
|
||||
for idx, (num, title, start) in enumerate(phases):
|
||||
if num == phase_num:
|
||||
end = phases[idx+1][2] if idx+1 < len(phases) else len(lines)
|
||||
print(''.join(lines[start:end]).rstrip())
|
||||
return
|
||||
print(f"Phase {phase_num} not found.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def add_item(lines, phases, phase_num, item):
|
||||
for idx, (num, title, start) in enumerate(phases):
|
||||
if num == phase_num:
|
||||
end = phases[idx+1][2] if idx+1 < len(phases) else len(lines)
|
||||
# find insertion point before end, after last task line
|
||||
insert = end
|
||||
for j in range(start+1, end):
|
||||
if lines[j].startswith('###'): break
|
||||
if re.match(r"^\s*- \[.\]", lines[j]):
|
||||
insert = j+1
|
||||
lines.insert(insert, f"- [ ] {item}\n")
|
||||
return lines
|
||||
print(f"Phase {phase_num} not found.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="RoadmapAgent: view or update the project roadmap (docs/ROADMAP.md)"
|
||||
description="RoadmapAgent: manage docs/ROADMAP.md"
|
||||
)
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument(
|
||||
'--view', '-v',
|
||||
action='store_true',
|
||||
help='Display the current roadmap'
|
||||
)
|
||||
group.add_argument(
|
||||
'--add', '-a',
|
||||
metavar='ITEM',
|
||||
help='Append a new item to the roadmap'
|
||||
)
|
||||
group.add_argument('--list-phases', action='store_true', help='List all roadmap phases')
|
||||
group.add_argument('--view-phase', metavar='NUM', help='View tasks for a specific phase')
|
||||
group.add_argument('--add-item', nargs=2, metavar=('NUM', 'ITEM'), help='Add a new incomplete task to a phase')
|
||||
args = parser.parse_args()
|
||||
roadmap_path = Path(__file__).parent.parent / 'docs' / 'ROADMAP.md'
|
||||
|
||||
if args.view:
|
||||
if not roadmap_path.exists():
|
||||
print(f"Roadmap file not found at {roadmap_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print(roadmap_path.read_text())
|
||||
roadmap_path = Path(__file__).resolve().parents[2] / 'docs' / 'ROADMAP.md'
|
||||
if not roadmap_path.exists():
|
||||
print(f"Roadmap file not found at {roadmap_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
lines, phases = parse_roadmap(roadmap_path)
|
||||
|
||||
if args.list_phases:
|
||||
list_phases(phases)
|
||||
sys.exit(0)
|
||||
|
||||
if args.add:
|
||||
# Append new roadmap item
|
||||
entry = f"- {args.add}\n"
|
||||
if args.view_phase:
|
||||
view_phase(lines, phases, args.view_phase)
|
||||
sys.exit(0)
|
||||
|
||||
if args.add_item:
|
||||
num, item = args.add_item
|
||||
new_lines = add_item(lines, phases, num, item)
|
||||
try:
|
||||
with open(roadmap_path, 'a') as f:
|
||||
f.write(entry)
|
||||
print(f"Added roadmap item: {args.add}")
|
||||
roadmap_path.write_text(''.join(new_lines))
|
||||
print(f"Added item to Phase {num}: {item}")
|
||||
sys.exit(0)
|
||||
except Exception as e:
|
||||
print(f"Failed to update roadmap: {e}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user