Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/blackcell/adapters/execution/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,40 @@ def validate_base_commit(self, repository_root: Path, base_commit: str) -> None:
if commit.return_code != 0:
raise WorktreeLifecycleError(WorktreeFailureCode.BASE_COMMIT_NOT_FOUND)

def changed_paths_between(
self,
repository_root: Path,
*,
base_commit: str,
head_commit: str,
) -> tuple[str, ...]:
"""Return normalized cumulative path effects for one admitted commit range."""

root = _canonical_repository_root(repository_root)
self.validate_base_commit(root, base_commit)
self.validate_base_commit(root, head_commit)
ancestor = self._git_at(
root,
("merge-base", "--is-ancestor", base_commit, head_commit),
)
if ancestor.return_code != 0:
raise WorktreeLifecycleError(WorktreeFailureCode.WORKTREE_CONFLICT)
changed = self._require_success(
self._git_at(
root,
(
"diff",
"--name-only",
"--no-renames",
"-z",
base_commit,
head_commit,
"--",
),
)
)
return self._path_output(changed)

def retain_plan_base_commit(
self,
repository_root: Path,
Expand Down
389 changes: 368 additions & 21 deletions src/blackcell/bootstrap/execution_plan.py

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions src/blackcell/bootstrap/execution_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
MAX_CHANGE_PROPOSAL_BYTES,
)
from blackcell.orchestration.execution_plan import (
ExecutionAuthority,
ExecutionPolicyKernel,
GoalSpec,
PlanningRequest,
RunLifecycleStatus,
planning_payload,
Expand Down Expand Up @@ -101,6 +103,10 @@ def run_once(self) -> ExecutionWorkerCycleResult: ...
class ExecutionReconciliationPort(Protocol):
def next_generated_run(self) -> GeneratedRun | None: ...

def generated_execution_goal(self, run_id: str) -> GoalSpec: ...

def generated_execution_authority(self, run_id: str) -> ExecutionAuthority: ...

def should_cancel_generated_run(self, run_id: str) -> bool: ...

def reconcile_startup(self, *, principal_id: str) -> tuple[object, ...]: ...
Expand Down Expand Up @@ -202,6 +208,7 @@ def from_config(
evidence=ExecutionEvidenceCollector(boundaries.worktrees),
changes=TextChangeExecutor(boundaries.worktrees),
cancel_requested=runtime.should_cancel_generated_run,
authority_for_run=runtime.generated_execution_authority,
)
observer = (
None if telemetry.recorder is None else ExecutionTraceObserver(telemetry.recorder)
Expand All @@ -216,7 +223,9 @@ def from_config(
boundaries.planner,
execution_executor,
ExecutionPolicyKernel(),
)
),
authority_for_run=runtime.generated_execution_authority,
goal_for_run=runtime.generated_execution_goal,
)
except Exception:
telemetry.shutdown()
Expand Down Expand Up @@ -253,11 +262,14 @@ def _run_generated_once(
generated = self.runtime.next_generated_run()
if generated is None:
return None
budget = GatewayBudget(
config.provider.max_input_tokens,
config.provider.max_output_tokens,
config.provider.timeout_ceiling_seconds * 1_000,
config.provider.max_cost_microusd,
budget = _intersect_budget(
GatewayBudget(
config.provider.max_input_tokens,
config.provider.max_output_tokens,
config.provider.timeout_ceiling_seconds * 1_000,
config.provider.max_cost_microusd,
),
generated.authority.budget,
)
payload_size = len(canonical_json_bytes(planning_payload(generated.goal)))
request = PlanningRequest(
Expand Down Expand Up @@ -336,6 +348,15 @@ def serve(self, *, once: bool = False) -> int:
self.shutdown()


def _intersect_budget(left: GatewayBudget, right: GatewayBudget) -> GatewayBudget:
return GatewayBudget(
min(left.max_input_tokens, right.max_input_tokens),
min(left.max_output_tokens, right.max_output_tokens),
min(left.max_latency_ms, right.max_latency_ms),
min(left.max_cost_microusd, right.max_cost_microusd),
)


def validate_execution_worker_runtime_config(
config: RuntimeProcessConfig,
*,
Expand Down
Loading