devflow-toolkit 0.3.3__py3-none-any.whl → 0.3.5__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
@@ -35,7 +35,7 @@ def version() -> None:
35
35
  try:
36
36
  current_version = package_version("devflow-toolkit")
37
37
  except PackageNotFoundError:
38
- current_version = "0.3.3"
38
+ current_version = "0.3.5"
39
39
  console.print(f"DevFlow v{current_version}")
40
40
 
41
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.3. "
60
+ f"Stage '{stage}' is not available in DevFlow 0.3.5. "
61
61
  "Only the 'spec' stage can be approved."
62
62
  )
63
63
  raise UnsupportedStageError(msg)
@@ -38,16 +38,38 @@ def resolve_harness(
38
38
  *,
39
39
  allow_prompt: bool,
40
40
  require_installed: bool,
41
+ force_prompt: bool = False,
41
42
  ) -> tuple[str | None, list[str]]:
42
- """Resolve ``auto`` and verify that concrete harnesses exist."""
43
+ """Resolve ``auto`` and verify that concrete harnesses exist.
44
+
45
+ When ``force_prompt`` is true and the terminal is interactive, the
46
+ user is asked to choose a harness even if one is already configured.
47
+ """
43
48
  canonical = validate_harness_name(requested)
44
49
  if canonical == "none":
45
50
  return None, []
46
51
 
52
+ detected = detect_harnesses()
53
+ if force_prompt and allow_prompt:
54
+ names = [harness.name for harness in detected]
55
+ if not names:
56
+ return None, [
57
+ "No supported agent harness was found on PATH. DevFlow will use "
58
+ "deterministic static analysis.",
59
+ ]
60
+ default = canonical if canonical in names else names[0]
61
+ chosen = _prompt_for_harness(
62
+ names,
63
+ default=default,
64
+ include_none=True,
65
+ )
66
+ if chosen is None or chosen == "none":
67
+ return None, []
68
+ return chosen, []
69
+
47
70
  if canonical != "auto" and not require_installed:
48
71
  return canonical, []
49
72
 
50
- detected = detect_harnesses()
51
73
  prompt = _prompt_for_harness if allow_prompt else None
52
74
  selection = select_harness(canonical, detected, prompt=prompt)
53
75
  return selection.harness, list(selection.warnings)
@@ -82,17 +104,29 @@ def print_setup_result(
82
104
  console.print(f"[yellow]Warning:[/yellow] {warning}")
83
105
 
84
106
 
85
- def _prompt_for_harness(names: list[str]) -> str | None:
107
+ def _prompt_for_harness(
108
+ names: list[str],
109
+ *,
110
+ default: str | None = None,
111
+ include_none: bool = False,
112
+ ) -> str | None:
86
113
  if not sys.stdin.isatty():
87
114
  return None
88
- typer.echo("Multiple agent harnesses are installed:")
115
+ choices = [*names]
116
+ if include_none:
117
+ choices.append("none")
118
+ typer.echo("Available agent harnesses:")
89
119
  for name in names:
90
- typer.echo(f" - {name}")
120
+ suffix = " (configured)" if name == default else ""
121
+ typer.echo(f" - {name}{suffix}")
122
+ if include_none:
123
+ typer.echo(" - none (deterministic static analysis)")
91
124
  while True:
92
125
  answer = typer.prompt(
93
- "Agent harness (" + "/".join(names) + ")",
126
+ "Agent harness (" + "/".join(choices) + ")",
127
+ default=default or "",
94
128
  )
95
129
  canonical = canonical_harness_name(answer)
96
- if canonical in names:
130
+ if canonical in choices:
97
131
  return canonical
98
- typer.echo(f"Choose one of: {', '.join(names)}")
132
+ typer.echo(f"Choose one of: {', '.join(choices)}")
devflow/commands/spec.py CHANGED
@@ -188,6 +188,7 @@ def _create_specification(
188
188
  requested_harness = validate_harness_name(
189
189
  "none" if no_agent else (harness or config.agent_harness)
190
190
  )
191
+ explicit_harness = no_agent or harness is not None
191
192
  execution_mode, mode_warnings = _execution_mode(
192
193
  mode or config.execution_mode,
193
194
  )
@@ -208,6 +209,7 @@ def _create_specification(
208
209
  requested_harness,
209
210
  allow_prompt=allow_prompt,
210
211
  require_installed=True,
212
+ force_prompt=not explicit_harness,
211
213
  )
212
214
  adapter = adapter_for(selected_harness) if selected_harness else None
213
215
 
@@ -245,7 +247,7 @@ def _create_specification(
245
247
  if result.discovery is not None:
246
248
  console.print(
247
249
  f"[bold]Discovery:[/bold] {result.discovery.status} "
248
- f"({len(result.discovery.pending_blocking)} blocking, "
250
+ f"({len(result.discovery.pending_questions)} pending, "
249
251
  f"{len(result.discovery.pending_assumptions)} assumptions)"
250
252
  )
251
253
  if result.discovery_digest:
@@ -568,6 +570,6 @@ def _print_result(
568
570
  f"[bold]Discovery:[/bold] {result.discovery.status}"
569
571
  )
570
572
  console.print(
571
- "\nNext: review the specification, resolve any remaining "
572
- "non-blocking questions, and approve it before implementation."
573
+ "\nNext: review the specification and approve it before "
574
+ "implementation."
573
575
  )
@@ -128,6 +128,7 @@ def _print_discovery(
128
128
  return
129
129
  console.print(
130
130
  f" status: {discovery.status} · "
131
+ f"{len(discovery.pending_questions)} pending · "
131
132
  f"{len(discovery.pending_blocking)} blocking · "
132
133
  f"{len(discovery.pending_assumptions)} assumptions"
133
134
  )
devflow/core/discovery.py CHANGED
@@ -3,7 +3,7 @@
3
3
  Discovery is deliberately separate from specification. It records the
4
4
  questions that change scope, the answers supplied by a human, and the
5
5
  technical assumptions proposed by DevFlow. A specification may only be
6
- generated when every blocking question is answered and every proposed
6
+ generated when every question is answered and every proposed
7
7
  assumption has been explicitly accepted.
8
8
  """
9
9
 
@@ -232,6 +232,79 @@ _COMMENT_DECISION_WORDS = {
232
232
  "usuario",
233
233
  "user",
234
234
  }
235
+ _COMMENT_AUTHOR_WORDS = {
236
+ "author",
237
+ "autor",
238
+ "autora",
239
+ "escritor",
240
+ "writer",
241
+ }
242
+ _COMMENT_EDIT_WORDS = {
243
+ "actualizar",
244
+ "borrar",
245
+ "crud",
246
+ "delete",
247
+ "editar",
248
+ "edit",
249
+ "eliminar",
250
+ "update",
251
+ }
252
+ _COMMENT_MODERATION_WORDS = {
253
+ "approve",
254
+ "aprobar",
255
+ "moderacion",
256
+ "moderar",
257
+ "moderation",
258
+ "moderator",
259
+ "review",
260
+ "revision",
261
+ "revisar",
262
+ }
263
+ _COMMENT_VALIDATION_WORDS = {
264
+ "length",
265
+ "longitud",
266
+ "sanitize",
267
+ "sanitizar",
268
+ "validacion",
269
+ "validate",
270
+ "validation",
271
+ }
272
+ _COMMENT_ORDER_WORDS = {
273
+ "latest",
274
+ "order",
275
+ "orden",
276
+ "ordenar",
277
+ "pagination",
278
+ "paginacion",
279
+ "recent",
280
+ "sort",
281
+ }
282
+ _COMMENT_LIFECYCLE_WORDS = {
283
+ "anonymize",
284
+ "anonimizar",
285
+ "cascade",
286
+ "cascada",
287
+ "lifecycle",
288
+ "soft",
289
+ }
290
+ _COMMENT_ADMIN_WORDS = {"admin", "administracion"}
291
+ _COMMENT_COMPATIBILITY_WORDS = {
292
+ "backward",
293
+ "compatibilidad",
294
+ "compatibility",
295
+ "legacy",
296
+ "retrocompatible",
297
+ }
298
+ _AUTH_MECHANISM_WORDS = {
299
+ "allauth",
300
+ "cookie",
301
+ "jwt",
302
+ "login",
303
+ "oauth",
304
+ "session",
305
+ "sesion",
306
+ "token",
307
+ }
235
308
  _PERSISTENCE_DECISIONS = {
236
309
  "archivo",
237
310
  "database",
@@ -408,6 +481,14 @@ class DiscoveryDocument:
408
481
  if question.blocking and not question.is_answered
409
482
  )
410
483
 
484
+ @property
485
+ def pending_questions(self) -> tuple[DiscoveryQuestion, ...]:
486
+ return tuple(
487
+ question
488
+ for question in self.questions
489
+ if not question.is_answered
490
+ )
491
+
411
492
  @property
412
493
  def pending_assumptions(
413
494
  self,
@@ -420,7 +501,7 @@ class DiscoveryDocument:
420
501
 
421
502
  @property
422
503
  def derived_status(self) -> str:
423
- if self.pending_blocking or self.pending_assumptions:
504
+ if self.pending_questions or self.pending_assumptions:
424
505
  return DISCOVERY_AWAITING
425
506
  if self.status == DISCOVERY_PENDING:
426
507
  return DISCOVERY_PENDING
@@ -432,7 +513,7 @@ class DiscoveryDocument:
432
513
 
433
514
  def blockers(self) -> tuple[str, ...]:
434
515
  messages: list[str] = []
435
- for question in self.pending_blocking:
516
+ for question in self.pending_questions:
436
517
  messages.append(f"{question.id}: {question.question}")
437
518
  for assumption in self.pending_assumptions:
438
519
  messages.append(
@@ -544,13 +625,13 @@ class DiscoveryManager:
544
625
  if (
545
626
  document.status == DISCOVERY_COMPLETE
546
627
  and (
547
- document.pending_blocking
628
+ document.pending_questions
548
629
  or document.pending_assumptions
549
630
  )
550
631
  ):
551
632
  msg = (
552
633
  "Discovery is marked complete but still has pending "
553
- "blocking questions or assumptions."
634
+ "questions or assumptions."
554
635
  )
555
636
  raise DiscoveryError(msg)
556
637
  return replace(document, status=document.derived_status)
@@ -618,6 +699,69 @@ class DiscoveryManager:
618
699
  )
619
700
  return replace(updated, status=updated.derived_status)
620
701
 
702
+ def add_questions(
703
+ self,
704
+ document: DiscoveryDocument,
705
+ questions: tuple[str, ...] | list[str],
706
+ *,
707
+ category: str = "functional_scope",
708
+ reason: str = (
709
+ "The specification agent found a decision that must be recorded "
710
+ "during Discovery."
711
+ ),
712
+ blocking: bool = True,
713
+ at: str | None = None,
714
+ ) -> DiscoveryDocument:
715
+ """Append unresolved specification questions to Discovery.
716
+
717
+ New questions receive the next ``Qn`` identifiers. Duplicate
718
+ question text is ignored. The document is marked awaiting
719
+ clarification until every added question is answered.
720
+ """
721
+ if category not in QUESTION_CATEGORIES:
722
+ msg = f"Invalid discovery question category: {category!r}"
723
+ raise DiscoveryError(msg)
724
+ timestamp = at or format_timestamp(self.clock.now())
725
+ next_number = 1
726
+ for question in document.questions:
727
+ match = re.match(r"^Q(\d+)$", question.id)
728
+ if match:
729
+ next_number = max(next_number, int(match.group(1)) + 1)
730
+
731
+ known = {
732
+ question.question.strip().casefold()
733
+ for question in document.questions
734
+ }
735
+ additions: list[DiscoveryQuestion] = []
736
+ for value in questions:
737
+ text = value.strip()
738
+ if not text:
739
+ continue
740
+ if len(text) > MAX_TEXT_LENGTH:
741
+ text = text[:MAX_TEXT_LENGTH].rstrip()
742
+ if text.casefold() in known:
743
+ continue
744
+ known.add(text.casefold())
745
+ additions.append(
746
+ DiscoveryQuestion(
747
+ id=f"Q{next_number}",
748
+ category=category,
749
+ question=text,
750
+ reason=reason,
751
+ blocking=blocking,
752
+ )
753
+ )
754
+ next_number += 1
755
+
756
+ if not additions:
757
+ return document
758
+ updated = replace(
759
+ document,
760
+ questions=tuple([*document.questions, *additions]),
761
+ updated_at=timestamp,
762
+ )
763
+ return replace(updated, status=updated.derived_status)
764
+
621
765
  def accept(
622
766
  self,
623
767
  document: DiscoveryDocument,
@@ -758,13 +902,13 @@ class DiscoveryManager:
758
902
  if (
759
903
  document.status == DISCOVERY_COMPLETE
760
904
  and (
761
- document.pending_blocking
905
+ document.pending_questions
762
906
  or document.pending_assumptions
763
907
  )
764
908
  ):
765
909
  msg = (
766
910
  "Discovery is marked complete but still has pending "
767
- "blocking questions or assumptions."
911
+ "questions or assumptions."
768
912
  )
769
913
  raise DiscoveryError(msg)
770
914
  return document
@@ -1103,24 +1247,171 @@ class DiscoveryPlanner:
1103
1247
  )
1104
1248
  )
1105
1249
 
1106
- if (
1107
- words & _COMMENT_WORDS
1108
- and not (words & _COMMENT_DECISION_WORDS)
1109
- ):
1110
- add_question(
1111
- "security_authentication",
1112
- "Who may create, edit or delete comments, and how are they "
1113
- "identified?",
1114
- "Comment ownership, authentication and moderation change "
1115
- "permissions, data fields and API behavior.",
1116
- (
1117
- "Any visitor may comment without authentication.",
1118
- "Only authenticated users may comment.",
1119
- "Only authenticated users may comment, edit or delete their "
1120
- "own comments.",
1121
- "Comments require review before publication.",
1122
- ),
1123
- )
1250
+ if words & _COMMENT_WORDS:
1251
+ if words & _COMMENT_AUTHOR_WORDS:
1252
+ add_question(
1253
+ "functional_scope",
1254
+ "What does 'comments by the book author' mean here: comments "
1255
+ "written by users about a book and its author, or comments "
1256
+ "written by the book's author? Which entity does a comment "
1257
+ "belong to?",
1258
+ "The interpretation changes the actors, the data model and "
1259
+ "the permissions of the feature.",
1260
+ (
1261
+ "Users comment on a book; the author is only the subject.",
1262
+ "The book's author writes comments on their own book.",
1263
+ "Other (describe the intended meaning).",
1264
+ ),
1265
+ )
1266
+
1267
+ if not (words & _COMMENT_DECISION_WORDS):
1268
+ add_question(
1269
+ "security_authentication",
1270
+ "Who may create, edit or delete comments, and which "
1271
+ "authentication mechanism identifies them (session login, "
1272
+ "API token, other)?",
1273
+ "Comment ownership, authentication and moderation change "
1274
+ "permissions, data fields and API behavior.",
1275
+ (
1276
+ "Any visitor may comment without authentication.",
1277
+ "Only authenticated users may comment.",
1278
+ "Only authenticated users may comment, edit or delete their "
1279
+ "own comments.",
1280
+ "Comments require review before publication.",
1281
+ ),
1282
+ )
1283
+ elif not (words & _AUTH_MECHANISM_WORDS):
1284
+ add_question(
1285
+ "security_authentication",
1286
+ "Which authentication mechanism must a user use before "
1287
+ "commenting (session login, API token, OAuth, other)?",
1288
+ "The authentication method changes routes, dependencies, "
1289
+ "session handling and security tests.",
1290
+ (
1291
+ "Reuse the existing session login.",
1292
+ "Use API tokens for a JSON API.",
1293
+ "Use an external identity provider.",
1294
+ "Other (describe).",
1295
+ ),
1296
+ )
1297
+
1298
+ if not (words & _COMMENT_EDIT_WORDS):
1299
+ add_question(
1300
+ "user_behavior",
1301
+ "May users edit or delete their own comments after creating "
1302
+ "them? May administrators or moderators delete any comment?",
1303
+ "Edit and delete rules change permissions, auditing, "
1304
+ "endpoints and acceptance criteria.",
1305
+ (
1306
+ "No editing or deletion after creation.",
1307
+ "Users may edit and delete only their own comments.",
1308
+ "Users may edit their own comments; administrators may "
1309
+ "delete any comment.",
1310
+ ),
1311
+ )
1312
+
1313
+ if not (words & _COMMENT_MODERATION_WORDS):
1314
+ add_question(
1315
+ "user_behavior",
1316
+ "Are comments published immediately, or do they require "
1317
+ "moderation or review before they are visible?",
1318
+ "Moderation changes visibility, status fields, permissions "
1319
+ "and the user-visible workflow.",
1320
+ (
1321
+ "Publish immediately.",
1322
+ "Hold every comment for moderation.",
1323
+ "Only hold comments that match a risk rule.",
1324
+ ),
1325
+ )
1326
+
1327
+ if not (words & _COMMENT_VALIDATION_WORDS):
1328
+ add_question(
1329
+ "user_behavior",
1330
+ "What validation applies to comment text: required non-empty "
1331
+ "content, minimum or maximum length, and sanitization?",
1332
+ "Validation rules change storage limits, error handling and "
1333
+ "security tests.",
1334
+ (
1335
+ "Only reject empty comments.",
1336
+ "Set a maximum length and reject empty comments.",
1337
+ "Other (describe the limits).",
1338
+ ),
1339
+ )
1340
+
1341
+ if not (words & _COMMENT_ORDER_WORDS):
1342
+ add_question(
1343
+ "functional_scope",
1344
+ "In what order should comments be displayed, and should all "
1345
+ "comments be shown or only a limited page?",
1346
+ "Ordering and pagination change the query, API contract and "
1347
+ "user-visible behavior.",
1348
+ (
1349
+ "Newest first, show all comments.",
1350
+ "Oldest first, show all comments.",
1351
+ "Newest first with pagination.",
1352
+ ),
1353
+ )
1354
+
1355
+ if not (words & _COMMENT_LIFECYCLE_WORDS):
1356
+ add_question(
1357
+ "data_persistence",
1358
+ "What should happen to comments when the related book or the "
1359
+ "commenting user is deleted: cascade delete, anonymize, or "
1360
+ "prevent deletion?",
1361
+ "Data lifecycle rules change foreign keys, migrations and "
1362
+ "retention behavior.",
1363
+ (
1364
+ "Delete comments in cascade.",
1365
+ "Anonymize comments and keep them.",
1366
+ "Prevent deleting a book or user that has comments.",
1367
+ ),
1368
+ )
1369
+
1370
+ if not (words & _COMMENT_ADMIN_WORDS):
1371
+ add_question(
1372
+ "functional_scope",
1373
+ "Should the new comment model be registered in the admin "
1374
+ "site, and which list, search or filter fields are required?",
1375
+ "Admin registration changes the operability of the feature "
1376
+ "and the fields that must be searchable.",
1377
+ (
1378
+ "Register comments in the admin with basic list fields.",
1379
+ "Register comments with search and filters.",
1380
+ "Do not register comments in the admin.",
1381
+ ),
1382
+ )
1383
+
1384
+ if not (words & _COMMENT_COMPATIBILITY_WORDS):
1385
+ add_question(
1386
+ "user_behavior",
1387
+ "Are there backward-compatibility requirements for existing "
1388
+ "data, models, URLs, templates or API clients?",
1389
+ "Compatibility constraints change migrations, routing and "
1390
+ "the allowed scope of the change.",
1391
+ (
1392
+ "Keep existing models, URLs and template behavior unchanged.",
1393
+ "Migrations may change existing behavior.",
1394
+ "Other (describe the compatibility rules).",
1395
+ ),
1396
+ )
1397
+
1398
+ if not _has_phrase(
1399
+ text,
1400
+ {"out of scope", "fuera de alcance", "out-of-scope"},
1401
+ ):
1402
+ add_question(
1403
+ "functional_scope",
1404
+ "What is explicitly out of scope for this comment feature "
1405
+ "(for example editing, moderation, ratings, notifications or "
1406
+ "an external API)?",
1407
+ "An explicit exclusion prevents the specification from "
1408
+ "silently expanding the change.",
1409
+ (
1410
+ "Only create and list comments.",
1411
+ "Include editing and deleting own comments.",
1412
+ "Other (describe the exclusions).",
1413
+ ),
1414
+ )
1124
1415
 
1125
1416
  if (
1126
1417
  words & _DATA_WORDS
@@ -1206,7 +1497,7 @@ class DiscoveryPlanner:
1206
1497
  ),
1207
1498
  )
1208
1499
 
1209
- questions = questions[:4]
1500
+ questions = questions[:10]
1210
1501
  question_ids = {question.id for question in questions}
1211
1502
  assumptions = [
1212
1503
  assumption