mirror of
https://github.com/openai/codex.git
synced 2026-04-24 22:54:54 +00:00
wip
This commit is contained in:
@@ -75,72 +75,6 @@ def status():
|
||||
for r in rows:
|
||||
print(fmt.format(*r))
|
||||
|
||||
@cli.command()
|
||||
def applyfrontmatter():
|
||||
"""Add TOML frontmatter to task files missing it."""
|
||||
for md in sorted(task_dir().glob('*.md')):
|
||||
if md.name == 'task-template.md' or md.name.endswith('-plan.md'):
|
||||
continue
|
||||
text = md.read_text(encoding='utf-8')
|
||||
stripped = text.lstrip()
|
||||
# skip files with existing TOML frontmatter
|
||||
if stripped.startswith('+++'):
|
||||
continue
|
||||
# migrate YAML frontmatter if present
|
||||
if stripped.startswith('---'):
|
||||
lines = text.splitlines()
|
||||
# find end of YAML frontmatter
|
||||
end = None
|
||||
for idx, line in enumerate(lines[1:], 1):
|
||||
if line.strip() == '---':
|
||||
end = idx
|
||||
break
|
||||
if end is None:
|
||||
click.echo(f'Malformed YAML frontmatter in {md}', err=True)
|
||||
continue
|
||||
front = '\n'.join(lines[1:end])
|
||||
try:
|
||||
import yaml
|
||||
|
||||
data = yaml.safe_load(front)
|
||||
except ImportError:
|
||||
click.echo(f'Missing PyYAML to parse YAML frontmatter in {md}', err=True)
|
||||
continue
|
||||
task_id = str(data.get('id', '')).strip()
|
||||
title = data.get('title', '').strip()
|
||||
status = data.get('status', '').strip()
|
||||
body = '\n'.join(lines[end + 1 :])
|
||||
else:
|
||||
# no frontmatter: extract from markdown content
|
||||
task_id = md.stem.split('-', 1)[0]
|
||||
lines = text.splitlines()
|
||||
# parse title from heading
|
||||
title = ''
|
||||
for line in lines:
|
||||
if line.startswith('# Task '):
|
||||
parts = line.split(':', 1)
|
||||
title = parts[1].strip() if len(parts) == 2 else line.lstrip('# ').strip()
|
||||
break
|
||||
if not title:
|
||||
click.echo(f'Could not parse title from {md}', err=True)
|
||||
continue
|
||||
# parse status from Status section
|
||||
status = ''
|
||||
in_status = False
|
||||
for line in lines:
|
||||
if in_status and line.strip().startswith('**General Status**:'):
|
||||
status = line.split(':', 1)[1].strip()
|
||||
break
|
||||
if line.strip() == '## Status':
|
||||
in_status = True
|
||||
if not status:
|
||||
status = 'Not started'
|
||||
body = text
|
||||
# apply TOML frontmatter
|
||||
meta = TaskMeta(id=task_id, title=title, status=status)
|
||||
save_task(md, meta, body)
|
||||
click.echo(f'Applied TOML frontmatter to {md}')
|
||||
|
||||
@cli.command()
|
||||
@click.argument('task_id')
|
||||
@click.argument('status')
|
||||
|
||||
Reference in New Issue
Block a user