devflow-toolkit 0.4.2__py3-none-any.whl → 0.4.4__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.
Files changed (36) hide show
  1. devflow/adapters/antigravity.py +21 -7
  2. devflow/adapters/claude_code.py +27 -6
  3. devflow/adapters/instructions.py +3 -1
  4. devflow/adapters/kiro.py +21 -7
  5. devflow/adapters/opencode.py +55 -34
  6. devflow/commands/approve.py +3 -2
  7. devflow/commands/config.py +2 -1
  8. devflow/commands/doctor.py +2 -1
  9. devflow/commands/harness.py +3 -2
  10. devflow/commands/init.py +4 -3
  11. devflow/commands/recover.py +2 -1
  12. devflow/commands/reopen.py +2 -1
  13. devflow/commands/security.py +2 -1
  14. devflow/commands/spec.py +70 -4
  15. devflow/commands/status.py +30 -17
  16. devflow/core/artifacts/store.py +29 -3
  17. devflow/core/config.py +27 -1
  18. devflow/core/discovery.py +48 -6
  19. devflow/core/ports.py +9 -1
  20. devflow/core/safe_files.py +36 -0
  21. devflow/core/security_tools.py +24 -7
  22. devflow/core/spec_workflow.py +211 -5
  23. devflow/core/specification.py +20 -3
  24. devflow/core/state/events.py +56 -7
  25. devflow/core/state/lock.py +5 -1
  26. devflow/core/state/manager.py +61 -1
  27. devflow/core/state/signing.py +107 -0
  28. devflow/hooks/claude_guard.py +10 -1
  29. devflow/prompts/__init__.py +13 -2
  30. devflow/prompts/discovery.md +16 -1
  31. devflow/prompts/spec.md +6 -0
  32. {devflow_toolkit-0.4.2.dist-info → devflow_toolkit-0.4.4.dist-info}/METADATA +85 -17
  33. {devflow_toolkit-0.4.2.dist-info → devflow_toolkit-0.4.4.dist-info}/RECORD +36 -34
  34. {devflow_toolkit-0.4.2.dist-info → devflow_toolkit-0.4.4.dist-info}/WHEEL +0 -0
  35. {devflow_toolkit-0.4.2.dist-info → devflow_toolkit-0.4.4.dist-info}/entry_points.txt +0 -0
  36. {devflow_toolkit-0.4.2.dist-info → devflow_toolkit-0.4.4.dist-info}/licenses/LICENSE +0 -0
@@ -3,7 +3,9 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
+ import os
6
7
  import subprocess
8
+ import tempfile
7
9
  from pathlib import Path
8
10
  from typing import Any
9
11
 
@@ -39,6 +41,10 @@ class AntigravityAdapter(HarnessAdapter):
39
41
  name = "antigravity"
40
42
  display_name = "Antigravity"
41
43
  executable = "agy"
44
+ agent_definition_files = (
45
+ f".agents/agents/{INTERACTIVE_AGENT}.md",
46
+ f".agents/agents/{READONLY_AGENT}.md",
47
+ )
42
48
 
43
49
  def setup(self, context: SetupContext) -> SetupResult:
44
50
  changes: list[FileChange] = []
@@ -157,14 +163,22 @@ class AntigravityAdapter(HarnessAdapter):
157
163
 
158
164
  def list_models(self) -> tuple[ModelOption, ...]:
159
165
  """Return models reported by ``agy models``."""
166
+ if not self.is_available():
167
+ return ()
160
168
  try:
161
- result = subprocess.run( # noqa: S603
162
- [self.executable, "models"],
163
- capture_output=True,
164
- text=True,
165
- timeout=30,
166
- check=False,
167
- )
169
+ # Run outside the project so the harness does not load the
170
+ # repository's own configuration, plugins or MCP servers.
171
+ with tempfile.TemporaryDirectory() as neutral:
172
+ result = subprocess.run( # noqa: S603
173
+ [self.executable, "models"],
174
+ capture_output=True,
175
+ text=True,
176
+ timeout=30,
177
+ check=False,
178
+ cwd=neutral,
179
+ # OpenCode resolves the project from PWD, not the cwd.
180
+ env={**os.environ, "PWD": neutral},
181
+ )
168
182
  except (OSError, subprocess.SubprocessError):
169
183
  return ()
170
184
  if result.returncode != 0:
@@ -19,6 +19,7 @@ from devflow.adapters.instructions import (
19
19
  write_gitignore_entries,
20
20
  write_text_managed,
21
21
  )
22
+ from devflow.core.safe_files import WORKFLOW_STATE_FILES
22
23
 
23
24
 
24
25
  class ClaudeCodeAdapter(HarnessAdapter):
@@ -65,11 +66,16 @@ class ClaudeCodeAdapter(HarnessAdapter):
65
66
  "manual" if context.mode == "interactive" else "dontAsk"
66
67
  )
67
68
  model = ("--model", context.model) if context.model else ()
69
+ # Load only the user's own settings and no MCP servers: hooks,
70
+ # permissions and MCP servers committed in the project's .claude/ or
71
+ # .mcp.json must not run with DevFlow's agent session.
72
+ isolation = ("--setting-sources", "user", "--strict-mcp-config")
68
73
 
69
74
  if context.mode == "interactive":
70
75
  argv = (
71
76
  self.executable,
72
77
  *model,
78
+ *isolation,
73
79
  "--permission-mode",
74
80
  permission_mode,
75
81
  "--settings",
@@ -85,6 +91,7 @@ class ClaudeCodeAdapter(HarnessAdapter):
85
91
  self.executable,
86
92
  "-p",
87
93
  *model,
94
+ *isolation,
88
95
  "--output-format",
89
96
  "text",
90
97
  "--permission-mode",
@@ -125,9 +132,12 @@ class ClaudeCodeAdapter(HarnessAdapter):
125
132
  ):
126
133
  return {}
127
134
  allowed = context.spec_directory.parent
135
+ # Claude Code runs the hook from the project directory; `-P` keeps a
136
+ # `devflow/` package in an untrusted project from replacing the guard.
128
137
  command = " ".join(
129
138
  [
130
139
  shlex.quote(sys.executable),
140
+ "-P",
131
141
  "-m",
132
142
  "devflow.hooks.claude_guard",
133
143
  shlex.quote(str(allowed)),
@@ -145,12 +155,11 @@ class ClaudeCodeAdapter(HarnessAdapter):
145
155
  def _permission_rules(
146
156
  self,
147
157
  context: RunContext,
148
- ) -> dict[str, list[str]]:
158
+ ) -> dict[str, object]:
159
+ # Reads inside the project need no rule. A bare "Read" allow would
160
+ # also pre-approve reads anywhere on disk, so none is added.
149
161
  allow: list[str] = []
150
- deny: list[str] = []
151
-
152
- if context.permissions.allow_project_read:
153
- allow.extend(["Read", "Grep", "Glob"])
162
+ deny: list[str] = ["mcp__*", "Read(./**/.env)", "Read(./**/.env.*)"]
154
163
 
155
164
  if context.permissions.allow_source_code_changes:
156
165
  allow.extend(["Edit", "Write", "Bash"])
@@ -163,7 +172,19 @@ class ClaudeCodeAdapter(HarnessAdapter):
163
172
  )
164
173
 
165
174
  deny.extend(["WebFetch", "WebSearch", "Task"])
175
+ for name in WORKFLOW_STATE_FILES:
176
+ deny.extend(
177
+ [
178
+ f"Edit(.devflow/specs/**/{name})",
179
+ f"Write(.devflow/specs/**/{name})",
180
+ ]
181
+ )
166
182
  if not context.permissions.allow_source_code_changes:
167
183
  deny.extend(["Bash", "NotebookEdit"])
168
184
 
169
- return {"allow": allow, "deny": deny}
185
+ return {
186
+ "allow": allow,
187
+ "deny": deny,
188
+ "blockReadsOutsideWorkingDirectories": True,
189
+ "blockWritesOutsideWorkingDirectories": True,
190
+ }
@@ -76,7 +76,9 @@ def _write_atomic(path: Path, content: str) -> None:
76
76
 
77
77
  mode = 0o644
78
78
  try:
79
- mode = stat.S_IMODE(path.stat().st_mode)
79
+ # Keep the owner's read/write choice, but never carry over special,
80
+ # executable or world-writable bits from the file being replaced.
81
+ mode = stat.S_IMODE(path.stat().st_mode) & 0o664
80
82
  except OSError:
81
83
  pass
82
84
  os.chmod(temporary, mode)
devflow/adapters/kiro.py CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import os
5
6
  import subprocess
7
+ import tempfile
6
8
 
7
9
  from devflow.adapters.base import (
8
10
  FileChange,
@@ -31,6 +33,10 @@ class KiroAdapter(HarnessAdapter):
31
33
  name = "kiro"
32
34
  display_name = "Kiro"
33
35
  executable = "kiro-cli"
36
+ agent_definition_files = (
37
+ f".kiro/agents/{INTERACTIVE_AGENT}.json",
38
+ f".kiro/agents/{READONLY_AGENT}.json",
39
+ )
34
40
 
35
41
  def setup(self, context: SetupContext) -> SetupResult:
36
42
  changes: list[FileChange] = []
@@ -154,14 +160,22 @@ class KiroAdapter(HarnessAdapter):
154
160
 
155
161
  def list_models(self) -> tuple[ModelOption, ...]:
156
162
  """Return models reported by ``kiro-cli chat --list-models``."""
163
+ if not self.is_available():
164
+ return ()
157
165
  try:
158
- result = subprocess.run( # noqa: S603
159
- [self.executable, "chat", "--list-models"],
160
- capture_output=True,
161
- text=True,
162
- timeout=30,
163
- check=False,
164
- )
166
+ # Run outside the project so the harness does not load the
167
+ # repository's own configuration, plugins or MCP servers.
168
+ with tempfile.TemporaryDirectory() as neutral:
169
+ result = subprocess.run( # noqa: S603
170
+ [self.executable, "chat", "--list-models"],
171
+ capture_output=True,
172
+ text=True,
173
+ timeout=30,
174
+ check=False,
175
+ cwd=neutral,
176
+ # OpenCode resolves the project from PWD, not the cwd.
177
+ env={**os.environ, "PWD": neutral},
178
+ )
165
179
  except (OSError, subprocess.SubprocessError):
166
180
  return ()
167
181
  if result.returncode != 0:
@@ -2,7 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import os
5
6
  import subprocess
7
+ import tempfile
6
8
 
7
9
  import yaml
8
10
 
@@ -15,6 +17,7 @@ from devflow.adapters.base import (
15
17
  SetupResult,
16
18
  )
17
19
  from devflow.core.ports import ModelOption
20
+ from devflow.core.safe_files import WORKFLOW_STATE_FILES
18
21
  from devflow.adapters.instructions import (
19
22
  MANAGED_MARKER,
20
23
  render_agent_instructions,
@@ -33,6 +36,10 @@ class OpenCodeAdapter(HarnessAdapter):
33
36
  name = "opencode"
34
37
  display_name = "OpenCode"
35
38
  executable = "opencode"
39
+ agent_definition_files = (
40
+ f".opencode/agents/{INTERACTIVE_AGENT}.md",
41
+ f".opencode/agents/{READONLY_AGENT}.md",
42
+ )
36
43
 
37
44
  def setup(self, context: SetupContext) -> SetupResult:
38
45
  changes: list[FileChange] = []
@@ -148,14 +155,22 @@ class OpenCodeAdapter(HarnessAdapter):
148
155
 
149
156
  def list_models(self) -> tuple[ModelOption, ...]:
150
157
  """Return models reported by ``opencode models``."""
158
+ if not self.is_available():
159
+ return ()
151
160
  try:
152
- result = subprocess.run( # noqa: S603
153
- [self.executable, "models"],
154
- capture_output=True,
155
- text=True,
156
- timeout=30,
157
- check=False,
158
- )
161
+ # Run outside the project so the harness does not load the
162
+ # repository's own configuration, plugins or MCP servers.
163
+ with tempfile.TemporaryDirectory() as neutral:
164
+ result = subprocess.run( # noqa: S603
165
+ [self.executable, "models"],
166
+ capture_output=True,
167
+ text=True,
168
+ timeout=30,
169
+ check=False,
170
+ cwd=neutral,
171
+ # OpenCode resolves the project from PWD, not the cwd.
172
+ env={**os.environ, "PWD": neutral},
173
+ )
159
174
  except (OSError, subprocess.SubprocessError):
160
175
  return ()
161
176
  if result.returncode != 0:
@@ -247,52 +262,58 @@ class OpenCodeAdapter(HarnessAdapter):
247
262
  *,
248
263
  interactive: bool,
249
264
  ) -> list[dict[str, str]]:
250
- permissions: list[dict[str, str]] = []
265
+ """Build OpenCode V2 rules; the last matching rule wins.
266
+
267
+ OpenCode starts every agent from an allow-all policy, so the list
268
+ opens with a deny-all rule. Anything not granted below, such as MCP
269
+ tools, skills or image generation, stays denied.
270
+ """
271
+ specs = context.config.specifications_path.relative_to(
272
+ context.config.root
273
+ ).as_posix()
274
+ permissions: list[dict[str, str]] = [
275
+ {"action": "*", "resource": "*", "effect": "deny"},
276
+ ]
251
277
  if context.permissions.allow_project_read:
252
278
  for action in ("read", "glob", "grep"):
253
279
  permissions.append(
254
280
  {"action": action, "resource": "*", "effect": "allow"}
255
281
  )
282
+ for pattern, effect in (
283
+ ("*.env", "deny"),
284
+ ("*.env.*", "deny"),
285
+ ("*.env.example", "allow"),
286
+ ):
287
+ permissions.append(
288
+ {"action": "read", "resource": pattern, "effect": effect}
289
+ )
256
290
 
257
291
  if context.permissions.allow_source_code_changes:
258
292
  permissions.append(
259
293
  {"action": "edit", "resource": "*", "effect": "allow"}
260
294
  )
295
+ permissions.append(
296
+ {"action": "shell", "resource": "*", "effect": "allow"}
297
+ )
261
298
  elif context.permissions.allow_spec_write:
262
299
  permissions.append(
263
- {"action": "edit", "resource": "*", "effect": "deny"}
300
+ {"action": "edit", "resource": f"{specs}/*", "effect": "allow"}
264
301
  )
302
+ for name in WORKFLOW_STATE_FILES:
265
303
  permissions.append(
266
304
  {
267
305
  "action": "edit",
268
- "resource": ".devflow/specs/**",
269
- "effect": "allow",
306
+ "resource": f"{specs}/*/{name}",
307
+ "effect": "deny",
270
308
  }
271
309
  )
272
- else:
310
+ if interactive:
273
311
  permissions.append(
274
- {"action": "edit", "resource": "*", "effect": "deny"}
312
+ {"action": "question", "resource": "*", "effect": "allow"}
275
313
  )
276
-
277
- permissions.extend(
278
- [
279
- {
280
- "action": "shell",
281
- "resource": "*",
282
- "effect": (
283
- "allow"
284
- if context.permissions.allow_source_code_changes
285
- else "deny"
286
- ),
287
- },
288
- {
289
- "action": "question",
290
- "resource": "*",
291
- "effect": "allow" if interactive else "deny",
292
- },
293
- {"action": "webfetch", "resource": "*", "effect": "deny"},
294
- {"action": "websearch", "resource": "*", "effect": "deny"},
295
- {"action": "subagent", "resource": "*", "effect": "deny"},
296
- ]
314
+ # Paths outside the project are checked against external_directory
315
+ # before read or edit rules.
316
+ permissions.append(
317
+ {"action": "external_directory", "resource": "*", "effect": "deny"}
297
318
  )
298
319
  return permissions
@@ -7,6 +7,7 @@ from pathlib import Path
7
7
 
8
8
  import typer
9
9
  from rich.console import Console
10
+ from rich.markup import escape
10
11
 
11
12
  from devflow.commands.security import offer_security_tools
12
13
  from devflow.core.artifacts.errors import ArtifactError
@@ -54,7 +55,7 @@ def approve(
54
55
  NotADirectoryError,
55
56
  OSError,
56
57
  ) as error:
57
- error_console.print(f"[red]Error:[/red] {error}")
58
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
58
59
  raise typer.Exit(code=1) from error
59
60
 
60
61
 
@@ -76,7 +77,7 @@ def _approve(spec_id: str, path: Path, stage: str) -> None:
76
77
  location = WorkflowLocator(config.specifications_path).find(spec_id)
77
78
  result = manager.approve(location, normalized)
78
79
  for warning in result.warnings:
79
- console.print(f"[yellow]Warning:[/yellow] {warning}")
80
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
80
81
 
81
82
  if not result.changed:
82
83
  console.print(
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import typer
8
8
  from rich.console import Console
9
+ from rich.markup import escape
9
10
 
10
11
  from devflow.core.config import ConfigError, ConfigManager
11
12
  from devflow.core.project import ProjectDetector
@@ -40,7 +41,7 @@ def language(
40
41
  NotADirectoryError,
41
42
  OSError,
42
43
  ) as error:
43
- error_console.print(f"[red]Error:[/red] {error}")
44
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
44
45
  raise typer.Exit(code=1) from error
45
46
 
46
47
  console.print(
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import typer
8
8
  from rich.console import Console
9
+ from rich.markup import escape
9
10
 
10
11
  from devflow.core.artifacts.errors import ArtifactError
11
12
  from devflow.core.config import ConfigError, ConfigManager
@@ -40,7 +41,7 @@ def doctor(
40
41
  NotADirectoryError,
41
42
  OSError,
42
43
  ) as error:
43
- error_console.print(f"[red]Error:[/red] {error}")
44
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
44
45
  raise typer.Exit(code=1) from error
45
46
  if not healthy:
46
47
  raise typer.Exit(code=1)
@@ -7,6 +7,7 @@ from pathlib import Path
7
7
 
8
8
  import typer
9
9
  from rich.console import Console
10
+ from rich.markup import escape
10
11
 
11
12
  from devflow.adapters.detector import (
12
13
  detect_harnesses,
@@ -160,7 +161,7 @@ def print_setup_result(
160
161
  relative = change.path.relative_to(root)
161
162
  console.print(f"[{color}]Agent integration {label}:[/{color}] {relative}")
162
163
  for warning in result.warnings:
163
- console.print(f"[yellow]Warning:[/yellow] {warning}")
164
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
164
165
 
165
166
 
166
167
  def _prompt_for_harness(
@@ -197,7 +198,7 @@ def _load_harness_config(path: Path) -> tuple[Path, DevFlowConfig]:
197
198
 
198
199
 
199
200
  def _harness_error(error: Exception) -> None:
200
- error_console.print(f"[red]Error:[/red] {error}")
201
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
201
202
 
202
203
 
203
204
  @harness_app.command("current")
devflow/commands/init.py CHANGED
@@ -8,6 +8,7 @@ from typing import Optional
8
8
 
9
9
  import typer
10
10
  from rich.console import Console
11
+ from rich.markup import escape
11
12
 
12
13
  from devflow.adapters.agents import AgentsFileWriter
13
14
  from devflow.commands.harness import (
@@ -150,7 +151,7 @@ def init(
150
151
  NotADirectoryError,
151
152
  OSError,
152
153
  ) as error:
153
- error_console.print(f"[red]Error:[/red] {error}")
154
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
154
155
  raise typer.Exit(code=1) from error
155
156
 
156
157
 
@@ -475,7 +476,7 @@ def _refresh_existing(
475
476
  )
476
477
 
477
478
  for warning in constitution.warnings:
478
- console.print(f"[yellow]Warning:[/yellow] {warning}")
479
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
479
480
 
480
481
  _report_harness(
481
482
  config.agent_harness,
@@ -622,7 +623,7 @@ def _report_harness(
622
623
  f"[bold]Execution mode:[/bold] {config.execution_mode}"
623
624
  )
624
625
  for warning in warnings:
625
- console.print(f"[yellow]Warning:[/yellow] {warning}")
626
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
626
627
  if setup_result is not None:
627
628
  print_setup_result(setup_result, config.root, console)
628
629
 
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import typer
8
8
  from rich.console import Console
9
+ from rich.markup import escape
9
10
 
10
11
  from devflow.core.artifacts.errors import ArtifactError
11
12
  from devflow.core.config import ConfigError, ConfigManager
@@ -40,7 +41,7 @@ def recover(
40
41
  NotADirectoryError,
41
42
  OSError,
42
43
  ) as error:
43
- error_console.print(f"[red]Error:[/red] {error}")
44
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
44
45
  raise typer.Exit(code=1) from error
45
46
 
46
47
 
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import typer
8
8
  from rich.console import Console
9
+ from rich.markup import escape
9
10
 
10
11
  from devflow.core.artifacts.errors import ArtifactError
11
12
  from devflow.core.config import ConfigError, ConfigManager
@@ -54,7 +55,7 @@ def reopen(
54
55
  NotADirectoryError,
55
56
  OSError,
56
57
  ) as error:
57
- error_console.print(f"[red]Error:[/red] {error}")
58
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
58
59
  raise typer.Exit(code=1) from error
59
60
 
60
61
 
@@ -4,6 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import typer
6
6
  from rich.console import Console
7
+ from rich.markup import escape
7
8
 
8
9
  from devflow.core import security_tools
9
10
  from devflow.core.config import ConfigManager, DevFlowConfig
@@ -27,7 +28,7 @@ def install_security_tools(
27
28
  for message in result.messages:
28
29
  console.print(f"[green]{message}[/green]")
29
30
  for warning in result.warnings:
30
- console.print(f"[yellow]Warning:[/yellow] {warning}")
31
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
31
32
 
32
33
 
33
34
  def decline_security_tools(config: DevFlowConfig) -> None:
devflow/commands/spec.py CHANGED
@@ -3,11 +3,13 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import sys
6
+ from dataclasses import replace
6
7
  from pathlib import Path
7
8
  from typing import Optional
8
9
 
9
10
  import typer
10
11
  from rich.console import Console
12
+ from rich.markup import escape
11
13
 
12
14
  from devflow.adapters.base import execute_invocation
13
15
  from devflow.commands.harness import (
@@ -20,6 +22,7 @@ from devflow.core.architecture import ArchitectureError
20
22
  from devflow.core.artifacts.errors import ArtifactError
21
23
  from devflow.core.config import (
22
24
  EXECUTION_MODES,
25
+ AgentPermissions,
23
26
  ConfigError,
24
27
  ConfigManager,
25
28
  DevFlowConfig,
@@ -112,6 +115,15 @@ def spec(
112
115
  "changing the configuration."
113
116
  ),
114
117
  ),
118
+ allow_source_changes: bool = typer.Option(
119
+ False,
120
+ "--allow-source-changes",
121
+ help=(
122
+ "Confirm that the agent may edit source code and run shell "
123
+ "commands when .devflow/config.yaml enables "
124
+ "agent.permissions.allow_source_code_changes."
125
+ ),
126
+ ),
115
127
  auto: bool = typer.Option(
116
128
  False,
117
129
  "--auto",
@@ -135,6 +147,7 @@ def spec(
135
147
  language,
136
148
  model,
137
149
  auto,
150
+ allow_source_changes,
138
151
  )
139
152
  except (
140
153
  ArchitectureError,
@@ -149,7 +162,7 @@ def spec(
149
162
  NotADirectoryError,
150
163
  OSError,
151
164
  ) as error:
152
- error_console.print(f"[red]Error:[/red] {error}")
165
+ error_console.print(f"[red]Error:[/red] {escape(str(error))}")
153
166
  raise typer.Exit(code=1) from error
154
167
 
155
168
 
@@ -164,6 +177,7 @@ def _create_specification(
164
177
  language: Optional[str] = None,
165
178
  model: Optional[str] = None,
166
179
  auto: bool = False,
180
+ allow_source_changes: bool = False,
167
181
  ) -> None:
168
182
  request = (description or "").strip()
169
183
  resume = (continue_id or "").strip() or None
@@ -237,6 +251,13 @@ def _create_specification(
237
251
  force_prompt=not explicit_harness,
238
252
  )
239
253
  adapter = adapter_for(selected_harness) if selected_harness else None
254
+ if adapter is not None:
255
+ config = _confirm_source_changes(
256
+ config,
257
+ adapter.display_name,
258
+ allowed=allow_source_changes,
259
+ allow_prompt=allow_prompt,
260
+ )
240
261
 
241
262
  stop_after_discovery = (
242
263
  not auto
@@ -244,7 +265,10 @@ def _create_specification(
244
265
  and execution_mode == "interactive"
245
266
  )
246
267
 
247
- workflow = SpecWorkflow(executor=execute_invocation)
268
+ workflow = SpecWorkflow(
269
+ executor=execute_invocation,
270
+ notify=lambda warning: _print_warnings([warning]),
271
+ )
248
272
  result = workflow.run(
249
273
  SpecWorkflowRequest(
250
274
  description=request,
@@ -512,9 +536,51 @@ def _execution_mode(mode: str) -> tuple[str, list[str]]:
512
536
  return normalized, warnings
513
537
 
514
538
 
539
+ def _confirm_source_changes(
540
+ config: DevFlowConfig,
541
+ harness_name: str,
542
+ *,
543
+ allowed: bool,
544
+ allow_prompt: bool,
545
+ ) -> DevFlowConfig:
546
+ """Require the developer to confirm source-change authority.
547
+
548
+ .devflow/config.yaml is committed with the project, so a cloned
549
+ repository could otherwise grant the agent shell and write access on
550
+ its own. The grant needs --allow-source-changes or an explicit answer
551
+ before the agent starts; otherwise the run is limited to specs.
552
+ """
553
+ permissions = config.permissions
554
+ if not permissions.allow_source_code_changes or allowed:
555
+ return config
556
+ question = (
557
+ ".devflow/config.yaml sets agent.permissions."
558
+ f"allow_source_code_changes, which lets {harness_name} edit source "
559
+ "code and run shell commands during this run. Allow it?"
560
+ )
561
+ if allow_prompt and typer.confirm(question, default=False):
562
+ return config
563
+ _print_warnings(
564
+ [
565
+ "Source code changes were not granted for this run; the agent may "
566
+ "only write specifications. Pass --allow-source-changes to grant "
567
+ "them."
568
+ ]
569
+ )
570
+ restricted = AgentPermissions(
571
+ allow_project_read=permissions.allow_project_read,
572
+ allow_workflow_write=permissions.allow_workflow_write,
573
+ allow_source_code_changes=False,
574
+ )
575
+ return replace(
576
+ config,
577
+ agent=replace(config.agent, permissions=restricted),
578
+ )
579
+
580
+
515
581
  def _print_warnings(warnings: list[str]) -> None:
516
582
  for warning in warnings:
517
- console.print(f"[yellow]Warning:[/yellow] {warning}")
583
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
518
584
 
519
585
 
520
586
  def _print_blocked(
@@ -557,7 +623,7 @@ def _print_result(
557
623
  config: DevFlowConfig,
558
624
  ) -> None:
559
625
  for warning in result.constitution_warnings:
560
- console.print(f"[yellow]Warning:[/yellow] {warning}")
626
+ console.print(f"[yellow]Warning:[/yellow] {escape(warning)}")
561
627
 
562
628
  spec = result.spec
563
629
  if spec is None: