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
@@ -1,6 +1,6 @@
1
1
  import { UsageError } from '../lib/cli-flags.js';
2
2
  import { hostRegistry } from '../lib/host-assets.js';
3
- import { HOST_COMPONENTS, HOST_FLAGS, runHostAdd, runHostList, runHostRemove } from './host.js';
3
+ import { HOST_COMPONENTS, HOST_FLAGS, runHostAdd, runHostInspect, runHostList, runHostRemove } from './host.js';
4
4
  import { runInit } from './init.js';
5
5
  import { runMcpState } from './mcp-state.js';
6
6
  import { runSourceRefresh } from './source-refresh.js';
@@ -107,13 +107,26 @@ export const COMMANDS = [
107
107
  examples: ['cwf host remove codex', 'cwf host remove dsh --component hook'],
108
108
  run: (args) => runHostRemove(args)
109
109
  },
110
+ {
111
+ path: ['host', 'inspect'],
112
+ summary: 'Report machine-level host installation state without changing it',
113
+ usage: 'host inspect [host] [--json]',
114
+ flags: [flag('--json')],
115
+ positional: { min: 0, max: 1, name: '[host]' },
116
+ notes: [
117
+ 'Read-only: it reports installed, missing, stale, broken or unsupported and never repairs, installs or removes.',
118
+ 'Without a host, every declared host is inspected; an unknown host is a usage error.'
119
+ ],
120
+ examples: ['cwf host inspect', 'cwf host inspect qoder --json'],
121
+ run: (args, context) => runHostInspect(args, context)
122
+ },
110
123
  {
111
124
  path: ['host', 'list'],
112
125
  summary: 'List declared hosts and whether this project selected them',
113
126
  usage: 'host list [target] [--json]',
114
127
  flags: [flag('--json')],
115
128
  positional: { min: 0, max: 1, name: '[target]' },
116
- notes: ['Reports declarations and project selection only; installed-state health is what `./.cowork-flow/run doctor` checks.'],
129
+ notes: ['Reports declarations and project selection only; `cwf host inspect` reads each host\'s installed state, and doctor consumes that read model.'],
117
130
  examples: ['cwf host list', 'cwf host list --json'],
118
131
  run: (args, context) => runHostList(args, context)
119
132
  },
@@ -149,7 +162,9 @@ export const COMMANDS = [
149
162
  // Old names. `permanent` aliases are spellings already
150
163
  // written outside this repository (MCP client configs);
151
164
  // the rest print a migration note on stderr and go away
152
- // after two minor releases.
165
+ // after the shared retirement policy.
166
+ const ALIAS_RETIREMENT_POLICY = 'two more minor releases';
167
+
153
168
  export const ALIASES = [
154
169
  { name: 'init', command: ['project', 'init'], args: [], permanent: true },
155
170
  { name: 'sync', command: ['project', 'sync'], args: [], permanent: true },
@@ -211,7 +226,7 @@ export function aliasReplacement(alias) {
211
226
 
212
227
  export function aliasNotice(alias) {
213
228
  return `note: "${PROGRAM} ${alias.name}" is now "${aliasReplacement(alias)}"; `
214
- + 'the old name keeps working for two more minor releases.\n';
229
+ + `the old name keeps working for ${ALIAS_RETIREMENT_POLICY}.\n`;
215
230
  }
216
231
 
217
232
 
@@ -282,7 +297,7 @@ function renderRootHelp() {
282
297
  );
283
298
  const aliasWidth = Math.max(...ALIASES.map((alias) => alias.name.length));
284
299
  for (const alias of ALIASES) {
285
- const suffix = alias.permanent ? '(permanent)' : '(removed after two minor releases)';
300
+ const suffix = alias.permanent ? '(permanent)' : `(removed after ${ALIAS_RETIREMENT_POLICY})`;
286
301
  lines.push(` ${alias.name.padEnd(aliasWidth)} -> ${aliasReplacement(alias)} ${suffix}`);
287
302
  }
288
303
  return `${lines.join('\n')}\n`;
@@ -1,6 +1,6 @@
1
1
  import { homedir } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
 
4
- export function getDshHome() {
5
- return process.env.DSH_HOME || join(homedir(), '.dsh');
4
+ export function getDshHome(env = process.env) {
5
+ return env.DSH_HOME || join(homedir(), '.dsh');
6
6
  }
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.0
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/env python3
2
+ """Plan skeleton generation and readiness finalization CLI."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ from adapters.cli.execution_context_args import (
12
+ build_internal_execution_context_parser,
13
+ execution_context_from_namespace,
14
+ )
15
+ from adapters.cli.task_support import (
16
+ Colors,
17
+ colored,
18
+ resolve_task_dir,
19
+ slugify,
20
+ )
21
+ from infra.paths import FILE_TASK_JSON, get_repo_root
22
+ from runtime.session_state import (
23
+ PROVENANCE_PROCESS_FALLBACK,
24
+ get_active_task,
25
+ )
26
+ from services.plan_readiness import PlanReadinessError, PlanReadinessService
27
+ from services.plan_scaffold import PlanScaffoldError, PlanScaffoldService
28
+
29
+
30
+ def _build_parser() -> argparse.ArgumentParser:
31
+ parser = argparse.ArgumentParser(
32
+ description="Generate a plan skeleton or finalize planning artifacts",
33
+ parents=[build_internal_execution_context_parser()],
34
+ )
35
+ subparsers = parser.add_subparsers(dest="command", required=True)
36
+
37
+ new_parser = subparsers.add_parser(
38
+ "new",
39
+ help="Create a plan skeleton from the installed localized template",
40
+ )
41
+ new_parser.add_argument("--title", required=True, help="Plan title")
42
+ new_parser.add_argument(
43
+ "--slug",
44
+ help="ASCII plan slug; defaults to the title when it slugifies",
45
+ )
46
+ new_parser.add_argument(
47
+ "--force",
48
+ action="store_true",
49
+ help="Overwrite an existing plan file",
50
+ )
51
+ new_parser.add_argument(
52
+ "--date",
53
+ help="Plan date prefix in YYYY-MM-DD form (default: today)",
54
+ )
55
+
56
+ finalize_parser = subparsers.add_parser(
57
+ "finalize",
58
+ help="Validate planning artifacts and record the plan-ready snapshot",
59
+ )
60
+ finalize_parser.add_argument(
61
+ "dir",
62
+ nargs="?",
63
+ help="Task directory or name; defaults to the active task",
64
+ )
65
+ finalize_parser.add_argument(
66
+ "--json",
67
+ action="store_true",
68
+ help="Print the plan-ready snapshot as JSON",
69
+ )
70
+ return parser
71
+
72
+
73
+ def _resolve_task(args: argparse.Namespace, repo_root: Path) -> Path | None:
74
+ target = getattr(args, "dir", None)
75
+ if target:
76
+ task_dir = resolve_task_dir(target, repo_root)
77
+ else:
78
+ active = get_active_task(repo_root)
79
+ if not active.context_key:
80
+ print(
81
+ colored(
82
+ "Error: Missing session context. Set "
83
+ "COWORK_FLOW_CONTEXT_ID or pass a task dir.",
84
+ Colors.RED,
85
+ ),
86
+ file=sys.stderr,
87
+ )
88
+ return None
89
+ if active.task_path and active.provenance == PROVENANCE_PROCESS_FALLBACK:
90
+ print(
91
+ colored(
92
+ "Error: Session binding is process-fallback (shared); "
93
+ "set COWORK_FLOW_CONTEXT_ID to the session value shown "
94
+ "in the workflow-state header, or pass a task dir "
95
+ "explicitly.",
96
+ Colors.RED,
97
+ ),
98
+ file=sys.stderr,
99
+ )
100
+ return None
101
+ if not active.task_path:
102
+ print(
103
+ colored(
104
+ "Error: No active task set for this session",
105
+ Colors.RED,
106
+ ),
107
+ file=sys.stderr,
108
+ )
109
+ return None
110
+ task_dir = repo_root / active.task_path
111
+
112
+ if not task_dir.is_dir() or not (task_dir / FILE_TASK_JSON).is_file():
113
+ print(
114
+ colored(
115
+ f"Error: Task not found or task.json missing: {task_dir}",
116
+ Colors.RED,
117
+ ),
118
+ file=sys.stderr,
119
+ )
120
+ return None
121
+ return task_dir
122
+
123
+
124
+ def _cmd_new(args: argparse.Namespace, repo_root: Path) -> int:
125
+ slug = args.slug or slugify(args.title)
126
+ if not slug:
127
+ print(
128
+ colored(
129
+ "Error: could not generate an ASCII slug from the title; "
130
+ "pass --slug <ascii-slug>",
131
+ Colors.RED,
132
+ ),
133
+ file=sys.stderr,
134
+ )
135
+ return 1
136
+ try:
137
+ plan_path = PlanScaffoldService(repo_root).create(
138
+ args.title,
139
+ slug,
140
+ force=bool(args.force),
141
+ date_prefix=args.date,
142
+ )
143
+ except PlanScaffoldError as error:
144
+ print(
145
+ colored(
146
+ f"Error: Failed to create plan skeleton [{error.code}]: "
147
+ f"{error.detail}",
148
+ Colors.RED,
149
+ ),
150
+ file=sys.stderr,
151
+ )
152
+ return 1
153
+ try:
154
+ display = plan_path.resolve().relative_to(repo_root.resolve()).as_posix()
155
+ except ValueError:
156
+ display = str(plan_path)
157
+ print(display)
158
+ return 0
159
+
160
+
161
+ def _cmd_finalize(args: argparse.Namespace, repo_root: Path) -> int:
162
+ task_dir = _resolve_task(args, repo_root)
163
+ if task_dir is None:
164
+ return 1
165
+ try:
166
+ snapshot = PlanReadinessService(repo_root).finalize(task_dir)
167
+ except PlanReadinessError as error:
168
+ print(
169
+ colored("Error: Plan is not ready for review", Colors.RED),
170
+ file=sys.stderr,
171
+ )
172
+ for blocker in error.blockers:
173
+ print(f" - {blocker}", file=sys.stderr)
174
+ print(
175
+ "Hint: fill the planning artifacts, then rerun "
176
+ "`./.cowork-flow/run plan finalize <task-dir>`.",
177
+ file=sys.stderr,
178
+ )
179
+ return 1
180
+
181
+ if getattr(args, "json", False):
182
+ print(json.dumps(snapshot, ensure_ascii=False, indent=2))
183
+ else:
184
+ print(colored("Plan is ready for human review.", Colors.GREEN))
185
+ print(f" planDigest: {snapshot['planDigest']}")
186
+ print(f" anchorDigest: {snapshot['anchorDigest']}")
187
+ print(f" readyAt: {snapshot['readyAt']}")
188
+ print(
189
+ " Next: review the plan and anchor, then start the task. "
190
+ "Start will reject any later edit to either file."
191
+ )
192
+ return 0
193
+
194
+
195
+ def main(argv: list[str] | None = None) -> int:
196
+ args = _build_parser().parse_args(argv)
197
+ execution_context = execution_context_from_namespace(args)
198
+ if not execution_context.is_default:
199
+ print(
200
+ colored(
201
+ "Error: plan commands must run in the main session; "
202
+ "delegated contexts cannot finalize a task.",
203
+ Colors.RED,
204
+ ),
205
+ file=sys.stderr,
206
+ )
207
+ return 2
208
+
209
+ repo_root = get_repo_root()
210
+ if args.command == "new":
211
+ return _cmd_new(args, repo_root)
212
+ if args.command == "finalize":
213
+ return _cmd_finalize(args, repo_root)
214
+ return 1
215
+
216
+
217
+ if __name__ == "__main__":
218
+ raise SystemExit(main())
@@ -283,6 +283,10 @@ def _validate_platform(
283
283
  errors.append(
284
284
  f"illegal capability {platform.id}:{name}={value}"
285
285
  )
286
+ # The manifest carries the platform facts that ship into projects; the
287
+ # adapter is the copy the project runtime reads. The duplication is
288
+ # deliberate, so this equality check is what keeps both sides in step:
289
+ # editing either one alone is a validation error.
286
290
  if capabilities != platform.capabilities:
287
291
  errors.append(
288
292
  f"capability mismatch between manifest and adapter: {platform.id}"
@@ -20,6 +20,7 @@ from pathlib import Path
20
20
  from typing import Any, NamedTuple
21
21
 
22
22
  from adapters.host.policy_base import DEFAULT_DIGEST_POLICY, HostPolicy, default_policy
23
+ from services.decision_anchor_schema import parse_decision_anchor
23
24
 
24
25
 
25
26
  TAG_RE = re.compile(
@@ -358,8 +359,6 @@ def _decision_anchor_block(
358
359
  if effective_status not in DECISION_ANCHOR_STATES:
359
360
  return None
360
361
  try:
361
- from services.fact_view import parse_decision_anchor
362
-
363
362
  text = (root / task_path / "decision-anchor.md").read_text(
364
363
  encoding="utf-8"
365
364
  )
@@ -428,7 +427,6 @@ def _stage_contract_block(
428
427
  from services.fact_view import (
429
428
  build_stage_contract,
430
429
  file_scope_whitelist,
431
- parse_decision_anchor,
432
430
  spec_digest_items,
433
431
  spec_pointer_files,
434
432
  )
@@ -4,7 +4,6 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import json
7
- import os
8
7
  from pathlib import Path
9
8
 
10
9
 
@@ -27,15 +26,3 @@ def read_text_utf8(path: Path) -> str:
27
26
  return path.read_text(encoding="utf-8")
28
27
  except (OSError, UnicodeDecodeError):
29
28
  return ""
30
-
31
-
32
- def write_json_file(path: Path, data: dict) -> bool:
33
- """Write dict to JSON file atomically (temp + os.replace)."""
34
- try:
35
- json_text = json.dumps(data, indent=2, ensure_ascii=False)
36
- tmp_path = path.with_name(f"{path.name}.{os.getpid()}.tmp")
37
- tmp_path.write_text(json_text, encoding="utf-8")
38
- os.replace(tmp_path, path)
39
- return True
40
- except OSError:
41
- return False
@@ -23,6 +23,7 @@ configure_cli_encoding()
23
23
  COMMAND_SCRIPTS = {
24
24
  "resume": "adapters/cli/resume.py",
25
25
  "task": "adapters/cli/task.py",
26
+ "plan": "adapters/cli/plan.py",
26
27
  "get-context": "adapters/cli/get_context.py",
27
28
  "get_context": "adapters/cli/get_context.py",
28
29
  "get-developer": "adapters/cli/get_developer.py",
@@ -35,7 +36,7 @@ COMMAND_SCRIPTS = {
35
36
  }
36
37
  RESERVED_COMMAND_NAMES = (*COMMAND_SCRIPTS, "python", "help", "-h", "--help")
37
38
 
38
- CONTEXT_AWARE_COMMANDS = {"resume", "task", "subagent"}
39
+ CONTEXT_AWARE_COMMANDS = {"resume", "task", "plan", "subagent"}
39
40
 
40
41
 
41
42
  def print_usage() -> None:
@@ -49,6 +50,7 @@ def print_usage() -> None:
49
50
  Common commands:
50
51
  resume
51
52
  task
53
+ plan
52
54
  state
53
55
  get-context
54
56
  get-developer
@@ -15,7 +15,7 @@ import json
15
15
  from pathlib import Path
16
16
  from typing import Any
17
17
 
18
- from services.fact_view import parse_decision_anchor
18
+ from services.decision_anchor_schema import parse_decision_anchor
19
19
 
20
20
  EVIDENCE_FILE = "evidence.jsonl"
21
21
  EVIDENCE_KINDS = ("test", "command", "manual")
@@ -11,6 +11,7 @@ which set a newly generated anchor uses.
11
11
  from __future__ import annotations
12
12
 
13
13
  import re
14
+ from typing import Any
14
15
 
15
16
  GOAL = "goal"
16
17
  ACCEPTANCE = "acceptance"
@@ -57,6 +58,13 @@ HEADING_RE = re.compile(r"^##\s*(.+?)\s*$")
57
58
  ACCEPTANCE_RE = re.compile(
58
59
  r"^\s*-\s*(?:\[([ xX])\]?\s*)?(AC-[A-Za-z0-9-]+)\s*[::]\s*(.+?)\s*$"
59
60
  )
61
+ REJECTED_RE = re.compile(r"^\s*-\s*\*\*(.+?)\*\*")
62
+
63
+ GOAL_TRUNCATE = 300
64
+ VERIFY_COMMAND_TRUNCATE = 120
65
+ VERIFY_COMMAND_MAX = 10
66
+ SCOPE_BOUNDARY_TRUNCATE = 160
67
+
60
68
  LIST_ITEM_RE = re.compile(r"^\s*[-*]\s")
61
69
  LIST_PREFIX_RE = re.compile(r"^\s*[-*+]\s*")
62
70
  FENCE_MARKER_RE = re.compile(r"^(```|~~~)")
@@ -226,3 +234,60 @@ def present_sections(text: str) -> set[str]:
226
234
  def acceptance_section_lines(text: str) -> list[str]:
227
235
  """Raw lines under the acceptance heading, up to the next heading."""
228
236
  return section_lines(text, ACCEPTANCE)
237
+
238
+
239
+ def parse_decision_anchor(text: str) -> dict[str, Any]:
240
+ """Extract goal / acceptance criteria / rejected option names / declared
241
+ verification commands / scope boundary from a decision-anchor.md body.
242
+ Section headings may be the Chinese set or the English aliases (see
243
+ spec/contracts/decision-anchor.md); parsing is line-level and degrades to
244
+ empty values when sections are missing."""
245
+ goal_lines: list[str] = []
246
+ acceptance: list[dict[str, str]] = []
247
+ rejected: list[str] = []
248
+ verify_commands: list[str] = []
249
+ scope_boundary = ""
250
+ section: str | None = None
251
+ for raw in text.splitlines():
252
+ heading = HEADING_RE.match(raw.strip())
253
+ if heading:
254
+ section = canonical_section(heading.group(1))
255
+ continue
256
+ if section == GOAL:
257
+ if raw.strip():
258
+ goal_lines.append(raw.strip())
259
+ elif section == ACCEPTANCE:
260
+ match = ACCEPTANCE_RE.match(raw)
261
+ if match:
262
+ acceptance.append(
263
+ {
264
+ "id": match.group(2),
265
+ "text": match.group(3),
266
+ "checked": match.group(1) in ("x", "X"),
267
+ }
268
+ )
269
+ elif section == REJECTED:
270
+ match = REJECTED_RE.match(raw)
271
+ if match:
272
+ rejected.append(match.group(1).strip())
273
+ elif section == VERIFICATION:
274
+ command = raw.strip()
275
+ if command.startswith("- "):
276
+ command = command[2:].strip()
277
+ if command.startswith("<!--"):
278
+ # Scaffold instructions and author notes are not commands.
279
+ continue
280
+ if is_spec_check_line(command):
281
+ continue
282
+ if command and len(verify_commands) < VERIFY_COMMAND_MAX:
283
+ verify_commands.append(command[:VERIFY_COMMAND_TRUNCATE])
284
+ elif section == SCOPE:
285
+ if raw.strip() and not scope_boundary:
286
+ scope_boundary = raw.strip()[:SCOPE_BOUNDARY_TRUNCATE]
287
+ return {
288
+ "goal": "\n".join(goal_lines)[:GOAL_TRUNCATE],
289
+ "acceptanceCriteria": acceptance,
290
+ "rejectedOptions": rejected,
291
+ "validationCommands": verify_commands,
292
+ "scopeBoundary": scope_boundary,
293
+ }
@@ -12,85 +12,12 @@ them from file conventions.
12
12
  from __future__ import annotations
13
13
 
14
14
  import json
15
- import re
16
15
  from datetime import datetime, timezone
17
16
  from pathlib import Path
18
17
  from typing import Any
19
18
 
20
- from services.decision_anchor_schema import (
21
- ACCEPTANCE,
22
- ACCEPTANCE_RE,
23
- GOAL,
24
- HEADING_RE,
25
- REJECTED,
26
- SCOPE,
27
- VERIFICATION,
28
- canonical_section,
29
- is_spec_check_line,
30
- )
31
-
32
- GOAL_TRUNCATE = 300
33
- VERIFY_COMMAND_TRUNCATE = 120
34
- VERIFY_COMMAND_MAX = 10
35
- SCOPE_BOUNDARY_TRUNCATE = 160
36
- REJECTED_RE = re.compile(r"^\s*-\s*\*\*(.+?)\*\*")
37
-
38
-
39
- def parse_decision_anchor(text: str) -> dict[str, Any]:
40
- """Extract goal / acceptance criteria / rejected option names / declared
41
- verification commands / scope boundary from a decision-anchor.md body.
42
- Section headings may be the Chinese set or the English aliases (see
43
- spec/contracts/decision-anchor.md); parsing is line-level and degrades to
44
- empty values when sections are missing."""
45
- goal_lines: list[str] = []
46
- acceptance: list[dict[str, str]] = []
47
- rejected: list[str] = []
48
- verify_commands: list[str] = []
49
- scope_boundary = ""
50
- section: str | None = None
51
- for raw in text.splitlines():
52
- heading = HEADING_RE.match(raw.strip())
53
- if heading:
54
- section = canonical_section(heading.group(1))
55
- continue
56
- if section == GOAL:
57
- if raw.strip():
58
- goal_lines.append(raw.strip())
59
- elif section == ACCEPTANCE:
60
- match = ACCEPTANCE_RE.match(raw)
61
- if match:
62
- acceptance.append(
63
- {
64
- "id": match.group(2),
65
- "text": match.group(3),
66
- "checked": match.group(1) in ("x", "X"),
67
- }
68
- )
69
- elif section == REJECTED:
70
- match = REJECTED_RE.match(raw)
71
- if match:
72
- rejected.append(match.group(1).strip())
73
- elif section == VERIFICATION:
74
- command = raw.strip()
75
- if command.startswith("- "):
76
- command = command[2:].strip()
77
- if command.startswith("<!--"):
78
- # Scaffold instructions and author notes are not commands.
79
- continue
80
- if is_spec_check_line(command):
81
- continue
82
- if command and len(verify_commands) < VERIFY_COMMAND_MAX:
83
- verify_commands.append(command[:VERIFY_COMMAND_TRUNCATE])
84
- elif section == SCOPE:
85
- if raw.strip() and not scope_boundary:
86
- scope_boundary = raw.strip()[:SCOPE_BOUNDARY_TRUNCATE]
87
- return {
88
- "goal": "\n".join(goal_lines)[:GOAL_TRUNCATE],
89
- "acceptanceCriteria": acceptance,
90
- "rejectedOptions": rejected,
91
- "validationCommands": verify_commands,
92
- "scopeBoundary": scope_boundary,
93
- }
19
+ # Re-exported for existing callers; the parser has one definition.
20
+ from services.decision_anchor_schema import parse_decision_anchor
94
21
 
95
22
 
96
23
  def _now_iso() -> str:
@@ -15,8 +15,8 @@ from dataclasses import dataclass
15
15
  from pathlib import Path
16
16
 
17
17
  from infra.git_snapshot import collect_changed_paths_since
18
+ from services.decision_anchor_schema import parse_decision_anchor
18
19
  from services.fact_view import (
19
- parse_decision_anchor,
20
20
  spec_pointer_files,
21
21
  task_baseline,
22
22
  task_data,