Jonathan Haas commited on
Commit ·
cd2e524
1
Parent(s): 997bd23
refactor: split planner and automation action handlers
Browse filesFiles changed (10)
- TODO.md+58-52
- src/jarvis/tools/services_domains/home_orch_automation_apply_action.pyAdded+90
- src/jarvis/tools/services_domains/home_orch_automation_apply_status.py+9-200
- src/jarvis/tools/services_domains/home_orch_automation_rollback_action.pyAdded+85
- src/jarvis/tools/services_domains/home_orch_automation_status_action.pyAdded+52
- src/jarvis/tools/services_domains/planner_engine_plan_action.pyAdded+46
- src/jarvis/tools/services_domains/planner_engine_plan_graph.py+15-191
- src/jarvis/tools/services_domains/planner_engine_self_critique_action.pyAdded+36
- src/jarvis/tools/services_domains/planner_engine_task_graph_actions.pyAdded+135
- tests/test_import_boundaries.py+6
12343 unmodified lines891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677# Jarvis TODO — Wave 65 (Smart-Home Mutation Policy Split)Last updated: 2026-02-273 unmodified lines- `[x]` Completed## Completion summary- Total items: 31- Completed: 31- Remaining: 0---## A) Scope and baseline- [x] `W65-A01` Profile post-Wave-64 hotspots and select highest policy-concentration candidate.- [x] `W65-A02` Select `home_mutation_policy.py` for focused decomposition.- [x] `W65-A03` Preserve all `smart_home` response text and policy decisions.- [x] `W65-A04` Preserve identity/audit/preview semantics and guardrail ordering.## B) Validation + identity split- [x] `W65-B01` Create `home_mutation_policy_validate_identity.py`.- [x] `W65-B02` Move field/domain/action/data validation checks.- [x] `W65-B03` Move dry-run/safe-mode normalization.- [x] `W65-B04` Move identity authorization and denied audit path.- [x] `W65-B05` Move strict-confirm and sensitive-confirm enforcement.- [x] `W65-B06` Return normalized context payload for downstream guardrails.## C) Guardrail split- [x] `W65-C01` Create `home_mutation_policy_guardrails.py`.- [x] `W65-C02` Move ambiguous high-risk target denial logic.- [x] `W65-C03` Move area-policy enforcement logic.- [x] `W65-C04` Move plan-preview gating and preview audit path.- [x] `W65-C05` Preserve preview risk-level mapping by domain sensitivity.## D) Wrapper reduction- [x] `W65-D01` Reduce `home_mutation_policy.py` to orchestrator wrapper.- [x] `W65-D02` Wire wrapper through validate-then-guardrails flow.## E) Boundaries and validation- [x] `W65-E01` Extend import-boundary coverage for new policy split modules.- [x] `W65-E02` Run focused lint on changed modules.- [x] `W65-E03` Run targeted pytest for `smart_home` behavior.- [x] `W65-E04` Run `tests/test_import_boundaries.py`.- [x] `W65-E05` Run full `make check`.- [x] `W65-E06` Run full `make security-gate`.- [x] `W65-E07` Run `./scripts/jarvis_readiness.sh fast`.## F) Release loop- [x] `W65-F01` Record line-count outcomes for split module.- [x] `W65-F02` Commit Wave 65 tranche.- [x] `W65-F03` Push Wave 65 to origin/main.---## Outcome snapshot (completed)- Wrapper concentration reduction:- `home_mutation_policy.py`: `231 -> 26`- New extracted modules:- `home_mutation_policy_validate_identity.py`- `home_mutation_policy_guardrails.py`- Validation status:- Focused lint: pass.- Targeted pytest (`smart_home`): `41 passed`.- `tests/test_import_boundaries.py`: pass.- `make check`: `702 passed`.- `make security-gate`: `702 passed`; fault subset `3 passed`.- `./scripts/jarvis_readiness.sh fast`: pass; strict eval `159/159`.12343 unmodified lines891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283# Jarvis TODO — Wave 66 (Planner + Automation Action Decomposition)Last updated: 2026-02-273 unmodified lines- `[x]` Completed## Completion summary- Total items: 36- Completed: 36- Remaining: 0---## A) Scope and baseline- [x] `W66-A01` Profile current largest remaining service-domain modules.- [x] `W66-A02` Select `home_orch_automation_apply_status.py` for action-level split.- [x] `W66-A03` Select `planner_engine_plan_graph.py` for action-level split.- [x] `W66-A04` Preserve action contracts and response payload compatibility.## B) Home automation action split- [x] `W66-B01` Create `home_orch_automation_apply_action.py`.- [x] `W66-B02` Move `home_orch_automation_apply` implementation.- [x] `W66-B03` Create `home_orch_automation_rollback_action.py`.- [x] `W66-B04` Move `home_orch_automation_rollback` implementation.- [x] `W66-B05` Create `home_orch_automation_status_action.py`.- [x] `W66-B06` Move `home_orch_automation_status` implementation.- [x] `W66-B07` Reduce `home_orch_automation_apply_status.py` to export wrapper.## C) Planner plan/graph split- [x] `W66-C01` Create `planner_engine_plan_action.py`.- [x] `W66-C02` Move `planner_plan` implementation.- [x] `W66-C03` Create `planner_engine_task_graph_actions.py`.- [x] `W66-C04` Move `planner_task_graph_create` implementation.- [x] `W66-C05` Move `planner_task_graph_update` implementation.- [x] `W66-C06` Move `planner_task_graph_resume` implementation.- [x] `W66-C07` Create `planner_engine_self_critique_action.py`.- [x] `W66-C08` Move `planner_self_critique` implementation.- [x] `W66-C09` Reduce `planner_engine_plan_graph.py` to export wrapper.## D) Boundaries and validation- [x] `W66-D01` Extend import-boundary coverage for new home automation action modules.- [x] `W66-D02` Extend import-boundary coverage for new planner action modules.- [x] `W66-D03` Run focused lint on all changed modules.- [x] `W66-D04` Run targeted pytest for automation/planner flows.- [x] `W66-D05` Run `tests/test_import_boundaries.py`.- [x] `W66-D06` Run full `make check`.- [x] `W66-D07` Run full `make security-gate`.- [x] `W66-D08` Run `./scripts/jarvis_readiness.sh fast`.## E) Release loop- [x] `W66-E01` Record line-count outcomes for wrapper reductions.- [x] `W66-E02` Commit Wave 66 tranche.- [x] `W66-E03` Push Wave 66 to origin/main.---## Outcome snapshot (completed)- Wrapper concentration reductions:- `home_orch_automation_apply_status.py`: `204 -> 13`- `planner_engine_plan_graph.py`: `195 -> 19`- New extracted modules:- `home_orch_automation_apply_action.py`- `home_orch_automation_rollback_action.py`- `home_orch_automation_status_action.py`- `planner_engine_plan_action.py`- `planner_engine_task_graph_actions.py`- `planner_engine_self_critique_action.py`- Validation status:- Focused lint: pass.- Targeted pytest: pass.- `tests/test_import_boundaries.py`: pass.- `make check`: `708 passed`.- `make security-gate`: `708 passed`; fault subset `3 passed`.- `./scripts/jarvis_readiness.sh fast`: pass; strict eval `159/159`.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990"""Apply action for home automation drafts."""
from __future__ import annotations
import timefrom typing import Any
def _services(): from jarvis.tools import services as s
return s
async def home_orch_automation_apply(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _record_service_error = s._record_service_error _expansion_payload_response = s._expansion_payload_response _as_bool = s._as_bool _home_automation_drafts = s._home_automation_drafts _home_automation_applied = s._home_automation_applied _automation_entry_from_draft = s._automation_entry_from_draft _structured_diff = s._structured_diff _apply_ha_automation_config = s._apply_ha_automation_config
draft_id = str(args.get("draft_id", "")).strip() draft = _home_automation_drafts.get(draft_id) if not isinstance(draft, dict): _record_service_error("home_orchestrator", start_time, "not_found") return {"content": [{"type": "text", "text": "draft_id not found."}]} automation_id = str(draft.get("automation_id", "")).strip() dry_run = _as_bool(args.get("dry_run"), default=True) confirm = _as_bool(args.get("confirm"), default=False) ha_apply = _as_bool(args.get("ha_apply"), default=True) applied_row = _home_automation_applied.get(automation_id, {}) previous = applied_row.get("current") if isinstance(applied_row, dict) and isinstance(applied_row.get("current"), dict) else {} current = draft.get("config") if isinstance(draft.get("config"), dict) else {} diff = _structured_diff(previous if isinstance(previous, dict) else {}, current if isinstance(current, dict) else {}) if dry_run: payload = { "action": "automation_apply", "dry_run": True, "draft": _automation_entry_from_draft(draft), "diff": diff, "ha_apply": bool(ha_apply), } record_summary("home_orchestrator", "ok", start_time, effect="automation_apply_preview", risk="low") return _expansion_payload_response(payload) if not confirm: _record_service_error("home_orchestrator", start_time, "confirm_required") return {"content": [{"type": "text", "text": "automation_apply requires confirm=true when dry_run=false."}]} ha_status = "skipped" if ha_apply: ok, error_code = await _apply_ha_automation_config(automation_id, current if isinstance(current, dict) else {}) if not ok: _record_service_error("home_orchestrator", start_time, error_code or "unexpected") return {"content": [{"type": "text", "text": f"Home Assistant automation apply failed: {error_code or 'unexpected'}."}]} ha_status = "applied" row = _home_automation_applied.setdefault(automation_id, {"history": []}) history = row.get("history") if not isinstance(history, list): history = [] existing_current = row.get("current") if isinstance(existing_current, dict) and existing_current: history.append( { "config": existing_current, "saved_at": float(row.get("updated_at", time.time()) or time.time()), "source_draft_id": str(row.get("last_draft_id", "")), } ) if len(history) > 20: history = history[-20:] row["history"] = history row["current"] = current row["updated_at"] = time.time() row["last_draft_id"] = draft_id draft["status"] = "applied" draft["updated_at"] = time.time() payload = { "action": "automation_apply", "dry_run": False, "applied": True, "ha_status": ha_status, "draft": _automation_entry_from_draft(draft), "diff": diff, } record_summary("home_orchestrator", "ok", start_time, effect="automation_apply", risk="medium") return _expansion_payload_response(payload)1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032041 unmodified linefrom __future__ import annotationsimport timefrom typing import Anydef _services():from jarvis.tools import services as sreturn sasync def home_orch_automation_apply(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_record_service_error = s._record_service_error_expansion_payload_response = s._expansion_payload_response_as_bool = s._as_bool_home_automation_drafts = s._home_automation_drafts_home_automation_applied = s._home_automation_applied_automation_entry_from_draft = s._automation_entry_from_draft_structured_diff = s._structured_diff_apply_ha_automation_config = s._apply_ha_automation_configdraft_id = str(args.get("draft_id", "")).strip()draft = _home_automation_drafts.get(draft_id)if not isinstance(draft, dict):_record_service_error("home_orchestrator", start_time, "not_found")return {"content": [{"type": "text", "text": "draft_id not found."}]}automation_id = str(draft.get("automation_id", "")).strip()dry_run = _as_bool(args.get("dry_run"), default=True)confirm = _as_bool(args.get("confirm"), default=False)ha_apply = _as_bool(args.get("ha_apply"), default=True)applied_row = _home_automation_applied.get(automation_id, {})previous = applied_row.get("current") if isinstance(applied_row, dict) and isinstance(applied_row.get("current"), dict) else {}current = draft.get("config") if isinstance(draft.get("config"), dict) else {}diff = _structured_diff(previous if isinstance(previous, dict) else {}, current if isinstance(current, dict) else {})if dry_run:payload = {"action": "automation_apply","dry_run": True,"draft": _automation_entry_from_draft(draft),"diff": diff,"ha_apply": bool(ha_apply),}record_summary("home_orchestrator", "ok", start_time, effect="automation_apply_preview", risk="low")return _expansion_payload_response(payload)if not confirm:_record_service_error("home_orchestrator", start_time, "confirm_required")return {"content": [{"type": "text", "text": "automation_apply requires confirm=true when dry_run=false."}]}ha_status = "skipped"if ha_apply:ok, error_code = await _apply_ha_automation_config(automation_id, current if isinstance(current, dict) else {})if not ok:_record_service_error("home_orchestrator", start_time, error_code or "unexpected")return {"content": [{"type": "text", "text": f"Home Assistant automation apply failed: {error_code or 'unexpected'}."}]}ha_status = "applied"row = _home_automation_applied.setdefault(automation_id, {"history": []})history = row.get("history")if not isinstance(history, list):history = []existing_current = row.get("current")if isinstance(existing_current, dict) and existing_current:history.append({"config": existing_current,"saved_at": float(row.get("updated_at", time.time()) or time.time()),"source_draft_id": str(row.get("last_draft_id", "")),})if len(history) > 20:history = history[-20:]row["history"] = historyrow["current"] = currentrow["updated_at"] = time.time()row["last_draft_id"] = draft_iddraft["status"] = "applied"draft["updated_at"] = time.time()payload = {"action": "automation_apply","dry_run": False,"applied": True,"ha_status": ha_status,"draft": _automation_entry_from_draft(draft),"diff": diff,}record_summary("home_orchestrator", "ok", start_time, effect="automation_apply", risk="medium")return _expansion_payload_response(payload)async def home_orch_automation_rollback(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_record_service_error = s._record_service_error_expansion_payload_response = s._expansion_payload_response_as_bool = s._as_bool_slugify_identifier = s._slugify_identifier_home_automation_applied = s._home_automation_applied_structured_diff = s._structured_diff_apply_ha_automation_config = s._apply_ha_automation_config_delete_ha_automation_config = s._delete_ha_automation_configautomation_id = _slugify_identifier(str(args.get("automation_id", "")).strip(), fallback="")if not automation_id:_record_service_error("home_orchestrator", start_time, "missing_fields")return {"content": [{"type": "text", "text": "automation_id is required for automation_rollback."}]}row = _home_automation_applied.get(automation_id)if not isinstance(row, dict):_record_service_error("home_orchestrator", start_time, "not_found")return {"content": [{"type": "text", "text": "automation_id has no applied state."}]}current = row.get("current") if isinstance(row.get("current"), dict) else {}history = row.get("history") if isinstance(row.get("history"), list) else []previous_entry = history[-1] if history else {}previous = previous_entry.get("config") if isinstance(previous_entry, dict) and isinstance(previous_entry.get("config"), dict) else {}dry_run = _as_bool(args.get("dry_run"), default=True)confirm = _as_bool(args.get("confirm"), default=False)ha_apply = _as_bool(args.get("ha_apply"), default=True)diff = _structured_diff(current if isinstance(current, dict) else {}, previous if isinstance(previous, dict) else {})if dry_run:payload = {"action": "automation_rollback","dry_run": True,"automation_id": automation_id,"has_previous_revision": bool(previous),"diff": diff,"ha_apply": bool(ha_apply),}record_summary("home_orchestrator", "ok", start_time, effect="automation_rollback_preview", risk="low")return _expansion_payload_response(payload)if not confirm:_record_service_error("home_orchestrator", start_time, "confirm_required")return {"content": [{"type": "text", "text": "automation_rollback requires confirm=true when dry_run=false."}]}ha_status = "skipped"if ha_apply:if isinstance(previous, dict) and previous:ok, error_code = await _apply_ha_automation_config(automation_id, previous)else:ok, error_code = await _delete_ha_automation_config(automation_id)if not ok:_record_service_error("home_orchestrator", start_time, error_code or "unexpected")return {"content": [{"type": "text", "text": f"Home Assistant automation rollback failed: {error_code or 'unexpected'}."}]}ha_status = "rolled_back"if history:history.pop()if isinstance(previous, dict) and previous:row["current"] = previousrow["history"] = historyrow["updated_at"] = time.time()else:_home_automation_applied.pop(automation_id, None)payload = {"action": "automation_rollback","dry_run": False,"rolled_back": True,"ha_status": ha_status,"automation_id": automation_id,"restored_revision": bool(previous),"diff": diff,}record_summary("home_orchestrator", "ok", start_time, effect="automation_rollback", risk="medium")return _expansion_payload_response(payload)async def home_orch_automation_status(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_expansion_payload_response = s._expansion_payload_response_slugify_identifier = s._slugify_identifier_home_automation_drafts = s._home_automation_drafts_home_automation_applied = s._home_automation_applied_automation_entry_from_draft = s._automation_entry_from_draftdraft_id = str(args.get("draft_id", "")).strip()automation_id = _slugify_identifier(str(args.get("automation_id", "")).strip(), fallback="")if draft_id:row = _home_automation_drafts.get(draft_id)payload = {"action": "automation_status", "draft_id": draft_id, "draft": _automation_entry_from_draft(row or {})}elif automation_id:row = _home_automation_applied.get(automation_id, {})payload = {"action": "automation_status","automation_id": automation_id,"applied": {"automation_id": automation_id,"has_current": bool(isinstance(row, dict) and isinstance(row.get("current"), dict) and row.get("current")),"history_count": len(row.get("history", [])) if isinstance(row, dict) and isinstance(row.get("history"), list) else 0,"updated_at": float(row.get("updated_at", 0.0) or 0.0) if isinstance(row, dict) else 0.0,},}else:payload = {"action": "automation_status","draft_count": len(_home_automation_drafts),"applied_count": len(_home_automation_applied),"drafts": [_automation_entry_from_draft(row)for row in sorted(_home_automation_drafts.values(), key=lambda item: str(item.get("draft_id", "")))[:100]],"applied_ids": sorted(_home_automation_applied.keys())[:100],}record_summary("home_orchestrator", "ok", start_time, effect="automation_status", risk="low")return _expansion_payload_response(payload)1 unmodified line23456789101112131 unmodified linefrom __future__ import annotationsfrom jarvis.tools.services_domains.home_orch_automation_apply_action import home_orch_automation_applyfrom jarvis.tools.services_domains.home_orch_automation_rollback_action import home_orch_automation_rollbackfrom jarvis.tools.services_domains.home_orch_automation_status_action import home_orch_automation_status__all__ = ["home_orch_automation_apply","home_orch_automation_rollback","home_orch_automation_status",]
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485"""Rollback action for home automation state."""
from __future__ import annotations
import timefrom typing import Any
def _services(): from jarvis.tools import services as s
return s
async def home_orch_automation_rollback(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _record_service_error = s._record_service_error _expansion_payload_response = s._expansion_payload_response _as_bool = s._as_bool _slugify_identifier = s._slugify_identifier _home_automation_applied = s._home_automation_applied _structured_diff = s._structured_diff _apply_ha_automation_config = s._apply_ha_automation_config _delete_ha_automation_config = s._delete_ha_automation_config
automation_id = _slugify_identifier(str(args.get("automation_id", "")).strip(), fallback="") if not automation_id: _record_service_error("home_orchestrator", start_time, "missing_fields") return {"content": [{"type": "text", "text": "automation_id is required for automation_rollback."}]} row = _home_automation_applied.get(automation_id) if not isinstance(row, dict): _record_service_error("home_orchestrator", start_time, "not_found") return {"content": [{"type": "text", "text": "automation_id has no applied state."}]} current = row.get("current") if isinstance(row.get("current"), dict) else {} history = row.get("history") if isinstance(row.get("history"), list) else [] previous_entry = history[-1] if history else {} previous = previous_entry.get("config") if isinstance(previous_entry, dict) and isinstance(previous_entry.get("config"), dict) else {} dry_run = _as_bool(args.get("dry_run"), default=True) confirm = _as_bool(args.get("confirm"), default=False) ha_apply = _as_bool(args.get("ha_apply"), default=True) diff = _structured_diff(current if isinstance(current, dict) else {}, previous if isinstance(previous, dict) else {}) if dry_run: payload = { "action": "automation_rollback", "dry_run": True, "automation_id": automation_id, "has_previous_revision": bool(previous), "diff": diff, "ha_apply": bool(ha_apply), } record_summary("home_orchestrator", "ok", start_time, effect="automation_rollback_preview", risk="low") return _expansion_payload_response(payload) if not confirm: _record_service_error("home_orchestrator", start_time, "confirm_required") return {"content": [{"type": "text", "text": "automation_rollback requires confirm=true when dry_run=false."}]} ha_status = "skipped" if ha_apply: if isinstance(previous, dict) and previous: ok, error_code = await _apply_ha_automation_config(automation_id, previous) else: ok, error_code = await _delete_ha_automation_config(automation_id) if not ok: _record_service_error("home_orchestrator", start_time, error_code or "unexpected") return {"content": [{"type": "text", "text": f"Home Assistant automation rollback failed: {error_code or 'unexpected'}."}]} ha_status = "rolled_back" if history: history.pop() if isinstance(previous, dict) and previous: row["current"] = previous row["history"] = history row["updated_at"] = time.time() else: _home_automation_applied.pop(automation_id, None) payload = { "action": "automation_rollback", "dry_run": False, "rolled_back": True, "ha_status": ha_status, "automation_id": automation_id, "restored_revision": bool(previous), "diff": diff, } record_summary("home_orchestrator", "ok", start_time, effect="automation_rollback", risk="medium") return _expansion_payload_response(payload)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152"""Status action for home automation drafts/applied state."""
from __future__ import annotations
from typing import Any
def _services(): from jarvis.tools import services as s
return s
async def home_orch_automation_status(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _expansion_payload_response = s._expansion_payload_response _slugify_identifier = s._slugify_identifier _home_automation_drafts = s._home_automation_drafts _home_automation_applied = s._home_automation_applied _automation_entry_from_draft = s._automation_entry_from_draft
draft_id = str(args.get("draft_id", "")).strip() automation_id = _slugify_identifier(str(args.get("automation_id", "")).strip(), fallback="") if draft_id: row = _home_automation_drafts.get(draft_id) payload = {"action": "automation_status", "draft_id": draft_id, "draft": _automation_entry_from_draft(row or {})} elif automation_id: row = _home_automation_applied.get(automation_id, {}) payload = { "action": "automation_status", "automation_id": automation_id, "applied": { "automation_id": automation_id, "has_current": bool(isinstance(row, dict) and isinstance(row.get("current"), dict) and row.get("current")), "history_count": len(row.get("history", [])) if isinstance(row, dict) and isinstance(row.get("history"), list) else 0, "updated_at": float(row.get("updated_at", 0.0) or 0.0) if isinstance(row, dict) else 0.0, }, } else: payload = { "action": "automation_status", "draft_count": len(_home_automation_drafts), "applied_count": len(_home_automation_applied), "drafts": [ _automation_entry_from_draft(row) for row in sorted(_home_automation_drafts.values(), key=lambda item: str(item.get("draft_id", "")))[:100] ], "applied_ids": sorted(_home_automation_applied.keys())[:100], } record_summary("home_orchestrator", "ok", start_time, effect="automation_status", risk="low") return _expansion_payload_response(payload)12345678910111213141516171819202122232425262728293031323334353637383940414243444546"""Plan action for planner engine."""
from __future__ import annotations
from typing import Any
def _services(): from jarvis.tools import services as s
return s
async def planner_plan(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _record_service_error = s._record_service_error _expansion_payload_response = s._expansion_payload_response _as_str_list = s._as_str_list
goal = str(args.get("goal", "")).strip() if not goal: _record_service_error("planner_engine", start_time, "missing_fields") return {"content": [{"type": "text", "text": "goal is required."}]} steps = _as_str_list(args.get("steps")) if not steps: steps = ["Clarify constraints", "Execute tool actions", "Verify outcomes", "Report completion"] payload = { "action": "plan", "goal": goal, "planner": { "steps": steps, "retry_policy": "retry_failed_steps_once_then_escalate", "rollback_hints": [ "Store pre-change state when possible.", "Use dry-run for medium/high-risk actions first.", ], }, "executor": { "mode": "deterministic", "checkpointing": True, "max_retries_per_step": 1, }, } record_summary("planner_engine", "ok", start_time, effect="plan_generated", risk="low") return _expansion_payload_response(payload)1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951 unmodified linefrom __future__ import annotationsimport timefrom typing import Anydef _services():from jarvis.tools import services as sreturn sasync def planner_plan(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_record_service_error = s._record_service_error_expansion_payload_response = s._expansion_payload_response_as_str_list = s._as_str_listgoal = str(args.get("goal", "")).strip()if not goal:_record_service_error("planner_engine", start_time, "missing_fields")return {"content": [{"type": "text", "text": "goal is required."}]}steps = _as_str_list(args.get("steps"))if not steps:steps = ["Clarify constraints", "Execute tool actions", "Verify outcomes", "Report completion"]payload = {"action": "plan","goal": goal,"planner": {"steps": steps,"retry_policy": "retry_failed_steps_once_then_escalate","rollback_hints": ["Store pre-change state when possible.","Use dry-run for medium/high-risk actions first.",],},"executor": {"mode": "deterministic","checkpointing": True,"max_retries_per_step": 1,},}record_summary("planner_engine", "ok", start_time, effect="plan_generated", risk="low")return _expansion_payload_response(payload)async def planner_task_graph_create(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_expansion_payload_response = s._expansion_payload_response_as_str_list = s._as_str_list_planner_task_graphs = s._planner_task_graphs_planner_ready_nodes = s._planner_ready_nodesPLANNER_TASK_GRAPH_MAX = s.PLANNER_TASK_GRAPH_MAXtitle = str(args.get("title", "Task Graph")).strip() or "Task Graph"steps = args.get("steps") if isinstance(args.get("steps"), list) else []nodes: list[dict[str, Any]] = []for idx, row in enumerate(steps):if isinstance(row, dict):node_id = str(row.get("id", f"n{idx+1}")).strip() or f"n{idx+1}"text = str(row.get("text", f"Step {idx+1}")).strip() or f"Step {idx+1}"deps = _as_str_list(row.get("depends_on"), lower=False)else:node_id = f"n{idx+1}"text = str(row).strip() or f"Step {idx+1}"deps = []nodes.append({"id": node_id, "text": text, "depends_on": deps, "status": "pending"})if not nodes:nodes = [{"id": "n1", "text": "Execute goal", "depends_on": [], "status": "pending"}]graph_id = f"graph-{s._planner_task_seq}"s._planner_task_seq += 1graph = {"graph_id": graph_id,"title": title,"nodes": nodes,"created_at": time.time(),"updated_at": time.time(),}_planner_task_graphs[graph_id] = graphif len(_planner_task_graphs) > PLANNER_TASK_GRAPH_MAX:oldest = sorted(_planner_task_graphs.items(),key=lambda pair: float(pair[1].get("updated_at", 0.0)),)[: len(_planner_task_graphs) - PLANNER_TASK_GRAPH_MAX]for key, _ in oldest:_planner_task_graphs.pop(key, None)payload = {"action": "task_graph_create","graph_id": graph_id,"node_count": len(nodes),"ready_nodes": _planner_ready_nodes(graph),}record_summary("planner_engine", "ok", start_time, effect="graph_created", risk="low")return _expansion_payload_response(payload)async def planner_task_graph_update(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_record_service_error = s._record_service_error_expansion_payload_response = s._expansion_payload_response_planner_task_graphs = s._planner_task_graphs_planner_ready_nodes = s._planner_ready_nodesgraph_id = str(args.get("graph_id", "")).strip()node_id = str(args.get("node_id", "")).strip()status = str(args.get("status", "pending")).strip().lower()if status not in {"pending", "in_progress", "blocked", "done"}:_record_service_error("planner_engine", start_time, "invalid_data")return {"content": [{"type": "text", "text": "status must be pending|in_progress|blocked|done."}]}graph = _planner_task_graphs.get(graph_id)if not isinstance(graph, dict):_record_service_error("planner_engine", start_time, "not_found")return {"content": [{"type": "text", "text": "graph_id not found."}]}updated = Falsefor node in graph.get("nodes", []):if isinstance(node, dict) and str(node.get("id", "")) == node_id:node["status"] = statusupdated = Truebreakif not updated:_record_service_error("planner_engine", start_time, "not_found")return {"content": [{"type": "text", "text": "node_id not found."}]}graph["updated_at"] = time.time()payload = {"action": "task_graph_update","graph_id": graph_id,"updated": True,"ready_nodes": _planner_ready_nodes(graph),}record_summary("planner_engine", "ok", start_time, effect="graph_updated", risk="low")return _expansion_payload_response(payload)async def planner_task_graph_resume(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_record_service_error = s._record_service_error_expansion_payload_response = s._expansion_payload_response_planner_task_graphs = s._planner_task_graphs_planner_ready_nodes = s._planner_ready_nodesgraph_id = str(args.get("graph_id", "")).strip()if graph_id:graph = _planner_task_graphs.get(graph_id)if not isinstance(graph, dict):_record_service_error("planner_engine", start_time, "not_found")return {"content": [{"type": "text", "text": "graph_id not found."}]}payload = {"action": "task_graph_resume","graph_id": graph_id,"ready_nodes": _planner_ready_nodes(graph),}else:payload = {"action": "task_graph_resume","graphs": [{"graph_id": key,"ready_nodes": _planner_ready_nodes(row),}for key, row in sorted(_planner_task_graphs.items())],}record_summary("planner_engine", "ok", start_time, effect="graph_resume", risk="low")return _expansion_payload_response(payload)async def planner_self_critique(args: dict[str, Any], *, start_time: float) -> dict[str, Any]:s = _services()record_summary = s.record_summary_expansion_payload_response = s._expansion_payload_responseplan = args.get("plan") if isinstance(args.get("plan"), dict) else {}steps = plan.get("steps")step_count = len(steps) if isinstance(steps, list) else 0complexity = "high" if step_count >= 8 else "medium" if step_count >= 4 else "low"warnings: list[str] = []if step_count >= 8:warnings.append("Plan has many steps; consider decomposition.")if any("delete" in str(step).lower() for step in (steps or [])):warnings.append("Contains destructive operations; require confirmation checkpoints.")payload = {"action": "self_critique","complexity": complexity,"step_count": step_count,"warnings": warnings,"recommendation": "approve" if not warnings else "revise",}record_summary("planner_engine", "ok", start_time, effect=f"critique:{payload['recommendation']}", risk="low")return _expansion_payload_response(payload)1 unmodified line23456789101112131415161718191 unmodified linefrom __future__ import annotationsfrom jarvis.tools.services_domains.planner_engine_plan_action import planner_planfrom jarvis.tools.services_domains.planner_engine_self_critique_action import planner_self_critiquefrom jarvis.tools.services_domains.planner_engine_task_graph_actions import (planner_task_graph_create,planner_task_graph_resume,planner_task_graph_update,)__all__ = ["planner_plan","planner_task_graph_create","planner_task_graph_update","planner_task_graph_resume","planner_self_critique",]
123456789101112131415161718192021222324252627282930313233343536"""Self-critique action for planner engine."""
from __future__ import annotations
from typing import Any
def _services(): from jarvis.tools import services as s
return s
async def planner_self_critique(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _expansion_payload_response = s._expansion_payload_response
plan = args.get("plan") if isinstance(args.get("plan"), dict) else {} steps = plan.get("steps") step_count = len(steps) if isinstance(steps, list) else 0 complexity = "high" if step_count >= 8 else "medium" if step_count >= 4 else "low" warnings: list[str] = [] if step_count >= 8: warnings.append("Plan has many steps; consider decomposition.") if any("delete" in str(step).lower() for step in (steps or [])): warnings.append("Contains destructive operations; require confirmation checkpoints.") payload = { "action": "self_critique", "complexity": complexity, "step_count": step_count, "warnings": warnings, "recommendation": "approve" if not warnings else "revise", } record_summary("planner_engine", "ok", start_time, effect=f"critique:{payload['recommendation']}", risk="low") return _expansion_payload_response(payload)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135"""Task graph actions for planner engine."""
from __future__ import annotations
import timefrom typing import Any
def _services(): from jarvis.tools import services as s
return s
async def planner_task_graph_create(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _expansion_payload_response = s._expansion_payload_response _as_str_list = s._as_str_list _planner_task_graphs = s._planner_task_graphs _planner_ready_nodes = s._planner_ready_nodes PLANNER_TASK_GRAPH_MAX = s.PLANNER_TASK_GRAPH_MAX
title = str(args.get("title", "Task Graph")).strip() or "Task Graph" steps = args.get("steps") if isinstance(args.get("steps"), list) else [] nodes: list[dict[str, Any]] = [] for idx, row in enumerate(steps): if isinstance(row, dict): node_id = str(row.get("id", f"n{idx+1}")).strip() or f"n{idx+1}" text = str(row.get("text", f"Step {idx+1}")).strip() or f"Step {idx+1}" deps = _as_str_list(row.get("depends_on"), lower=False) else: node_id = f"n{idx+1}" text = str(row).strip() or f"Step {idx+1}" deps = [] nodes.append({"id": node_id, "text": text, "depends_on": deps, "status": "pending"}) if not nodes: nodes = [{"id": "n1", "text": "Execute goal", "depends_on": [], "status": "pending"}] graph_id = f"graph-{s._planner_task_seq}" s._planner_task_seq += 1 graph = { "graph_id": graph_id, "title": title, "nodes": nodes, "created_at": time.time(), "updated_at": time.time(), } _planner_task_graphs[graph_id] = graph if len(_planner_task_graphs) > PLANNER_TASK_GRAPH_MAX: oldest = sorted( _planner_task_graphs.items(), key=lambda pair: float(pair[1].get("updated_at", 0.0)), )[: len(_planner_task_graphs) - PLANNER_TASK_GRAPH_MAX] for key, _ in oldest: _planner_task_graphs.pop(key, None) payload = { "action": "task_graph_create", "graph_id": graph_id, "node_count": len(nodes), "ready_nodes": _planner_ready_nodes(graph), } record_summary("planner_engine", "ok", start_time, effect="graph_created", risk="low") return _expansion_payload_response(payload)
async def planner_task_graph_update(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _record_service_error = s._record_service_error _expansion_payload_response = s._expansion_payload_response _planner_task_graphs = s._planner_task_graphs _planner_ready_nodes = s._planner_ready_nodes
graph_id = str(args.get("graph_id", "")).strip() node_id = str(args.get("node_id", "")).strip() status = str(args.get("status", "pending")).strip().lower() if status not in {"pending", "in_progress", "blocked", "done"}: _record_service_error("planner_engine", start_time, "invalid_data") return {"content": [{"type": "text", "text": "status must be pending|in_progress|blocked|done."}]} graph = _planner_task_graphs.get(graph_id) if not isinstance(graph, dict): _record_service_error("planner_engine", start_time, "not_found") return {"content": [{"type": "text", "text": "graph_id not found."}]} updated = False for node in graph.get("nodes", []): if isinstance(node, dict) and str(node.get("id", "")) == node_id: node["status"] = status updated = True break if not updated: _record_service_error("planner_engine", start_time, "not_found") return {"content": [{"type": "text", "text": "node_id not found."}]} graph["updated_at"] = time.time() payload = { "action": "task_graph_update", "graph_id": graph_id, "updated": True, "ready_nodes": _planner_ready_nodes(graph), } record_summary("planner_engine", "ok", start_time, effect="graph_updated", risk="low") return _expansion_payload_response(payload)
async def planner_task_graph_resume(args: dict[str, Any], *, start_time: float) -> dict[str, Any]: s = _services() record_summary = s.record_summary _record_service_error = s._record_service_error _expansion_payload_response = s._expansion_payload_response _planner_task_graphs = s._planner_task_graphs _planner_ready_nodes = s._planner_ready_nodes
graph_id = str(args.get("graph_id", "")).strip() if graph_id: graph = _planner_task_graphs.get(graph_id) if not isinstance(graph, dict): _record_service_error("planner_engine", start_time, "not_found") return {"content": [{"type": "text", "text": "graph_id not found."}]} payload = { "action": "task_graph_resume", "graph_id": graph_id, "ready_nodes": _planner_ready_nodes(graph), } else: payload = { "action": "task_graph_resume", "graphs": [ { "graph_id": key, "ready_nodes": _planner_ready_nodes(row), } for key, row in sorted(_planner_task_graphs.items()) ], } record_summary("planner_engine", "ok", start_time, effect="graph_resume", risk="low") return _expansion_payload_response(payload)27 unmodified lines28293031323357 unmodified lines91929394959627 unmodified lines("jarvis.tools.services_domains.home_orch_plan_exec", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_automation", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_tasks", "jarvis.tools.services"),("jarvis.tools.services_domains.home_control", "jarvis.tools.services"),("jarvis.tools.services_domains.home_mutation", "jarvis.tools.services"),("jarvis.tools.services_domains.home_mutation_preflight", "jarvis.tools.services"),57 unmodified lines("jarvis.tools.services_domains.integrations_deadletter", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_domain", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_plan_graph", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_deferred", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_autonomy", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_autonomy_schedule_checkpoint", "jarvis.tools.services"),27 unmodified lines28293031323334353657 unmodified lines94959697989910010110227 unmodified lines("jarvis.tools.services_domains.home_orch_plan_exec", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_automation", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_tasks", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_automation_apply_action", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_automation_rollback_action", "jarvis.tools.services"),("jarvis.tools.services_domains.home_orch_automation_status_action", "jarvis.tools.services"),("jarvis.tools.services_domains.home_control", "jarvis.tools.services"),("jarvis.tools.services_domains.home_mutation", "jarvis.tools.services"),("jarvis.tools.services_domains.home_mutation_preflight", "jarvis.tools.services"),57 unmodified lines("jarvis.tools.services_domains.integrations_deadletter", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_domain", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_plan_graph", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_plan_action", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_task_graph_actions", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_self_critique_action", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_deferred", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_autonomy", "jarvis.tools.services"),("jarvis.tools.services_domains.planner_engine_autonomy_schedule_checkpoint", "jarvis.tools.services"),
TODO.md+58-52
src/jarvis/tools/services_domains/home_orch_automation_apply_action.pyAdded+90
src/jarvis/tools/services_domains/home_orch_automation_apply_status.py+9-200
src/jarvis/tools/services_domains/home_orch_automation_rollback_action.pyAdded+85
src/jarvis/tools/services_domains/home_orch_automation_status_action.pyAdded+52
src/jarvis/tools/services_domains/planner_engine_plan_action.pyAdded+46
src/jarvis/tools/services_domains/planner_engine_plan_graph.py+15-191
src/jarvis/tools/services_domains/planner_engine_self_critique_action.pyAdded+36
src/jarvis/tools/services_domains/planner_engine_task_graph_actions.pyAdded+135
tests/test_import_boundaries.py+6