devflow-toolkit 0.3.23__tar.gz → 0.3.24__tar.gz

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 (84) hide show
  1. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/CHANGELOG.md +32 -0
  2. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/PKG-INFO +32 -12
  3. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/README.md +5 -3
  4. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/docs/REFERENCE.md +31 -11
  5. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/pyproject.toml +1 -1
  6. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/discovery.py +11 -24
  7. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/spec_workflow.py +100 -7
  8. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/specification.py +10 -0
  9. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/prompts/__init__.py +23 -7
  10. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/prompts/discovery.md +4 -1
  11. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_discovery.py +5 -3
  12. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_discovery_decisions.py +39 -0
  13. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_spec_workflow.py +98 -0
  14. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/.gitignore +0 -0
  15. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/LICENSE +0 -0
  16. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/PUBLISHING.md +0 -0
  17. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/__init__.py +0 -0
  18. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/__init__.py +0 -0
  19. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/agents.py +0 -0
  20. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/antigravity.py +0 -0
  21. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/base.py +0 -0
  22. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/claude_code.py +0 -0
  23. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/codex.py +0 -0
  24. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/detector.py +0 -0
  25. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/instructions.py +0 -0
  26. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/kiro.py +0 -0
  27. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/opencode.py +0 -0
  28. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/adapters/registry.py +0 -0
  29. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/cli.py +0 -0
  30. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/__init__.py +0 -0
  31. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/approve.py +0 -0
  32. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/config.py +0 -0
  33. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/doctor.py +0 -0
  34. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/harness.py +0 -0
  35. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/init.py +0 -0
  36. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/recover.py +0 -0
  37. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/reopen.py +0 -0
  38. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/spec.py +0 -0
  39. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/commands/status.py +0 -0
  40. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/__init__.py +0 -0
  41. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/architecture.py +0 -0
  42. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/artifacts/__init__.py +0 -0
  43. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/artifacts/errors.py +0 -0
  44. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/artifacts/models.py +0 -0
  45. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/artifacts/store.py +0 -0
  46. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/clock.py +0 -0
  47. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/config.py +0 -0
  48. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/constitution.py +0 -0
  49. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/file_types.py +0 -0
  50. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/ports.py +0 -0
  51. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/profile_manager.py +0 -0
  52. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/project.py +0 -0
  53. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/recovery.py +0 -0
  54. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/__init__.py +0 -0
  55. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/errors.py +0 -0
  56. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/events.py +0 -0
  57. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/locator.py +0 -0
  58. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/lock.py +0 -0
  59. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/manager.py +0 -0
  60. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/models.py +0 -0
  61. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/core/state/transitions.py +0 -0
  62. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/models/__init__.py +0 -0
  63. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/models/profile.py +0 -0
  64. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/models/project.py +0 -0
  65. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/ai-rag/constitution/ai-rag-standards.md +0 -0
  66. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/ai-rag/profile.yaml +0 -0
  67. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/base/constitution/architecture.md +0 -0
  68. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/base/constitution/code-standards.md +0 -0
  69. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/base/constitution/constitution.md +0 -0
  70. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/base/profile.yaml +0 -0
  71. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/django-backend/constitution/django-standards.md +0 -0
  72. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/django-backend/profile.yaml +0 -0
  73. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/fastapi-backend/constitution/fastapi-standards.md +0 -0
  74. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/profiles/fastapi-backend/profile.yaml +0 -0
  75. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/prompts/discovery-repair.md +0 -0
  76. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/src/devflow/prompts/spec.md +0 -0
  77. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_cli.py +0 -0
  78. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_event_log.py +0 -0
  79. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_greenfield.py +0 -0
  80. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_hardening.py +0 -0
  81. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_harness_adapters.py +0 -0
  82. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_recovery.py +0 -0
  83. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_state.py +0 -0
  84. {devflow_toolkit-0.3.23 → devflow_toolkit-0.3.24}/tests/test_state_replay.py +0 -0
@@ -2,6 +2,38 @@
2
2
 
3
3
  All notable changes to DevFlow Toolkit are documented in this file.
4
4
 
5
+ ## 0.3.24 - 2026-11-09
6
+
7
+ ### Added
8
+
9
+ - The specification agent can resolve up to 3 missing decisions in its
10
+ own interactive session, with the Discovery rules. The answers are
11
+ recorded in `discovery.yaml` as decisions resolved by the user, and
12
+ DevFlow writes the new Discovery digest into the spec header.
13
+
14
+ ### Changed
15
+
16
+ - The specification agent speaks to the user, and writes the questions
17
+ it adds, in the configured language.
18
+ - Completeness is always derived from the decisions: a record marked
19
+ `complete` with pending questions is read as `awaiting_clarification`,
20
+ and a question with `status: awaiting_clarification` or `open` is read
21
+ as `pending`.
22
+ - A `next_level` option marked as recommended is ignored, because the
23
+ recommended option is level 1.
24
+
25
+ ### Fixed
26
+
27
+ - The specification prompt no longer tells the agent to set a question
28
+ status to `awaiting_clarification`.
29
+ - When the specification agent leaves `discovery.yaml` invalid, DevFlow
30
+ no longer writes its deterministic draft. It stops and asks for
31
+ `devflow spec --continue`, which repairs the file.
32
+
33
+ ### Package
34
+
35
+ - Package version is `0.3.24`.
36
+
5
37
  ## 0.3.23 - 2026-11-09
6
38
 
7
39
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: devflow-toolkit
3
- Version: 0.3.23
3
+ Version: 0.3.24
4
4
  Summary: Specification workflow toolkit for AI-assisted software changes
5
5
  Author: DevFlow contributors
6
6
  License-Expression: MIT
@@ -32,7 +32,7 @@ Description-Content-Type: text/markdown
32
32
 
33
33
  # DevFlow Toolkit
34
34
 
35
- **Current version: `0.3.23`.**
35
+ **Current version: `0.3.24`.**
36
36
 
37
37
  DevFlow is a command-line toolkit for leading AI models and coding
38
38
  agents through specification-driven changes in real software projects.
@@ -152,7 +152,7 @@ pip install devflow-toolkit
152
152
  To install a specific built artifact instead:
153
153
 
154
154
  ```bash
155
- pip install devflow_toolkit-0.3.23-py3-none-any.whl
155
+ pip install devflow_toolkit-0.3.24-py3-none-any.whl
156
156
  ```
157
157
 
158
158
  Verify the installation:
@@ -428,7 +428,7 @@ as an architectural constraint when it is present.
428
428
 
429
429
  ### Harnesses
430
430
 
431
- | Harness | Status in 0.3.23 |
431
+ | Harness | Status in 0.3.24 |
432
432
  | --- | --- |
433
433
  | OpenCode | Verified end-to-end; interactive Discovery uses the `question` tool |
434
434
  | Antigravity | Custom agents and scoped permissions generated; `agy` loading and print mode verified |
@@ -684,10 +684,28 @@ specification is generated. `devflow approve` rejects a
684
684
  specification that still lists open questions.
685
685
 
686
686
  In an interactive run the specification agent checks for missing
687
- decisions **before** writing. If one is missing, it appends the question
688
- to `discovery.yaml` and stops without writing `spec.md`, so no tokens are
689
- spent on a document that would be discarded. When an agent lists
690
- questions in section 7, nested bullets stay part of the same question.
687
+ decisions **before** writing:
688
+
689
+ - **Up to 3 missing decisions:** it asks you in the same session, with
690
+ the same rules as Discovery (recommended level-1 option first, a
691
+ next-level option with its reason, security never assumed). Your
692
+ answers are recorded in `discovery.yaml` as decisions resolved by you,
693
+ and then it writes the spec. DevFlow writes the new Discovery digest
694
+ into the spec header, because the agent cannot compute it.
695
+ - **More than 3, or no answer:** it records them as `pending`, sets the
696
+ record to `awaiting_clarification` and stops without writing
697
+ `spec.md`, so no tokens are spent on a document that would be
698
+ discarded.
699
+
700
+ If the agent leaves `discovery.yaml` invalid, DevFlow writes no
701
+ specification and asks you to run `devflow spec --continue`, which
702
+ repairs the file first. When an agent lists questions in section 7,
703
+ nested bullets stay part of the same question.
704
+
705
+ DevFlow derives completeness from the decisions themselves: a record
706
+ marked `complete` with pending questions is treated as
707
+ `awaiting_clarification`, and a question written with
708
+ `status: awaiting_clarification` is read as `pending`.
691
709
 
692
710
  ### Level-based Discovery
693
711
 
@@ -712,7 +730,9 @@ everything at once:
712
730
  ```
713
731
 
714
732
  If the user chooses it, the answer uses that exact text. If not,
715
- DevFlow treats it as a suggestion for a later specification.
733
+ DevFlow treats it as a suggestion for a later specification. The
734
+ recommended option is level 1, so a `next_level` marked as
735
+ recommended is ignored.
716
736
  4. **No deeper than this level.** More advanced decisions found along
717
737
  the way, and parts of a large request left for later, are recorded in
718
738
  `deferred`:
@@ -748,7 +768,7 @@ for each item; the agent does not write it.
748
768
  8. If artifacts exist without workflow state, diagnose with
749
769
  `devflow doctor <id>` and repair with `devflow recover <id>`.
750
770
 
751
- Available commands in `0.3.23`:
771
+ Available commands in `0.3.24`:
752
772
 
753
773
  | Command | Status |
754
774
  | --- | --- |
@@ -981,7 +1001,7 @@ devflow approve 001
981
1001
  ```
982
1002
 
983
1003
  Approval is explicit and binds the decision to the current artifact
984
- digests. For a `0.3.23` change it binds `spec.md`, `discovery.yaml` and,
1004
+ digests. For a `0.3.24` change it binds `spec.md`, `discovery.yaml` and,
985
1005
  when a manifest applies, the architecture manifest digest. Repeating the
986
1006
  same approval is a no-op. If an artifact changes after validation,
987
1007
  DevFlow marks it stale and refuses approval until it is regenerated and
@@ -992,7 +1012,7 @@ and names the pending questions and assumptions. Approval also rejects a
992
1012
  specification whose section 7 still lists open questions. Legacy `0.2.0`
993
1013
  changes without `discovery.yaml` remain approvable with a warning.
994
1014
 
995
- Only the `spec` stage is available in `0.3.23`, so `--stage` is optional
1015
+ Only the `spec` stage is available in `0.3.24`, so `--stage` is optional
996
1016
  and defaults to `spec`. `--stage plan` and `--stage review` are
997
1017
  rejected. There are no `plan`, `implement` or
998
1018
  `review` commands in this release.
@@ -10,7 +10,7 @@ approved specification instead of a vague chat request.
10
10
  approval live in `.devflow/`, so any agent or teammate can pick up
11
11
  the work.
12
12
 
13
- Current version: `0.3.23` · Python 3.11+ · Linux and macOS
13
+ Current version: `0.3.24` · Python 3.11+ · Linux and macOS
14
14
 
15
15
  ## Install
16
16
 
@@ -76,8 +76,10 @@ devflow spec --continue 001
76
76
  ```
77
77
 
78
78
  Each command opens at most one chat. Run it again if there are pending
79
- questions, and once more to write `spec.md`. Exit the chat only after
80
- the agent says `spec.md` is written.
79
+ questions, and once more to write `spec.md`. If the agent writing the
80
+ spec finds up to 3 missing decisions, it asks you right there and then
81
+ writes the spec. Exit the chat only after the agent says `spec.md` is
82
+ written.
81
83
 
82
84
  Prefer one command for both phases? Add `--auto` to the first command:
83
85
  `devflow spec "Add a contact form" --auto`.
@@ -1,6 +1,6 @@
1
1
  # DevFlow Toolkit
2
2
 
3
- **Current version: `0.3.23`.**
3
+ **Current version: `0.3.24`.**
4
4
 
5
5
  DevFlow is a command-line toolkit for leading AI models and coding
6
6
  agents through specification-driven changes in real software projects.
@@ -120,7 +120,7 @@ pip install devflow-toolkit
120
120
  To install a specific built artifact instead:
121
121
 
122
122
  ```bash
123
- pip install devflow_toolkit-0.3.23-py3-none-any.whl
123
+ pip install devflow_toolkit-0.3.24-py3-none-any.whl
124
124
  ```
125
125
 
126
126
  Verify the installation:
@@ -396,7 +396,7 @@ as an architectural constraint when it is present.
396
396
 
397
397
  ### Harnesses
398
398
 
399
- | Harness | Status in 0.3.23 |
399
+ | Harness | Status in 0.3.24 |
400
400
  | --- | --- |
401
401
  | OpenCode | Verified end-to-end; interactive Discovery uses the `question` tool |
402
402
  | Antigravity | Custom agents and scoped permissions generated; `agy` loading and print mode verified |
@@ -652,10 +652,28 @@ specification is generated. `devflow approve` rejects a
652
652
  specification that still lists open questions.
653
653
 
654
654
  In an interactive run the specification agent checks for missing
655
- decisions **before** writing. If one is missing, it appends the question
656
- to `discovery.yaml` and stops without writing `spec.md`, so no tokens are
657
- spent on a document that would be discarded. When an agent lists
658
- questions in section 7, nested bullets stay part of the same question.
655
+ decisions **before** writing:
656
+
657
+ - **Up to 3 missing decisions:** it asks you in the same session, with
658
+ the same rules as Discovery (recommended level-1 option first, a
659
+ next-level option with its reason, security never assumed). Your
660
+ answers are recorded in `discovery.yaml` as decisions resolved by you,
661
+ and then it writes the spec. DevFlow writes the new Discovery digest
662
+ into the spec header, because the agent cannot compute it.
663
+ - **More than 3, or no answer:** it records them as `pending`, sets the
664
+ record to `awaiting_clarification` and stops without writing
665
+ `spec.md`, so no tokens are spent on a document that would be
666
+ discarded.
667
+
668
+ If the agent leaves `discovery.yaml` invalid, DevFlow writes no
669
+ specification and asks you to run `devflow spec --continue`, which
670
+ repairs the file first. When an agent lists questions in section 7,
671
+ nested bullets stay part of the same question.
672
+
673
+ DevFlow derives completeness from the decisions themselves: a record
674
+ marked `complete` with pending questions is treated as
675
+ `awaiting_clarification`, and a question written with
676
+ `status: awaiting_clarification` is read as `pending`.
659
677
 
660
678
  ### Level-based Discovery
661
679
 
@@ -680,7 +698,9 @@ everything at once:
680
698
  ```
681
699
 
682
700
  If the user chooses it, the answer uses that exact text. If not,
683
- DevFlow treats it as a suggestion for a later specification.
701
+ DevFlow treats it as a suggestion for a later specification. The
702
+ recommended option is level 1, so a `next_level` marked as
703
+ recommended is ignored.
684
704
  4. **No deeper than this level.** More advanced decisions found along
685
705
  the way, and parts of a large request left for later, are recorded in
686
706
  `deferred`:
@@ -716,7 +736,7 @@ for each item; the agent does not write it.
716
736
  8. If artifacts exist without workflow state, diagnose with
717
737
  `devflow doctor <id>` and repair with `devflow recover <id>`.
718
738
 
719
- Available commands in `0.3.23`:
739
+ Available commands in `0.3.24`:
720
740
 
721
741
  | Command | Status |
722
742
  | --- | --- |
@@ -949,7 +969,7 @@ devflow approve 001
949
969
  ```
950
970
 
951
971
  Approval is explicit and binds the decision to the current artifact
952
- digests. For a `0.3.23` change it binds `spec.md`, `discovery.yaml` and,
972
+ digests. For a `0.3.24` change it binds `spec.md`, `discovery.yaml` and,
953
973
  when a manifest applies, the architecture manifest digest. Repeating the
954
974
  same approval is a no-op. If an artifact changes after validation,
955
975
  DevFlow marks it stale and refuses approval until it is regenerated and
@@ -960,7 +980,7 @@ and names the pending questions and assumptions. Approval also rejects a
960
980
  specification whose section 7 still lists open questions. Legacy `0.2.0`
961
981
  changes without `discovery.yaml` remain approvable with a warning.
962
982
 
963
- Only the `spec` stage is available in `0.3.23`, so `--stage` is optional
983
+ Only the `spec` stage is available in `0.3.24`, so `--stage` is optional
964
984
  and defaults to `spec`. `--stage plan` and `--stage review` are
965
985
  rejected. There are no `plan`, `implement` or
966
986
  `review` commands in this release.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "devflow-toolkit"
7
- version = "0.3.23"
7
+ version = "0.3.24"
8
8
  description = "Specification workflow toolkit for AI-assisted software changes"
9
9
  readme = "docs/REFERENCE.md"
10
10
  license = "MIT"
@@ -53,6 +53,9 @@ QUESTION_STATUSES = (
53
53
  QUESTION_ASSUMED,
54
54
  QUESTION_ANSWERED,
55
55
  )
56
+ # Agents sometimes write the record status on a question. Both mean the
57
+ # decision is still open.
58
+ QUESTION_PENDING_ALIASES = frozenset({"awaiting_clarification", "open"})
56
59
  QUESTION_WRITTEN_STATUSES = (
57
60
  QUESTION_PENDING,
58
61
  QUESTION_RESOLVED,
@@ -108,6 +111,7 @@ ASSUMPTION_STATUSES = (ASSUMPTION_PENDING, ASSUMPTION_ACCEPTED)
108
111
  ASSUMPTION_SOURCES = ("agent_default", "human", "existing_convention")
109
112
 
110
113
  _QUESTION_ID = re.compile(r"^Q\d{1,3}$")
114
+ _RECOMMENDED = re.compile(r"recom+end", re.IGNORECASE)
111
115
  _ASSUMPTION_ID = re.compile(r"^A\d{1,3}$")
112
116
 
113
117
  _STOPWORDS = {
@@ -904,18 +908,8 @@ class DiscoveryManager:
904
908
  msg = f"Invalid YAML in discovery file: {path}: {detail}"
905
909
  raise DiscoveryError(msg) from error
906
910
  document = self._parse(data, directory)
907
- if (
908
- document.status == DISCOVERY_COMPLETE
909
- and (
910
- document.pending_questions
911
- or document.pending_assumptions
912
- )
913
- ):
914
- msg = (
915
- "Discovery is marked complete but still has pending "
916
- "questions or assumptions."
917
- )
918
- raise DiscoveryError(msg)
911
+ # Completeness is derived from the decisions, never from the
912
+ # status an agent wrote.
919
913
  return replace(document, status=document.derived_status)
920
914
 
921
915
  def write(
@@ -1241,18 +1235,6 @@ class DiscoveryManager:
1241
1235
  assumptions=assumptions,
1242
1236
  deferred=deferred,
1243
1237
  )
1244
- if (
1245
- document.status == DISCOVERY_COMPLETE
1246
- and (
1247
- document.pending_questions
1248
- or document.pending_assumptions
1249
- )
1250
- ):
1251
- msg = (
1252
- "Discovery is marked complete but still has pending "
1253
- "questions or assumptions."
1254
- )
1255
- raise DiscoveryError(msg)
1256
1238
  return document
1257
1239
 
1258
1240
  def _question(
@@ -1291,6 +1273,8 @@ class DiscoveryManager:
1291
1273
  )
1292
1274
  raise DiscoveryError(msg)
1293
1275
  status = _text(mapping.get("status"), f"{identifier}.status")
1276
+ if status in QUESTION_PENDING_ALIASES:
1277
+ status = QUESTION_PENDING
1294
1278
  if status not in QUESTION_STATUSES:
1295
1279
  msg = (
1296
1280
  f"Invalid status for {identifier}: {status!r}. "
@@ -1327,6 +1311,9 @@ class DiscoveryManager:
1327
1311
  f"{identifier}.next_level.why",
1328
1312
  ),
1329
1313
  )
1314
+ # The recommended option is level 1, never the next level.
1315
+ if _RECOMMENDED.search(next_level.option):
1316
+ next_level = None
1330
1317
  resolution_source = _optional_text(
1331
1318
  mapping.get("resolution_source"),
1332
1319
  f"{identifier}.resolution_source",
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from dataclasses import dataclass
5
+ from dataclasses import dataclass, replace
6
6
  from pathlib import Path
7
7
 
8
8
  from devflow.core.architecture import (
@@ -61,6 +61,15 @@ from devflow.prompts import (
61
61
  )
62
62
 
63
63
 
64
+ class SpecDiscoveryInvalidError(Exception):
65
+ """Raised when the specification agent leaves discovery.yaml invalid."""
66
+
67
+ def __init__(self, reason: str, warnings: tuple[str, ...] = ()) -> None:
68
+ self.reason = reason
69
+ self.warnings = warnings
70
+ super().__init__(reason)
71
+
72
+
64
73
  class SpecOpenQuestionsError(Exception):
65
74
  """Raised when the specification agent leaves decisions unresolved."""
66
75
 
@@ -633,6 +642,37 @@ class SpecWorkflow:
633
642
  discovery_digest=discovery_digest,
634
643
  archive=archive_existing,
635
644
  )
645
+ except SpecDiscoveryInvalidError as error:
646
+ if prepared.path.is_file():
647
+ ArtifactStore(prepared.root).archive(prepared.path)
648
+ prepared.path.unlink(missing_ok=True)
649
+ warnings.append(
650
+ "the specification agent left discovery.yaml invalid: "
651
+ f"{error.reason}. No specification was written. Run 'devflow "
652
+ f"spec --continue {prepared.spec_id}' to repair it."
653
+ )
654
+ return self._build_result(
655
+ spec=None,
656
+ harness_name=adapter.display_name,
657
+ execution_mode=request.execution_mode,
658
+ warnings=warnings,
659
+ run_warnings=list(error.warnings),
660
+ setup_result=setup_result,
661
+ constitution=constitution,
662
+ project_mode=project_mode,
663
+ architecture=architecture,
664
+ discovery=discovery,
665
+ discovery_digest=discovery_digest,
666
+ discovery_path=discovery_path,
667
+ discovery_source=discovery_source,
668
+ discovery_created=discovery_created,
669
+ blocked=True,
670
+ spec_written=False,
671
+ spec_reused=False,
672
+ continuation=continuation,
673
+ directory=prepared.directory,
674
+ discovery_valid=False,
675
+ )
636
676
  except SpecOpenQuestionsError as error:
637
677
  if prepared.path.is_file():
638
678
  ArtifactStore(prepared.root).archive(prepared.path)
@@ -694,6 +734,31 @@ class SpecWorkflow:
694
734
  continuation=continuation,
695
735
  directory=prepared.directory,
696
736
  )
737
+ current_digest = self._discovery_digest(
738
+ discovery_manager,
739
+ prepared.directory,
740
+ )
741
+ if current_digest and current_digest != discovery_digest:
742
+ discovery = discovery_manager.load(
743
+ prepared.directory,
744
+ required=True,
745
+ )
746
+ discovery_digest = current_digest
747
+ discovery_source = "agent"
748
+ prepared = self.manager.prepare(
749
+ description=description,
750
+ config=config,
751
+ project=project,
752
+ constitution=constitution,
753
+ profiles=profiles,
754
+ project_mode=project_mode,
755
+ architecture=architecture,
756
+ discovery=discovery,
757
+ discovery_digest=discovery_digest,
758
+ directory=prepared.directory,
759
+ spec_id=prepared.spec_id,
760
+ )
761
+ self.manager.materialize_context(prepared)
697
762
  return self._build_result(
698
763
  spec=spec,
699
764
  harness_name=adapter.display_name,
@@ -1059,8 +1124,35 @@ class SpecWorkflow:
1059
1124
  run_warnings,
1060
1125
  )
1061
1126
  if prepared.path.is_file():
1062
- self._raise_if_returned_to_discovery(prepared, run_warnings)
1127
+ current = self._raise_if_returned_to_discovery(
1128
+ prepared,
1129
+ run_warnings,
1130
+ )
1063
1131
  content = prepared.path.read_text(encoding="utf-8")
1132
+ current_digest = self._discovery_digest(
1133
+ DiscoveryManager(prepared.root),
1134
+ prepared.directory,
1135
+ )
1136
+ if (
1137
+ current is not None
1138
+ and discovery_digest
1139
+ and current_digest
1140
+ and current_digest != discovery_digest
1141
+ ):
1142
+ # Decisions answered by the user during this session are
1143
+ # part of Discovery. DevFlow binds the spec to the new
1144
+ # record, because the agent cannot compute the digest.
1145
+ prepared = replace(
1146
+ prepared,
1147
+ discovery=current,
1148
+ discovery_digest=current_digest,
1149
+ )
1150
+ discovery_digest = current_digest
1151
+ if discovery_digest:
1152
+ content = self.manager.stamp_discovery_digest(
1153
+ content,
1154
+ discovery_digest,
1155
+ )
1064
1156
  self._raise_if_open_questions(
1065
1157
  content,
1066
1158
  discovery_digest,
@@ -1156,7 +1248,7 @@ class SpecWorkflow:
1156
1248
  self,
1157
1249
  prepared: PreparedSpec,
1158
1250
  run_warnings: list[str],
1159
- ) -> None:
1251
+ ) -> DiscoveryDocument | None:
1160
1252
  """Stop when the agent recorded new decisions instead of a spec."""
1161
1253
  try:
1162
1254
  current = DiscoveryManager(prepared.root).load(
@@ -1164,12 +1256,13 @@ class SpecWorkflow:
1164
1256
  required=True,
1165
1257
  )
1166
1258
  except DiscoveryError as error:
1167
- run_warnings.append(
1168
- f"the specification agent left an invalid discovery.yaml: {error}"
1169
- )
1170
- return
1259
+ raise SpecDiscoveryInvalidError(
1260
+ str(error),
1261
+ tuple(run_warnings),
1262
+ ) from error
1171
1263
  if current is not None and not current.is_complete:
1172
1264
  raise SpecOpenQuestionsError((), tuple(run_warnings))
1265
+ return current
1173
1266
 
1174
1267
  def _raise_if_open_questions(
1175
1268
  self,
@@ -1087,6 +1087,16 @@ class SpecificationManager:
1087
1087
  cleaned = cleaned[start:]
1088
1088
  return cleaned.strip()
1089
1089
 
1090
+ def stamp_discovery_digest(self, content: str, digest: str) -> str:
1091
+ """Write the authoritative Discovery digest into the header row."""
1092
+ return re.sub(
1093
+ r"^(\|\s*Discovery digest\s*\|).*$",
1094
+ lambda match: f"{match.group(1)} `{digest}` |",
1095
+ content,
1096
+ count=1,
1097
+ flags=re.MULTILINE,
1098
+ )
1099
+
1090
1100
  def with_next_specs(
1091
1101
  self,
1092
1102
  content: str,
@@ -17,6 +17,10 @@ PROMPTS_ROOT = Path(__file__).resolve().parent
17
17
  # normal English/Spanish text uses roughly four characters per token.
18
18
  MAX_DECISION_CONTEXT_CHARS = 8_000
19
19
 
20
+ # Missing decisions the specification agent may ask in its own session
21
+ # before the change has to return to a separate Discovery session.
22
+ MAX_IN_SESSION_DECISIONS = 3
23
+
20
24
 
21
25
  class PromptError(Exception):
22
26
  """Raised when a bundled prompt cannot be loaded."""
@@ -372,7 +376,9 @@ def _language_note(language: str) -> str:
372
376
  "`AC-XXX` identifier, field name, path, command, code block and "
373
377
  "digest exactly as shown in this prompt. Do not translate or "
374
378
  "reformat those tokens. Do not write the specification in English "
375
- "unless the target language is `en`."
379
+ "unless the target language is `en`.\n\n"
380
+ "Speak to the user, and write every question you add to the "
381
+ "discovery record, in the same target language."
376
382
  )
377
383
 
378
384
 
@@ -468,12 +474,22 @@ def _mode_instructions(
468
474
  "You are running interactively. Discovery is complete; use its "
469
475
  "recorded answers and accepted assumptions as settled decisions. "
470
476
  "Before writing, check that every decision the specification "
471
- "needs is recorded. If one is missing, do not write the "
472
- "specification: append each missing decision to the discovery "
473
- "record as a pending question with options and a `next_level`, "
474
- "set its `status` to `awaiting_clarification`, and tell the user "
475
- "to exit this session so DevFlow returns to Discovery. Otherwise "
476
- "write the complete specification to "
477
+ "needs is recorded. If up to "
478
+ f"{MAX_IN_SESSION_DECISIONS} decisions are missing, ask the user "
479
+ "now in one batch, with the structured question tool when "
480
+ "available: put the recommended level-1 option first, add one "
481
+ "more advanced next-level option with a one-sentence reason, and "
482
+ "never assume a security decision. Record each answer in the "
483
+ "discovery record as a new question with the next `Qn` id, "
484
+ "`status: resolved`, `resolution_source: user`, the chosen option "
485
+ "text as `answer`, `answered_by: user`, `answered_at`, `options` "
486
+ "and `next_level`; DevFlow updates the Discovery digest in the "
487
+ "specification header. If more decisions are missing or the user "
488
+ "does not answer, append them as questions with `status: "
489
+ "pending`, set the root `status` of the record to "
490
+ "`awaiting_clarification`, do not write the specification and "
491
+ "tell the user to exit this session so DevFlow returns to "
492
+ "Discovery. Otherwise write the complete specification to "
477
493
  f"`{spec_path}` using the available file tools. Do not finish "
478
494
  "until the file exists and contains the "
479
495
  "complete document. Then tell the user that the specification is "
@@ -52,7 +52,8 @@ traces that path instead of solving everything at once.
52
52
  the decision one level further and record it in `next_level`:
53
53
  `option` is the exact option text (also listed in `options`) and
54
54
  `why` explains in one sentence what it improves and when it is worth
55
- it. If the user picks it, record the answer with that exact text. If
55
+ it. It is never the recommended level-1 option; DevFlow ignores a
56
+ `next_level` marked as recommended. If the user picks it, record the answer with that exact text. If
56
57
  not, DevFlow proposes it as a next specification. Do not ask
57
58
  follow-up questions about the next level in this specification.
58
59
  4. **Do not go deeper than this level.** When an answer opens a more
@@ -279,6 +280,8 @@ Valid materialities are `critical`, `functional`, `technical` and
279
280
  `cosmetic`.
280
281
 
281
282
  Valid question statuses are `pending`, `resolved` and `assumed`.
283
+ `awaiting_clarification` and `complete` belong only to the root
284
+ `status` of the record.
282
285
  `answered` is a legacy alias that DevFlow reads as `resolved`; write
283
286
  `resolved` in new records. Valid assumption statuses are
284
287
  `pending_acceptance` and `accepted`.
@@ -482,7 +482,7 @@ def test_discovery_answers_and_acceptance_are_persistent(
482
482
  assert complete.decisions()
483
483
 
484
484
 
485
- def test_discovery_rejects_complete_with_pending_blockers(
485
+ def test_discovery_derives_status_when_marked_complete_with_pending(
486
486
  tmp_path: Path,
487
487
  ) -> None:
488
488
  _project(tmp_path)
@@ -512,8 +512,10 @@ def test_discovery_rejects_complete_with_pending_blockers(
512
512
  yaml.safe_dump(document.to_dict(), sort_keys=False),
513
513
  )
514
514
 
515
- with pytest.raises(DiscoveryError):
516
- _discovery(tmp_path).load(directory, required=True)
515
+ loaded = _discovery(tmp_path).load(directory, required=True)
516
+ assert loaded is not None
517
+ assert not loaded.is_complete
518
+ assert loaded.status == "awaiting_clarification"
517
519
 
518
520
 
519
521
  def test_discovery_load_reports_yaml_line_and_column(
@@ -539,3 +539,42 @@ def test_decision_context_lists_suggested_next_specs() -> None:
539
539
 
540
540
  assert "### Suggested next specifications" in context
541
541
  assert "Expire tokens after 24 hours (Q1)" in context
542
+
543
+
544
+ def test_question_status_aliases_mean_pending(tmp_path: Path) -> None:
545
+ directory = _directory(tmp_path)
546
+ data = _document(
547
+ questions=(_leveled_question("Q1", answer=None),),
548
+ ).to_dict()
549
+ data["status"] = "complete"
550
+ data["questions"][0]["status"] = "awaiting_clarification"
551
+ (directory / "discovery.yaml").write_text(
552
+ yaml.safe_dump(data, sort_keys=False),
553
+ encoding="utf-8",
554
+ )
555
+
556
+ loaded = DiscoveryManager(tmp_path).load(directory, required=True)
557
+
558
+ assert loaded is not None
559
+ assert loaded.questions[0].is_pending
560
+ assert not loaded.is_complete
561
+
562
+
563
+ def test_recommended_option_is_not_a_next_level(tmp_path: Path) -> None:
564
+ directory = _directory(tmp_path)
565
+ data = _document(
566
+ questions=(_leveled_question("Q1", answer=None),),
567
+ ).to_dict()
568
+ data["questions"][0]["next_level"] = {
569
+ "option": "Sign in automatically (recomendado).",
570
+ "why": "Saves a step.",
571
+ }
572
+ (directory / "discovery.yaml").write_text(
573
+ yaml.safe_dump(data, sort_keys=False),
574
+ encoding="utf-8",
575
+ )
576
+
577
+ loaded = DiscoveryManager(tmp_path).load(directory, required=True)
578
+
579
+ assert loaded is not None
580
+ assert loaded.questions[0].next_level is None
@@ -892,3 +892,101 @@ def test_devflow_writes_suggested_next_specs_section() -> None:
892
892
  assert "None." in manager.with_next_specs(VALID_SPEC, None).split(
893
893
  "### 10.1"
894
894
  )[1]
895
+
896
+
897
+ def _complete_discovery_then(
898
+ tmp_path: Path,
899
+ spec_phase,
900
+ ) -> tuple[SpecWorkflowResult, FakeAdapter]:
901
+ config = _config(tmp_path)
902
+ adapter = FakeAdapter()
903
+
904
+ def executor(invocation: Invocation) -> InvocationResult:
905
+ assert adapter.run_context is not None
906
+ manager = DiscoveryManager(invocation.cwd)
907
+ directory = adapter.run_context.spec_directory
908
+ if "Discovery Task" in adapter.run_context.prompt:
909
+ document = manager.load(directory, required=True)
910
+ for question in document.pending_questions:
911
+ document = manager.answer(
912
+ document,
913
+ question.id,
914
+ "Use the existing project behavior.",
915
+ )
916
+ manager.write(directory, document)
917
+ else:
918
+ spec_phase(manager, directory, adapter.run_context)
919
+ return InvocationResult(returncode=0, stdout="", stderr="")
920
+
921
+ _run(
922
+ config,
923
+ adapter=adapter,
924
+ executor=executor,
925
+ mode="interactive",
926
+ stop_after_discovery=True,
927
+ )
928
+ result = _run(
929
+ config,
930
+ adapter=adapter,
931
+ executor=executor,
932
+ mode="interactive",
933
+ stop_after_discovery=True,
934
+ description="",
935
+ continue_spec_id="001",
936
+ )
937
+ return result, adapter
938
+
939
+
940
+ def test_spec_agent_resolves_a_missing_decision_in_session(
941
+ tmp_path: Path,
942
+ ) -> None:
943
+ def spec_phase(manager, directory, run_context) -> None:
944
+ document = manager.add_questions(
945
+ document=manager.load(directory, required=True),
946
+ questions=("What happens after registration?",),
947
+ )
948
+ added = document.questions[-1].id
949
+ document = manager.answer(
950
+ document,
951
+ added,
952
+ "Redirect to the login page.",
953
+ )
954
+ manager.write(directory, document)
955
+ run_context.spec_path.write_text(
956
+ VALID_SPEC.replace("{{DISCOVERY_DIGEST}}", "sha256:pending"),
957
+ encoding="utf-8",
958
+ )
959
+
960
+ result, adapter = _complete_discovery_then(tmp_path, spec_phase)
961
+
962
+ assert result.blocked is False
963
+ assert result.spec is not None
964
+ digest = ArtifactStore(tmp_path).digest_file(
965
+ result.directory / "discovery.yaml"
966
+ )
967
+ assert result.discovery_digest == digest
968
+ assert result.discovery is not None
969
+ assert result.discovery.is_complete
970
+ content = result.spec.path.read_text(encoding="utf-8")
971
+ assert f"| Discovery digest | `{digest}` |" in content
972
+ assert adapter.run_context is not None
973
+ assert "If up to 3 decisions are missing" in adapter.run_context.prompt
974
+ assert "Speak to the user" in adapter.run_context.prompt
975
+
976
+
977
+ def test_invalid_discovery_from_spec_agent_blocks_without_fallback(
978
+ tmp_path: Path,
979
+ ) -> None:
980
+ def spec_phase(manager, directory, run_context) -> None:
981
+ (directory / "discovery.yaml").write_text(
982
+ "questions: [unclosed\n",
983
+ encoding="utf-8",
984
+ )
985
+
986
+ result, _ = _complete_discovery_then(tmp_path, spec_phase)
987
+
988
+ assert result.blocked is True
989
+ assert result.spec is None
990
+ assert result.discovery_valid is False
991
+ assert not (result.directory / "spec.md").exists()
992
+ assert any("left discovery.yaml invalid" in w for w in result.warnings)