devflow-toolkit 0.3.1__py3-none-any.whl → 0.3.3__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.
devflow/cli.py CHANGED
@@ -6,7 +6,9 @@ import typer
6
6
  from rich.console import Console
7
7
 
8
8
  from devflow.commands.approve import approve as approve_command
9
+ from devflow.commands.doctor import doctor as doctor_command
9
10
  from devflow.commands.init import init as init_command
11
+ from devflow.commands.recover import recover as recover_command
10
12
  from devflow.commands.spec import spec as spec_command
11
13
  from devflow.commands.status import status as status_command
12
14
 
@@ -23,6 +25,8 @@ app.command("init")(init_command)
23
25
  app.command("spec")(spec_command)
24
26
  app.command("approve")(approve_command)
25
27
  app.command("status")(status_command)
28
+ app.command("doctor")(doctor_command)
29
+ app.command("recover")(recover_command)
26
30
 
27
31
 
28
32
  @app.command()
@@ -31,7 +35,7 @@ def version() -> None:
31
35
  try:
32
36
  current_version = package_version("devflow-toolkit")
33
37
  except PackageNotFoundError:
34
- current_version = "0.3.1"
38
+ current_version = "0.3.3"
35
39
  console.print(f"DevFlow v{current_version}")
36
40
 
37
41
 
@@ -57,7 +57,7 @@ def _approve(spec_id: str, path: Path, stage: str) -> None:
57
57
  normalized = stage.strip().lower()
58
58
  if normalized != "spec":
59
59
  msg = (
60
- f"Stage '{stage}' is not available in DevFlow 0.3.1. "
60
+ f"Stage '{stage}' is not available in DevFlow 0.3.3. "
61
61
  "Only the 'spec' stage can be approved."
62
62
  )
63
63
  raise UnsupportedStageError(msg)
@@ -0,0 +1,145 @@
1
+ """Implementation of the devflow doctor command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import typer
8
+ from rich.console import Console
9
+
10
+ from devflow.core.artifacts.errors import ArtifactError
11
+ from devflow.core.config import ConfigError, ConfigManager
12
+ from devflow.core.discovery import DiscoveryError
13
+ from devflow.core.project import ProjectDetector
14
+ from devflow.core.recovery import ChangeInspection, inspect_change
15
+ from devflow.core.state import StateError, WorkflowLocator
16
+
17
+ console = Console()
18
+ error_console = Console(stderr=True)
19
+
20
+
21
+ def doctor(
22
+ spec_id: str = typer.Argument(
23
+ ...,
24
+ help="Change id (001) or change directory (001-add-health).",
25
+ ),
26
+ path: Path = typer.Argument(
27
+ Path("."),
28
+ help="Project root or a path inside it.",
29
+ ),
30
+ ) -> None:
31
+ """Diagnose a change, including artifacts written without state."""
32
+ try:
33
+ healthy = _doctor(spec_id, path)
34
+ except (
35
+ ArtifactError,
36
+ ConfigError,
37
+ DiscoveryError,
38
+ StateError,
39
+ FileNotFoundError,
40
+ NotADirectoryError,
41
+ OSError,
42
+ ) as error:
43
+ error_console.print(f"[red]Error:[/red] {error}")
44
+ raise typer.Exit(code=1) from error
45
+ if not healthy:
46
+ raise typer.Exit(code=1)
47
+
48
+
49
+ def _doctor(spec_id: str, path: Path) -> bool:
50
+ root = ProjectDetector().find_root(path)
51
+ config = ConfigManager(root).load()
52
+ location = WorkflowLocator(config.specifications_path).find(spec_id)
53
+ inspection = inspect_change(config, location)
54
+
55
+ console.print(f"[bold]Change:[/bold] {location.change}")
56
+ console.print(f"[bold]Directory:[/bold] {location.directory}")
57
+ console.print(
58
+ "[bold]Workflow:[/bold] "
59
+ + (
60
+ f"present ({inspection.workflow_status})"
61
+ if inspection.workflow_present
62
+ else "[yellow]missing[/yellow]"
63
+ )
64
+ )
65
+ console.print(
66
+ "[bold]Events:[/bold] "
67
+ + ("present" if inspection.events_present else "[yellow]missing[/yellow]")
68
+ )
69
+ _print_discovery(inspection)
70
+ _print_spec(inspection)
71
+
72
+ if inspection.warnings:
73
+ console.print("\n[bold]Warnings[/bold]")
74
+ for warning in inspection.warnings:
75
+ console.print(f"[yellow]- {warning}[/yellow]")
76
+ if inspection.orphans:
77
+ console.print("\n[bold]Orphan artifacts[/bold]")
78
+ for orphan in inspection.orphans:
79
+ console.print(f"[yellow]- {orphan} is not registered[/yellow]")
80
+
81
+ if inspection.healthy:
82
+ console.print("\n[bold green]Diagnosis: healthy.[/bold green]")
83
+ return True
84
+
85
+ if inspection.can_recover:
86
+ console.print(
87
+ "\n[bold yellow]Diagnosis: recoverable without regenerating the "
88
+ "artifacts.[/bold yellow]"
89
+ )
90
+ console.print(
91
+ "[bold]Next:[/bold] "
92
+ f"devflow recover {location.spec_id} {root}"
93
+ )
94
+ elif inspection.can_resume:
95
+ console.print(
96
+ "\n[bold yellow]Diagnosis: Discovery is complete but the "
97
+ "specification is missing.[/bold yellow]"
98
+ )
99
+ console.print(
100
+ "[bold]Next:[/bold] "
101
+ f"devflow spec --continue {location.spec_id} {root}"
102
+ )
103
+ console.print(
104
+ "[dim]The existing Discovery record will be reused.[/dim]"
105
+ )
106
+ else:
107
+ console.print(
108
+ "\n[bold yellow]Diagnosis: needs attention.[/bold yellow]"
109
+ )
110
+ console.print(
111
+ "[dim]Resolve the issues above before approving or continuing "
112
+ "this change.[/dim]"
113
+ )
114
+ return False
115
+
116
+
117
+ def _print_discovery(inspection: ChangeInspection) -> None:
118
+ console.print("\n[bold]Discovery[/bold]")
119
+ if not inspection.discovery_present:
120
+ console.print(" [yellow]missing discovery.yaml[/yellow]")
121
+ return
122
+ if inspection.discovery_error:
123
+ console.print(
124
+ f" [yellow]invalid: {inspection.discovery_error}[/yellow]"
125
+ )
126
+ return
127
+ console.print(
128
+ f" status: {inspection.discovery_status} · "
129
+ f"digest: {inspection.discovery_digest}"
130
+ )
131
+
132
+
133
+ def _print_spec(inspection: ChangeInspection) -> None:
134
+ console.print("\n[bold]Specification[/bold]")
135
+ if not inspection.spec_present:
136
+ console.print(" [yellow]missing spec.md[/yellow]")
137
+ return
138
+ if inspection.spec_valid:
139
+ console.print(
140
+ f" valid · digest: {inspection.spec_digest}"
141
+ )
142
+ else:
143
+ console.print(
144
+ f" [yellow]invalid: {inspection.spec_error}[/yellow]"
145
+ )
@@ -0,0 +1,78 @@
1
+ """Implementation of the devflow recover command."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import typer
8
+ from rich.console import Console
9
+
10
+ from devflow.core.artifacts.errors import ArtifactError
11
+ from devflow.core.config import ConfigError, ConfigManager
12
+ from devflow.core.discovery import DiscoveryError
13
+ from devflow.core.project import ProjectDetector
14
+ from devflow.core.recovery import recover_change
15
+ from devflow.core.state import StateError, WorkflowLocator
16
+
17
+ console = Console()
18
+ error_console = Console(stderr=True)
19
+
20
+
21
+ def recover(
22
+ spec_id: str = typer.Argument(
23
+ ...,
24
+ help="Change id (001) or change directory (001-add-health).",
25
+ ),
26
+ path: Path = typer.Argument(
27
+ Path("."),
28
+ help="Project root or a path inside it.",
29
+ ),
30
+ ) -> None:
31
+ """Register existing valid artifacts in a missing workflow state."""
32
+ try:
33
+ _recover(spec_id, path)
34
+ except (
35
+ ArtifactError,
36
+ ConfigError,
37
+ DiscoveryError,
38
+ StateError,
39
+ FileNotFoundError,
40
+ NotADirectoryError,
41
+ OSError,
42
+ ) as error:
43
+ error_console.print(f"[red]Error:[/red] {error}")
44
+ raise typer.Exit(code=1) from error
45
+
46
+
47
+ def _recover(spec_id: str, path: Path) -> None:
48
+ root = ProjectDetector().find_root(path)
49
+ config = ConfigManager(root).load()
50
+ location = WorkflowLocator(config.specifications_path).find(spec_id)
51
+ result = recover_change(config, location)
52
+
53
+ if not result.recovered:
54
+ console.print(
55
+ f"[bold]{location.change}[/bold] already has workflow state "
56
+ f"([bold]{result.state.status}[/bold]). Nothing to recover."
57
+ )
58
+ console.print(
59
+ f"[dim]Run 'devflow status {location.spec_id}' to inspect it.[/dim]"
60
+ )
61
+ return
62
+
63
+ console.print(
64
+ f"[bold green]Recovered[/bold green] {location.change} without "
65
+ "regenerating its artifacts."
66
+ )
67
+ console.print(f"Workflow status: {result.state.status}")
68
+ console.print(
69
+ "Registered: discovery "
70
+ f"{result.inspection.discovery_digest}"
71
+ )
72
+ console.print(
73
+ f"Registered: spec {result.inspection.spec_digest}"
74
+ )
75
+ console.print(
76
+ "\n[bold]Next:[/bold] review the specification, then run "
77
+ f"'devflow approve {location.spec_id}'."
78
+ )
devflow/commands/spec.py CHANGED
@@ -30,6 +30,7 @@ from devflow.core.constitution import ConstitutionError
30
30
  from devflow.core.discovery import DiscoveryError
31
31
  from devflow.core.profile_manager import ProfileError
32
32
  from devflow.core.project import ProjectDetector
33
+ from devflow.core.recovery import ensure_resumable_state
33
34
  from devflow.core.spec_workflow import (
34
35
  SpecWorkflow,
35
36
  SpecWorkflowRequest,
@@ -103,6 +104,15 @@ def spec(
103
104
  "Defaults to the configured language."
104
105
  ),
105
106
  ),
107
+ auto: bool = typer.Option(
108
+ False,
109
+ "--auto",
110
+ help=(
111
+ "Run Discovery and Specification in one invocation. By default an "
112
+ "interactive run stops after Discovery so you can choose the "
113
+ "specification harness."
114
+ ),
115
+ ),
106
116
  ) -> None:
107
117
  """Generate or resume a specification for a change request."""
108
118
  try:
@@ -115,6 +125,7 @@ def spec(
115
125
  project_mode,
116
126
  continue_id,
117
127
  language,
128
+ auto,
118
129
  )
119
130
  except (
120
131
  ArchitectureError,
@@ -142,6 +153,7 @@ def _create_specification(
142
153
  project_mode: Optional[str],
143
154
  continue_id: Optional[str],
144
155
  language: Optional[str] = None,
156
+ auto: bool = False,
145
157
  ) -> None:
146
158
  request = (description or "").strip()
147
159
  resume = (continue_id or "").strip() or None
@@ -199,6 +211,13 @@ def _create_specification(
199
211
  )
200
212
  adapter = adapter_for(selected_harness) if selected_harness else None
201
213
 
214
+ stop_after_discovery = (
215
+ not auto
216
+ and resume is None
217
+ and selected_harness is not None
218
+ and execution_mode == "interactive"
219
+ )
220
+
202
221
  workflow = SpecWorkflow(executor=execute_invocation)
203
222
  result = workflow.run(
204
223
  SpecWorkflowRequest(
@@ -210,6 +229,7 @@ def _create_specification(
210
229
  project_mode=effective_project_mode,
211
230
  continue_spec_id=resume,
212
231
  language=documentation_language,
232
+ stop_after_discovery=stop_after_discovery,
213
233
  )
214
234
  )
215
235
 
@@ -243,7 +263,25 @@ def _create_specification(
243
263
  print_setup_result(result.setup_result, config.root, console)
244
264
  _print_warnings(list(result.run_warnings))
245
265
 
246
- if result.blocked:
266
+ if result.stopped_after_discovery:
267
+ stopped = WorkflowLocator(
268
+ config.specifications_path
269
+ ).from_directory(result.directory)
270
+ console.print(
271
+ "\n[bold green]Discovery complete.[/bold green] "
272
+ "The specification was not generated."
273
+ )
274
+ next_command = (
275
+ f"devflow spec --continue {stopped.spec_id} ."
276
+ )
277
+ if selected_harness is not None:
278
+ next_command += f" --harness {selected_harness}"
279
+ console.print(f"[bold]Next:[/bold] {next_command}")
280
+ console.print(
281
+ "[dim]Choose another harness with --harness, or run both phases "
282
+ "in one invocation with --auto.[/dim]"
283
+ )
284
+ elif result.blocked:
247
285
  _print_blocked(result=result, config=config)
248
286
  elif result.spec_reused and result.spec is not None:
249
287
  console.print(
@@ -272,6 +310,7 @@ def _ensure_continuable(config: DevFlowConfig, selector: str) -> None:
272
310
  project_root=config.root,
273
311
  )
274
312
  location = WorkflowLocator(config.specifications_path).find(selector)
313
+ ensure_resumable_state(config, location)
275
314
  state = manager.load(location)
276
315
  allowed = {
277
316
  WorkflowStatus.DRAFT.value,
@@ -0,0 +1,304 @@
1
+ """Inspect and recover changes written without workflow state."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from devflow.core.architecture import (
8
+ ArchitectureError,
9
+ ArchitectureManifest,
10
+ ArchitectureManifestLoader,
11
+ )
12
+ from devflow.core.artifacts.errors import ArtifactError
13
+ from devflow.core.artifacts.store import ArtifactStore
14
+ from devflow.core.config import DevFlowConfig
15
+ from devflow.core.discovery import DiscoveryError, DiscoveryManager
16
+ from devflow.core.specification import SpecificationManager
17
+ from devflow.core.state import (
18
+ ChangeLocation,
19
+ StateError,
20
+ WorkflowLocator,
21
+ WorkflowStateManager,
22
+ )
23
+ from devflow.core.state.models import WorkflowState
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class ChangeInspection:
28
+ """Read-only diagnostic view of one change directory."""
29
+
30
+ location: ChangeLocation
31
+ events_present: bool
32
+ workflow_present: bool
33
+ workflow_status: str
34
+ discovery_present: bool
35
+ discovery_complete: bool
36
+ discovery_status: str
37
+ discovery_digest: str
38
+ discovery_error: str
39
+ spec_present: bool
40
+ spec_valid: bool
41
+ spec_digest: str
42
+ spec_error: str
43
+ architecture_digest: str
44
+ warnings: tuple[str, ...] = ()
45
+ orphans: tuple[str, ...] = ()
46
+ can_recover: bool = False
47
+
48
+ @property
49
+ def healthy(self) -> bool:
50
+ """Return whether the change has a complete, current workflow."""
51
+ return (
52
+ self.events_present
53
+ and self.workflow_present
54
+ and not self.warnings
55
+ and not self.orphans
56
+ )
57
+
58
+ @property
59
+ def can_resume(self) -> bool:
60
+ """Return whether Discovery is complete but the spec is missing."""
61
+ return (
62
+ not self.events_present
63
+ and not self.workflow_present
64
+ and self.discovery_present
65
+ and self.discovery_complete
66
+ and not self.spec_present
67
+ )
68
+
69
+
70
+ @dataclass(frozen=True)
71
+ class RecoveryResult:
72
+ """Outcome of registering orphaned artifacts."""
73
+
74
+ inspection: ChangeInspection
75
+ state: WorkflowState
76
+ recovered: bool = True
77
+
78
+
79
+ def inspect_change(
80
+ config: DevFlowConfig,
81
+ location: ChangeLocation,
82
+ ) -> ChangeInspection:
83
+ """Inspect workflow, Discovery and specification without repairing."""
84
+ store = ArtifactStore(config.root)
85
+ manager = WorkflowStateManager(
86
+ config.specifications_path,
87
+ project_root=config.root,
88
+ )
89
+ events_present = location.events_path.is_file()
90
+ workflow_present = location.workflow_path.is_file()
91
+ warnings: list[str] = []
92
+ orphans: tuple[str, ...] = ()
93
+ workflow_status = ""
94
+
95
+ if events_present:
96
+ try:
97
+ current = manager.status(location)
98
+ except StateError as error:
99
+ warnings.append(str(error))
100
+ else:
101
+ workflow_status = current.state.status
102
+ warnings.extend(current.warnings)
103
+ orphans = current.orphans
104
+ elif workflow_present:
105
+ warnings.append(
106
+ "workflow.yaml exists without events.jsonl; the projection cannot "
107
+ "be trusted. Restore the event log or remove the orphan projection."
108
+ )
109
+
110
+ discovery_path = location.directory / "discovery.yaml"
111
+ discovery_present = discovery_path.is_file()
112
+ discovery_complete = False
113
+ discovery_status = ""
114
+ discovery_digest = ""
115
+ discovery_error = ""
116
+ if discovery_present:
117
+ try:
118
+ discovery = DiscoveryManager(config.root).load(
119
+ location.directory,
120
+ required=True,
121
+ )
122
+ except DiscoveryError as error:
123
+ discovery_error = str(error)
124
+ else:
125
+ if discovery is not None:
126
+ discovery_complete = discovery.is_complete
127
+ discovery_status = discovery.status
128
+ if not discovery_error:
129
+ try:
130
+ discovery_digest = store.digest_file(discovery_path)
131
+ except ArtifactError as error:
132
+ discovery_error = str(error)
133
+
134
+ architecture: ArchitectureManifest | None = None
135
+ architecture_digest = ""
136
+ try:
137
+ architecture = ArchitectureManifestLoader().load(
138
+ config.root,
139
+ required=config.project_mode == "greenfield",
140
+ )
141
+ except ArchitectureError as error:
142
+ warnings.append(f"Architecture manifest: {error}")
143
+ else:
144
+ if architecture is not None:
145
+ architecture_digest = architecture.digest
146
+
147
+ spec_path = location.directory / "spec.md"
148
+ spec_present = spec_path.is_file()
149
+ spec_valid = False
150
+ spec_digest = ""
151
+ spec_error = ""
152
+ if spec_present:
153
+ try:
154
+ spec_digest = store.digest_file(spec_path)
155
+ spec_text = spec_path.read_text(encoding="utf-8")
156
+ spec_valid, spec_error = SpecificationManager().validate(
157
+ spec_text,
158
+ project_mode=config.project_mode,
159
+ architecture=architecture,
160
+ discovery_digest=discovery_digest or None,
161
+ )
162
+ except (ArtifactError, OSError) as error:
163
+ spec_error = str(error)
164
+ else:
165
+ spec_error = "spec.md is missing"
166
+
167
+ can_recover = (
168
+ not events_present
169
+ and not workflow_present
170
+ and discovery_complete
171
+ and spec_valid
172
+ )
173
+
174
+ return ChangeInspection(
175
+ location=location,
176
+ events_present=events_present,
177
+ workflow_present=workflow_present,
178
+ workflow_status=workflow_status,
179
+ discovery_present=discovery_present,
180
+ discovery_complete=discovery_complete,
181
+ discovery_status=discovery_status,
182
+ discovery_digest=discovery_digest,
183
+ discovery_error=discovery_error,
184
+ spec_present=spec_present,
185
+ spec_valid=spec_valid,
186
+ spec_digest=spec_digest,
187
+ spec_error=spec_error,
188
+ architecture_digest=architecture_digest,
189
+ warnings=tuple(warnings),
190
+ orphans=orphans,
191
+ can_recover=can_recover,
192
+ )
193
+
194
+
195
+ def ensure_resumable_state(
196
+ config: DevFlowConfig,
197
+ location: ChangeLocation,
198
+ ) -> bool:
199
+ """Create missing workflow state so ``spec --continue`` can resume.
200
+
201
+ Discovery is registered with its current digest. The specification is
202
+ not required or created. Returns ``True`` when state was created.
203
+ """
204
+ if location.events_path.is_file() or location.workflow_path.is_file():
205
+ return False
206
+ discovery_path = location.directory / "discovery.yaml"
207
+ if not discovery_path.is_file():
208
+ return False
209
+
210
+ inspection = inspect_change(config, location)
211
+ manager = WorkflowStateManager(
212
+ config.specifications_path,
213
+ project_root=config.root,
214
+ )
215
+ manager.initialize_change(location.directory)
216
+ location = WorkflowLocator(config.specifications_path).from_directory(
217
+ location.directory
218
+ )
219
+ manager.record_artifact(
220
+ location,
221
+ stage="discovery",
222
+ path=discovery_path,
223
+ validated=inspection.discovery_complete,
224
+ source="existing",
225
+ )
226
+ return True
227
+
228
+
229
+ def recover_change(
230
+ config: DevFlowConfig,
231
+ location: ChangeLocation,
232
+ ) -> RecoveryResult:
233
+ """Register existing valid artifacts in a missing workflow state.
234
+
235
+ Running this function again once a workflow exists is safe: it returns
236
+ the current state without changing it.
237
+ """
238
+ inspection = inspect_change(config, location)
239
+ manager = WorkflowStateManager(
240
+ config.specifications_path,
241
+ project_root=config.root,
242
+ )
243
+ if inspection.events_present:
244
+ return RecoveryResult(
245
+ inspection=inspection,
246
+ state=manager.status(location).state,
247
+ recovered=False,
248
+ )
249
+ if inspection.workflow_present:
250
+ raise StateError(
251
+ f"Cannot recover {location.change}: workflow.yaml exists without "
252
+ "events.jsonl. Restore the event log or remove the orphan "
253
+ "projection, then run 'devflow doctor' again."
254
+ )
255
+ if not inspection.discovery_present:
256
+ raise StateError(
257
+ f"Cannot recover {location.change}: discovery.yaml is missing. "
258
+ "Run 'devflow spec' first."
259
+ )
260
+ if not inspection.discovery_complete:
261
+ detail = inspection.discovery_error or (
262
+ f"Discovery status is '{inspection.discovery_status}'."
263
+ )
264
+ raise StateError(
265
+ f"Cannot recover {location.change}: Discovery is not complete. "
266
+ f"{detail} Resolve it with 'devflow spec --continue "
267
+ f"{location.spec_id}'."
268
+ )
269
+ if not inspection.spec_present:
270
+ raise StateError(
271
+ f"Cannot recover {location.change}: spec.md is missing. "
272
+ f"Run 'devflow spec --continue {location.spec_id}' first."
273
+ )
274
+ if not inspection.spec_valid:
275
+ raise StateError(
276
+ f"Cannot recover {location.change}: spec.md is invalid. "
277
+ f"{inspection.spec_error}"
278
+ )
279
+
280
+ manager.initialize_change(location.directory)
281
+ location = WorkflowLocator(config.specifications_path).from_directory(
282
+ location.directory
283
+ )
284
+ manager.record_artifact(
285
+ location,
286
+ stage="discovery",
287
+ path=location.directory / "discovery.yaml",
288
+ validated=True,
289
+ source="existing",
290
+ )
291
+ metadata: dict[str, str] = {
292
+ "discovery_digest": inspection.discovery_digest,
293
+ }
294
+ if inspection.architecture_digest:
295
+ metadata["architecture_digest"] = inspection.architecture_digest
296
+ state = manager.record_artifact(
297
+ location,
298
+ stage="spec",
299
+ path=location.directory / "spec.md",
300
+ validated=True,
301
+ source="existing",
302
+ metadata=metadata,
303
+ )
304
+ return RecoveryResult(inspection=inspection, state=state)
@@ -65,6 +65,7 @@ class SpecWorkflowRequest:
65
65
  project_mode: str = "existing"
66
66
  continue_spec_id: str | None = None
67
67
  language: str = ""
68
+ stop_after_discovery: bool = False
68
69
 
69
70
 
70
71
  @dataclass(frozen=True)
@@ -92,6 +93,7 @@ class SpecWorkflowResult:
92
93
  spec_reused: bool = False
93
94
  continuation: bool = False
94
95
  directory: Path | None = None
96
+ stopped_after_discovery: bool = False
95
97
 
96
98
 
97
99
  class SpecWorkflow:
@@ -349,6 +351,32 @@ class SpecWorkflow:
349
351
  directory=prepared.directory,
350
352
  )
351
353
 
354
+ if request.stop_after_discovery:
355
+ return self._build_result(
356
+ spec=None,
357
+ harness_name=(
358
+ adapter.display_name if adapter is not None else None
359
+ ),
360
+ execution_mode=request.execution_mode,
361
+ warnings=warnings,
362
+ run_warnings=[],
363
+ setup_result=setup_result,
364
+ constitution=constitution,
365
+ project_mode=project_mode,
366
+ architecture=architecture,
367
+ discovery=discovery,
368
+ discovery_digest=discovery_digest,
369
+ discovery_path=discovery_path,
370
+ discovery_source=discovery_source,
371
+ discovery_created=discovery_created,
372
+ blocked=False,
373
+ spec_written=False,
374
+ spec_reused=False,
375
+ continuation=continuation,
376
+ directory=prepared.directory,
377
+ stopped_after_discovery=True,
378
+ )
379
+
352
380
  reused_spec = self._reusable_spec(
353
381
  prepared=prepared,
354
382
  continuation=continuation,
@@ -902,6 +930,7 @@ class SpecWorkflow:
902
930
  spec_reused: bool,
903
931
  continuation: bool,
904
932
  directory: Path,
933
+ stopped_after_discovery: bool = False,
905
934
  ) -> SpecWorkflowResult:
906
935
  return SpecWorkflowResult(
907
936
  spec=spec,
@@ -927,6 +956,7 @@ class SpecWorkflow:
927
956
  spec_reused=spec_reused,
928
957
  continuation=continuation,
929
958
  directory=directory,
959
+ stopped_after_discovery=stopped_after_discovery,
930
960
  )
931
961
 
932
962
  @staticmethod
@@ -842,7 +842,9 @@ class WorkflowStateManager:
842
842
  raise InvalidStateError(msg)
843
843
  msg = (
844
844
  f"No workflow state found for {location.change}. "
845
- "Run 'devflow spec' first."
845
+ "Run 'devflow spec' first, or run 'devflow doctor "
846
+ f"{location.spec_id}' if the change already has context.md, "
847
+ "discovery.yaml and spec.md."
846
848
  )
847
849
  raise ChangeNotFoundError(msg)
848
850
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: devflow-toolkit
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Specification workflow toolkit for AI-assisted software changes
5
5
  Author: DevFlow contributors
6
6
  License-Expression: MIT
@@ -42,7 +42,7 @@ anyone starts implementing it. DevFlow owns the workflow state; the
42
42
  selected agent harness is only the execution backend that drafts the
43
43
  specification.
44
44
 
45
- This is the `0.3.1` MVP. It implements the **discovery and
45
+ This is the `0.3.3` MVP. It implements the **discovery and
46
46
  specification stages only**. It supports two specification contexts:
47
47
  **Existing Project** (the default) and **Greenfield**. It is not a
48
48
  complete SDD platform and does not include planning, implementation or
@@ -114,7 +114,7 @@ pip install devflow-toolkit
114
114
  To install a specific built artifact instead:
115
115
 
116
116
  ```bash
117
- pip install devflow_toolkit-0.3.1-py3-none-any.whl
117
+ pip install devflow_toolkit-0.3.3-py3-none-any.whl
118
118
  ```
119
119
 
120
120
  Verify the installation:
@@ -278,7 +278,7 @@ as an architectural constraint when it is present.
278
278
 
279
279
  ### Harnesses
280
280
 
281
- | Harness | Status in 0.3.1 |
281
+ | Harness | Status in 0.3.3 |
282
282
  | --- | --- |
283
283
  | OpenCode | Verified end-to-end in non-interactive mode |
284
284
  | Codex | Integration files are generated, but not verified for this release |
@@ -409,8 +409,10 @@ require Discovery.
409
409
  5. Review `spec.md` and resolve any remaining non-blocking questions.
410
410
  6. Record the approval.
411
411
  7. Inspect the state, artifacts and approval digests.
412
+ 8. If artifacts exist without workflow state, diagnose with
413
+ `devflow doctor <id>` and repair with `devflow recover <id>`.
412
414
 
413
- Available commands in `0.3.1`:
415
+ Available commands in `0.3.3`:
414
416
 
415
417
  | Command | Status |
416
418
  | --- | --- |
@@ -418,6 +420,8 @@ Available commands in `0.3.1`:
418
420
  | `devflow spec` | Implemented: Discovery, specification, and `--continue` |
419
421
  | `devflow approve <id> --stage spec` | Implemented |
420
422
  | `devflow status <id>` | Implemented |
423
+ | `devflow doctor <id>` | Implemented: read-only diagnostics |
424
+ | `devflow recover <id>` | Implemented: register existing artifacts |
421
425
  | `devflow version` | Implemented |
422
426
  | `devflow plan` | Not implemented |
423
427
  | `devflow approve <id> --stage plan` | Rejected |
@@ -449,12 +453,32 @@ The command:
449
453
  5. writes the deterministic evidence or declared architecture to
450
454
  `context.md`;
451
455
  6. stops without `spec.md` when a blocking decision remains;
452
- 7. if Discovery is complete, invokes the selected harness with the
453
- shared DevFlow prompt, validates the returned specification, and
456
+ 7. in an interactive run, stops after Discovery is complete and prints
457
+ the next command, so you can choose the harness for the
458
+ specification;
459
+ 8. on `--continue` (or with `--auto`) invokes the selected harness with
460
+ the specification prompt, validates the returned specification, and
454
461
  binds it to the Discovery digest;
455
- 8. writes `spec.md` and registers the Discovery and specification
462
+ 9. writes `spec.md` and registers the Discovery and specification
456
463
  digests in the event log and the workflow projection.
457
464
 
465
+ An interactive `devflow spec` therefore uses two harness invocations:
466
+ one for Discovery and one for the specification. The first run stops at
467
+ the Discovery checkpoint. The second run resumes with the harness you
468
+ choose:
469
+
470
+ ```bash
471
+ devflow spec "Add a GET /patients endpoint"
472
+ devflow spec --continue 006 . --harness opencode
473
+ ```
474
+
475
+ Use `--auto` to run both phases in a single invocation, as earlier
476
+ releases did:
477
+
478
+ ```bash
479
+ devflow spec "Add a GET /patients endpoint" --auto
480
+ ```
481
+
458
482
  Resume an existing change:
459
483
 
460
484
  ```bash
@@ -465,7 +489,10 @@ devflow spec --continue 006
465
489
  and project mode, loads Discovery, and stops until blocking decisions
466
490
  are resolved. It reuses a current validated specification when the
467
491
  Discovery digest still matches; otherwise it archives the old
468
- specification and generates a new one.
492
+ specification and generates a new one. If an interrupted run left a
493
+ complete `discovery.yaml` without `workflow.yaml`, `--continue` creates
494
+ the missing state and registers Discovery before generating the
495
+ specification.
469
496
 
470
497
  For an existing project, DevFlow inspects relevant code and
471
498
  dependencies. For Greenfield, it uses the declared architecture and
@@ -475,13 +502,18 @@ Useful options:
475
502
 
476
503
  ```bash
477
504
  devflow spec "Description" --harness opencode --mode non-interactive
505
+ devflow spec "Description" --auto
478
506
  devflow spec "Description" --no-agent
479
507
  devflow spec "Description" --language es
480
508
  devflow spec "Change in a real project" --project-mode existing
481
509
  devflow spec "Create a new service" --project-mode greenfield
482
- devflow spec --continue 006
510
+ devflow spec --continue 006 --harness opencode
483
511
  ```
484
512
 
513
+ `--auto` keeps the older one-shot flow: Discovery and the specification
514
+ run in the same invocation. Without it, an interactive run stops at the
515
+ Discovery checkpoint.
516
+
485
517
  `spec --language <code>` overrides the configured language for that run
486
518
  without changing `.devflow/config.yaml`. The deterministic `--no-agent`
487
519
  draft remains in English; the language setting applies to specifications
@@ -504,6 +536,56 @@ devflow status 001-add-a-get-patients-endpoint
504
536
  approvals, stale artifacts and orphan files. It reconciles
505
537
  `workflow.yaml` from `events.jsonl` before reporting.
506
538
 
539
+ ### Diagnose and recover a change
540
+
541
+ If `context.md`, `discovery.yaml` or `spec.md` were written outside
542
+ `devflow spec`, the change can exist on disk without `workflow.yaml`,
543
+ `events.jsonl` or `runs/`. In that case `status` reports that no workflow
544
+ state was found.
545
+
546
+ Diagnose the change without changing anything:
547
+
548
+ ```bash
549
+ devflow doctor 001
550
+ ```
551
+
552
+ `doctor` checks the workflow, Discovery and specification, reports
553
+ orphan artifacts, and exits non-zero when the change is unhealthy.
554
+
555
+ If Discovery is complete but the specification is missing (for example,
556
+ an interrupted interactive run), `doctor` prints the resume command:
557
+
558
+ ```bash
559
+ devflow spec --continue 001
560
+ ```
561
+
562
+ `--continue` creates the missing workflow state, registers the existing
563
+ Discovery digest and generates the specification without repeating
564
+ Discovery.
565
+
566
+ If `discovery.yaml` is complete and `spec.md` is structurally valid,
567
+ register the existing artifacts without regenerating them:
568
+
569
+ ```bash
570
+ devflow recover 001
571
+ ```
572
+
573
+ `recover` creates the missing workflow state and registers Discovery and
574
+ the specification with `source: existing`. It preserves the artifact
575
+ bytes and their digests, does not modify `spec.md`, and does not approve
576
+ the change. Running it again after recovery is a no-op.
577
+
578
+ Recovery does not bypass review. After recovering, inspect
579
+ `devflow status 001`, then approve explicitly:
580
+
581
+ ```bash
582
+ devflow approve 001 --stage spec
583
+ ```
584
+
585
+ If Discovery is incomplete or `spec.md` is invalid, `recover` refuses to
586
+ register the artifacts and names the problem. Resolve it with
587
+ `devflow spec --continue 001` first.
588
+
507
589
  ### Approve the specification
508
590
 
509
591
  ```bash
@@ -511,7 +593,7 @@ devflow approve 001 --stage spec
511
593
  ```
512
594
 
513
595
  Approval is explicit and binds the decision to the current artifact
514
- digests. For a `0.3.1` change it binds `spec.md`, `discovery.yaml` and,
596
+ digests. For a `0.3.3` change it binds `spec.md`, `discovery.yaml` and,
515
597
  when a manifest applies, the architecture manifest digest. Repeating the
516
598
  same approval is a no-op. If an artifact changes after validation,
517
599
  DevFlow marks it stale and refuses approval until it is regenerated and
@@ -521,7 +603,7 @@ Discovery must be complete before approval. If it is not, approval fails
521
603
  and names the pending questions and assumptions. Legacy `0.2.0` changes
522
604
  without `discovery.yaml` remain approvable with a warning.
523
605
 
524
- Only the `spec` stage is available in `0.3.1`. `--stage plan` and
606
+ Only the `spec` stage is available in `0.3.3`. `--stage plan` and
525
607
  `--stage review` are rejected. There are no `plan`, `implement` or
526
608
  `review` commands in this release.
527
609
 
@@ -545,6 +627,7 @@ my-project/
545
627
  │ ├── spec.md # only when Discovery is complete
546
628
  │ ├── workflow.yaml # projection of events.jsonl
547
629
  │ ├── events.jsonl # append-only source of truth
630
+ │ ├── runs/ # agent run metadata
548
631
  │ └── .lock # per-change advisory lock
549
632
  ├── AGENTS.md
550
633
  ├── opencode.json # when OpenCode is selected
@@ -1,5 +1,5 @@
1
1
  devflow/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- devflow/cli.py,sha256=lCnMvIA62Tew5E1VEn7T6ZKCyWZnHDYUpmvbv57HSdM,965
2
+ devflow/cli.py,sha256=bRixXdFKqRPQENKs5FMfGFlWJEQDp0E-jMQPvdPiR-g,1168
3
3
  devflow/adapters/__init__.py,sha256=WcsjXQTKzHNzMAHx82-sdJQeR3ceHRVqLWTUtRlaraE,867
4
4
  devflow/adapters/agents.py,sha256=4d54hDfBgnIP4zOKcZqAG-Qa-jfuuxzFL-akZS2qYtw,1309
5
5
  devflow/adapters/base.py,sha256=YggY_IwHExdybl5S9NjwZSlmmcw9Y6z7DhQsl3JLvXs,2055
@@ -11,10 +11,12 @@ devflow/adapters/kiro.py,sha256=8l5y7ZYffg_T9eciM28NKGHil_zgdT96mAdYK4oBZ0U,6111
11
11
  devflow/adapters/opencode.py,sha256=DonmvAKyWK2v5-X2XrL0n2iptFp7qLgOlh-X8n_8I-w,6492
12
12
  devflow/adapters/registry.py,sha256=NLd_tf7dAiZUa6gbQFcwPogurZyjbMNbzjjXozAD4xs,1177
13
13
  devflow/commands/__init__.py,sha256=yOLtd_4R4xdlMgAzihzIT35oyV_qcz0br-aoLebRj1c,157
14
- devflow/commands/approve.py,sha256=WzDItynHqnvAWzn_1kzo2ZkRsRbAEtLNsc20ySC6WHw,2740
14
+ devflow/commands/approve.py,sha256=TXjMLopcN1qOgwCfhjMzAWt-bfdUeHoBo19fwGniEic,2740
15
+ devflow/commands/doctor.py,sha256=vYk2i3OksbGpHEUFsqi7c4w44mAXRmY0OeEdO8h5j_M,4161
15
16
  devflow/commands/harness.py,sha256=r_RSAi7gXK8QNucC6eV-RzXHJycmmR03dzihqLVgdiU,2791
16
17
  devflow/commands/init.py,sha256=B-rW-etZ-Rptt9YW43YZ5mN_l3gfGczuXW9kpmHDOWQ,15420
17
- devflow/commands/spec.py,sha256=_h2-QIXxVME2iPPD9mIk6uabPnkQTdXwK9dfqp_cDZ0,14558
18
+ devflow/commands/recover.py,sha256=sV9x5-30E_3XRBe7JItDiSG-pqrowRzjqOkC_eyrhFQ,2165
19
+ devflow/commands/spec.py,sha256=gK0wsvpJk5xNqMlZLQnKEJU9CEKtV2g5Vbw6-iR6Kuw,15775
18
20
  devflow/commands/status.py,sha256=HtBCIF8U0bmkyS6wS7IEvggo89FzGRGBCsFfPrKzLpU,4369
19
21
  devflow/core/__init__.py,sha256=hN7i4-PDaZ7y4P8qRpZl_lJvIiPyQaN1TDGnw2BecYU,427
20
22
  devflow/core/architecture.py,sha256=qllllsUVqA76LiSU6z_s4U8dxMcs6ClKXU16HxI3yOI,13692
@@ -25,7 +27,8 @@ devflow/core/discovery.py,sha256=xFlY9aLLs8NgJGe13PmjYIB8dibUgOv1i6e8i5QG650,352
25
27
  devflow/core/ports.py,sha256=R6ybjAdJEdtTKFc4FMFTX0TVwRfDwPoWCsu-BHrhI5A,4071
26
28
  devflow/core/profile_manager.py,sha256=QnnJka2KIKD2tCSWJkGTOUEFMgmQT0Z9Qv173JKWKHw,8937
27
29
  devflow/core/project.py,sha256=SINU6KSRIpX5rPlPy8nWMfQuHas_VF1bAIVafhbcgCg,13330
28
- devflow/core/spec_workflow.py,sha256=uCpvImVIL7kVyVjUsiePccSy3RNw9jX6Pj06r47gCao,28534
30
+ devflow/core/recovery.py,sha256=W2If6Ymb3ISwMN8IVQYCwptDUzhxejlF-P2NvMYyZP0,8818
31
+ devflow/core/spec_workflow.py,sha256=Fnvdc-izYL6ncfLORN-7av_NzILnjhzHTeTFEvdSr0Y,29532
29
32
  devflow/core/specification.py,sha256=aHAL_U8Tl0YBokUJKneqUyCPenY6xtcPlZUgKmUsEMw,65719
30
33
  devflow/core/artifacts/__init__.py,sha256=gt9xahPynoxv75FMq1ZJx91ILTIv4ExuvX1Ymrxwr2c,627
31
34
  devflow/core/artifacts/errors.py,sha256=hwZxnLFcUTtEjDWtN6rUCkM69EN19LGVlc6HD-pNZyk,493
@@ -36,7 +39,7 @@ devflow/core/state/errors.py,sha256=dgF-x4TCxQTXc1OifyT8UZSU-0PBhATjO1x6OTMagac,
36
39
  devflow/core/state/events.py,sha256=IfwFCC0jbrQsH1tzADyqwm8HtWo5fR7QDD85M6JH8N0,20698
37
40
  devflow/core/state/locator.py,sha256=J6ZnVzcY_KzwKqBXbAOnfG9FrRzSCaYMqFeMQ7ptjIc,3256
38
41
  devflow/core/state/lock.py,sha256=94llvwHtCc5WOw-Uq8kDCu4iOBpRM4ccp6Q6fLZpYZ0,2089
39
- devflow/core/state/manager.py,sha256=eCCylS-qcECTGOBJi_qS54nv86u-bYKMcNauHDz7sFk,27850
42
+ devflow/core/state/manager.py,sha256=L7Ksn91rI4rlr7bZbIENUS2_ntS0CmRKEdO2dTAWA3I,27982
40
43
  devflow/core/state/models.py,sha256=4GTrS34ymbJIyBeZkcCi0z0e1bsq67vdxRSnSQ9O3gc,4654
41
44
  devflow/core/state/transitions.py,sha256=Go0zLhxcujWhaZEGg7JMqcC_UJU_nEFEBbpKIqrCtrs,3581
42
45
  devflow/models/__init__.py,sha256=hXX3IDZbHgklmuzVVlpiRs5SSPnrkO5kN1-k2hIEk7E,156
@@ -56,8 +59,8 @@ devflow/prompts/__init__.py,sha256=j30n28MIIGJtTV-9jAutke0icTj5WXJbfUBYbQUA_QI,7
56
59
  devflow/prompts/discovery.md,sha256=rwuCgD70yhFCw3MbygPr5jOxGof2_naKcKUVOlvmRRc,3716
57
60
  devflow/prompts/spec.greenfield.md,sha256=HEq2_rC-Aom9XFzYyyHdtedSECJe0aK8jz5WbNLL5MY,4724
58
61
  devflow/prompts/spec.md,sha256=b1cVZNlOG197JxhMZlL5xA1sThDPsCDcAuLTrmkXzBk,3392
59
- devflow_toolkit-0.3.1.dist-info/METADATA,sha256=C_h2XeyCEVDXgjO7emxt5QcbTlVAiPIkfUPkjySTtkw,23010
60
- devflow_toolkit-0.3.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
61
- devflow_toolkit-0.3.1.dist-info/entry_points.txt,sha256=wPmqE1081vi8s3xf-Wfzfvpl-44IKgwx7OGoLEK3u7o,44
62
- devflow_toolkit-0.3.1.dist-info/licenses/LICENSE,sha256=Wa04lstC8Goe4b9IYfEYWB2k7nokYBejZl6NdyAl8rA,1077
63
- devflow_toolkit-0.3.1.dist-info/RECORD,,
62
+ devflow_toolkit-0.3.3.dist-info/METADATA,sha256=6SsIsm-iO4-dbhTYkYOG6A_kFD__LiafQvenpNZPB7M,25936
63
+ devflow_toolkit-0.3.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
64
+ devflow_toolkit-0.3.3.dist-info/entry_points.txt,sha256=wPmqE1081vi8s3xf-Wfzfvpl-44IKgwx7OGoLEK3u7o,44
65
+ devflow_toolkit-0.3.3.dist-info/licenses/LICENSE,sha256=Wa04lstC8Goe4b9IYfEYWB2k7nokYBejZl6NdyAl8rA,1077
66
+ devflow_toolkit-0.3.3.dist-info/RECORD,,