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
@@ -1,44 +1,44 @@
1
- from typing import Any, Callable, Dict, List
2
- import inspect
3
- import logging
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
- class EventBus:
8
- """Simple asynchronous event bus for DevCouncil orchestration."""
9
- def __init__(self):
10
- self._listeners: Dict[str, List[Callable]] = {}
11
-
12
- def subscribe(self, event_type: str, callback: Callable):
13
- if event_type not in self._listeners:
14
- self._listeners[event_type] = []
15
- self._listeners[event_type].append(callback)
16
-
17
- async def emit(self, event_type: str, payload: Any = None):
18
- """Emit an event asynchronously to all registered listeners.
19
-
20
- Supports both sync and async callbacks.
21
- """
22
- logger.debug(f"Event emitted: {event_type}")
23
- if event_type in self._listeners:
24
- for callback in self._listeners[event_type]:
25
- try:
26
- if inspect.iscoroutinefunction(callback):
27
- await callback(payload)
28
- else:
29
- callback(payload)
30
- except Exception as e:
31
- logger.error(f"Error in event listener for {event_type}: {e}")
32
-
33
- # Global event bus instance
34
- bus = EventBus()
35
-
36
- # Standard Event Types
37
- class EventTypes:
38
- PLANNING_STARTED = "planning_started"
39
- PLANNING_COMPLETED = "planning_completed"
40
- TASK_EXECUTING = "task_executing"
41
- TASK_VERIFIED = "task_verified"
42
- TASK_BLOCKED = "task_blocked"
43
- GATE_FAILED = "gate_failed"
44
- MODEL_CALLED = "model_called"
1
+ from typing import Any, Callable, Dict, List
2
+ import inspect
3
+ import logging
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ class EventBus:
8
+ """Simple asynchronous event bus for DevCouncil orchestration."""
9
+ def __init__(self):
10
+ self._listeners: Dict[str, List[Callable]] = {}
11
+
12
+ def subscribe(self, event_type: str, callback: Callable):
13
+ if event_type not in self._listeners:
14
+ self._listeners[event_type] = []
15
+ self._listeners[event_type].append(callback)
16
+
17
+ async def emit(self, event_type: str, payload: Any = None):
18
+ """Emit an event asynchronously to all registered listeners.
19
+
20
+ Supports both sync and async callbacks.
21
+ """
22
+ logger.debug(f"Event emitted: {event_type}")
23
+ if event_type in self._listeners:
24
+ for callback in self._listeners[event_type]:
25
+ try:
26
+ if inspect.iscoroutinefunction(callback):
27
+ await callback(payload)
28
+ else:
29
+ callback(payload)
30
+ except Exception as e:
31
+ logger.error(f"Error in event listener for {event_type}: {e}")
32
+
33
+ # Global event bus instance
34
+ bus = EventBus()
35
+
36
+ # Standard Event Types
37
+ class EventTypes:
38
+ PLANNING_STARTED = "planning_started"
39
+ PLANNING_COMPLETED = "planning_completed"
40
+ TASK_EXECUTING = "task_executing"
41
+ TASK_VERIFIED = "task_verified"
42
+ TASK_BLOCKED = "task_blocked"
43
+ GATE_FAILED = "gate_failed"
44
+ MODEL_CALLED = "model_called"
@@ -1,44 +1,44 @@
1
- import logging
2
- import json
3
- from pathlib import Path
4
- from typing import Optional, Any
5
-
6
- from devcouncil.app.state_machine import StateMachine, ProjectPhase
7
- from devcouncil.app.run_context import RunContext
8
- from devcouncil.app.events import bus, EventTypes
1
+ import logging
2
+ import json
3
+ from pathlib import Path
4
+ from typing import Optional, Any
5
+
6
+ from devcouncil.app.state_machine import StateMachine, ProjectPhase
7
+ from devcouncil.app.run_context import RunContext
8
+ from devcouncil.app.events import bus, EventTypes
9
9
  from devcouncil.storage.db import get_db
10
10
  from devcouncil.storage.repositories import StateRepository
11
11
  from devcouncil.telemetry.traces import TraceLogger
12
-
13
- logger = logging.getLogger(__name__)
14
-
15
- class Orchestrator:
16
- """Central orchestrator managing the workflow lifecycle and state transitions."""
17
- def __init__(self, project_root: Path, persist_state: bool = True):
18
- self.project_root = project_root
19
- self.persist_state = persist_state
20
-
21
- db = get_db(self.project_root)
22
- if db:
23
- with db.get_session() as session:
24
- repo = StateRepository(session)
25
- state = repo.get_state()
26
- if state:
27
- self.state_machine = StateMachine(ProjectPhase(state.current_phase))
28
- self.state_machine._history = [ProjectPhase(p) for p in json.loads(state.history_json)]
29
- else:
30
- self.state_machine = StateMachine(ProjectPhase.NEW)
31
- else:
32
- self.state_machine = StateMachine(ProjectPhase.NEW)
33
-
34
- self.current_run: Optional[RunContext] = None
35
-
36
- def reset_state_machine(self, initial: ProjectPhase = ProjectPhase.NEW):
37
- """Start a new lifecycle sequence without depending on prior persisted phase."""
38
- self.state_machine = StateMachine(initial)
39
-
40
- async def start_run(self, run_id: str, goal: str) -> RunContext:
41
- """Start a new orchestration run."""
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ class Orchestrator:
16
+ """Central orchestrator managing the workflow lifecycle and state transitions."""
17
+ def __init__(self, project_root: Path, persist_state: bool = True):
18
+ self.project_root = project_root
19
+ self.persist_state = persist_state
20
+
21
+ db = get_db(self.project_root)
22
+ if db:
23
+ with db.get_session() as session:
24
+ repo = StateRepository(session)
25
+ state = repo.get_state()
26
+ if state:
27
+ self.state_machine = StateMachine(ProjectPhase(state.current_phase))
28
+ self.state_machine._history = [ProjectPhase(p) for p in json.loads(state.history_json)]
29
+ else:
30
+ self.state_machine = StateMachine(ProjectPhase.NEW)
31
+ else:
32
+ self.state_machine = StateMachine(ProjectPhase.NEW)
33
+
34
+ self.current_run: Optional[RunContext] = None
35
+
36
+ def reset_state_machine(self, initial: ProjectPhase = ProjectPhase.NEW):
37
+ """Start a new lifecycle sequence without depending on prior persisted phase."""
38
+ self.state_machine = StateMachine(initial)
39
+
40
+ async def start_run(self, run_id: str, goal: str) -> RunContext:
41
+ """Start a new orchestration run."""
42
42
  self.current_run = RunContext(
43
43
  run_id=run_id,
44
44
  project_root=str(self.project_root),
@@ -51,24 +51,24 @@ class Orchestrator:
51
51
  run_id=run_id,
52
52
  summary=f"Planning started: {goal}",
53
53
  )
54
-
55
- await bus.emit(EventTypes.PLANNING_STARTED, {"run_id": run_id, "goal": goal})
56
- return self.current_run
57
-
58
- async def transition_to(self, target_phase: ProjectPhase):
59
- """Transition the project phase and emit events."""
60
- old_phase = self.state_machine.phase
61
- self.state_machine.transition(target_phase)
62
-
63
- db = get_db(self.project_root)
64
- if db and self.persist_state:
65
- with db.get_session() as session:
66
- repo = StateRepository(session)
67
- repo.save_state(
68
- self.state_machine.phase.value,
69
- [p.value for p in self.state_machine.history]
70
- )
71
-
54
+
55
+ await bus.emit(EventTypes.PLANNING_STARTED, {"run_id": run_id, "goal": goal})
56
+ return self.current_run
57
+
58
+ async def transition_to(self, target_phase: ProjectPhase):
59
+ """Transition the project phase and emit events."""
60
+ old_phase = self.state_machine.phase
61
+ self.state_machine.transition(target_phase)
62
+
63
+ db = get_db(self.project_root)
64
+ if db and self.persist_state:
65
+ with db.get_session() as session:
66
+ repo = StateRepository(session)
67
+ repo.save_state(
68
+ self.state_machine.phase.value,
69
+ [p.value for p in self.state_machine.history]
70
+ )
71
+
72
72
  logger.info(f"Transitioned from {old_phase.value} to {target_phase.value}")
73
73
  TraceLogger(self.project_root).log_event(
74
74
  "phase_transition",
@@ -79,14 +79,14 @@ class Orchestrator:
79
79
 
80
80
  if target_phase == ProjectPhase.PLAN_APPROVED:
81
81
  await bus.emit(EventTypes.PLANNING_COMPLETED, {"run_id": self.current_run.run_id if self.current_run else None})
82
-
83
- def save_run_artifact(self, name: str, data: Any, is_json: bool = True):
84
- """Save a local artifact specific to this run (in .devcouncil/runs/)."""
85
- if not self.current_run:
86
- logger.warning("Attempted to save artifact without an active run context.")
87
- return
88
-
89
- if is_json:
90
- self.current_run.save_json_artifact(name, data)
91
- else:
92
- self.current_run.save_artifact(name, data)
82
+
83
+ def save_run_artifact(self, name: str, data: Any, is_json: bool = True):
84
+ """Save a local artifact specific to this run (in .devcouncil/runs/)."""
85
+ if not self.current_run:
86
+ logger.warning("Attempted to save artifact without an active run context.")
87
+ return
88
+
89
+ if is_json:
90
+ self.current_run.save_json_artifact(name, data)
91
+ else:
92
+ self.current_run.save_artifact(name, data)
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ from devcouncil.artifacts.graph import ArtifactGraph
4
+
5
+
6
+ def compute_phase(graph: ArtifactGraph, persisted_phase: str | None = None) -> str:
7
+ """Compute the current project phase, honoring explicit persisted state first."""
8
+ if persisted_phase:
9
+ return persisted_phase
10
+
11
+ reqs = list(graph.requirements.values())
12
+ tasks = list(graph.tasks.values())
13
+ blocking_gaps = graph.blocking_gaps()
14
+ if not reqs and not tasks:
15
+ return "NEW"
16
+ if reqs and not tasks:
17
+ return "REQUIREMENTS_DRAFTED"
18
+ if blocking_gaps:
19
+ return "TASK_BLOCKED"
20
+ if tasks:
21
+ statuses = {task.status for task in tasks}
22
+ if "running" in statuses:
23
+ return "TASK_EXECUTING"
24
+ if "blocked" in statuses:
25
+ return "TASK_BLOCKED"
26
+ if all(status in {"verified", "done"} for status in statuses):
27
+ return "PROJECT_DONE"
28
+ return "PLAN_APPROVED"
29
+ return "NEW"
@@ -1,39 +1,39 @@
1
- from pathlib import Path
2
- from datetime import datetime, timezone
3
- from pydantic import BaseModel, Field
4
- from typing import Optional, List, Dict, Any
5
- import json
6
- import logging
7
-
8
- logger = logging.getLogger(__name__)
9
-
10
- class RunContext(BaseModel):
11
- """Context object encapsulating the current execution run."""
12
- run_id: str
13
- project_root: str
14
- goal: Optional[str] = None
15
- start_time: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
16
- active_tasks: List[str] = Field(default_factory=list)
17
- metadata: Dict[str, Any] = Field(default_factory=dict)
18
-
19
- @property
20
- def run_dir(self) -> Path:
21
- return Path(self.project_root) / ".devcouncil" / "runs" / self.run_id
22
-
23
- def initialize(self):
24
- """Create the necessary run directory and sub-folders."""
25
- self.run_dir.mkdir(parents=True, exist_ok=True)
26
- logger.info(f"Initialized run context at {self.run_dir}")
27
-
28
- def save_artifact(self, filename: str, content: str):
29
- """Save a text artifact associated with this run."""
30
- path = self.run_dir / filename
31
- path.write_text(content, encoding="utf-8")
32
- logger.debug(f"Saved artifact to {path}")
33
-
34
- def save_json_artifact(self, filename: str, data: Any):
35
- """Save a JSON artifact associated with this run."""
36
- path = self.run_dir / filename
37
- with open(path, "w", encoding="utf-8") as f:
38
- json.dump(data, f, indent=2)
39
- logger.debug(f"Saved JSON artifact to {path}")
1
+ from pathlib import Path
2
+ from datetime import datetime, timezone
3
+ from pydantic import BaseModel, Field
4
+ from typing import Optional, List, Dict, Any
5
+ import json
6
+ import logging
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+ class RunContext(BaseModel):
11
+ """Context object encapsulating the current execution run."""
12
+ run_id: str
13
+ project_root: str
14
+ goal: Optional[str] = None
15
+ start_time: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
16
+ active_tasks: List[str] = Field(default_factory=list)
17
+ metadata: Dict[str, Any] = Field(default_factory=dict)
18
+
19
+ @property
20
+ def run_dir(self) -> Path:
21
+ return Path(self.project_root) / ".devcouncil" / "runs" / self.run_id
22
+
23
+ def initialize(self):
24
+ """Create the necessary run directory and sub-folders."""
25
+ self.run_dir.mkdir(parents=True, exist_ok=True)
26
+ logger.info(f"Initialized run context at {self.run_dir}")
27
+
28
+ def save_artifact(self, filename: str, content: str):
29
+ """Save a text artifact associated with this run."""
30
+ path = self.run_dir / filename
31
+ path.write_text(content, encoding="utf-8")
32
+ logger.debug(f"Saved artifact to {path}")
33
+
34
+ def save_json_artifact(self, filename: str, data: Any):
35
+ """Save a JSON artifact associated with this run."""
36
+ path = self.run_dir / filename
37
+ with open(path, "w", encoding="utf-8") as f:
38
+ json.dump(data, f, indent=2)
39
+ logger.debug(f"Saved JSON artifact to {path}")
@@ -1,108 +1,108 @@
1
- """Gating state machine for DevCouncil project lifecycle.
2
-
3
- States (from §12):
4
- NEW -> REPO_MAPPED -> REQUIREMENTS_DRAFTED -> PLANS_GENERATED
5
- -> CRITIQUES_GENERATED -> ARBITRATED -> AWAITING_USER_DECISIONS
6
- -> PLAN_APPROVED -> TASK_READY -> TASK_EXECUTING -> TASK_VERIFYING
7
- -> TASK_BLOCKED | TASK_VERIFIED -> PROJECT_DONE
8
- """
9
-
10
- from __future__ import annotations
11
-
12
- from enum import Enum
13
- from typing import Dict, List, Set
14
-
15
-
16
-
17
- class ProjectPhase(str, Enum):
18
- NEW = "NEW"
19
- REPO_MAPPED = "REPO_MAPPED"
20
- REQUIREMENTS_DRAFTED = "REQUIREMENTS_DRAFTED"
21
- PLANS_GENERATED = "PLANS_GENERATED"
22
- CRITIQUES_GENERATED = "CRITIQUES_GENERATED"
23
- ARBITRATED = "ARBITRATED"
24
- AWAITING_USER_DECISIONS = "AWAITING_USER_DECISIONS"
25
- PLAN_APPROVED = "PLAN_APPROVED"
26
- TASK_READY = "TASK_READY"
27
- TASK_EXECUTING = "TASK_EXECUTING"
28
- TASK_VERIFYING = "TASK_VERIFYING"
29
- TASK_BLOCKED = "TASK_BLOCKED"
30
- TASK_VERIFIED = "TASK_VERIFIED"
31
- PROJECT_DONE = "PROJECT_DONE"
32
-
33
-
34
- # Valid transitions: from_phase -> set of valid next phases
35
- TRANSITIONS: Dict[ProjectPhase, Set[ProjectPhase]] = {
36
- ProjectPhase.NEW: {ProjectPhase.REPO_MAPPED},
37
- ProjectPhase.REPO_MAPPED: {ProjectPhase.REQUIREMENTS_DRAFTED},
38
- ProjectPhase.REQUIREMENTS_DRAFTED: {ProjectPhase.PLANS_GENERATED},
39
- ProjectPhase.PLANS_GENERATED: {ProjectPhase.CRITIQUES_GENERATED},
40
- ProjectPhase.CRITIQUES_GENERATED: {ProjectPhase.ARBITRATED},
41
- ProjectPhase.ARBITRATED: {
42
- ProjectPhase.AWAITING_USER_DECISIONS,
43
- ProjectPhase.PLAN_APPROVED,
44
- },
45
- ProjectPhase.AWAITING_USER_DECISIONS: {ProjectPhase.PLAN_APPROVED},
46
- ProjectPhase.PLAN_APPROVED: {ProjectPhase.TASK_READY},
47
- ProjectPhase.TASK_READY: {ProjectPhase.TASK_EXECUTING},
48
- ProjectPhase.TASK_EXECUTING: {ProjectPhase.TASK_VERIFYING},
49
- ProjectPhase.TASK_VERIFYING: {
50
- ProjectPhase.TASK_VERIFIED,
51
- ProjectPhase.TASK_BLOCKED,
52
- },
53
- ProjectPhase.TASK_BLOCKED: {
54
- ProjectPhase.TASK_READY, # after repair
55
- },
56
- ProjectPhase.TASK_VERIFIED: {
57
- ProjectPhase.TASK_READY, # next task
58
- ProjectPhase.PROJECT_DONE,
59
- },
60
- ProjectPhase.PROJECT_DONE: set(),
61
- }
62
-
63
-
64
- class InvalidTransitionError(Exception):
65
- """Raised when a state transition is not allowed."""
66
-
67
- def __init__(self, current: ProjectPhase, target: ProjectPhase):
68
- self.current = current
69
- self.target = target
70
- super().__init__(
71
- f"Invalid transition: {current.value} -> {target.value}. "
72
- f"Valid targets: {', '.join(t.value for t in TRANSITIONS.get(current, set()))}"
73
- )
74
-
75
-
76
- class StateMachine:
77
- """Manages project phase transitions with validation."""
78
-
79
- def __init__(self, initial: ProjectPhase = ProjectPhase.NEW):
80
- self._phase = initial
81
- self._history: List[ProjectPhase] = [initial]
82
-
83
- @property
84
- def phase(self) -> ProjectPhase:
85
- return self._phase
86
-
87
- @property
88
- def history(self) -> List[ProjectPhase]:
89
- return list(self._history)
90
-
91
- def can_transition(self, target: ProjectPhase) -> bool:
92
- """Check if a transition to the target phase is valid."""
93
- valid = TRANSITIONS.get(self._phase, set())
94
- return target in valid
95
-
96
- def transition(self, target: ProjectPhase) -> None:
97
- """Transition to a new phase.
98
-
99
- Raises InvalidTransitionError if the transition is not allowed.
100
- """
101
- if not self.can_transition(target):
102
- raise InvalidTransitionError(self._phase, target)
103
- self._phase = target
104
- self._history.append(target)
105
-
106
- def valid_transitions(self) -> Set[ProjectPhase]:
107
- """Return the set of valid next phases from the current state."""
108
- return TRANSITIONS.get(self._phase, set())
1
+ """Gating state machine for DevCouncil project lifecycle.
2
+
3
+ States (from §12):
4
+ NEW -> REPO_MAPPED -> REQUIREMENTS_DRAFTED -> PLANS_GENERATED
5
+ -> CRITIQUES_GENERATED -> ARBITRATED -> AWAITING_USER_DECISIONS
6
+ -> PLAN_APPROVED -> TASK_READY -> TASK_EXECUTING -> TASK_VERIFYING
7
+ -> TASK_BLOCKED | TASK_VERIFIED -> PROJECT_DONE
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from enum import Enum
13
+ from typing import Dict, List, Set
14
+
15
+
16
+
17
+ class ProjectPhase(str, Enum):
18
+ NEW = "NEW"
19
+ REPO_MAPPED = "REPO_MAPPED"
20
+ REQUIREMENTS_DRAFTED = "REQUIREMENTS_DRAFTED"
21
+ PLANS_GENERATED = "PLANS_GENERATED"
22
+ CRITIQUES_GENERATED = "CRITIQUES_GENERATED"
23
+ ARBITRATED = "ARBITRATED"
24
+ AWAITING_USER_DECISIONS = "AWAITING_USER_DECISIONS"
25
+ PLAN_APPROVED = "PLAN_APPROVED"
26
+ TASK_READY = "TASK_READY"
27
+ TASK_EXECUTING = "TASK_EXECUTING"
28
+ TASK_VERIFYING = "TASK_VERIFYING"
29
+ TASK_BLOCKED = "TASK_BLOCKED"
30
+ TASK_VERIFIED = "TASK_VERIFIED"
31
+ PROJECT_DONE = "PROJECT_DONE"
32
+
33
+
34
+ # Valid transitions: from_phase -> set of valid next phases
35
+ TRANSITIONS: Dict[ProjectPhase, Set[ProjectPhase]] = {
36
+ ProjectPhase.NEW: {ProjectPhase.REPO_MAPPED},
37
+ ProjectPhase.REPO_MAPPED: {ProjectPhase.REQUIREMENTS_DRAFTED},
38
+ ProjectPhase.REQUIREMENTS_DRAFTED: {ProjectPhase.PLANS_GENERATED},
39
+ ProjectPhase.PLANS_GENERATED: {ProjectPhase.CRITIQUES_GENERATED},
40
+ ProjectPhase.CRITIQUES_GENERATED: {ProjectPhase.ARBITRATED},
41
+ ProjectPhase.ARBITRATED: {
42
+ ProjectPhase.AWAITING_USER_DECISIONS,
43
+ ProjectPhase.PLAN_APPROVED,
44
+ },
45
+ ProjectPhase.AWAITING_USER_DECISIONS: {ProjectPhase.PLAN_APPROVED},
46
+ ProjectPhase.PLAN_APPROVED: {ProjectPhase.TASK_READY},
47
+ ProjectPhase.TASK_READY: {ProjectPhase.TASK_EXECUTING},
48
+ ProjectPhase.TASK_EXECUTING: {ProjectPhase.TASK_VERIFYING},
49
+ ProjectPhase.TASK_VERIFYING: {
50
+ ProjectPhase.TASK_VERIFIED,
51
+ ProjectPhase.TASK_BLOCKED,
52
+ },
53
+ ProjectPhase.TASK_BLOCKED: {
54
+ ProjectPhase.TASK_READY, # after repair
55
+ },
56
+ ProjectPhase.TASK_VERIFIED: {
57
+ ProjectPhase.TASK_READY, # next task
58
+ ProjectPhase.PROJECT_DONE,
59
+ },
60
+ ProjectPhase.PROJECT_DONE: set(),
61
+ }
62
+
63
+
64
+ class InvalidTransitionError(Exception):
65
+ """Raised when a state transition is not allowed."""
66
+
67
+ def __init__(self, current: ProjectPhase, target: ProjectPhase):
68
+ self.current = current
69
+ self.target = target
70
+ super().__init__(
71
+ f"Invalid transition: {current.value} -> {target.value}. "
72
+ f"Valid targets: {', '.join(t.value for t in TRANSITIONS.get(current, set()))}"
73
+ )
74
+
75
+
76
+ class StateMachine:
77
+ """Manages project phase transitions with validation."""
78
+
79
+ def __init__(self, initial: ProjectPhase = ProjectPhase.NEW):
80
+ self._phase = initial
81
+ self._history: List[ProjectPhase] = [initial]
82
+
83
+ @property
84
+ def phase(self) -> ProjectPhase:
85
+ return self._phase
86
+
87
+ @property
88
+ def history(self) -> List[ProjectPhase]:
89
+ return list(self._history)
90
+
91
+ def can_transition(self, target: ProjectPhase) -> bool:
92
+ """Check if a transition to the target phase is valid."""
93
+ valid = TRANSITIONS.get(self._phase, set())
94
+ return target in valid
95
+
96
+ def transition(self, target: ProjectPhase) -> None:
97
+ """Transition to a new phase.
98
+
99
+ Raises InvalidTransitionError if the transition is not allowed.
100
+ """
101
+ if not self.can_transition(target):
102
+ raise InvalidTransitionError(self._phase, target)
103
+ self._phase = target
104
+ self._history.append(target)
105
+
106
+ def valid_transitions(self) -> Set[ProjectPhase]:
107
+ """Return the set of valid next phases from the current state."""
108
+ return TRANSITIONS.get(self._phase, set())
@@ -1 +1 @@
1
- """Artifact package: graph, coverage, and validation for the persistent artifact DAG."""
1
+ """Artifact package: graph, coverage, and validation for the persistent artifact DAG."""