edify-agents-cli 0.2.0__py3-none-any.whl

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.
Files changed (102) hide show
  1. edify/__init__.py +19 -0
  2. edify/__main__.py +6 -0
  3. edify/_toml.py +286 -0
  4. edify/agents.py +261 -0
  5. edify/anim.py +499 -0
  6. edify/assets/commands/build.md +64 -0
  7. edify/assets/commands/plan.md +68 -0
  8. edify/assets/commands/spec.md +63 -0
  9. edify/assets/commands/tasks.md +65 -0
  10. edify/assets/commands/verify.md +67 -0
  11. edify/assets/formats/plan.example.md +455 -0
  12. edify/assets/formats/plan.format.md +128 -0
  13. edify/assets/formats/spec.example.md +483 -0
  14. edify/assets/formats/spec.format.md +116 -0
  15. edify/assets/formats/tasks.example.md +712 -0
  16. edify/assets/formats/tasks.format.md +199 -0
  17. edify/assets/harvest/harvest.md +91 -0
  18. edify/assets/harvest/sources.md +295 -0
  19. edify/assets/harvest/vocab.md +52 -0
  20. edify/assets/manifest.md +30 -0
  21. edify/assets/mcp/default-registry.md +66 -0
  22. edify/assets/skills/adversary.md +61 -0
  23. edify/assets/skills/debugger.md +64 -0
  24. edify/assets/skills/implementer-general.md +53 -0
  25. edify/assets/skills/implementer-go.md +63 -0
  26. edify/assets/skills/implementer-node.md +61 -0
  27. edify/assets/skills/implementer-postgres.md +63 -0
  28. edify/assets/skills/implementer-python.md +65 -0
  29. edify/assets/skills/implementer-react.md +65 -0
  30. edify/assets/skills/planner.md +58 -0
  31. edify/assets/skills/test-writer-node.md +64 -0
  32. edify/assets/skills/test-writer-python.md +60 -0
  33. edify/assets/skills/verifier.md +67 -0
  34. edify/assets/templates/CLAUDE.md +18 -0
  35. edify/assets.py +77 -0
  36. edify/cli.py +681 -0
  37. edify/commands/__init__.py +1 -0
  38. edify/commands/check_cmd.py +72 -0
  39. edify/commands/doctor_cmd.py +206 -0
  40. edify/commands/feedback_cmd.py +90 -0
  41. edify/commands/governance_cmd.py +65 -0
  42. edify/commands/graph_cmd.py +156 -0
  43. edify/commands/harvest_cmd.py +538 -0
  44. edify/commands/init_cmd.py +333 -0
  45. edify/commands/init_new_cmd.py +151 -0
  46. edify/commands/license_cmd.py +80 -0
  47. edify/commands/mcp_cmd.py +159 -0
  48. edify/commands/self_cmd.py +185 -0
  49. edify/commands/setup_cmd.py +79 -0
  50. edify/commands/skills_cmd.py +177 -0
  51. edify/commands/upgrade_cmd.py +178 -0
  52. edify/context.py +57 -0
  53. edify/conventions.py +275 -0
  54. edify/detect.py +313 -0
  55. edify/distribution.py +40 -0
  56. edify/errors.py +66 -0
  57. edify/feedback.py +207 -0
  58. edify/formats/__init__.py +11 -0
  59. edify/formats/check.py +573 -0
  60. edify/formats/document.py +238 -0
  61. edify/formats/finding.py +50 -0
  62. edify/formats/fix.py +114 -0
  63. edify/formats/mcp.py +126 -0
  64. edify/formats/plan.py +151 -0
  65. edify/formats/skill.py +139 -0
  66. edify/formats/spec.py +164 -0
  67. edify/formats/tasks.py +321 -0
  68. edify/governance.py +316 -0
  69. edify/graph/__init__.py +11 -0
  70. edify/graph/extract.py +351 -0
  71. edify/graph/ignore.py +107 -0
  72. edify/graph/langs/__init__.py +93 -0
  73. edify/graph/langs/ctags.py +145 -0
  74. edify/graph/langs/markdown.py +41 -0
  75. edify/graph/langs/patterns.py +361 -0
  76. edify/graph/langs/python_ast.py +154 -0
  77. edify/graph/langs/sqlish.py +86 -0
  78. edify/graph/model.py +102 -0
  79. edify/graph/queries.py +211 -0
  80. edify/graph/store.py +157 -0
  81. edify/harvest/__init__.py +28 -0
  82. edify/harvest/ledger.py +191 -0
  83. edify/harvest/screen.py +236 -0
  84. edify/harvest/sources.py +298 -0
  85. edify/host.py +345 -0
  86. edify/interview.py +354 -0
  87. edify/library.py +176 -0
  88. edify/licensing/__init__.py +30 -0
  89. edify/licensing/ed25519.py +154 -0
  90. edify/licensing/projects.py +223 -0
  91. edify/licensing/tier.py +172 -0
  92. edify/licensing/token.py +149 -0
  93. edify/paths.py +282 -0
  94. edify/selfinstall.py +244 -0
  95. edify/skills.py +108 -0
  96. edify/tsv.py +109 -0
  97. edify/ui.py +334 -0
  98. edify_agents_cli-0.2.0.dist-info/METADATA +408 -0
  99. edify_agents_cli-0.2.0.dist-info/RECORD +102 -0
  100. edify_agents_cli-0.2.0.dist-info/WHEEL +4 -0
  101. edify_agents_cli-0.2.0.dist-info/entry_points.txt +2 -0
  102. edify_agents_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
edify/formats/skill.py ADDED
@@ -0,0 +1,139 @@
1
+ """The skill file: eight frontmatter fields and a short plain body.
2
+
3
+ Loose metadata is fine for a wiki and useless for a lookup table, so an unknown
4
+ key, a missing required key, or a value outside its set makes the file invalid —
5
+ reported by `edify check` and skipped by the indexer.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import re
11
+ from dataclasses import dataclass, field
12
+ from pathlib import Path
13
+
14
+ from .document import parse_document
15
+
16
+ REQUIRED_FIELDS = ("name", "description", "kind", "role", "phase", "tech", "provenance")
17
+ OPTIONAL_FIELDS = ("license", "source", "updated")
18
+ ALL_FIELDS = REQUIRED_FIELDS + OPTIONAL_FIELDS
19
+
20
+ KINDS = ("skill", "agent")
21
+ ROLES = ("planner", "adversary", "test", "implementer", "debugger", "verifier")
22
+ PROVENANCE = ("original", "adapted", "client")
23
+ PHASES = tuple(str(n) for n in range(8))
24
+
25
+ # ≤80 lines for a skill, ≤150 for a deep specialist carrying real stack-specific
26
+ # knowledge. Past about eighty lines the marginal line displaces the actual work.
27
+ BUDGET = {"skill": 80, "agent": 150}
28
+
29
+ _NAME = re.compile(r"^[a-z0-9][a-z0-9-]*$")
30
+
31
+
32
+ @dataclass
33
+ class Skill:
34
+ path: Path
35
+ rel: str
36
+ name: str = ""
37
+ description: str = ""
38
+ kind: str = ""
39
+ role: str = ""
40
+ phases: list[str] = field(default_factory=list)
41
+ tech: list[str] = field(default_factory=list)
42
+ provenance: str = ""
43
+ license: str = ""
44
+ source: str = ""
45
+ body_lines: int = 0
46
+ total_lines: int = 0
47
+ field_lines: dict[str, int] = field(default_factory=dict)
48
+ unknown_fields: list[str] = field(default_factory=list)
49
+
50
+ @property
51
+ def budget(self) -> int:
52
+ return BUDGET.get(self.kind, 80)
53
+
54
+ @property
55
+ def over_budget(self) -> bool:
56
+ return self.body_lines > self.budget
57
+
58
+ def index_rows(self) -> list[list[str]]:
59
+ """One row per (role, phase, tech) triple — the shape `resolve` searches."""
60
+ rows: list[list[str]] = []
61
+ techs = self.tech or ["any"]
62
+ phases = self.phases or ["-"]
63
+ for phase in phases:
64
+ for tech in techs:
65
+ rows.append([self.role, phase, tech, self.name, self.rel])
66
+ return rows
67
+
68
+
69
+ def parse(path: Path, rel: str | None = None) -> Skill:
70
+ doc = parse_document(path, rel)
71
+ skill = Skill(path=path, rel=rel or path.as_posix())
72
+ skill.total_lines = len(doc.lines)
73
+ skill.body_lines = max(0, len(doc.lines) - doc.frontmatter_end)
74
+ skill.field_lines = dict(doc.frontmatter_lines)
75
+
76
+ fm = doc.frontmatter
77
+ skill.name = fm.get("name", "")
78
+ skill.description = fm.get("description", "")
79
+ skill.kind = fm.get("kind", "")
80
+ skill.role = fm.get("role", "")
81
+ skill.phases = doc.list_field("phase")
82
+ skill.tech = doc.list_field("tech")
83
+ skill.provenance = fm.get("provenance", "")
84
+ skill.license = fm.get("license", "")
85
+ skill.source = fm.get("source", "")
86
+ skill.unknown_fields = [k for k in fm if k not in ALL_FIELDS]
87
+ return skill
88
+
89
+
90
+ def validate(skill: Skill) -> list[tuple[str, str, int]]:
91
+ """(code, message, line) for everything wrong with this file's metadata."""
92
+ problems: list[tuple[str, str, int]] = []
93
+
94
+ def at(key: str) -> int:
95
+ return skill.field_lines.get(key, 1)
96
+
97
+ for key in REQUIRED_FIELDS:
98
+ value = getattr(skill, "phases" if key == "phase" else key, "")
99
+ if not value:
100
+ problems.append(("skill-missing-field", f"required frontmatter key `{key}` is missing", 1))
101
+
102
+ if skill.name and not _NAME.match(skill.name):
103
+ problems.append(("skill-bad-name", f"`name: {skill.name}` is not [a-z0-9-]+", at("name")))
104
+ if skill.kind and skill.kind not in KINDS:
105
+ problems.append(("skill-bad-kind", f"`kind: {skill.kind}` is not one of {'|'.join(KINDS)}", at("kind")))
106
+ if skill.role and skill.role not in ROLES:
107
+ problems.append(("skill-bad-role", f"`role: {skill.role}` is not one of {'|'.join(ROLES)}", at("role")))
108
+ for phase in skill.phases:
109
+ if phase not in PHASES:
110
+ problems.append(("skill-bad-phase", f"phase `{phase}` is not 0-7", at("phase")))
111
+ if skill.provenance and skill.provenance not in PROVENANCE:
112
+ problems.append(
113
+ ("skill-bad-provenance", f"`provenance: {skill.provenance}` is not one of {'|'.join(PROVENANCE)}", at("provenance"))
114
+ )
115
+ if skill.provenance == "adapted" and not skill.license:
116
+ problems.append(
117
+ ("skill-missing-license", "an adapted skill needs `license` — an SPDX id plus repo@commit", at("provenance"))
118
+ )
119
+ for key in skill.unknown_fields:
120
+ problems.append(("skill-unknown-field", f"unknown frontmatter key `{key}`", at(key)))
121
+ if skill.over_budget:
122
+ problems.append(
123
+ (
124
+ "skill-over-budget",
125
+ f"{skill.body_lines} lines of body, budget is {skill.budget} for kind `{skill.kind or 'skill'}`",
126
+ 1,
127
+ )
128
+ )
129
+ return problems
130
+
131
+
132
+ def load_all(directory: Path, root: Path | None = None) -> list[Skill]:
133
+ out: list[Skill] = []
134
+ if not directory.is_dir():
135
+ return out
136
+ for path in sorted(directory.glob("*.md")):
137
+ rel = path.relative_to(root).as_posix() if root else path.name
138
+ out.append(parse(path, rel))
139
+ return out
edify/formats/spec.py ADDED
@@ -0,0 +1,164 @@
1
+ """`spec.md` — what is being built and why.
2
+
3
+ Parses the sections a downstream command actually consumes: the requirements, the
4
+ assertions with their verification kinds, the closure checklist, and the open
5
+ questions. Everything else in the file is for a human and is left alone.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass, field
11
+ from pathlib import Path
12
+
13
+ from .document import Document, Row, parse_document
14
+
15
+ # The whole legal set, ordered from the cheapest evidence to the strongest.
16
+ VERIFICATION_KINDS = ("types", "example", "contract", "property", "model", "proof", "observation")
17
+
18
+ # Above this rung an assertion has to be budgeted in plan.md, because an
19
+ # unbudgeted model check silently becomes an example test during the build.
20
+ BUDGETED_KINDS = ("model", "proof")
21
+
22
+ REQUIRED_SECTIONS = ("brief", "intent", "constraints", "requirements", "assertions")
23
+ EXPECTED_SECTIONS = REQUIRED_SECTIONS + ("what this entails", "open questions", "non-goals")
24
+
25
+
26
+ @dataclass
27
+ class Requirement:
28
+ id: str
29
+ text: str
30
+ assertions: list[str]
31
+ line: int
32
+
33
+
34
+ @dataclass
35
+ class Assertion:
36
+ id: str
37
+ text: str
38
+ kind: str
39
+ citation: str
40
+ line: int
41
+
42
+
43
+ @dataclass
44
+ class ChecklistItem:
45
+ id: str
46
+ text: str
47
+ status: str
48
+ line: int
49
+
50
+
51
+ @dataclass
52
+ class Spec:
53
+ doc: Document
54
+ feature: str = ""
55
+ status: str = ""
56
+ requirements: list[Requirement] = field(default_factory=list)
57
+ assertions: list[Assertion] = field(default_factory=list)
58
+ checklist: list[ChecklistItem] = field(default_factory=list)
59
+ open_questions: list[Row] = field(default_factory=list)
60
+
61
+ @property
62
+ def rel(self) -> str:
63
+ return self.doc.rel
64
+
65
+ def assertion_ids(self) -> set[str]:
66
+ return {a.id for a in self.assertions}
67
+
68
+ def requirement_ids(self) -> set[str]:
69
+ return {r.id for r in self.requirements}
70
+
71
+ def checklist_ids(self) -> set[str]:
72
+ return {c.id for c in self.checklist}
73
+
74
+ def kind_of(self, assertion_id: str) -> str:
75
+ for a in self.assertions:
76
+ if a.id == assertion_id:
77
+ return a.kind
78
+ return ""
79
+
80
+
81
+ def parse(path: Path, rel: str | None = None) -> Spec:
82
+ doc = parse_document(path, rel)
83
+ spec = Spec(doc=doc)
84
+ spec.feature = doc.frontmatter.get("feature", "")
85
+ spec.status = doc.frontmatter.get("status", "")
86
+
87
+ section = doc.section("Requirements")
88
+ if section:
89
+ for table in section.tables:
90
+ id_col = table.column("id", "#")
91
+ text_col = table.column("requirement", "what it is", "description")
92
+ asserts_col = table.column("assertions", "asserted by", "proven by")
93
+ for row in table.rows:
94
+ rid = _clean(row.get(id_col if id_col >= 0 else 0))
95
+ if not rid or rid.startswith("-"):
96
+ continue
97
+ spec.requirements.append(
98
+ Requirement(
99
+ id=rid,
100
+ text=row.get(text_col if text_col >= 0 else 1),
101
+ assertions=_ids(row.get(asserts_col)) if asserts_col >= 0 else [],
102
+ line=row.line,
103
+ )
104
+ )
105
+
106
+ section = doc.section("Assertions")
107
+ if section:
108
+ for table in section.tables:
109
+ id_col = table.column("id", "#")
110
+ text_col = table.column("assertion", "statement", "what it is")
111
+ kind_col = table.column("verification", "kind", "verified by", "how")
112
+ cite_col = table.column("citation", "where", "cite")
113
+ for row in table.rows:
114
+ aid = _clean(row.get(id_col if id_col >= 0 else 0))
115
+ if not aid or aid.startswith("-"):
116
+ continue
117
+ spec.assertions.append(
118
+ Assertion(
119
+ id=aid,
120
+ text=row.get(text_col if text_col >= 0 else 1),
121
+ kind=_clean(row.get(kind_col)).lower() if kind_col >= 0 else "",
122
+ citation=row.get(cite_col) if cite_col >= 0 else "",
123
+ line=row.line,
124
+ )
125
+ )
126
+
127
+ section = doc.section("What this entails", "Closure checklist")
128
+ if section:
129
+ for table in section.tables:
130
+ id_col = table.column("id", "#")
131
+ text_col = table.column("entails", "what it is", "item", "requirement")
132
+ status_col = table.column("status", "state", "satisfied by", "resolution")
133
+ for row in table.rows:
134
+ cid = _clean(row.get(id_col if id_col >= 0 else 0))
135
+ if not cid or cid.startswith("-"):
136
+ continue
137
+ spec.checklist.append(
138
+ ChecklistItem(
139
+ id=cid,
140
+ text=row.get(text_col if text_col >= 0 else 1),
141
+ status=row.get(status_col) if status_col >= 0 else "",
142
+ line=row.line,
143
+ )
144
+ )
145
+
146
+ section = doc.section("Open questions")
147
+ if section:
148
+ for table in section.tables:
149
+ spec.open_questions.extend(table.rows)
150
+
151
+ return spec
152
+
153
+
154
+ def _clean(value: str) -> str:
155
+ return value.strip().strip("`*_ ")
156
+
157
+
158
+ def _ids(value: str) -> list[str]:
159
+ out: list[str] = []
160
+ for token in value.replace(",", " ").split():
161
+ token = _clean(token)
162
+ if token and token not in ("-", "—", "none"):
163
+ out.append(token)
164
+ return out
edify/formats/tasks.py ADDED
@@ -0,0 +1,321 @@
1
+ """`tasks.md` — exactly what will change, where, in what order.
2
+
3
+ The most important format in the system. Its precision is the difference between a
4
+ build that runs on a cheap model in one pass and one that stalls on every third
5
+ task, so this parser is strict about the five questions every task block answers:
6
+ where does it land, what does right look like, what are the steps, how do I know it
7
+ worked, and what does it depend on.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import re
13
+ from dataclasses import dataclass, field
14
+ from pathlib import Path
15
+
16
+ from .document import Document, Row, Section, Table, parse_document
17
+
18
+ PHASE_NAMES = {
19
+ 0: "Foundation",
20
+ 1: "Contracts",
21
+ 2: "Verification",
22
+ 3: "Core",
23
+ 4: "Surfaces",
24
+ 5: "Integration",
25
+ 6: "Hardening",
26
+ 7: "Proof",
27
+ }
28
+
29
+ FILE_ACTIONS = ("new", "edit", "delete")
30
+
31
+ _TASK_HEADING = re.compile(r"^(?P<id>T-\d+[a-z]?)\s*[·:\-—]\s*(?P<title>.+)$")
32
+ _PHASE_FIELD = re.compile(r"\bPhase\s+(?P<phase>\d+)\b", re.IGNORECASE)
33
+ _ROLE_FIELD = re.compile(r"\bRole\s+(?P<role>[\w\-]+)", re.IGNORECASE)
34
+ _SKILL_FIELD = re.compile(r"\bSkill\s+(?P<skill>[\w\-]+)", re.IGNORECASE)
35
+ _SIZE_FIELD = re.compile(r"\bSize\s+(?P<size>xs|s|m|l|xl)\b", re.IGNORECASE)
36
+ _DISCHARGES = re.compile(r"^\s*Discharges\s+(?P<ids>.+)$", re.IGNORECASE)
37
+ _VERIFICATION = re.compile(r"^\s*Verification\s+(?P<kinds>.+)$", re.IGNORECASE)
38
+ _DEPENDS = re.compile(r"^\s*Depends on\s+(?P<ids>.*?)(?:·|$)", re.IGNORECASE)
39
+ _PARALLEL = re.compile(r"Parallel with\s+(?P<ids>.+)$", re.IGNORECASE)
40
+ _RANGE = re.compile(r"^(?P<start>\d+)\s*[-–]\s*(?P<end>\d+)$")
41
+
42
+
43
+ @dataclass
44
+ class FileRef:
45
+ path: str
46
+ range: str
47
+ action: str
48
+ line: int
49
+
50
+ @property
51
+ def has_range(self) -> bool:
52
+ return bool(_RANGE.match(self.range.strip()) or self.range.strip().isdigit())
53
+
54
+ @property
55
+ def bounds(self) -> tuple[int, int] | None:
56
+ text = self.range.strip()
57
+ m = _RANGE.match(text)
58
+ if m:
59
+ return int(m.group("start")), int(m.group("end"))
60
+ if text.isdigit():
61
+ return int(text), int(text)
62
+ return None
63
+
64
+
65
+ @dataclass
66
+ class Task:
67
+ id: str
68
+ title: str
69
+ line: int
70
+ end_line: int
71
+ phase: int | None = None
72
+ role: str = ""
73
+ skill: str = ""
74
+ size: str = ""
75
+ discharges: list[str] = field(default_factory=list)
76
+ verification: list[str] = field(default_factory=list)
77
+ depends_on: list[str] = field(default_factory=list)
78
+ parallel_with: list[str] = field(default_factory=list)
79
+ files: list[FileRef] = field(default_factory=list)
80
+ patterns: list[str] = field(default_factory=list)
81
+ steps: list[str] = field(default_factory=list)
82
+ done_when: list[str] = field(default_factory=list)
83
+ files_table_line: int = 0
84
+
85
+ @property
86
+ def edits(self) -> list[FileRef]:
87
+ return [f for f in self.files if f.action.lower() == "edit"]
88
+
89
+ @property
90
+ def paths(self) -> list[str]:
91
+ return [f.path for f in self.files]
92
+
93
+
94
+ @dataclass
95
+ class Phase:
96
+ number: int
97
+ name: str
98
+ task_ids: list[str]
99
+ parallel: str
100
+ exit_check: str
101
+ line: int
102
+
103
+
104
+ @dataclass
105
+ class CoverageRow:
106
+ source: str
107
+ what: str
108
+ cells: list[str]
109
+ line: int
110
+
111
+ @property
112
+ def discharged(self) -> str:
113
+ return " ".join(c for c in self.cells if c.strip())
114
+
115
+
116
+ @dataclass
117
+ class Tasks:
118
+ doc: Document
119
+ feature: str = ""
120
+ status: str = ""
121
+ spec_ref: str = ""
122
+ tasks: list[Task] = field(default_factory=list)
123
+ phases: list[Phase] = field(default_factory=list)
124
+ coverage: list[CoverageRow] = field(default_factory=list)
125
+ decisions: list[Row] = field(default_factory=list)
126
+
127
+ @property
128
+ def rel(self) -> str:
129
+ return self.doc.rel
130
+
131
+ def by_id(self, task_id: str) -> Task | None:
132
+ for task in self.tasks:
133
+ if task.id == task_id:
134
+ return task
135
+ return None
136
+
137
+ def in_phase(self, number: int) -> list[Task]:
138
+ return [t for t in self.tasks if t.phase == number]
139
+
140
+
141
+ def parse(path: Path, rel: str | None = None) -> Tasks:
142
+ doc = parse_document(path, rel)
143
+ out = Tasks(doc=doc)
144
+ out.feature = doc.frontmatter.get("feature", "")
145
+ out.status = doc.frontmatter.get("status", "")
146
+ out.spec_ref = doc.frontmatter.get("spec", "")
147
+
148
+ current_phase: int | None = None
149
+ for section in doc.sections:
150
+ if section.level == 2:
151
+ m = re.match(r"^phase\s+(\d+)", section.key)
152
+ current_phase = int(m.group(1)) if m else None
153
+ if section.key.startswith("phases"):
154
+ out.phases.extend(_phases(section))
155
+ elif section.key.startswith("coverage"):
156
+ out.coverage.extend(_coverage(section))
157
+ elif section.key.startswith("decisions"):
158
+ for table in section.tables:
159
+ out.decisions.extend(table.rows)
160
+ continue
161
+
162
+ heading = _TASK_HEADING.match(section.title)
163
+ if heading and section.level == 3:
164
+ out.tasks.append(_task(section, heading, current_phase))
165
+
166
+ return out
167
+
168
+
169
+ # ---------------------------------------------------------------------------
170
+
171
+
172
+ def _task(section: Section, heading: re.Match[str], fallback_phase: int | None) -> Task:
173
+ task = Task(
174
+ id=heading.group("id"),
175
+ title=heading.group("title").strip(),
176
+ line=section.line,
177
+ end_line=section.end_line,
178
+ phase=fallback_phase,
179
+ )
180
+
181
+ block: str | None = None
182
+ for offset, raw in enumerate(section.lines):
183
+ lineno = section.line + 1 + offset
184
+ line = raw.rstrip()
185
+ stripped = line.strip()
186
+ lowered = stripped.lower()
187
+
188
+ m = _PHASE_FIELD.search(line)
189
+ if m and not task.role:
190
+ task.phase = int(m.group("phase"))
191
+ m = _ROLE_FIELD.search(line)
192
+ if m and not task.role:
193
+ task.role = m.group("role")
194
+ m = _SKILL_FIELD.search(line)
195
+ if m and not task.skill:
196
+ task.skill = m.group("skill")
197
+ m = _SIZE_FIELD.search(line)
198
+ if m and not task.size:
199
+ task.size = m.group("size").lower()
200
+
201
+ m = _DISCHARGES.match(line)
202
+ if m:
203
+ task.discharges = _ids(m.group("ids"))
204
+ continue
205
+ m = _VERIFICATION.match(line)
206
+ if m:
207
+ task.verification = _kinds(m.group("kinds"))
208
+ continue
209
+ m = _DEPENDS.match(line)
210
+ if m:
211
+ task.depends_on = _ids(m.group("ids"))
212
+ m = _PARALLEL.search(line)
213
+ if m:
214
+ task.parallel_with = _ids(m.group("ids"))
215
+
216
+ if lowered in ("files", "**files**", "files:"):
217
+ block = "files"
218
+ continue
219
+ if lowered.startswith("follow the pattern"):
220
+ block = "pattern"
221
+ continue
222
+ if lowered in ("steps", "**steps**", "steps:"):
223
+ block = "steps"
224
+ continue
225
+ if lowered.startswith("done when"):
226
+ block = "done"
227
+ continue
228
+ if stripped.startswith("#") or lowered.startswith("files:"):
229
+ block = None
230
+
231
+ if block == "pattern" and stripped.startswith(("-", "*")):
232
+ task.patterns.append(stripped.lstrip("-* ").strip())
233
+ elif block == "pattern" and stripped and not stripped.startswith("|"):
234
+ if task.patterns:
235
+ task.patterns[-1] += " " + stripped
236
+ elif block == "steps" and re.match(r"^\d+[.)]\s+", stripped):
237
+ task.steps.append(re.sub(r"^\d+[.)]\s+", "", stripped))
238
+ elif block == "steps" and stripped and task.steps and not stripped.startswith("|"):
239
+ task.steps[-1] += " " + stripped
240
+ elif block == "done" and stripped.startswith(("-", "*")):
241
+ task.done_when.append(stripped.lstrip("-* ").strip())
242
+ elif block == "done" and stripped and task.done_when and not stripped.startswith("|"):
243
+ task.done_when[-1] += " " + stripped
244
+
245
+ for table in section.tables:
246
+ path_col = table.column("path", "file")
247
+ range_col = table.column("range", "lines")
248
+ action_col = table.column("action")
249
+ if path_col < 0 or action_col < 0:
250
+ continue
251
+ task.files_table_line = table.line
252
+ for row in table.rows:
253
+ path_value = row.get(path_col).strip("`")
254
+ if not path_value or set(path_value) <= {"-", "—"}:
255
+ continue
256
+ task.files.append(
257
+ FileRef(
258
+ path=path_value,
259
+ range=row.get(range_col) if range_col >= 0 else "",
260
+ action=row.get(action_col),
261
+ line=row.line,
262
+ )
263
+ )
264
+ return task
265
+
266
+
267
+ def _phases(section: Section) -> list[Phase]:
268
+ out: list[Phase] = []
269
+ for table in section.tables:
270
+ num_col = table.column("#", "phase number")
271
+ name_col = table.column("phase", "name")
272
+ tasks_col = table.column("tasks")
273
+ parallel_col = table.column("parallel-safe", "parallel")
274
+ exit_col = table.column("exit check", "exit")
275
+ for row in table.rows:
276
+ raw_num = row.get(num_col if num_col >= 0 else 0)
277
+ if not raw_num.strip().isdigit():
278
+ continue
279
+ out.append(
280
+ Phase(
281
+ number=int(raw_num.strip()),
282
+ name=row.get(name_col) if name_col >= 0 else "",
283
+ task_ids=_ids(row.get(tasks_col)) if tasks_col >= 0 else [],
284
+ parallel=row.get(parallel_col) if parallel_col >= 0 else "",
285
+ exit_check=row.get(exit_col) if exit_col >= 0 else "",
286
+ line=row.line,
287
+ )
288
+ )
289
+ return out
290
+
291
+
292
+ def _coverage(section: Section) -> list[CoverageRow]:
293
+ out: list[CoverageRow] = []
294
+ for table in section.tables:
295
+ for row in table.rows:
296
+ source = row.get(0)
297
+ if not source or set(source) <= {"-", "—", " "}:
298
+ continue
299
+ out.append(
300
+ CoverageRow(
301
+ source=source,
302
+ what=row.get(1),
303
+ cells=[row.get(i) for i in range(2, max(3, len(table.headers)))],
304
+ line=row.line,
305
+ )
306
+ )
307
+ return out
308
+
309
+
310
+ def _ids(value: str) -> list[str]:
311
+ out: list[str] = []
312
+ for token in re.split(r"[,\s·∥]+", value):
313
+ token = token.strip().strip("`*_")
314
+ if token and token not in ("-", "—", "and", "all", "none"):
315
+ out.append(token)
316
+ return out
317
+
318
+
319
+ def _kinds(value: str) -> list[str]:
320
+ cleaned = re.sub(r"\([^)]*\)", " ", value)
321
+ return [t.strip().lower() for t in re.split(r"[,\s]+", cleaned) if t.strip()]