devflow-toolkit 0.3.14__py3-none-any.whl → 0.3.16__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.
@@ -0,0 +1,284 @@
1
+ """Google Antigravity (``agy``) harness adapter."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ import yaml
10
+
11
+ from devflow.adapters.base import (
12
+ FileChange,
13
+ HarnessAdapter,
14
+ Invocation,
15
+ RunContext,
16
+ SetupContext,
17
+ SetupResult,
18
+ )
19
+ from devflow.adapters.instructions import (
20
+ MANAGED_MARKER,
21
+ render_agent_instructions,
22
+ write_gitignore_entries,
23
+ write_text_managed,
24
+ )
25
+
26
+ INTERACTIVE_AGENT = "devflow-spec"
27
+ READONLY_AGENT = "devflow-spec-readonly"
28
+
29
+ _READ_TOOLS = ["read_file"]
30
+ _WRITE_TOOLS = ["write_file"]
31
+ _QUESTION_TOOLS = ["ask_question"]
32
+
33
+
34
+ class AntigravityAdapter(HarnessAdapter):
35
+ """Generate Antigravity custom agents and invoke ``agy``."""
36
+
37
+ name = "antigravity"
38
+ display_name = "Antigravity"
39
+ executable = "agy"
40
+
41
+ def setup(self, context: SetupContext) -> SetupResult:
42
+ changes: list[FileChange] = []
43
+ warnings: list[str] = []
44
+ ignored: list[str] = []
45
+
46
+ instructions = render_agent_instructions(
47
+ project=context.project,
48
+ profiles=list(context.profiles),
49
+ constitution_files=list(context.constitution_files),
50
+ config=context.config,
51
+ )
52
+ result = write_text_managed(
53
+ context.root / "AGENTS.md",
54
+ instructions,
55
+ root=context.root,
56
+ )
57
+ changes.append(FileChange(path=result.path, status=result.status))
58
+ if result.status != "skipped":
59
+ ignored.append("AGENTS.md")
60
+ else:
61
+ warnings.append(
62
+ "AGENTS.md contains unmanaged content and was left untouched."
63
+ )
64
+
65
+ agents_directory = context.root / ".agents" / "agents"
66
+ interactive = write_text_managed(
67
+ agents_directory / f"{INTERACTIVE_AGENT}.md",
68
+ self._render_agent(
69
+ name=INTERACTIVE_AGENT,
70
+ description=(
71
+ "DevFlow specification agent. Reads the project, asks "
72
+ "clarifying questions and writes only DevFlow specs."
73
+ ),
74
+ context=context,
75
+ interactive=True,
76
+ ),
77
+ root=context.root,
78
+ )
79
+ changes.append(
80
+ FileChange(path=interactive.path, status=interactive.status)
81
+ )
82
+ if interactive.status != "skipped":
83
+ ignored.append(f".agents/agents/{INTERACTIVE_AGENT}.md")
84
+ else:
85
+ warnings.append(
86
+ f"Existing .agents/agents/{INTERACTIVE_AGENT}.md is unmanaged "
87
+ "and was left untouched."
88
+ )
89
+
90
+ readonly = write_text_managed(
91
+ agents_directory / f"{READONLY_AGENT}.md",
92
+ self._render_agent(
93
+ name=READONLY_AGENT,
94
+ description=(
95
+ "Read-only DevFlow specification agent. Returns a complete "
96
+ "specification without modifying the project."
97
+ ),
98
+ context=context,
99
+ interactive=False,
100
+ ),
101
+ root=context.root,
102
+ )
103
+ changes.append(
104
+ FileChange(path=readonly.path, status=readonly.status)
105
+ )
106
+ if readonly.status != "skipped":
107
+ ignored.append(f".agents/agents/{READONLY_AGENT}.md")
108
+ else:
109
+ warnings.append(
110
+ f"Existing .agents/agents/{READONLY_AGENT}.md is unmanaged "
111
+ "and was left untouched."
112
+ )
113
+
114
+ if ignored:
115
+ gitignore = write_gitignore_entries(context.root, ignored)
116
+ changes.append(
117
+ FileChange(path=gitignore.path, status=gitignore.status)
118
+ )
119
+
120
+ return SetupResult(changes=tuple(changes), warnings=tuple(warnings))
121
+
122
+ def build_run(self, context: RunContext) -> Invocation:
123
+ root = context.root
124
+ settings = json.dumps(
125
+ self._settings(context),
126
+ separators=(",", ":"),
127
+ )
128
+ if context.mode == "interactive":
129
+ argv = (
130
+ self.executable,
131
+ "--settings",
132
+ settings,
133
+ "--agent",
134
+ INTERACTIVE_AGENT,
135
+ "--prompt-interactive",
136
+ context.prompt,
137
+ )
138
+ return Invocation(argv=argv, cwd=root, interactive=True)
139
+
140
+ argv = (
141
+ self.executable,
142
+ "--settings",
143
+ settings,
144
+ "--agent",
145
+ READONLY_AGENT,
146
+ "--output-format",
147
+ "text",
148
+ "--print",
149
+ context.prompt,
150
+ )
151
+ return Invocation(argv=argv, cwd=root, interactive=False)
152
+
153
+ def permission_warnings(
154
+ self,
155
+ context: RunContext,
156
+ ) -> tuple[str, ...]:
157
+ warnings: list[str] = []
158
+ if not context.permissions.allow_project_read:
159
+ warnings.append(
160
+ "Project reads are disabled; Antigravity cannot inspect the "
161
+ "codebase. DevFlow will use deterministic analysis."
162
+ )
163
+ if context.mode == "interactive" and (
164
+ context.permissions.allow_source_code_changes
165
+ ):
166
+ warnings.append(
167
+ "Antigravity can write anywhere in the project because source "
168
+ "code changes are allowed. The specification prompt still "
169
+ "forbids implementing the change."
170
+ )
171
+ if context.mode == "non-interactive" and (
172
+ context.permissions.allow_source_code_changes
173
+ ):
174
+ warnings.append(
175
+ "Antigravity print mode is read-only, so source code changes "
176
+ "are not granted for this run."
177
+ )
178
+ return tuple(warnings)
179
+
180
+ def _settings(self, context: RunContext) -> dict[str, Any]:
181
+ root = str(context.root)
182
+ allow: list[str] = []
183
+ deny: list[str] = []
184
+
185
+ if context.permissions.allow_project_read:
186
+ allow.append(f"read_file({root})")
187
+
188
+ if context.mode == "interactive":
189
+ if context.permissions.allow_source_code_changes:
190
+ allow.append(f"write_file({root})")
191
+ allow.append("command(*)")
192
+ elif context.permissions.allow_spec_write:
193
+ specs = str(Path(root) / ".devflow" / "specs")
194
+ allow.append(f"write_file({specs})")
195
+
196
+ if not context.permissions.allow_source_code_changes or (
197
+ context.mode != "interactive"
198
+ ):
199
+ deny.append("command(*)")
200
+ deny.extend(["read_url(*)", "execute_url(*)", "mcp(*)"])
201
+
202
+ if context.mode != "interactive" or not (
203
+ context.permissions.allow_spec_write
204
+ or context.permissions.allow_source_code_changes
205
+ ):
206
+ deny.append(f"write_file({root})")
207
+
208
+ return {
209
+ "trustedWorkspaces": [root],
210
+ "permissions": {"allow": allow, "deny": deny},
211
+ }
212
+
213
+ def _render_agent(
214
+ self,
215
+ *,
216
+ name: str,
217
+ description: str,
218
+ context: SetupContext,
219
+ interactive: bool,
220
+ ) -> str:
221
+ tools = list(_READ_TOOLS)
222
+ if interactive:
223
+ if (
224
+ context.permissions.allow_spec_write
225
+ or context.permissions.allow_source_code_changes
226
+ ):
227
+ tools.extend(_WRITE_TOOLS)
228
+ tools.extend(_QUESTION_TOOLS)
229
+ frontmatter = yaml.safe_dump(
230
+ {
231
+ "name": name,
232
+ "description": description,
233
+ "mainAgent": True,
234
+ "subagent": False,
235
+ "model": "inherit",
236
+ "commandExecutionPolicy": "sandbox" if interactive else "off",
237
+ "tools": tools,
238
+ },
239
+ sort_keys=False,
240
+ allow_unicode=True,
241
+ ).strip()
242
+
243
+ body = [
244
+ MANAGED_MARKER,
245
+ "# System Prompt",
246
+ "",
247
+ "You are the DevFlow specification agent for this project.",
248
+ "",
249
+ "Follow `AGENTS.md` and the project constitution. Analyze the "
250
+ "existing code before writing.",
251
+ "",
252
+ "Write only under `.devflow/specs/`. Never modify application "
253
+ "source code while generating a specification.",
254
+ "",
255
+ ]
256
+ if interactive:
257
+ body.extend(
258
+ [
259
+ "During interactive Discovery, call the `ask_question` tool "
260
+ "once per round with every independent pending decision, and "
261
+ "use it for assumption acceptance. Respect the batch size "
262
+ "from the task prompt instead of asking one question at a "
263
+ "time. Present the recorded options in the dialog instead of "
264
+ "asking in free-form prose, and wait for the user's selection "
265
+ "before recording anything.",
266
+ "",
267
+ ]
268
+ )
269
+ else:
270
+ body.extend(
271
+ [
272
+ "This run is non-interactive. Do not ask questions and do not "
273
+ "write files. Return the complete result as your final message.",
274
+ "",
275
+ ]
276
+ )
277
+ body.extend(
278
+ [
279
+ "The complete task, target path and output contract are provided "
280
+ "in the user prompt for each run.",
281
+ "",
282
+ ]
283
+ )
284
+ return f"---\n{frontmatter}\n---\n\n" + "\n".join(body)
devflow/adapters/codex.py CHANGED
@@ -23,6 +23,8 @@ class CodexAdapter(HarnessAdapter):
23
23
  name = "codex"
24
24
  display_name = "Codex"
25
25
  executable = "codex"
26
+ # Codex describes request_user_input as one to three short questions.
27
+ max_questions_per_call = 3
26
28
 
27
29
  def setup(self, context: SetupContext) -> SetupResult:
28
30
  content = render_agent_instructions(
@@ -190,10 +190,27 @@ class OpenCodeAdapter(HarnessAdapter):
190
190
  "Write only under `.devflow/specs/`. Never modify application "
191
191
  "source code while generating a specification.",
192
192
  "",
193
- "The complete task, target path and output contract are provided "
194
- "in the user prompt for each run.",
195
- "",
196
193
  ]
194
+ if interactive:
195
+ body.extend(
196
+ [
197
+ "During interactive Discovery, call the `question` tool once "
198
+ "per round with every independent pending decision, and use "
199
+ "it for assumption acceptance. Respect the batch size from "
200
+ "the task prompt instead of asking one question at a time. "
201
+ "Present the recorded options in the dialog instead of asking "
202
+ "in free-form prose, and wait for the user's selection before "
203
+ "recording anything.",
204
+ "",
205
+ ]
206
+ )
207
+ body.extend(
208
+ [
209
+ "The complete task, target path and output contract are provided "
210
+ "in the user prompt for each run.",
211
+ "",
212
+ ]
213
+ )
197
214
  return f"---\n{frontmatter}\n---\n\n" + "\n".join(body)
198
215
 
199
216
  def _permissions(
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from devflow.adapters.antigravity import AntigravityAdapter
5
6
  from devflow.adapters.base import HarnessAdapter
6
7
  from devflow.adapters.claude_code import ClaudeCodeAdapter
7
8
  from devflow.adapters.codex import CodexAdapter
@@ -16,6 +17,7 @@ def _create_registry() -> dict[str, HarnessAdapter]:
16
17
  OpenCodeAdapter(),
17
18
  ClaudeCodeAdapter(),
18
19
  KiroAdapter(),
20
+ AntigravityAdapter(),
19
21
  ]
20
22
  return {adapter.name: adapter for adapter in adapters}
21
23
 
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.14"
38
+ current_version = "0.3.16"
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.14. "
60
+ f"Stage '{stage}' is not available in DevFlow 0.3.16. "
61
61
  "Only the 'spec' stage can be approved."
62
62
  )
63
63
  raise UnsupportedStageError(msg)
@@ -55,7 +55,8 @@ def resolve_harness(
55
55
  if not names:
56
56
  msg = (
57
57
  "No supported agent harness was found on PATH. Install a harness "
58
- "(codex, opencode, claude-code or kiro) or pass --harness none / "
58
+ "(codex, opencode, claude-code, kiro or antigravity) or pass "
59
+ "--harness none / "
59
60
  "--no-agent to use deterministic static analysis explicitly."
60
61
  )
61
62
  raise ConfigError(msg)
devflow/commands/init.py CHANGED
@@ -76,7 +76,8 @@ def init(
76
76
  None,
77
77
  "--harness",
78
78
  help=(
79
- "Agent harness: auto, codex, opencode, claude-code, kiro or none."
79
+ "Agent harness: auto, codex, opencode, claude-code, kiro, "
80
+ "antigravity or none."
80
81
  ),
81
82
  ),
82
83
  mode: Optional[str] = typer.Option(
devflow/commands/spec.py CHANGED
@@ -68,7 +68,7 @@ def spec(
68
68
  "--harness",
69
69
  help=(
70
70
  "Agent harness for this run: auto, codex, opencode, claude-code, "
71
- "kiro or none."
71
+ "kiro, antigravity or none."
72
72
  ),
73
73
  ),
74
74
  mode: Optional[str] = typer.Option(
@@ -248,6 +248,7 @@ def _create_specification(
248
248
  console.print(
249
249
  f"[bold]Discovery:[/bold] {result.discovery.status} "
250
250
  f"({len(result.discovery.pending_questions)} pending, "
251
+ f"{len(result.discovery.pending_material)} material, "
251
252
  f"{len(result.discovery.pending_assumptions)} assumptions)"
252
253
  )
253
254
  if result.discovery_digest:
@@ -130,6 +130,7 @@ def _print_discovery(
130
130
  f" status: {discovery.status} · "
131
131
  f"{len(discovery.pending_questions)} pending · "
132
132
  f"{len(discovery.pending_blocking)} blocking · "
133
+ f"{len(discovery.pending_material)} material · "
133
134
  f"{len(discovery.pending_assumptions)} assumptions"
134
135
  )
135
136
  for question in discovery.questions:
@@ -140,7 +141,8 @@ def _print_discovery(
140
141
  else " (pending)"
141
142
  )
142
143
  console.print(
143
- f" {question.id} [{question.category}, {marker}] "
144
+ f" {question.id} [{question.category}, "
145
+ f"{question.effective_materiality}, {marker}] "
144
146
  f"{question.status}{answer}",
145
147
  soft_wrap=True,
146
148
  )
devflow/core/config.py CHANGED
@@ -23,6 +23,7 @@ DEFAULT_SPECIFICATIONS_PATH = Path(".devflow") / "specs"
23
23
  DEFAULT_PLANS_PATH = Path(".devflow") / "plans"
24
24
  DEFAULT_TEMPLATES_PATH = Path(".devflow") / "templates"
25
25
  DEFAULT_DOCUMENTATION_LANGUAGE = "en"
26
+ MAX_DISCOVERY_BUDGET = 100
26
27
 
27
28
  _LANGUAGE_ALIASES = {
28
29
  "aleman": "de",
@@ -48,11 +49,15 @@ SUPPORTED_HARNESSES = (
48
49
  "opencode",
49
50
  "claude-code",
50
51
  "kiro",
52
+ "antigravity",
51
53
  "none",
52
54
  )
53
55
  EXECUTION_MODES = ("interactive", "non-interactive")
54
56
 
55
57
  _HARNESS_ALIASES = {
58
+ "agy": "antigravity",
59
+ "antigravity": "antigravity",
60
+ "anti-gravity": "antigravity",
56
61
  "claude": "claude-code",
57
62
  "claude_code": "claude-code",
58
63
  "claude-code": "claude-code",
@@ -203,6 +208,19 @@ class AgentSettings:
203
208
  permissions: AgentPermissions = AgentPermissions()
204
209
 
205
210
 
211
+ @dataclass(frozen=True)
212
+ class DiscoverySettings:
213
+ """Deterministic limits for the Discovery decision loop."""
214
+
215
+ question_budget_initial: int = 6
216
+ question_budget_follow_up: int = 3
217
+ question_budget_maximum: int = 12
218
+ max_rounds: int = 3
219
+ batch_size: int = 6
220
+ assumptions_enabled: bool = True
221
+ require_explicit_acceptance: bool = True
222
+
223
+
206
224
  @dataclass(frozen=True)
207
225
  class DevFlowConfig:
208
226
  """Validated DevFlow configuration for a project."""
@@ -220,6 +238,7 @@ class DevFlowConfig:
220
238
  templates_path: Path
221
239
  documentation_language: str
222
240
  agent: AgentSettings
241
+ discovery: DiscoverySettings = DiscoverySettings()
223
242
 
224
243
  @property
225
244
  def agent_harness(self) -> str:
@@ -292,6 +311,11 @@ class ConfigManager:
292
311
  )
293
312
  agent = self._mapping(data.get("agent", {}), "agent")
294
313
  agent_settings = self._agent_settings(agent)
314
+ discovery = self._mapping(
315
+ data.get("discovery", {}),
316
+ "discovery",
317
+ )
318
+ discovery_settings = self._discovery_settings(discovery)
295
319
 
296
320
  profiles = self._string_list(
297
321
  data.get("profiles", []),
@@ -379,6 +403,7 @@ class ConfigManager:
379
403
  templates_path=templates_path,
380
404
  documentation_language=documentation_language,
381
405
  agent=agent_settings,
406
+ discovery=discovery_settings,
382
407
  )
383
408
 
384
409
  def create(
@@ -455,6 +480,21 @@ class ConfigManager:
455
480
  "documentation": {
456
481
  "language": language,
457
482
  },
483
+ "discovery": {
484
+ "question_budget": {
485
+ "initial": 6,
486
+ "follow_up": 3,
487
+ "maximum": 12,
488
+ },
489
+ "interaction": {
490
+ "batch_size": 6,
491
+ "max_rounds": 3,
492
+ },
493
+ "assumptions": {
494
+ "enabled": True,
495
+ "require_explicit_acceptance": True,
496
+ },
497
+ },
458
498
  "agent": {
459
499
  "harness": harness,
460
500
  "execution": {
@@ -680,6 +720,78 @@ class ConfigManager:
680
720
  ),
681
721
  )
682
722
 
723
+ def _discovery_settings(
724
+ self,
725
+ discovery: dict[str, Any],
726
+ ) -> DiscoverySettings:
727
+ budget = self._mapping(
728
+ discovery.get("question_budget", {}),
729
+ "discovery.question_budget",
730
+ )
731
+ interaction = self._mapping(
732
+ discovery.get("interaction", {}),
733
+ "discovery.interaction",
734
+ )
735
+ assumptions = self._mapping(
736
+ discovery.get("assumptions", {}),
737
+ "discovery.assumptions",
738
+ )
739
+ initial = self._bounded_integer(
740
+ budget.get("initial", 6),
741
+ "discovery.question_budget.initial",
742
+ minimum=0,
743
+ maximum=100,
744
+ )
745
+ follow_up = self._bounded_integer(
746
+ budget.get("follow_up", 3),
747
+ "discovery.question_budget.follow_up",
748
+ minimum=0,
749
+ maximum=100,
750
+ )
751
+ maximum = self._bounded_integer(
752
+ budget.get("maximum", 12),
753
+ "discovery.question_budget.maximum",
754
+ minimum=0,
755
+ maximum=MAX_DISCOVERY_BUDGET,
756
+ )
757
+ if maximum and initial > maximum:
758
+ msg = (
759
+ "discovery.question_budget.initial cannot exceed "
760
+ "discovery.question_budget.maximum."
761
+ )
762
+ raise ConfigError(msg)
763
+ if maximum and follow_up > maximum:
764
+ msg = (
765
+ "discovery.question_budget.follow_up cannot exceed "
766
+ "discovery.question_budget.maximum."
767
+ )
768
+ raise ConfigError(msg)
769
+ return DiscoverySettings(
770
+ question_budget_initial=initial,
771
+ question_budget_follow_up=follow_up,
772
+ question_budget_maximum=maximum,
773
+ max_rounds=self._bounded_integer(
774
+ interaction.get("max_rounds", 3),
775
+ "discovery.interaction.max_rounds",
776
+ minimum=1,
777
+ maximum=20,
778
+ ),
779
+ batch_size=self._bounded_integer(
780
+ interaction.get("batch_size", 6),
781
+ "discovery.interaction.batch_size",
782
+ minimum=1,
783
+ maximum=20,
784
+ ),
785
+ assumptions_enabled=self._boolean(
786
+ assumptions.get("enabled", True),
787
+ "discovery.assumptions.enabled",
788
+ ),
789
+ require_explicit_acceptance=self._boolean(
790
+ assumptions.get("require_explicit_acceptance", True),
791
+ "discovery.assumptions.require_explicit_acceptance",
792
+ ),
793
+ )
794
+
683
795
  def _write_atomic(self, content: str) -> None:
684
796
  target = self._target_path()
685
797
  target.parent.mkdir(parents=True, exist_ok=True)
@@ -735,6 +847,24 @@ class ConfigManager:
735
847
  raise ConfigError(msg)
736
848
  return value
737
849
 
850
+ def _bounded_integer(
851
+ self,
852
+ value: Any,
853
+ field: str,
854
+ *,
855
+ minimum: int,
856
+ maximum: int,
857
+ ) -> int:
858
+ if isinstance(value, bool) or not isinstance(value, int):
859
+ msg = f"{field} must be an integer."
860
+ raise ConfigError(msg)
861
+ if value < minimum or value > maximum:
862
+ msg = (
863
+ f"{field} must be between {minimum} and {maximum}."
864
+ )
865
+ raise ConfigError(msg)
866
+ return value
867
+
738
868
  def _technologies(self, value: Any) -> dict[str, list[str]]:
739
869
  if value is None:
740
870
  return {}