Skip to content

Commit 2da85e7

Browse files
hsinnearth7claude
andcommitted
fix(ci): resolve 68 ruff lint errors
- Remove unused variables (F841): coordinator, inventory_optimizer, kpi engine, risk_tools, test - Break long lines (E501): orchestrator agent tool lists and dict comprehension - Add strict=False to zip() calls (B905): athena, redshift, forecaster - Rename unused loop vars (B007): optimizer gen/ep/day → _gen/_ep/_day - Move Protocol import to top of file (E402): forecaster - Add noqa for validated SQL queries (S608): aws_backend - Suppress false positives in ruff config: S311 (simulation random), S104 (server bind) - Add per-file-ignores for test passwords: S106 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 165ac11 commit 2da85e7

12 files changed

Lines changed: 33 additions & 22 deletions

File tree

chaincommand/agents/coordinator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ async def run_cycle(self, context: Dict[str, Any]) -> Dict[str, Any]:
4545
}
4646

4747
agent_results = context.get("agent_results", {})
48-
products = context.get("products", [])
4948

5049
# Step 1: Conflict detection and resolution
5150
conflicts = self._detect_conflicts(agent_results)

chaincommand/agents/inventory_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def run_cycle(self, context: Dict[str, Any]) -> Dict[str, Any]:
4343
description="Check all inventory levels",
4444
input_data={},
4545
)
46-
inv_data = await self.act(inv_action)
46+
await self.act(inv_action)
4747
results["actions"].append(inv_action.model_dump())
4848

4949
products = context.get("products", [])

chaincommand/aws/athena_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def get_query_results(self, execution_id: str) -> List[Dict[str, Any]]:
145145
results = []
146146
for row in rows[1:]:
147147
values = [col.get("VarCharValue", "") for col in row["Data"]]
148-
results.append(dict(zip(headers, values)))
148+
results.append(dict(zip(headers, values, strict=False)))
149149
return results
150150

151151
def _start_query(self, sql: str) -> str:

chaincommand/aws/aws_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def query_kpi_trend(self, metric: str, days: int) -> list:
114114

115115
safe_days = max(1, min(int(days), 365))
116116
sql = (
117-
f"SELECT cycle, timestamp, {metric} "
117+
f"SELECT cycle, timestamp, {metric} " # noqa: S608
118118
f"FROM kpi_snapshots "
119119
f"WHERE timestamp >= DATEADD(day, -{safe_days}, GETDATE()) "
120120
f"ORDER BY cycle"
@@ -128,7 +128,7 @@ async def query_events(self, event_type: str, limit: int) -> list:
128128
return []
129129
safe_limit = max(1, min(int(limit), 500))
130130
sql = (
131-
f"SELECT event_id, timestamp, event_type, severity, source_agent, description "
131+
f"SELECT event_id, timestamp, event_type, severity, source_agent, description " # noqa: S608
132132
f"FROM events "
133133
f"WHERE event_type = '{event_type}' "
134134
f"ORDER BY timestamp DESC "

chaincommand/aws/redshift_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def query(self, sql: str, params: Optional[Tuple] = None) -> List[Dict[str, Any]
190190
columns = [desc[0] for desc in cursor.description] if cursor.description else []
191191
rows = cursor.fetchall()
192192
cursor.close()
193-
return [dict(zip(columns, row)) for row in rows]
193+
return [dict(zip(columns, row, strict=False)) for row in rows]
194194

195195
def insert_kpi_snapshot(self, cycle: int, snapshot: KPISnapshot) -> None:
196196
"""Direct INSERT of a KPI snapshot row."""

chaincommand/kpi/engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def calculate_snapshot(
3737
on_time_in_full = 0
3838
for po in delivered:
3939
if po.expected_delivery and po.created_at:
40-
on_time = True # simplified: assume delivered POs are on-time
40+
# simplified: assume delivered POs are on-time
4141
on_time_in_full += 1
4242
otif = on_time_in_full / max(len(delivered), 1)
4343

chaincommand/models/forecaster.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import random
66
from datetime import datetime, timedelta
7-
from typing import Dict, List
7+
from typing import Dict, List, Protocol, runtime_checkable
88

99
import numpy as np
1010
import pandas as pd
@@ -202,7 +202,7 @@ def predict(self, product_id: str, horizon: int = 30) -> List[ForecastResult]:
202202
return lstm_preds
203203

204204
results = []
205-
for lstm_r, xgb_r in zip(lstm_preds, xgb_preds):
205+
for lstm_r, xgb_r in zip(lstm_preds, xgb_preds, strict=False):
206206
w_l, w_x = weights["lstm"], weights["xgb"]
207207
demand = w_l * lstm_r.predicted_demand + w_x * xgb_r.predicted_demand
208208
lower = w_l * lstm_r.confidence_lower + w_x * xgb_r.confidence_lower
@@ -232,16 +232,14 @@ def _compute_mape(actual: np.ndarray, predicted: List[float]) -> float:
232232
if n == 0:
233233
return 100.0
234234
errors = []
235-
for a, p in zip(actual[:n], predicted[:n]):
235+
for a, p in zip(actual[:n], predicted[:n], strict=False):
236236
if a > 0:
237237
errors.append(abs(a - p) / a * 100)
238238
return float(np.mean(errors)) if errors else 100.0
239239

240240

241241
# ── v2.0: ForecastModel Protocol ─────────────────────────
242242

243-
from typing import Protocol, runtime_checkable
244-
245243

246244
@runtime_checkable
247245
class ForecastModel(Protocol):

chaincommand/models/optimizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def optimize(
5454
best = population[0]
5555
best_fitness_val = -1.0
5656

57-
for gen in range(self._generations):
57+
for _gen in range(self._generations):
5858
# Fitness = minimize total cost (holding + stockout penalty + ordering)
5959
fitness = []
6060
for individual in population:
@@ -142,11 +142,11 @@ def train(self, product: Product) -> None:
142142
}
143143

144144
epsilon = self._epsilon
145-
for ep in range(self._episodes):
145+
for _ep in range(self._episodes):
146146
stock = product.current_stock
147147
total_reward = 0
148148

149-
for day in range(30):
149+
for _day in range(30):
150150
# State discretization
151151
stock_level = "critical" if stock < product.safety_stock else \
152152
"low" if stock < product.reorder_point else \

chaincommand/orchestrator.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,19 +187,28 @@ async def _ui_event_handler(event: Any) -> None:
187187
_runtime.agents = {
188188
"demand_forecaster": DemandForecasterAgent(
189189
llm=llm,
190-
tools=[QueryDemandHistory(), RunDemandForecast(), GetForecastAccuracy(), ScanMarketIntelligence(), EmitEvent()],
190+
tools=[
191+
QueryDemandHistory(), RunDemandForecast(), GetForecastAccuracy(),
192+
ScanMarketIntelligence(), EmitEvent(),
193+
],
191194
),
192195
"strategic_planner": StrategicPlannerAgent(
193196
llm=llm,
194197
tools=[QueryKPIHistory(), OptimizeInventory(), QueryInventoryStatus(), EmitEvent()],
195198
),
196199
"inventory_optimizer": InventoryOptimizerAgent(
197200
llm=llm,
198-
tools=[QueryInventoryStatus(), CalculateReorderPoint(), AdjustSafetyStock(), OptimizeInventory(), EmitEvent()],
201+
tools=[
202+
QueryInventoryStatus(), CalculateReorderPoint(), AdjustSafetyStock(),
203+
OptimizeInventory(), EmitEvent(),
204+
],
199205
),
200206
"supplier_manager": SupplierManagerAgent(
201207
llm=llm,
202-
tools=[QuerySupplierInfo(), EvaluateSupplier(), CreatePurchaseOrder(), RequestHumanApproval(), EmitEvent()],
208+
tools=[
209+
QuerySupplierInfo(), EvaluateSupplier(), CreatePurchaseOrder(),
210+
RequestHumanApproval(), EmitEvent(),
211+
],
203212
),
204213
"logistics_coordinator": LogisticsCoordinatorAgent(
205214
llm=llm,
@@ -387,7 +396,10 @@ async def run_cycle(self) -> Dict[str, Any]:
387396

388397
return {
389398
"cycle": self._cycle_count,
390-
"agent_results": {k: v.get("analysis", "") if isinstance(v, dict) else "" for k, v in agent_results.items()},
399+
"agent_results": {
400+
k: v.get("analysis", "") if isinstance(v, dict) else ""
401+
for k, v in agent_results.items()
402+
},
391403
"kpi": snapshot.model_dump(),
392404
"violations": len(violations),
393405
"report": report_result.get("report", {}).get("report_id"),

chaincommand/tools/risk_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ async def execute(self, **kwargs: Any) -> Dict[str, Any]:
5959
supplier_id: str = kwargs.get("supplier_id", "")
6060

6161
suppliers = _runtime.suppliers or []
62-
products = _runtime.products or []
6362

6463
# Find relevant suppliers
6564
if product_id:

0 commit comments

Comments
 (0)