cowork-flow 2.4.1 → 2.5.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.en.md +2 -1
  3. package/README.md +2 -1
  4. package/docs/architecture.en.md +2 -0
  5. package/docs/architecture.md +2 -0
  6. package/docs/hosts.en.md +15 -0
  7. package/docs/hosts.md +15 -0
  8. package/package.json +2 -2
  9. package/presets/claude-code/.claude-plugin/plugin.json +1 -1
  10. package/presets/codex/.codex-plugin/plugin.json +1 -1
  11. package/presets/kimi-code/.kimi-plugin/plugin.json +1 -1
  12. package/presets/qoder/.qoder-plugin/plugin.json +1 -1
  13. package/presets/zcode/.zcode-plugin/plugin.json +1 -1
  14. package/src/commands/host-inspect.js +86 -0
  15. package/src/commands/host.js +42 -18
  16. package/src/commands/init.js +100 -3
  17. package/src/commands/install-claude-code-plugin.js +53 -2
  18. package/src/commands/install-codex-plugin.js +114 -4
  19. package/src/commands/install-dsh-hook.js +51 -0
  20. package/src/commands/install-dsh-preset.js +46 -4
  21. package/src/commands/install-kimi-code-plugin.js +61 -2
  22. package/src/commands/install-kimi-hook.js +84 -2
  23. package/src/commands/install-opencode-plugin.js +58 -2
  24. package/src/commands/install-qoder-plugin.js +67 -3
  25. package/src/commands/install-zcode-plugin.js +77 -2
  26. package/src/commands/registry.js +20 -5
  27. package/src/lib/dsh-home.js +2 -2
  28. package/template/.cowork-flow/.version +1 -1
  29. package/template/.cowork-flow/scripts/adapters/cli/plan.py +218 -0
  30. package/template/.cowork-flow/scripts/adapters/host/host_manifest.py +4 -0
  31. package/template/.cowork-flow/scripts/adapters/host/workflow_state_hook.py +1 -3
  32. package/template/.cowork-flow/scripts/infra/files.py +0 -13
  33. package/template/.cowork-flow/scripts/run.py +3 -1
  34. package/template/.cowork-flow/scripts/services/ac_evidence.py +1 -1
  35. package/template/.cowork-flow/scripts/services/decision_anchor_schema.py +65 -0
  36. package/template/.cowork-flow/scripts/services/fact_view.py +2 -75
  37. package/template/.cowork-flow/scripts/services/lifecycle_checks.py +1 -1
  38. package/template/.cowork-flow/scripts/services/plan_readiness.py +655 -0
  39. package/template/.cowork-flow/scripts/services/plan_scaffold.py +133 -0
  40. package/template/.cowork-flow/scripts/services/plan_schema.py +40 -0
  41. package/template/.cowork-flow/scripts/services/task_context.py +12 -0
  42. package/template/.cowork-flow/scripts/services/task_creation.py +23 -24
  43. package/template/.cowork-flow/spec/contracts/host-install-inspection.md +174 -0
  44. package/template/.cowork-flow/spec/contracts/index.md +1 -0
  45. package/template/.cowork-flow/spec/contracts/plan-binding.md +62 -4
  46. package/template/.cowork-flow/spec/runtime/contract-registry.json +17 -1
  47. package/template/skills/runtime-health/scripts/doctor.py +538 -489
  48. package/template/skills/task-planning/SKILL.md +24 -0
  49. package/template/skills/task-review/scripts/review_check.py +33 -6
@@ -0,0 +1,655 @@
1
+ #!/usr/bin/env python3
2
+ """Plan readiness: completeness checks and the approved-plan snapshot."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import hashlib
7
+ import re
8
+ from datetime import datetime, timezone
9
+ from pathlib import Path
10
+
11
+ from infra.config import get_language
12
+ from infra.files import read_text_utf8
13
+ from infra.paths import DIR_WORKFLOW
14
+ from services.decision_anchor_schema import (
15
+ ANGLE_SPAN_RE,
16
+ REQUIRED_SECTIONS,
17
+ VERIFICATION,
18
+ heading_for,
19
+ headings,
20
+ is_spec_check_result_line,
21
+ parse_decision_anchor,
22
+ present_sections,
23
+ section_headings,
24
+ spec_check_example,
25
+ verification_section_lines,
26
+ )
27
+ from services.plan_binding import plan_file_blockers, plan_template_blockers
28
+ from services.plan_schema import (
29
+ plan_acceptance_criteria,
30
+ plan_goal,
31
+ )
32
+ from services.task_gate_profiles import (
33
+ acceptance_row_blockers,
34
+ declares_light_profile,
35
+ dev_type_blocker,
36
+ )
37
+ from services.task_repository import TaskRepository, TaskRepositoryError
38
+
39
+
40
+ PLAN_READY_KEY = "planReady"
41
+ TASK_HEADING_RE = re.compile(r"^###\s+(?:任务|Task)\s+\d+\s*[::]\s*(.+?)\s*$")
42
+ H2_RE = re.compile(r"^##(?!#)\s+(.+?)\s*$")
43
+ BOLD_LABEL_RE = re.compile(r"^\*\*(.+?)\*\*\s*$")
44
+ FENCE_RE = re.compile(r"^(```|~~~)")
45
+ PLAN_TEMPLATE_PATH = f"{DIR_WORKFLOW}/templates/plan-template.md"
46
+
47
+ TASK_FIELDS = {
48
+ "zh-CN": (
49
+ "目的",
50
+ "代码事实来源",
51
+ "文件边界",
52
+ "关键符号",
53
+ "实现说明",
54
+ "测试证明",
55
+ "验证命令",
56
+ "完成条件",
57
+ "禁止漂移",
58
+ "偏差条件",
59
+ ),
60
+ "en-US": (
61
+ "Purpose",
62
+ "Code Fact Sources",
63
+ "File Boundaries",
64
+ "Key Symbols",
65
+ "Implementation Notes",
66
+ "Test Proof",
67
+ "Verification Command",
68
+ "Completion Conditions",
69
+ "Prohibited Drift",
70
+ "Deviation Conditions",
71
+ ),
72
+ }
73
+ TINY_TASK_FIELDS = {
74
+ "zh-CN": ("文件边界", "验证命令", "完成条件"),
75
+ "en-US": ("File Boundaries", "Verification Command", "Completion Conditions"),
76
+ }
77
+
78
+
79
+ class PlanReadinessError(RuntimeError):
80
+ """Raised when a plan is not ready for human review."""
81
+
82
+ def __init__(self, blockers: list[str]) -> None:
83
+ self.blockers = tuple(blockers)
84
+ super().__init__("plan is not ready")
85
+
86
+
87
+ class PlanReadinessService:
88
+ """Validate planning artifacts and persist the reviewed snapshot."""
89
+
90
+ def __init__(self, repo_root: Path) -> None:
91
+ self.repo_root = Path(repo_root)
92
+ self.repository = TaskRepository(self.repo_root)
93
+
94
+ def finalize(self, task_dir: Path) -> dict:
95
+ task_dir = Path(task_dir)
96
+ task_data = self._load_task(task_dir)
97
+ language = get_language(self.repo_root)
98
+ blockers = plan_readiness_blockers(
99
+ self.repo_root,
100
+ task_dir,
101
+ task_data,
102
+ language=language,
103
+ )
104
+ if blockers:
105
+ raise PlanReadinessError(blockers)
106
+
107
+ plan_path = _plan_path(self.repo_root, task_data)
108
+ anchor_path = task_dir / "decision-anchor.md"
109
+ snapshot = {
110
+ "planDigest": _file_digest(plan_path),
111
+ "anchorDigest": _file_digest(anchor_path),
112
+ "readyAt": datetime.now(timezone.utc).strftime(
113
+ "%Y-%m-%dT%H:%M:%SZ"
114
+ ),
115
+ "devType": _dev_type(task_data),
116
+ }
117
+ meta = dict(task_data.get("meta") or {})
118
+ meta[PLAN_READY_KEY] = snapshot
119
+ try:
120
+ self.repository.save(task_dir, {"meta": meta})
121
+ except TaskRepositoryError as error:
122
+ raise PlanReadinessError(
123
+ [f"task.json could not be updated with the plan-ready snapshot: {error}"]
124
+ ) from error
125
+ return snapshot
126
+
127
+ def _load_task(self, task_dir: Path) -> dict:
128
+ try:
129
+ return self.repository.load(task_dir)
130
+ except TaskRepositoryError as error:
131
+ raise PlanReadinessError(
132
+ [f"task.json could not be read: {error}"]
133
+ ) from error
134
+
135
+
136
+ def plan_readiness_blockers(
137
+ repo_root: Path,
138
+ task_dir: Path,
139
+ task_data: dict,
140
+ *,
141
+ language: str | None = None,
142
+ ) -> list[str]:
143
+ """Why the planning artifacts are not ready for human review."""
144
+ repo_root = Path(repo_root)
145
+ task_dir = Path(task_dir)
146
+ resolved_language = language or get_language(repo_root)
147
+ blockers = _planning_status_blockers(task_data)
148
+
149
+ blocking_plan_facts = plan_file_blockers(repo_root, task_data)
150
+ blockers.extend(blocking_plan_facts)
151
+ if blocking_plan_facts:
152
+ return blockers
153
+ blockers.extend(
154
+ plan_template_blockers(repo_root, task_data, resolved_language)
155
+ )
156
+
157
+ plan_path = _plan_path(repo_root, task_data)
158
+ plan_text = read_text_utf8(plan_path)
159
+ if not plan_text.strip():
160
+ blockers.append(f"plan is empty: {_display(repo_root, plan_path)}")
161
+ return blockers
162
+
163
+ goal, acceptance, content_blockers = _plan_content_blockers(
164
+ plan_text, resolved_language
165
+ )
166
+ blockers.extend(content_blockers)
167
+
168
+ template_path = repo_root / PLAN_TEMPLATE_PATH
169
+ template_text = (
170
+ read_text_utf8(template_path) if template_path.is_file() else ""
171
+ )
172
+ if not template_text.strip():
173
+ blockers.append(
174
+ "installed plan template is missing or empty; run "
175
+ "`cwf project sync .` before finalizing"
176
+ )
177
+ return blockers
178
+ blockers.extend(
179
+ _plan_structure_blockers(
180
+ plan_text,
181
+ template_text,
182
+ task_data,
183
+ resolved_language,
184
+ )
185
+ )
186
+ blockers.extend(
187
+ _anchor_artifact_blockers(
188
+ task_dir,
189
+ task_data,
190
+ goal,
191
+ acceptance,
192
+ resolved_language,
193
+ )
194
+ )
195
+ return blockers
196
+
197
+
198
+ def _planning_status_blockers(task_data: dict) -> list[str]:
199
+ status = task_data.get("status")
200
+ if status == "planning":
201
+ return []
202
+ return [
203
+ "plan finalize only runs on a planning task; "
204
+ f"current status is {status or 'missing'}"
205
+ ]
206
+
207
+
208
+ def _plan_content_blockers(
209
+ plan_text: str,
210
+ language: str,
211
+ ) -> tuple[str | None, list[dict[str, str]], list[str]]:
212
+ blockers: list[str] = []
213
+ goal = plan_goal(plan_text)
214
+ if not goal:
215
+ blockers.append(
216
+ "plan is missing its machine-readable goal line "
217
+ "(`**目标:**` / `**Goal:**`)"
218
+ )
219
+ elif not _has_concrete_text(goal):
220
+ blockers.append(
221
+ "plan goal line still uses a template placeholder; "
222
+ "replace it with the observable behavior"
223
+ )
224
+
225
+ acceptance = plan_acceptance_criteria(plan_text, language)
226
+ if not acceptance:
227
+ blockers.append(
228
+ "plan `## 验收标准` / `## Acceptance Criteria` has no AC-NNN rows"
229
+ )
230
+ else:
231
+ placeholder_rows = [
232
+ row["id"]
233
+ for row in acceptance
234
+ if not _has_concrete_text(row["text"])
235
+ ]
236
+ if placeholder_rows:
237
+ blockers.append(
238
+ "plan acceptance criterion(s) still use template placeholders: "
239
+ + ", ".join(placeholder_rows)
240
+ )
241
+ return goal, acceptance, blockers
242
+
243
+
244
+ def _expected_sections(language: str) -> tuple[str, ...]:
245
+ return {
246
+ "zh-CN": ("目标", "全局约束", "文件边界", "任务"),
247
+ "en-US": ("Goal", "Global Constraints", "File Boundaries", "Tasks"),
248
+ }.get(
249
+ language,
250
+ ("目标", "全局约束", "文件边界", "任务"),
251
+ )
252
+
253
+
254
+ def _plan_structure_blockers(
255
+ plan_text: str,
256
+ template_text: str,
257
+ task_data: dict,
258
+ language: str,
259
+ ) -> list[str]:
260
+ expected_sections = _expected_sections(language)
261
+ template_sections = {
262
+ heading: _raw_section_lines(template_text, heading)
263
+ for heading in expected_sections
264
+ }
265
+ template_fields = _task_fields(
266
+ template_sections.get(expected_sections[-1], [])
267
+ )
268
+ blockers: list[str] = []
269
+
270
+ for heading in expected_sections[:-1]:
271
+ if not _has_meaningful_lines(
272
+ _raw_section_lines(plan_text, heading),
273
+ template_sections.get(heading, []),
274
+ ):
275
+ blockers.append(
276
+ f"plan `## {heading}` has no concrete content; "
277
+ "fill the template placeholder before finalizing"
278
+ )
279
+
280
+ task_blocks = _task_blocks(plan_text)
281
+ if not task_blocks:
282
+ blockers.append(
283
+ "plan `## 任务` / `## Tasks` has no `### 任务 N` / `### Task N` block"
284
+ )
285
+ else:
286
+ blockers.extend(
287
+ _task_block_blockers(
288
+ task_blocks,
289
+ task_data,
290
+ language,
291
+ template_fields,
292
+ )
293
+ )
294
+ return blockers
295
+
296
+
297
+ def _task_block_blockers(
298
+ task_blocks: list[dict],
299
+ task_data: dict,
300
+ language: str,
301
+ template_fields: dict[str, list[str]],
302
+ ) -> list[str]:
303
+ blockers: list[str] = []
304
+ tiny = declares_light_profile(task_data)
305
+ required_fields = TINY_TASK_FIELDS.get(
306
+ language, TINY_TASK_FIELDS["zh-CN"]
307
+ ) if tiny else TASK_FIELDS.get(
308
+ language, TASK_FIELDS["zh-CN"]
309
+ )
310
+ missing_template_fields = [
311
+ field for field in required_fields if field not in template_fields
312
+ ]
313
+ if missing_template_fields:
314
+ blockers.append(
315
+ "installed plan template is missing task brief field(s): "
316
+ + ", ".join(missing_template_fields)
317
+ )
318
+ verification_field = (
319
+ "Verification Command"
320
+ if language == "en-US"
321
+ else "验证命令"
322
+ )
323
+ for block in task_blocks:
324
+ fields = _task_fields(block["lines"])
325
+ missing = [
326
+ field for field in required_fields if field not in fields
327
+ ]
328
+ if missing:
329
+ blockers.append(
330
+ f"plan task `### {block['heading']}` is missing brief "
331
+ f"field(s): {', '.join(missing)}"
332
+ )
333
+ continue
334
+ empty = [
335
+ field
336
+ for field in required_fields
337
+ if (
338
+ not _has_verification_command(fields[field])
339
+ if field == verification_field
340
+ else not _has_meaningful_lines(
341
+ fields[field], template_fields.get(field, [])
342
+ )
343
+ )
344
+ ]
345
+ if empty:
346
+ blockers.append(
347
+ f"plan task `### {block['heading']}` has empty brief "
348
+ f"field(s): {', '.join(empty)}"
349
+ )
350
+ return blockers
351
+
352
+
353
+ def _anchor_artifact_blockers(
354
+ task_dir: Path,
355
+ task_data: dict,
356
+ goal: str | None,
357
+ acceptance: list[dict[str, str]],
358
+ language: str,
359
+ ) -> list[str]:
360
+ blockers: list[str] = []
361
+ anchor_path = task_dir / "decision-anchor.md"
362
+ anchor_text = read_text_utf8(anchor_path)
363
+ if not anchor_text.strip():
364
+ blockers.append("decision-anchor.md is missing or empty")
365
+ else:
366
+ blockers.extend(_anchor_blockers(anchor_text, language))
367
+ blockers.extend(acceptance_row_blockers(anchor_text))
368
+ blockers.extend(
369
+ _anchor_spec_check_blockers(
370
+ anchor_text,
371
+ language,
372
+ _dev_type(task_data),
373
+ )
374
+ )
375
+ blockers.extend(_acceptance_sync_blockers(acceptance, anchor_text))
376
+ blockers.extend(_goal_sync_blockers(goal, anchor_text))
377
+
378
+ implement_index = task_dir / "implement.jsonl"
379
+ if not read_text_utf8(implement_index).strip():
380
+ blockers.append("implement.jsonl is missing or empty")
381
+
382
+ blockers.extend(dev_type_blocker(task_data))
383
+ return blockers
384
+
385
+
386
+ def plan_ready_snapshot_blockers(
387
+ repo_root: Path,
388
+ task_dir: Path,
389
+ task_data: dict,
390
+ *,
391
+ required: bool,
392
+ ) -> list[str]:
393
+ """Why the stored plan-ready snapshot is absent or no longer current."""
394
+ meta = task_data.get("meta")
395
+ meta = meta if isinstance(meta, dict) else {}
396
+ snapshot = meta.get(PLAN_READY_KEY)
397
+ if not isinstance(snapshot, dict):
398
+ if not required:
399
+ return []
400
+ return [
401
+ "strict task has no plan-ready snapshot; run plan finalize "
402
+ f"`{_display(Path(repo_root), Path(task_dir))}` "
403
+ "before human review/start"
404
+ ]
405
+
406
+ plan_path = _plan_path(Path(repo_root), task_data)
407
+ anchor_path = Path(task_dir) / "decision-anchor.md"
408
+ if not plan_path.is_file():
409
+ return [
410
+ "plan-ready snapshot is stale: the bound plan file is missing; "
411
+ "restore it and rerun `plan finalize`"
412
+ ]
413
+ if not anchor_path.is_file():
414
+ return [
415
+ "plan-ready snapshot is stale: decision-anchor.md is missing; "
416
+ "restore it and rerun `plan finalize`"
417
+ ]
418
+ if snapshot.get("planDigest") != _file_digest(plan_path) or snapshot.get(
419
+ "anchorDigest"
420
+ ) != _file_digest(anchor_path) or snapshot.get("devType") != _dev_type(
421
+ task_data
422
+ ):
423
+ return [
424
+ "plan-ready snapshot is stale: the plan, decision-anchor, or "
425
+ "dev_type changed after finalize; rerun `plan finalize` and "
426
+ "review the new version"
427
+ ]
428
+ return []
429
+
430
+
431
+ def _file_digest(path: Path) -> str:
432
+ return hashlib.sha256(Path(path).read_bytes()).hexdigest()
433
+
434
+
435
+ def _dev_type(task_data: dict) -> str | None:
436
+ value = task_data.get("dev_type")
437
+ return value.strip() if isinstance(value, str) and value.strip() else None
438
+
439
+
440
+ def _display(repo_root: Path, path: Path) -> str:
441
+ try:
442
+ return Path(path).resolve().relative_to(repo_root.resolve()).as_posix()
443
+ except (OSError, ValueError):
444
+ return str(path)
445
+
446
+
447
+ def _plan_path(repo_root: Path, task_data: dict) -> Path:
448
+ meta = task_data.get("meta")
449
+ plan_file = meta.get("planFile") if isinstance(meta, dict) else None
450
+ if not isinstance(plan_file, str) or not plan_file.strip():
451
+ return repo_root / DIR_WORKFLOW / "plans" / "__missing__"
452
+ return repo_root / plan_file.strip()
453
+
454
+
455
+ def _has_meaningful_lines(
456
+ lines: list[str],
457
+ template_lines: list[str] | tuple[str, ...] = (),
458
+ ) -> bool:
459
+ """Whether a section or field has content beyond its template body."""
460
+ template = {
461
+ normalized
462
+ for raw in template_lines
463
+ if (normalized := _normalize_placeholder_line(raw.strip()))
464
+ and not normalized.startswith(("```", "~~~"))
465
+ }
466
+ for raw in lines:
467
+ line = raw.strip()
468
+ if not line or line.startswith("<!--"):
469
+ continue
470
+ if line in ("```", "~~~") or line.startswith(("```", "~~~")):
471
+ continue
472
+ body = _normalize_placeholder_line(line)
473
+ if not body or body in template:
474
+ continue
475
+ if _has_concrete_text(body):
476
+ return True
477
+ return False
478
+
479
+
480
+ def _has_verification_command(lines: list[str]) -> bool:
481
+ """A verification field needs a concrete command inside a code fence."""
482
+ fence: str | None = None
483
+ for raw in lines:
484
+ marker = FENCE_RE.match(raw.strip())
485
+ if marker:
486
+ if fence is None:
487
+ fence = marker.group(1)
488
+ elif marker.group(1) == fence:
489
+ fence = None
490
+ continue
491
+ if fence is None:
492
+ continue
493
+ command = raw.strip()
494
+ if command.startswith(("#", "//")):
495
+ continue
496
+ if _has_concrete_text(command):
497
+ return True
498
+ return False
499
+
500
+
501
+ def _raw_section_lines(text: str, heading: str) -> list[str]:
502
+ """Raw lines under one `##` heading, including fenced code."""
503
+ body: list[str] = []
504
+ inside = False
505
+ for raw in text.splitlines():
506
+ match = H2_RE.match(raw.strip())
507
+ if match:
508
+ inside = match.group(1) == heading
509
+ continue
510
+ if inside:
511
+ body.append(raw)
512
+ return body
513
+
514
+
515
+ def _normalize_placeholder_line(line: str) -> str:
516
+ """Strip list and code-comment markers before template-line comparison."""
517
+ body = line[2:].strip() if line.startswith("- ") else line
518
+ body = body.lstrip("#> ").strip()
519
+ return re.sub(r"\s+", " ", body)
520
+
521
+
522
+ def _has_concrete_text(text: str) -> bool:
523
+ """Whether a line carries content beyond angle-bracket placeholders."""
524
+ cleaned = ANGLE_SPAN_RE.sub("", text)
525
+ return any(char.isalnum() for char in cleaned)
526
+
527
+
528
+ def _task_blocks(text: str) -> list[dict]:
529
+ blocks: list[dict] = []
530
+ current: dict | None = None
531
+ fence: str | None = None
532
+ for raw in text.splitlines():
533
+ stripped = raw.strip()
534
+ marker = FENCE_RE.match(stripped)
535
+ if marker:
536
+ if fence is None:
537
+ fence = marker.group(1)
538
+ elif marker.group(1) == fence:
539
+ fence = None
540
+ if current is not None:
541
+ current["lines"].append(raw)
542
+ continue
543
+ if fence is None:
544
+ task = TASK_HEADING_RE.match(stripped)
545
+ if task:
546
+ if current is not None:
547
+ blocks.append(current)
548
+ current = {"heading": task.group(1), "lines": []}
549
+ continue
550
+ if H2_RE.match(stripped):
551
+ if current is not None:
552
+ blocks.append(current)
553
+ current = None
554
+ continue
555
+ if current is not None:
556
+ current["lines"].append(raw)
557
+ if current is not None:
558
+ blocks.append(current)
559
+ return blocks
560
+
561
+
562
+ def _task_fields(lines: list[str]) -> dict[str, list[str]]:
563
+ fields: dict[str, list[str]] = {}
564
+ current: str | None = None
565
+ for raw in lines:
566
+ match = BOLD_LABEL_RE.match(raw.strip())
567
+ if match:
568
+ current = match.group(1).strip()
569
+ fields.setdefault(current, [])
570
+ continue
571
+ if current is not None:
572
+ fields[current].append(raw)
573
+ return fields
574
+
575
+
576
+ def _anchor_blockers(anchor_text: str, language: str) -> list[str]:
577
+ present = present_sections(anchor_text)
578
+ blockers = [
579
+ "decision-anchor.md missing required section: "
580
+ + " (or ".join(f"## {heading}" for heading in section_headings(section))
581
+ for section in REQUIRED_SECTIONS
582
+ if section not in present
583
+ ]
584
+ expected = heading_for(VERIFICATION, language)
585
+ if expected not in headings(anchor_text):
586
+ other = heading_for(
587
+ VERIFICATION,
588
+ "en-US" if language == "zh-CN" else "zh-CN",
589
+ )
590
+ if other in headings(anchor_text):
591
+ blockers.append(
592
+ f"decision-anchor.md uses `## {other}`; a {language} task "
593
+ f"requires `## {expected}`"
594
+ )
595
+ else:
596
+ blockers.append(
597
+ f"decision-anchor.md is missing `## {expected}`"
598
+ )
599
+ return blockers
600
+
601
+
602
+ def _anchor_spec_check_blockers(
603
+ anchor_text: str,
604
+ language: str,
605
+ dev_type: str | None,
606
+ ) -> list[str]:
607
+ expected = heading_for(VERIFICATION, language)
608
+ if expected not in headings(anchor_text):
609
+ return []
610
+ if not any(
611
+ is_spec_check_result_line(line, language)
612
+ for line in verification_section_lines(anchor_text)
613
+ ):
614
+ return [
615
+ f"decision-anchor.md `## {expected}` is missing a filled "
616
+ f"spec-check result, e.g. "
617
+ f"{spec_check_example(language, dev_type)}"
618
+ ]
619
+ return []
620
+
621
+
622
+ def _acceptance_sync_blockers(plan_rows: list[dict[str, str]], anchor_text: str) -> list[str]:
623
+ anchor_rows = parse_decision_anchor(anchor_text).get("acceptanceCriteria") or []
624
+ plan_ids = [row["id"] for row in plan_rows]
625
+ anchor_ids = [row.get("id") for row in anchor_rows]
626
+ if plan_ids != anchor_ids:
627
+ return [
628
+ "decision-anchor.md acceptance IDs do not match the plan: "
629
+ f"plan={plan_ids or 'none'} anchor={anchor_ids or 'none'}"
630
+ ]
631
+ for plan_row, anchor_row in zip(plan_rows, anchor_rows):
632
+ if plan_row["text"].strip() != str(anchor_row.get("text") or "").strip():
633
+ return [
634
+ f"decision-anchor.md {plan_row['id']} text differs from the plan; "
635
+ "update the anchor before finalizing"
636
+ ]
637
+ return []
638
+
639
+
640
+ def _goal_sync_blockers(plan_goal_text: str | None, anchor_text: str) -> list[str]:
641
+ if not plan_goal_text:
642
+ return []
643
+ anchor_goal = str(parse_decision_anchor(anchor_text).get("goal") or "").strip()
644
+ if not anchor_goal:
645
+ return ["decision-anchor.md has no goal text"]
646
+ normalized_plan = " ".join(plan_goal_text.split())
647
+ normalized_anchor = " ".join(anchor_goal.split())
648
+ if normalized_plan != normalized_anchor and not normalized_plan.startswith(
649
+ normalized_anchor
650
+ ):
651
+ return [
652
+ "decision-anchor.md goal differs from the plan goal; "
653
+ "align the anchor before finalizing"
654
+ ]
655
+ return []