devflow-toolkit 0.3.28__py3-none-any.whl → 0.4.2__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/commands/spec.py +10 -0
- devflow/commands/status.py +30 -0
- devflow/core/config.py +24 -36
- devflow/core/discovery.py +132 -1
- devflow/core/security_baseline.py +366 -0
- devflow/core/specification.py +86 -1
- devflow/prompts/__init__.py +103 -15
- devflow/prompts/discovery.md +41 -5
- devflow/prompts/spec.md +6 -0
- {devflow_toolkit-0.3.28.dist-info → devflow_toolkit-0.4.2.dist-info}/METADATA +82 -27
- {devflow_toolkit-0.3.28.dist-info → devflow_toolkit-0.4.2.dist-info}/RECORD +14 -13
- {devflow_toolkit-0.3.28.dist-info → devflow_toolkit-0.4.2.dist-info}/WHEEL +0 -0
- {devflow_toolkit-0.3.28.dist-info → devflow_toolkit-0.4.2.dist-info}/entry_points.txt +0 -0
- {devflow_toolkit-0.3.28.dist-info → devflow_toolkit-0.4.2.dist-info}/licenses/LICENSE +0 -0
devflow/commands/spec.py
CHANGED
|
@@ -191,6 +191,16 @@ def _create_specification(
|
|
|
191
191
|
detector = ProjectDetector()
|
|
192
192
|
root = detector.find_root(path)
|
|
193
193
|
config = ConfigManager(root).load()
|
|
194
|
+
if config.discovery.uses_legacy_defaults:
|
|
195
|
+
_print_warnings(
|
|
196
|
+
[
|
|
197
|
+
"Discovery uses the old limits (follow_up 3, maximum 12, "
|
|
198
|
+
"max_rounds 3), which can stop Discovery before every security "
|
|
199
|
+
"control is covered. Set discovery.question_budget.follow_up: 6, "
|
|
200
|
+
"maximum: 20 and discovery.interaction.max_rounds: 5 in "
|
|
201
|
+
".devflow/config.yaml."
|
|
202
|
+
]
|
|
203
|
+
)
|
|
194
204
|
|
|
195
205
|
if resume is not None:
|
|
196
206
|
_ensure_continuable(config, resume)
|
devflow/commands/status.py
CHANGED
|
@@ -20,6 +20,10 @@ from devflow.core.discovery import (
|
|
|
20
20
|
DiscoveryManager,
|
|
21
21
|
)
|
|
22
22
|
from devflow.core.project import ProjectDetector
|
|
23
|
+
from devflow.core.security_baseline import (
|
|
24
|
+
applicable_areas,
|
|
25
|
+
uncovered_controls,
|
|
26
|
+
)
|
|
23
27
|
from devflow.core.state import (
|
|
24
28
|
ChangeLocation,
|
|
25
29
|
ChangeStatus,
|
|
@@ -29,6 +33,7 @@ from devflow.core.state import (
|
|
|
29
33
|
WorkflowStatus,
|
|
30
34
|
artifact_blockers,
|
|
31
35
|
)
|
|
36
|
+
from devflow.prompts import coverage_texts, security_texts
|
|
32
37
|
|
|
33
38
|
console = Console()
|
|
34
39
|
error_console = Console(stderr=True)
|
|
@@ -245,6 +250,31 @@ def _print_discovery(
|
|
|
245
250
|
soft_wrap=True,
|
|
246
251
|
)
|
|
247
252
|
|
|
253
|
+
areas = applicable_areas(security_texts("", discovery))
|
|
254
|
+
if areas:
|
|
255
|
+
console.print(
|
|
256
|
+
" security baseline: "
|
|
257
|
+
+ ", ".join(area.label for area in areas),
|
|
258
|
+
soft_wrap=True,
|
|
259
|
+
)
|
|
260
|
+
missing = uncovered_controls(areas, coverage_texts(discovery))
|
|
261
|
+
if missing:
|
|
262
|
+
console.print(
|
|
263
|
+
" [yellow]level-1 controls not cited by any decision: "
|
|
264
|
+
+ ", ".join(control.asvs_id for control in missing)
|
|
265
|
+
+ "[/yellow]",
|
|
266
|
+
soft_wrap=True,
|
|
267
|
+
)
|
|
268
|
+
for risk in discovery.accepted_risks:
|
|
269
|
+
state = (
|
|
270
|
+
f"accepted by {risk.accepted_by}"
|
|
271
|
+
if risk.is_accepted
|
|
272
|
+
else "pending acceptance"
|
|
273
|
+
)
|
|
274
|
+
console.print(
|
|
275
|
+
f" {risk.id} [security risk] {state}: {risk.risk}",
|
|
276
|
+
soft_wrap=True,
|
|
277
|
+
)
|
|
248
278
|
for note in discovery.notes:
|
|
249
279
|
console.print(f" [yellow]corrected: {note}[/yellow]", soft_wrap=True)
|
|
250
280
|
|
devflow/core/config.py
CHANGED
|
@@ -20,10 +20,11 @@ from devflow.models.project import (
|
|
|
20
20
|
CONFIG_RELATIVE_PATH = Path(".devflow") / "config.yaml"
|
|
21
21
|
DEFAULT_CONSTITUTION_PATH = Path(".devflow") / "constitution"
|
|
22
22
|
DEFAULT_SPECIFICATIONS_PATH = Path(".devflow") / "specs"
|
|
23
|
-
DEFAULT_PLANS_PATH = Path(".devflow") / "plans"
|
|
24
|
-
DEFAULT_TEMPLATES_PATH = Path(".devflow") / "templates"
|
|
25
23
|
DEFAULT_DOCUMENTATION_LANGUAGE = "en"
|
|
26
24
|
MAX_DISCOVERY_BUDGET = 100
|
|
25
|
+
# follow_up, maximum and max_rounds written by `devflow init` before
|
|
26
|
+
# 0.4.1. They were too small once Discovery covered security levels.
|
|
27
|
+
LEGACY_DISCOVERY_LIMITS = (3, 12, 3)
|
|
27
28
|
|
|
28
29
|
_LANGUAGE_ALIASES = {
|
|
29
30
|
"aleman": "de",
|
|
@@ -214,10 +215,19 @@ class DiscoverySettings:
|
|
|
214
215
|
"""Deterministic limits for the Discovery decision loop."""
|
|
215
216
|
|
|
216
217
|
question_budget_initial: int = 6
|
|
217
|
-
question_budget_follow_up: int =
|
|
218
|
-
question_budget_maximum: int =
|
|
219
|
-
max_rounds: int =
|
|
218
|
+
question_budget_follow_up: int = 6
|
|
219
|
+
question_budget_maximum: int = 20
|
|
220
|
+
max_rounds: int = 5
|
|
220
221
|
batch_size: int = 6
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def uses_legacy_defaults(self) -> bool:
|
|
225
|
+
"""Return whether the limits are the pre-0.4.1 defaults."""
|
|
226
|
+
return (
|
|
227
|
+
self.question_budget_follow_up,
|
|
228
|
+
self.question_budget_maximum,
|
|
229
|
+
self.max_rounds,
|
|
230
|
+
) == LEGACY_DISCOVERY_LIMITS
|
|
221
231
|
assumptions_enabled: bool = True
|
|
222
232
|
require_explicit_acceptance: bool = True
|
|
223
233
|
|
|
@@ -235,8 +245,6 @@ class DevFlowConfig:
|
|
|
235
245
|
technologies: dict[str, list[str]]
|
|
236
246
|
constitution: ConstitutionSettings
|
|
237
247
|
specifications_path: Path
|
|
238
|
-
plans_path: Path
|
|
239
|
-
templates_path: Path
|
|
240
248
|
documentation_language: str
|
|
241
249
|
agent: AgentSettings
|
|
242
250
|
discovery: DiscoverySettings = DiscoverySettings()
|
|
@@ -306,11 +314,9 @@ class ConfigManager:
|
|
|
306
314
|
data.get("specifications"),
|
|
307
315
|
"specifications",
|
|
308
316
|
)
|
|
309
|
-
plans
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
"templates",
|
|
313
|
-
)
|
|
317
|
+
# `plans` and `templates` were written by `devflow init` before
|
|
318
|
+
# 0.4.2. Nothing uses them, so older files keep loading and the keys
|
|
319
|
+
# are ignored.
|
|
314
320
|
documentation = self._mapping(
|
|
315
321
|
data.get("documentation", {}),
|
|
316
322
|
"documentation",
|
|
@@ -339,14 +345,6 @@ class ConfigManager:
|
|
|
339
345
|
),
|
|
340
346
|
"specifications.path",
|
|
341
347
|
)
|
|
342
|
-
plans_path = self._relative_path(
|
|
343
|
-
plans.get("path", DEFAULT_PLANS_PATH.as_posix()),
|
|
344
|
-
"plans.path",
|
|
345
|
-
)
|
|
346
|
-
templates_path = self._relative_path(
|
|
347
|
-
templates.get("path", DEFAULT_TEMPLATES_PATH.as_posix()),
|
|
348
|
-
"templates.path",
|
|
349
|
-
)
|
|
350
348
|
|
|
351
349
|
technologies = self._technologies(data.get("technologies", {}))
|
|
352
350
|
|
|
@@ -405,8 +403,6 @@ class ConfigManager:
|
|
|
405
403
|
),
|
|
406
404
|
),
|
|
407
405
|
specifications_path=specifications_path,
|
|
408
|
-
plans_path=plans_path,
|
|
409
|
-
templates_path=templates_path,
|
|
410
406
|
documentation_language=documentation_language,
|
|
411
407
|
agent=agent_settings,
|
|
412
408
|
discovery=discovery_settings,
|
|
@@ -478,24 +474,18 @@ class ConfigManager:
|
|
|
478
474
|
"specifications": {
|
|
479
475
|
"path": DEFAULT_SPECIFICATIONS_PATH.as_posix(),
|
|
480
476
|
},
|
|
481
|
-
"plans": {
|
|
482
|
-
"path": DEFAULT_PLANS_PATH.as_posix(),
|
|
483
|
-
},
|
|
484
|
-
"templates": {
|
|
485
|
-
"path": DEFAULT_TEMPLATES_PATH.as_posix(),
|
|
486
|
-
},
|
|
487
477
|
"documentation": {
|
|
488
478
|
"language": language,
|
|
489
479
|
},
|
|
490
480
|
"discovery": {
|
|
491
481
|
"question_budget": {
|
|
492
482
|
"initial": 6,
|
|
493
|
-
"follow_up":
|
|
494
|
-
"maximum":
|
|
483
|
+
"follow_up": 6,
|
|
484
|
+
"maximum": 20,
|
|
495
485
|
},
|
|
496
486
|
"interaction": {
|
|
497
487
|
"batch_size": 6,
|
|
498
|
-
"max_rounds":
|
|
488
|
+
"max_rounds": 5,
|
|
499
489
|
},
|
|
500
490
|
"assumptions": {
|
|
501
491
|
"enabled": True,
|
|
@@ -646,8 +636,6 @@ class ConfigManager:
|
|
|
646
636
|
for path in (
|
|
647
637
|
config.constitution.path,
|
|
648
638
|
config.specifications_path,
|
|
649
|
-
config.plans_path,
|
|
650
|
-
config.templates_path,
|
|
651
639
|
):
|
|
652
640
|
resolved = path.resolve()
|
|
653
641
|
try:
|
|
@@ -782,13 +770,13 @@ class ConfigManager:
|
|
|
782
770
|
maximum=100,
|
|
783
771
|
)
|
|
784
772
|
follow_up = self._bounded_integer(
|
|
785
|
-
budget.get("follow_up",
|
|
773
|
+
budget.get("follow_up", 6),
|
|
786
774
|
"discovery.question_budget.follow_up",
|
|
787
775
|
minimum=0,
|
|
788
776
|
maximum=100,
|
|
789
777
|
)
|
|
790
778
|
maximum = self._bounded_integer(
|
|
791
|
-
budget.get("maximum",
|
|
779
|
+
budget.get("maximum", 20),
|
|
792
780
|
"discovery.question_budget.maximum",
|
|
793
781
|
minimum=0,
|
|
794
782
|
maximum=MAX_DISCOVERY_BUDGET,
|
|
@@ -810,7 +798,7 @@ class ConfigManager:
|
|
|
810
798
|
question_budget_follow_up=follow_up,
|
|
811
799
|
question_budget_maximum=maximum,
|
|
812
800
|
max_rounds=self._bounded_integer(
|
|
813
|
-
interaction.get("max_rounds",
|
|
801
|
+
interaction.get("max_rounds", 5),
|
|
814
802
|
"discovery.interaction.max_rounds",
|
|
815
803
|
minimum=1,
|
|
816
804
|
maximum=20,
|
devflow/core/discovery.py
CHANGED
|
@@ -157,6 +157,7 @@ ASSUMPTION_SOURCES = ("agent_default", "human", "existing_convention")
|
|
|
157
157
|
_QUESTION_ID = re.compile(r"^Q\d{1,3}$")
|
|
158
158
|
_RECOMMENDED = re.compile(r"recom+end", re.IGNORECASE)
|
|
159
159
|
_ASSUMPTION_ID = re.compile(r"^A\d{1,3}$")
|
|
160
|
+
_RISK_ID = re.compile(r"^R\d{1,3}$")
|
|
160
161
|
|
|
161
162
|
_STOPWORDS = {
|
|
162
163
|
"a",
|
|
@@ -714,6 +715,41 @@ class DiscoveryAssumption:
|
|
|
714
715
|
}
|
|
715
716
|
|
|
716
717
|
|
|
718
|
+
@dataclass(frozen=True)
|
|
719
|
+
class AcceptedRisk:
|
|
720
|
+
"""A security control the user explicitly decided not to apply now."""
|
|
721
|
+
|
|
722
|
+
id: str
|
|
723
|
+
risk: str
|
|
724
|
+
reason: str
|
|
725
|
+
control: str | None = None
|
|
726
|
+
status: str = ASSUMPTION_PENDING
|
|
727
|
+
accepted_by: str | None = None
|
|
728
|
+
accepted_at: str | None = None
|
|
729
|
+
review_by: str | None = None
|
|
730
|
+
|
|
731
|
+
@property
|
|
732
|
+
def is_accepted(self) -> bool:
|
|
733
|
+
return self.status == ASSUMPTION_ACCEPTED
|
|
734
|
+
|
|
735
|
+
def to_dict(self) -> dict[str, Any]:
|
|
736
|
+
data: dict[str, Any] = {"id": self.id}
|
|
737
|
+
if self.control:
|
|
738
|
+
data["control"] = self.control
|
|
739
|
+
data.update(
|
|
740
|
+
{
|
|
741
|
+
"risk": self.risk,
|
|
742
|
+
"reason": self.reason,
|
|
743
|
+
"status": self.status,
|
|
744
|
+
"accepted_by": self.accepted_by,
|
|
745
|
+
"accepted_at": self.accepted_at,
|
|
746
|
+
}
|
|
747
|
+
)
|
|
748
|
+
if self.review_by:
|
|
749
|
+
data["review_by"] = self.review_by
|
|
750
|
+
return data
|
|
751
|
+
|
|
752
|
+
|
|
717
753
|
@dataclass(frozen=True)
|
|
718
754
|
class DiscoveryDocument:
|
|
719
755
|
"""Persistent discovery record for one change."""
|
|
@@ -729,6 +765,7 @@ class DiscoveryDocument:
|
|
|
729
765
|
questions: tuple[DiscoveryQuestion, ...] = ()
|
|
730
766
|
assumptions: tuple[DiscoveryAssumption, ...] = ()
|
|
731
767
|
deferred: tuple[DeferredItem, ...] = ()
|
|
768
|
+
accepted_risks: tuple[AcceptedRisk, ...] = ()
|
|
732
769
|
# Minor problems DevFlow corrected while reading the record. They are
|
|
733
770
|
# reported to the user and never written back by themselves.
|
|
734
771
|
notes: tuple[str, ...] = ()
|
|
@@ -800,9 +837,20 @@ class DiscoveryDocument:
|
|
|
800
837
|
if not assumption.is_accepted
|
|
801
838
|
)
|
|
802
839
|
|
|
840
|
+
@property
|
|
841
|
+
def pending_risks(self) -> tuple[AcceptedRisk, ...]:
|
|
842
|
+
"""Return risks that still need explicit acceptance by a person."""
|
|
843
|
+
return tuple(
|
|
844
|
+
risk for risk in self.accepted_risks if not risk.is_accepted
|
|
845
|
+
)
|
|
846
|
+
|
|
803
847
|
@property
|
|
804
848
|
def derived_status(self) -> str:
|
|
805
|
-
if
|
|
849
|
+
if (
|
|
850
|
+
self.pending_questions
|
|
851
|
+
or self.pending_assumptions
|
|
852
|
+
or self.pending_risks
|
|
853
|
+
):
|
|
806
854
|
return DISCOVERY_AWAITING
|
|
807
855
|
if self.status == DISCOVERY_PENDING:
|
|
808
856
|
return DISCOVERY_PENDING
|
|
@@ -834,6 +882,11 @@ class DiscoveryDocument:
|
|
|
834
882
|
f"{assumption.id}: proposed assumption requires acceptance: "
|
|
835
883
|
f"{assumption.value}"
|
|
836
884
|
)
|
|
885
|
+
for risk in self.pending_risks:
|
|
886
|
+
messages.append(
|
|
887
|
+
f"{risk.id}: security risk requires explicit acceptance: "
|
|
888
|
+
f"{risk.risk}"
|
|
889
|
+
)
|
|
837
890
|
if not messages and self.status == DISCOVERY_PENDING:
|
|
838
891
|
messages.append("Discovery has not been completed.")
|
|
839
892
|
return tuple(messages)
|
|
@@ -898,6 +951,15 @@ class DiscoveryDocument:
|
|
|
898
951
|
if self.deferred
|
|
899
952
|
else {}
|
|
900
953
|
),
|
|
954
|
+
**(
|
|
955
|
+
{
|
|
956
|
+
"accepted_risks": [
|
|
957
|
+
risk.to_dict() for risk in self.accepted_risks
|
|
958
|
+
]
|
|
959
|
+
}
|
|
960
|
+
if self.accepted_risks
|
|
961
|
+
else {}
|
|
962
|
+
),
|
|
901
963
|
}
|
|
902
964
|
|
|
903
965
|
|
|
@@ -1279,6 +1341,17 @@ class DiscoveryManager:
|
|
|
1279
1341
|
self._deferred(item, index, question_ids)
|
|
1280
1342
|
for index, item in enumerate(deferred_data, start=1)
|
|
1281
1343
|
)
|
|
1344
|
+
risks_data = _list(mapping.get("accepted_risks"), "accepted_risks")
|
|
1345
|
+
if len(risks_data) > MAX_ASSUMPTIONS:
|
|
1346
|
+
msg = f"At most {MAX_ASSUMPTIONS} accepted risks are allowed."
|
|
1347
|
+
raise DiscoveryError(msg)
|
|
1348
|
+
accepted_risks = tuple(
|
|
1349
|
+
self._risk(item, index, notes=notes, default_time=updated_at)
|
|
1350
|
+
for index, item in enumerate(risks_data, start=1)
|
|
1351
|
+
)
|
|
1352
|
+
if len({risk.id for risk in accepted_risks}) != len(accepted_risks):
|
|
1353
|
+
msg = "Accepted risk ids must be unique."
|
|
1354
|
+
raise DiscoveryError(msg)
|
|
1282
1355
|
|
|
1283
1356
|
document = DiscoveryDocument(
|
|
1284
1357
|
version=version,
|
|
@@ -1292,6 +1365,7 @@ class DiscoveryManager:
|
|
|
1292
1365
|
questions=questions,
|
|
1293
1366
|
assumptions=assumptions,
|
|
1294
1367
|
deferred=deferred,
|
|
1368
|
+
accepted_risks=accepted_risks,
|
|
1295
1369
|
notes=tuple(notes),
|
|
1296
1370
|
)
|
|
1297
1371
|
return document
|
|
@@ -1498,6 +1572,63 @@ class DiscoveryManager:
|
|
|
1498
1572
|
next_level=next_level,
|
|
1499
1573
|
)
|
|
1500
1574
|
|
|
1575
|
+
def _risk(
|
|
1576
|
+
self,
|
|
1577
|
+
data: object,
|
|
1578
|
+
index: int,
|
|
1579
|
+
*,
|
|
1580
|
+
notes: list[str],
|
|
1581
|
+
default_time: str,
|
|
1582
|
+
) -> AcceptedRisk:
|
|
1583
|
+
mapping = _mapping(data, f"accepted_risks[{index}]")
|
|
1584
|
+
identifier = _text(mapping.get("id"), "accepted risk id")
|
|
1585
|
+
if not _RISK_ID.fullmatch(identifier):
|
|
1586
|
+
msg = f"Invalid accepted risk id: {identifier!r}"
|
|
1587
|
+
raise DiscoveryError(msg)
|
|
1588
|
+
status = _text(mapping.get("status"), f"{identifier}.status")
|
|
1589
|
+
if status not in ASSUMPTION_STATUSES:
|
|
1590
|
+
notes.append(
|
|
1591
|
+
f"{identifier}: unknown status {status!r} read as "
|
|
1592
|
+
f"{ASSUMPTION_PENDING!r}."
|
|
1593
|
+
)
|
|
1594
|
+
status = ASSUMPTION_PENDING
|
|
1595
|
+
accepted_by = _optional_text(
|
|
1596
|
+
mapping.get("accepted_by"),
|
|
1597
|
+
f"{identifier}.accepted_by",
|
|
1598
|
+
)
|
|
1599
|
+
accepted_at = _optional_text(
|
|
1600
|
+
mapping.get("accepted_at"),
|
|
1601
|
+
f"{identifier}.accepted_at",
|
|
1602
|
+
)
|
|
1603
|
+
if status == ASSUMPTION_ACCEPTED:
|
|
1604
|
+
if not accepted_by:
|
|
1605
|
+
accepted_by = "user"
|
|
1606
|
+
notes.append(f"{identifier}: missing accepted_by read as user.")
|
|
1607
|
+
if not accepted_at:
|
|
1608
|
+
accepted_at = default_time
|
|
1609
|
+
notes.append(
|
|
1610
|
+
f"{identifier}: missing accepted_at read as {default_time}."
|
|
1611
|
+
)
|
|
1612
|
+
else:
|
|
1613
|
+
accepted_by = None
|
|
1614
|
+
accepted_at = None
|
|
1615
|
+
return AcceptedRisk(
|
|
1616
|
+
id=identifier,
|
|
1617
|
+
control=_optional_text(
|
|
1618
|
+
mapping.get("control"),
|
|
1619
|
+
f"{identifier}.control",
|
|
1620
|
+
),
|
|
1621
|
+
risk=_limited_text(mapping.get("risk"), f"{identifier}.risk"),
|
|
1622
|
+
reason=_limited_text(mapping.get("reason"), f"{identifier}.reason"),
|
|
1623
|
+
status=status,
|
|
1624
|
+
accepted_by=accepted_by,
|
|
1625
|
+
accepted_at=accepted_at,
|
|
1626
|
+
review_by=_optional_text(
|
|
1627
|
+
mapping.get("review_by"),
|
|
1628
|
+
f"{identifier}.review_by",
|
|
1629
|
+
),
|
|
1630
|
+
)
|
|
1631
|
+
|
|
1501
1632
|
def _deferred(
|
|
1502
1633
|
self,
|
|
1503
1634
|
data: object,
|