devcouncil 0.1.0 → 0.2.0

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 (190) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +197 -494
  3. package/package.json +9 -2
  4. package/pyproject.toml +62 -27
  5. package/src/devcouncil/__main__.py +4 -4
  6. package/src/devcouncil/app/__init__.py +28 -28
  7. package/src/devcouncil/app/config.py +297 -108
  8. package/src/devcouncil/app/errors.py +23 -23
  9. package/src/devcouncil/app/events.py +44 -44
  10. package/src/devcouncil/app/orchestrator.py +67 -67
  11. package/src/devcouncil/app/project_status.py +29 -0
  12. package/src/devcouncil/app/run_context.py +39 -39
  13. package/src/devcouncil/app/state_machine.py +108 -108
  14. package/src/devcouncil/artifacts/__init__.py +1 -1
  15. package/src/devcouncil/artifacts/coverage.py +96 -96
  16. package/src/devcouncil/artifacts/graph.py +163 -143
  17. package/src/devcouncil/artifacts/migrations.py +20 -20
  18. package/src/devcouncil/artifacts/schemas.py +23 -23
  19. package/src/devcouncil/artifacts/serializer.py +21 -21
  20. package/src/devcouncil/artifacts/validators.py +27 -27
  21. package/src/devcouncil/assets/__init__.py +1 -0
  22. package/src/devcouncil/assets/devcouncil-logo.svg +60 -0
  23. package/src/devcouncil/assets/devcouncil_logo_premium.png +0 -0
  24. package/src/devcouncil/cli/commands/agents.py +292 -0
  25. package/src/devcouncil/cli/commands/artifacts.py +54 -48
  26. package/src/devcouncil/cli/commands/ast.py +22 -0
  27. package/src/devcouncil/cli/commands/baseline.py +35 -32
  28. package/src/devcouncil/cli/commands/check.py +209 -0
  29. package/src/devcouncil/cli/commands/config.py +115 -54
  30. package/src/devcouncil/cli/commands/cost.py +57 -0
  31. package/src/devcouncil/cli/commands/dashboard.py +31 -0
  32. package/src/devcouncil/cli/commands/doctor.py +291 -47
  33. package/src/devcouncil/cli/commands/evidence.py +48 -0
  34. package/src/devcouncil/cli/commands/go.py +656 -0
  35. package/src/devcouncil/cli/commands/handoff.py +69 -0
  36. package/src/devcouncil/cli/commands/hook.py +209 -33
  37. package/src/devcouncil/cli/commands/init.py +204 -57
  38. package/src/devcouncil/cli/commands/integrate.py +1171 -76
  39. package/src/devcouncil/cli/commands/lsp.py +20 -0
  40. package/src/devcouncil/cli/commands/map.py +96 -22
  41. package/src/devcouncil/cli/commands/plan.py +422 -210
  42. package/src/devcouncil/cli/commands/prompt.py +48 -34
  43. package/src/devcouncil/cli/commands/repair.py +89 -69
  44. package/src/devcouncil/cli/commands/report.py +120 -54
  45. package/src/devcouncil/cli/commands/reset_demo_state.py +33 -28
  46. package/src/devcouncil/cli/commands/rollback.py +55 -54
  47. package/src/devcouncil/cli/commands/run.py +285 -220
  48. package/src/devcouncil/cli/commands/runs.py +223 -0
  49. package/src/devcouncil/cli/commands/scaffold.py +32 -0
  50. package/src/devcouncil/cli/commands/semantic.py +47 -0
  51. package/src/devcouncil/cli/commands/setup.py +300 -20
  52. package/src/devcouncil/cli/commands/shell.py +73 -0
  53. package/src/devcouncil/cli/commands/show.py +76 -57
  54. package/src/devcouncil/cli/commands/skills.py +88 -0
  55. package/src/devcouncil/cli/commands/status.py +141 -105
  56. package/src/devcouncil/cli/commands/tasks.py +55 -41
  57. package/src/devcouncil/cli/commands/trace.py +49 -4
  58. package/src/devcouncil/cli/commands/verify.py +293 -128
  59. package/src/devcouncil/cli/commands/version.py +20 -20
  60. package/src/devcouncil/cli/commands/watch.py +574 -0
  61. package/src/devcouncil/cli/commands/watch_fs.py +40 -0
  62. package/src/devcouncil/cli/main.py +92 -25
  63. package/src/devcouncil/council/prompts/arbiter.md +19 -19
  64. package/src/devcouncil/council/prompts/critic_a.md +10 -10
  65. package/src/devcouncil/council/prompts/critic_b.md +10 -10
  66. package/src/devcouncil/council/prompts/implementation_reviewer.md +16 -16
  67. package/src/devcouncil/council/prompts/planner_a.md +16 -16
  68. package/src/devcouncil/council/prompts/planner_b.md +16 -16
  69. package/src/devcouncil/council/prompts/rebuttal.md +10 -10
  70. package/src/devcouncil/council/prompts/spec_writer.md +12 -12
  71. package/src/devcouncil/domain/assumption.py +17 -17
  72. package/src/devcouncil/domain/critique.py +32 -32
  73. package/src/devcouncil/domain/evidence.py +47 -27
  74. package/src/devcouncil/domain/gap.py +52 -26
  75. package/src/devcouncil/domain/requirement.py +22 -22
  76. package/src/devcouncil/domain/task.py +55 -26
  77. package/src/devcouncil/execution/__init__.py +1 -1
  78. package/src/devcouncil/execution/checkpoints.py +246 -0
  79. package/src/devcouncil/execution/context_builder.py +54 -54
  80. package/src/devcouncil/execution/executor.py +15 -15
  81. package/src/devcouncil/execution/fs_watcher.py +180 -0
  82. package/src/devcouncil/execution/handoff.py +102 -0
  83. package/src/devcouncil/execution/hook_policy.py +186 -77
  84. package/src/devcouncil/execution/patch.py +77 -28
  85. package/src/devcouncil/execution/permissions.py +52 -59
  86. package/src/devcouncil/execution/policy_engine.py +343 -0
  87. package/src/devcouncil/execution/prompt_builder.py +650 -38
  88. package/src/devcouncil/execution/shell_session.py +225 -0
  89. package/src/devcouncil/execution/task_runner.py +68 -64
  90. package/src/devcouncil/executors/__init__.py +1 -1
  91. package/src/devcouncil/executors/agent_registry.py +575 -0
  92. package/src/devcouncil/executors/coding_cli.py +736 -0
  93. package/src/devcouncil/executors/mini_swe.py +63 -63
  94. package/src/devcouncil/executors/native/agent.py +186 -85
  95. package/src/devcouncil/executors/openhands.py +56 -56
  96. package/src/devcouncil/gating/__init__.py +1 -1
  97. package/src/devcouncil/gating/checks/clean_git.py +52 -45
  98. package/src/devcouncil/gating/checks/planned_files_check.py +32 -32
  99. package/src/devcouncil/gating/checks/requirement_coverage.py +26 -26
  100. package/src/devcouncil/gating/checks/secret_scan_check.py +53 -34
  101. package/src/devcouncil/gating/policy.py +315 -167
  102. package/src/devcouncil/hardware.py +184 -0
  103. package/src/devcouncil/indexing/__init__.py +1 -1
  104. package/src/devcouncil/indexing/ast_matcher.py +168 -0
  105. package/src/devcouncil/indexing/graph_index.py +48 -48
  106. package/src/devcouncil/indexing/lsp.py +161 -0
  107. package/src/devcouncil/indexing/repo_mapper.py +1455 -204
  108. package/src/devcouncil/indexing/semantic_index.py +205 -0
  109. package/src/devcouncil/integrations/actions.py +146 -0
  110. package/src/devcouncil/integrations/check.py +423 -0
  111. package/src/devcouncil/integrations/github.py +35 -35
  112. package/src/devcouncil/integrations/github_intent.py +142 -0
  113. package/src/devcouncil/integrations/gitnexus.py +62 -27
  114. package/src/devcouncil/integrations/graphify.py +34 -34
  115. package/src/devcouncil/integrations/mcp/server.py +2072 -96
  116. package/src/devcouncil/integrations/opencode_devcouncil_plugin.mjs +24 -0
  117. package/src/devcouncil/integrations/pr_comments.py +62 -0
  118. package/src/devcouncil/live/__init__.py +2 -0
  119. package/src/devcouncil/live/cards.py +349 -0
  120. package/src/devcouncil/live/models.py +63 -0
  121. package/src/devcouncil/live/repair_prompt.py +83 -0
  122. package/src/devcouncil/live/reviewer.py +70 -0
  123. package/src/devcouncil/live/signals.py +135 -0
  124. package/src/devcouncil/live/summary.py +34 -0
  125. package/src/devcouncil/live/tasks.py +18 -0
  126. package/src/devcouncil/live/transcripts.py +141 -0
  127. package/src/devcouncil/llm/__init__.py +1 -1
  128. package/src/devcouncil/llm/cache.py +42 -38
  129. package/src/devcouncil/llm/model_defaults.yaml +44 -0
  130. package/src/devcouncil/llm/provider.py +627 -125
  131. package/src/devcouncil/llm/router.py +303 -118
  132. package/src/devcouncil/optimization/__init__.py +1 -0
  133. package/src/devcouncil/optimization/gepa_agent.py +318 -0
  134. package/src/devcouncil/planning/__init__.py +1 -1
  135. package/src/devcouncil/planning/arbiter_service.py +57 -57
  136. package/src/devcouncil/planning/correction_manifest.py +303 -0
  137. package/src/devcouncil/planning/critique_service.py +71 -66
  138. package/src/devcouncil/planning/plan_service.py +60 -46
  139. package/src/devcouncil/planning/prompt_enhancer_service.py +167 -0
  140. package/src/devcouncil/planning/repair_service.py +39 -39
  141. package/src/devcouncil/planning/spec_service.py +70 -44
  142. package/src/devcouncil/repo/ci_scaffold.py +157 -0
  143. package/src/devcouncil/repo/gitignore.py +123 -0
  144. package/src/devcouncil/repo/sca.py +374 -0
  145. package/src/devcouncil/reporting/github_check.py +32 -32
  146. package/src/devcouncil/reporting/json_report.py +30 -17
  147. package/src/devcouncil/reporting/markdown_report.py +83 -46
  148. package/src/devcouncil/reporting/report_builder.py +14 -14
  149. package/src/devcouncil/skills/__init__.py +19 -0
  150. package/src/devcouncil/skills/library/README.md +46 -0
  151. package/src/devcouncil/skills/library/ai-training.md +50 -0
  152. package/src/devcouncil/skills/library/android.md +50 -0
  153. package/src/devcouncil/skills/library/backend.md +52 -0
  154. package/src/devcouncil/skills/library/core-engineering.md +95 -0
  155. package/src/devcouncil/skills/library/data-engineering.md +47 -0
  156. package/src/devcouncil/skills/library/desktop.md +46 -0
  157. package/src/devcouncil/skills/library/devops.md +48 -0
  158. package/src/devcouncil/skills/library/game-dev.md +46 -0
  159. package/src/devcouncil/skills/library/ios.md +48 -0
  160. package/src/devcouncil/skills/library/mobile-cross-platform.md +46 -0
  161. package/src/devcouncil/skills/library/security.md +48 -0
  162. package/src/devcouncil/skills/library/systems.md +48 -0
  163. package/src/devcouncil/skills/library/web.md +47 -0
  164. package/src/devcouncil/skills/library/windows.md +47 -0
  165. package/src/devcouncil/skills/registry.py +330 -0
  166. package/src/devcouncil/storage/db.py +147 -66
  167. package/src/devcouncil/storage/models.py +204 -83
  168. package/src/devcouncil/storage/native.py +557 -0
  169. package/src/devcouncil/storage/repositories.py +388 -249
  170. package/src/devcouncil/telemetry/cost.py +140 -34
  171. package/src/devcouncil/telemetry/model_pricing.yaml +48 -0
  172. package/src/devcouncil/telemetry/pricing.py +28 -0
  173. package/src/devcouncil/telemetry/traces.py +62 -7
  174. package/src/devcouncil/telemetry/tracker.py +52 -49
  175. package/src/devcouncil/ui/__init__.py +1 -0
  176. package/src/devcouncil/ui/dashboard.py +423 -0
  177. package/src/devcouncil/utils/__init__.py +1 -1
  178. package/src/devcouncil/utils/redaction.py +147 -141
  179. package/src/devcouncil/utils/subprocess_env.py +69 -0
  180. package/src/devcouncil/verification/__init__.py +1 -1
  181. package/src/devcouncil/verification/acceptance_compiler.py +125 -0
  182. package/src/devcouncil/verification/ad_hoc_check.py +129 -0
  183. package/src/devcouncil/verification/diff_coverage.py +353 -0
  184. package/src/devcouncil/verification/implementation_reviewer.py +55 -55
  185. package/src/devcouncil/verification/next_actions.py +189 -0
  186. package/src/devcouncil/verification/sandbox.py +178 -0
  187. package/src/devcouncil/verification/test_resolver.py +91 -0
  188. package/src/devcouncil/verification/verifier.py +1342 -307
  189. package/uv.lock +205 -64
  190. package/src/devcouncil/indexing/symbol_index.py +0 -0
@@ -0,0 +1,225 @@
1
+ """Guarded shell command session for DevCouncil tasks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shlex
7
+ import shutil
8
+ import subprocess
9
+ import uuid
10
+ from pathlib import Path
11
+
12
+ from rich.console import Console
13
+
14
+ from devcouncil.domain.evidence import CommandResult
15
+ from devcouncil.domain.task import Task
16
+ from devcouncil.execution.checkpoints import CheckpointService
17
+ from devcouncil.execution.hook_policy import HookPolicy
18
+ from devcouncil.storage.db import get_db
19
+ from devcouncil.storage.native import ShellCommandRepository, ShellSessionRepository, TaskLeaseRepository
20
+ from devcouncil.storage.repositories import EvidenceRepository, TaskRepository
21
+ from devcouncil.telemetry.traces import TraceLogger
22
+
23
+
24
+ class ShellBackend:
25
+ def run_command(self, command: str, cwd: Path, env: dict[str, str] | None = None) -> subprocess.CompletedProcess[str]:
26
+ raise NotImplementedError
27
+
28
+
29
+ class CommandLoopBackend(ShellBackend):
30
+ def run_command(self, command: str, cwd: Path, env: dict[str, str] | None = None) -> subprocess.CompletedProcess[str]:
31
+ args = shlex.split(command, posix=(os.name != "nt"))
32
+ return subprocess.run(
33
+ args,
34
+ cwd=cwd,
35
+ capture_output=True,
36
+ text=True,
37
+ encoding="utf-8",
38
+ errors="replace",
39
+ env=env,
40
+ )
41
+
42
+
43
+ class ShellWrappedBackend(ShellBackend):
44
+ """Runs each command through an explicit shell (pwsh/bash/zsh/...)."""
45
+
46
+ _LAUNCHERS = {
47
+ "pwsh": ["pwsh", "-NoProfile", "-Command"],
48
+ "powershell": ["powershell", "-NoProfile", "-Command"],
49
+ "bash": ["bash", "-lc"],
50
+ "zsh": ["zsh", "-lc"],
51
+ "sh": ["sh", "-lc"],
52
+ }
53
+
54
+ def __init__(self, shell: str):
55
+ launcher = self._LAUNCHERS.get(shell)
56
+ if launcher is None:
57
+ supported = ", ".join(sorted(self._LAUNCHERS))
58
+ raise ValueError(f"Unknown shell backend '{shell}'. Use auto or one of: {supported}.")
59
+ if not shutil.which(launcher[0]):
60
+ raise ValueError(f"Shell '{launcher[0]}' is not installed or not on PATH.")
61
+ self.launcher = launcher
62
+
63
+ def run_command(self, command: str, cwd: Path, env: dict[str, str] | None = None) -> subprocess.CompletedProcess[str]:
64
+ return subprocess.run(
65
+ [*self.launcher, command],
66
+ cwd=cwd,
67
+ capture_output=True,
68
+ text=True,
69
+ encoding="utf-8",
70
+ errors="replace",
71
+ env=env,
72
+ )
73
+
74
+
75
+ _EVIDENCE_COMMAND_HINTS = ("pytest", "ruff", "mypy", "npm test", "npm run lint", "npm run typecheck")
76
+
77
+ console = Console()
78
+
79
+
80
+ class GuardedShellSession:
81
+ def __init__(self, project_root: Path, task: Task, *, shell: str = "auto"):
82
+ self.project_root = project_root.resolve()
83
+ self.task = task
84
+ self.shell = shell
85
+ # HookPolicy (not the bare TaskPolicyEngine) so a chained command is split into
86
+ # its segments and EACH is allowlisted, plus git-safety denies (force-push,
87
+ # --no-verify, protected-branch reset). Critical for the `--shell bash/zsh`
88
+ # backend, which hands the whole string to a real shell that interprets
89
+ # `;`/`&&`/`|` — a single whole-string allowlist match would let an allowed
90
+ # prefix smuggle an arbitrary command past the gate.
91
+ self.policy = HookPolicy(self.project_root)
92
+ self.backend: ShellBackend = (
93
+ CommandLoopBackend() if shell in {"auto", "loop"} else ShellWrappedBackend(shell)
94
+ )
95
+ self.lease_token: str | None = None
96
+ self.session_id: str | None = None
97
+ self.log_dir = self.project_root / ".devcouncil" / "logs"
98
+ self.log_dir.mkdir(parents=True, exist_ok=True)
99
+
100
+ def start(self, *, force: bool = False) -> None:
101
+ db = get_db(self.project_root)
102
+ if not db:
103
+ raise RuntimeError("DevCouncil not initialized.")
104
+ with db.get_session() as session:
105
+ lease = TaskLeaseRepository(session).acquire(
106
+ self.task.id,
107
+ owner="dev shell",
108
+ agent=self.shell,
109
+ force=force,
110
+ )
111
+ self.lease_token = lease.lease_token
112
+ shell_session = ShellSessionRepository(session).start(
113
+ self.task.id,
114
+ self.shell,
115
+ str(self.project_root),
116
+ lease_id=lease.id,
117
+ )
118
+ self.session_id = shell_session.id
119
+ self.task.status = "running"
120
+ TaskRepository(session).save(self.task)
121
+ CheckpointService(self.project_root).create_before(self.task.id)
122
+
123
+ def finish(self) -> None:
124
+ db = get_db(self.project_root)
125
+ if not db or not self.lease_token:
126
+ return
127
+ with db.get_session() as session:
128
+ if self.session_id:
129
+ ShellSessionRepository(session).finish(self.session_id, "finished")
130
+ TaskLeaseRepository(session).release(self.task.id, self.lease_token)
131
+
132
+ def run_one(self, command: str) -> int:
133
+ normalized = " ".join(command.split())
134
+ decision = self.policy.evaluate_command(normalized, self.task)
135
+ log_id = uuid.uuid4().hex[:8]
136
+ stdout_path = self.log_dir / f"{self.task.id}-{log_id}.stdout.log"
137
+ stderr_path = self.log_dir / f"{self.task.id}-{log_id}.stderr.log"
138
+
139
+ if decision.action == "deny":
140
+ self._record_command(normalized, "denied", reason=decision.reason)
141
+ TraceLogger(self.project_root).log_event(
142
+ "shell_command_denied",
143
+ {"command": normalized, "reason": decision.reason},
144
+ task_id=self.task.id,
145
+ )
146
+ # Tell the user *why* — a silent non-zero exit is unactionable.
147
+ console.print(
148
+ f"[red]Command denied for {self.task.id}:[/red] {decision.reason or 'not permitted by task policy.'}"
149
+ )
150
+ console.print(
151
+ "[dim]Add it to the task's allowed_commands, or run it outside DevCouncil.[/dim]"
152
+ )
153
+ return 1
154
+
155
+ try:
156
+ result = self.backend.run_command(normalized, self.project_root)
157
+ except (NotImplementedError, FileNotFoundError, OSError) as exc:
158
+ self._record_command(normalized, "denied", reason=str(exc))
159
+ console.print(f"[red]Could not run '{normalized}':[/red] {exc}")
160
+ return 1
161
+
162
+ stdout_path.write_text(result.stdout or "", encoding="utf-8")
163
+ stderr_path.write_text(result.stderr or "", encoding="utf-8")
164
+ # Echo the command output so the guarded shell is actually usable.
165
+ if result.stdout:
166
+ console.print(result.stdout, end="", markup=False, highlight=False)
167
+ if result.stderr:
168
+ console.print(result.stderr, end="", markup=False, highlight=False, style="dim")
169
+ status = "finished" if result.returncode == 0 else "failed"
170
+ self._record_command(
171
+ normalized,
172
+ status,
173
+ exit_code=result.returncode,
174
+ stdout_path=str(stdout_path),
175
+ stderr_path=str(stderr_path),
176
+ )
177
+ if any(hint in normalized for hint in _EVIDENCE_COMMAND_HINTS):
178
+ self._save_command_evidence(normalized, result.returncode, result.stdout or result.stderr or "")
179
+ TraceLogger(self.project_root).log_event(
180
+ "shell_command_finished",
181
+ {"command": normalized, "exit_code": result.returncode},
182
+ task_id=self.task.id,
183
+ )
184
+ return result.returncode
185
+
186
+ def _record_command(
187
+ self,
188
+ command: str,
189
+ status: str,
190
+ *,
191
+ exit_code: int | None = None,
192
+ reason: str = "",
193
+ stdout_path: str = "",
194
+ stderr_path: str = "",
195
+ ) -> None:
196
+ db = get_db(self.project_root)
197
+ if not db:
198
+ return
199
+ with db.get_session() as session:
200
+ ShellCommandRepository(session).record(
201
+ self.task.id,
202
+ command,
203
+ status,
204
+ session_id=self.session_id,
205
+ exit_code=exit_code,
206
+ reason=reason,
207
+ stdout_path=stdout_path,
208
+ stderr_path=stderr_path,
209
+ )
210
+
211
+ def _save_command_evidence(self, command: str, exit_code: int, summary: str) -> None:
212
+ db = get_db(self.project_root)
213
+ if not db:
214
+ return
215
+ with db.get_session() as session:
216
+ EvidenceRepository(session).save_command_result(
217
+ self.task.id,
218
+ CommandResult(
219
+ command=command,
220
+ exit_code=exit_code,
221
+ stdout_path="",
222
+ stderr_path="",
223
+ summary=summary[:500],
224
+ ),
225
+ )
@@ -1,34 +1,35 @@
1
- import hashlib
2
- import subprocess
3
- import logging
4
- import re
5
- import shlex
6
- from pathlib import Path
1
+ import hashlib
2
+ import os
3
+ import subprocess
4
+ import logging
5
+ import re
6
+ import shlex
7
+ from pathlib import Path
7
8
  from typing import Literal, Optional
8
- from devcouncil.domain.task import Task
9
- from devcouncil.execution.permissions import PermissionManager
10
- from devcouncil.domain.evidence import CommandResult
9
+ from devcouncil.domain.task import Task
10
+ from devcouncil.execution.permissions import PermissionManager
11
+ from devcouncil.domain.evidence import CommandResult
11
12
  from devcouncil.app.errors import ExecutionError
12
13
 
13
14
  from devcouncil.execution.patch import PatchEngine
14
15
  from devcouncil.execution.paths import resolve_project_path
15
16
  from devcouncil.telemetry.traces import TraceLogger
16
17
  from devcouncil.utils.redaction import redact_string
17
-
18
- logger = logging.getLogger(__name__)
19
-
20
- class TaskRunner:
21
- """Safely executes task actions while enforcing permission boundaries."""
22
-
23
- def __init__(self, project_root: Path, permission_manager: PermissionManager):
24
- self.project_root = project_root
25
- self.permissions = permission_manager
26
- self.patch_engine = PatchEngine(project_root)
27
-
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ class TaskRunner:
22
+ """Safely executes task actions while enforcing permission boundaries."""
23
+
24
+ def __init__(self, project_root: Path, permission_manager: PermissionManager):
25
+ self.project_root = project_root
26
+ self.permissions = permission_manager
27
+ self.patch_engine = PatchEngine(project_root)
28
+
28
29
  def _validate_path_within_root(self, path: str) -> None:
29
30
  """Ensure a path resolves to a location within the project root."""
30
31
  resolve_project_path(self.project_root, path)
31
-
32
+
32
33
  def apply_patch(self, patch: str, task: Task) -> bool:
33
34
  """Apply a patch if permissions allow (all affected files must be in planned_files)."""
34
35
  changes = self._extract_patch_changes(patch)
@@ -81,48 +82,51 @@ class TaskRunner:
81
82
  if not changes:
82
83
  raise ExecutionError("Patch does not declare any affected files.")
83
84
  return changes
84
-
85
- def _normalize_patch_path(self, raw_path: str) -> Optional[str]:
86
- raw_path = raw_path.strip().strip('"')
87
- if raw_path == "/dev/null":
88
- return None
89
- raw_path = re.sub(r"^[ab]/", "", raw_path)
90
- return raw_path.replace("\\", "/")
91
-
92
- def _save_command_log(self, task_id: str, command: str, stream: str, content: str) -> str:
93
- """Save command output to a log file and return the path."""
94
- log_dir = self.project_root / ".devcouncil" / "logs"
95
- log_dir.mkdir(parents=True, exist_ok=True)
96
- cmd_hash = hashlib.sha256(command.encode()).hexdigest()[:8]
85
+
86
+ def _normalize_patch_path(self, raw_path: str) -> Optional[str]:
87
+ raw_path = raw_path.strip().strip('"')
88
+ if raw_path == "/dev/null":
89
+ return None
90
+ raw_path = re.sub(r"^[ab]/", "", raw_path)
91
+ return raw_path.replace("\\", "/")
92
+
93
+ def _save_command_log(self, task_id: str, command: str, stream: str, content: str) -> str:
94
+ """Save command output to a log file and return the path."""
95
+ log_dir = self.project_root / ".devcouncil" / "logs"
96
+ log_dir.mkdir(parents=True, exist_ok=True)
97
+ cmd_hash = hashlib.sha256(command.encode()).hexdigest()[:8]
97
98
  filename = f"{task_id}-{cmd_hash}-{stream}.log"
98
99
  log_path = log_dir / filename
99
100
  log_path.write_text(redact_string(content), encoding="utf-8")
100
101
  return str(log_path)
101
-
102
- def run_command(self, command: str, task: Task) -> CommandResult:
103
- """Execute a shell command if allowed by permissions."""
104
- self.permissions.validate_action("shell", command, task)
105
-
106
- logger.info(f"Executing authorized command: {command}")
107
-
108
- try:
109
- from devcouncil.app.config import load_config
110
- config = load_config(self.project_root)
111
- timeout = config.execution.command_timeout
112
- except Exception:
113
- timeout = 300
114
-
115
- try:
116
- result = subprocess.run(
117
- shlex.split(command, posix=False),
118
- shell=False,
119
- capture_output=True,
120
- text=True,
121
- encoding="utf-8",
122
- errors="replace",
123
- cwd=self.project_root,
124
- timeout=timeout
125
- )
102
+
103
+ def run_command(self, command: str, task: Task) -> CommandResult:
104
+ """Execute a shell command if allowed by permissions."""
105
+ self.permissions.validate_action("shell", command, task)
106
+
107
+ logger.info(f"Executing authorized command: {command}")
108
+
109
+ try:
110
+ from devcouncil.app.config import load_config
111
+ config = load_config(self.project_root)
112
+ timeout = config.execution.command_timeout
113
+ except Exception:
114
+ timeout = 300
115
+
116
+ try:
117
+ result = subprocess.run(
118
+ # POSIX-correct tokenization on POSIX hosts (so quoted args like
119
+ # `pytest -k "a and b"` split right and match the allowlist), Windows
120
+ # rules on Windows. Matches shell_session.py.
121
+ shlex.split(command, posix=(os.name != "nt")),
122
+ shell=False,
123
+ capture_output=True,
124
+ text=True,
125
+ encoding="utf-8",
126
+ errors="replace",
127
+ cwd=self.project_root,
128
+ timeout=timeout
129
+ )
126
130
  stdout = result.stdout or ""
127
131
  stderr = result.stderr or ""
128
132
  stdout_path = self._save_command_log(task.id, command, "stdout", stdout)
@@ -136,20 +140,20 @@ class TaskRunner:
136
140
  summary=f"{command} exited {result.returncode}",
137
141
  )
138
142
  return CommandResult(
139
- command=command,
143
+ command=command,
140
144
  exit_code=result.returncode,
141
145
  stdout_path=stdout_path,
142
146
  stderr_path=stderr_path,
143
147
  summary=f"Exit code {result.returncode}. stdout: {stdout_summary}. stderr: {stderr_summary}"
144
148
  )
145
- except Exception as e:
146
- raise ExecutionError(f"Command execution failed: {e}")
147
-
149
+ except Exception as e:
150
+ raise ExecutionError(f"Command execution failed: {e}")
151
+
148
152
  def write_file(self, path: str, content: str, task: Task):
149
153
  """Write content to a file if allowed by permissions."""
150
154
  self._validate_path_within_root(path)
151
155
  full_path = resolve_project_path(self.project_root, path)
152
- operation = "modify" if full_path.exists() else "create"
156
+ operation: Literal["create", "modify"] = "modify" if full_path.exists() else "create"
153
157
  self.permissions.validate_action("file_write", path, task, operation=operation)
154
158
 
155
159
  logger.info(f"Writing authorized file: {path}")
@@ -1 +1 @@
1
-
1
+