Skip to content

Commit d28443c

Browse files
CraftBotclaude
andcommitted
Apply ruff format across repo to fix CI format check
`ruff format --check .` flagged 43 files; run `ruff format` to normalize them. Formatting-only changes, no behavior impact. Also gitignore local tooling artifacts (.playwright-mcp/, home snapshots, mascot pet_state, playbook progress) so they are never accidentally committed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent bd2962d commit d28443c

44 files changed

Lines changed: 731 additions & 262 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ agent_file_system/TASK_HISTORY.md
5656
!build_template.py
5757
docs/LIVING_UI_DEVELOPER_GUIDE.md
5858
agent_file_system/ACTIONS.md
59-
agent_bundle/
59+
agent_bundle/
60+
# Local tooling / runtime artifacts (never commit)
61+
.playwright-mcp/
62+
app/data/mascot/pet_state.json
63+
app/data/playbooks/PLAYBOOK_PROGRESS.md
64+
craftbot_live_home_snapshot.md
65+
mobile_home_snapshot.md

agent_core/core/impl/event_stream/event_stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def _maybe_push_datetime(self) -> None:
157157
last = self._last_datetime_ts
158158
if (
159159
last is None
160-
or (datetime.now(timezone.utc) - last).total_seconds() >= DATETIME_REFRESH_SECONDS
160+
or (datetime.now(timezone.utc) - last).total_seconds()
161+
>= DATETIME_REFRESH_SECONDS
161162
):
162163
self._append_datetime_event()
163164

agent_core/core/impl/llm/interface.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,7 @@ def _call_log_to_db(
448448
try:
449449
ctx = _llm_call_ctx.get() or {}
450450
start = ctx.get("start")
451-
latency_ms = (
452-
int((time.perf_counter() - start) * 1000) if start else 0
453-
)
451+
latency_ms = int((time.perf_counter() - start) * 1000) if start else 0
454452
self._record_llm_call(
455453
LLMCallRecord(
456454
provider=self.provider or "",
@@ -701,7 +699,8 @@ def create_session_cache(
701699
(self.provider == "byteplus" and self._byteplus_cache_manager)
702700
or (self.provider == "gemini" and self._gemini_cache_manager)
703701
or (
704-
self.provider in ("openai", "deepseek", "grok", "openrouter", "glm", "fugu")
702+
self.provider
703+
in ("openai", "deepseek", "grok", "openrouter", "glm", "fugu")
705704
and self.client
706705
) # OpenAI/DeepSeek/Grok/OpenRouter use automatic caching with prompt_cache_key (and cache_control for Anthropic-routed OpenRouter models)
707706
or (
@@ -857,7 +856,8 @@ def has_session_cache(self, task_id: str, call_type: str) -> bool:
857856
if self.provider == "gemini" and self._gemini_cache_manager:
858857
return True
859858
if (
860-
self.provider in ("openai", "deepseek", "grok", "openrouter", "glm", "fugu")
859+
self.provider
860+
in ("openai", "deepseek", "grok", "openrouter", "glm", "fugu")
861861
and self.client
862862
):
863863
return True
@@ -1111,9 +1111,7 @@ def _generate_response_with_session_sync(
11111111
{"role": "system", "content": effective_system_prompt}
11121112
]
11131113
for msg in history:
1114-
oa_messages.append(
1115-
{"role": msg["role"], "content": msg["content"]}
1116-
)
1114+
oa_messages.append({"role": msg["role"], "content": msg["content"]})
11171115
oa_messages.append({"role": "user", "content": user_prompt})
11181116

11191117
logger.debug(
@@ -1131,9 +1129,7 @@ def _generate_response_with_session_sync(
11311129
assistant_content = response.get("content", "")
11321130
if assistant_content and not response.get("error"):
11331131
history.append({"role": "user", "content": user_prompt})
1134-
history.append(
1135-
{"role": "assistant", "content": assistant_content}
1136-
)
1132+
history.append({"role": "assistant", "content": assistant_content})
11371133

11381134
return self._finalize_session_response(response, log_response)
11391135

@@ -1516,9 +1512,7 @@ def generate_response_with_session(
15161512
log_response: Whether to log the response.
15171513
prompt_name: Identity of the named prompt, for capture/profiling.
15181514
"""
1519-
self._begin_call(
1520-
prompt_name=prompt_name, call_type=call_type, task_id=task_id
1521-
)
1515+
self._begin_call(prompt_name=prompt_name, call_type=call_type, task_id=task_id)
15221516
return self._generate_response_with_session_sync(
15231517
task_id, call_type, user_prompt, system_prompt_for_new_session, log_response
15241518
)
@@ -1545,9 +1539,7 @@ async def generate_response_with_session_async(
15451539
"""
15461540
# Stamp here (caller's context) so asyncio.to_thread copies it into the
15471541
# worker thread where capture runs.
1548-
self._begin_call(
1549-
prompt_name=prompt_name, call_type=call_type, task_id=task_id
1550-
)
1542+
self._begin_call(prompt_name=prompt_name, call_type=call_type, task_id=task_id)
15511543
return await asyncio.to_thread(
15521544
self._generate_response_with_session_sync,
15531545
task_id,
@@ -1871,7 +1863,9 @@ def _generate_openai(
18711863
if prompt_tokens_details:
18721864
cached_tokens = getattr(prompt_tokens_details, "cached_tokens", 0) or 0
18731865
if not cached_tokens:
1874-
cached_tokens = getattr(response.usage, "prompt_cache_hit_tokens", 0) or 0
1866+
cached_tokens = (
1867+
getattr(response.usage, "prompt_cache_hit_tokens", 0) or 0
1868+
)
18751869

18761870
# Record cache metrics
18771871
provider_label = self.provider # "openai", "grok", "deepseek", etc.

agent_core/core/impl/memory/bm25_index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
try:
1818
from rank_bm25 import BM25Okapi
19+
1920
_HAS_BM25 = True
2021
except ImportError:
2122
BM25Okapi = None

agent_core/core/impl/memory/entity_extractor.py

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,89 @@
2121
from typing import List
2222

2323
_STOP = {
24-
"the", "a", "an", "and", "or", "but", "of", "in", "on", "at", "to", "for",
25-
"with", "by", "from", "as", "is", "are", "was", "were", "be", "been", "being",
26-
"have", "has", "had", "do", "does", "did", "will", "would", "should", "could",
27-
"may", "might", "must", "can", "i", "you", "he", "she", "it", "we", "they",
28-
"this", "that", "these", "those", "user", "agent", "task", "action", "event",
29-
"memory", "system", "note", "today", "yesterday", "tomorrow", "monday",
30-
"tuesday", "wednesday", "thursday", "friday", "saturday", "sunday",
31-
"january", "february", "march", "april", "may", "june", "july", "august",
32-
"september", "october", "november", "december",
24+
"the",
25+
"a",
26+
"an",
27+
"and",
28+
"or",
29+
"but",
30+
"of",
31+
"in",
32+
"on",
33+
"at",
34+
"to",
35+
"for",
36+
"with",
37+
"by",
38+
"from",
39+
"as",
40+
"is",
41+
"are",
42+
"was",
43+
"were",
44+
"be",
45+
"been",
46+
"being",
47+
"have",
48+
"has",
49+
"had",
50+
"do",
51+
"does",
52+
"did",
53+
"will",
54+
"would",
55+
"should",
56+
"could",
57+
"may",
58+
"might",
59+
"must",
60+
"can",
61+
"i",
62+
"you",
63+
"he",
64+
"she",
65+
"it",
66+
"we",
67+
"they",
68+
"this",
69+
"that",
70+
"these",
71+
"those",
72+
"user",
73+
"agent",
74+
"task",
75+
"action",
76+
"event",
77+
"memory",
78+
"system",
79+
"note",
80+
"today",
81+
"yesterday",
82+
"tomorrow",
83+
"monday",
84+
"tuesday",
85+
"wednesday",
86+
"thursday",
87+
"friday",
88+
"saturday",
89+
"sunday",
90+
"january",
91+
"february",
92+
"march",
93+
"april",
94+
"may",
95+
"june",
96+
"july",
97+
"august",
98+
"september",
99+
"october",
100+
"november",
101+
"december",
33102
}
34103

35104
# Capitalised words (incl. CamelCase), optionally chained: "Trading View",
36105
# "OpenAI", "CraftBot", "John Doe"
37-
_PROPER_NOUN_RE = re.compile(
38-
r"\b[A-Z][A-Za-z0-9]*(?:[ \-_][A-Z][A-Za-z0-9]*)*\b"
39-
)
106+
_PROPER_NOUN_RE = re.compile(r"\b[A-Z][A-Za-z0-9]*(?:[ \-_][A-Z][A-Za-z0-9]*)*\b")
40107

41108
# Quoted strings (single or double)
42109
_QUOTED_RE = re.compile(r"\"([^\"]{2,40})\"|'([^']{2,40})'")

agent_core/core/impl/memory/injector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def _is_memory_enabled() -> bool:
3838
outside the CraftBot app)."""
3939
try:
4040
from app.ui_layer.settings.memory_settings import is_memory_enabled
41+
4142
return is_memory_enabled()
4243
except ImportError:
4344
return True

agent_core/core/impl/memory/manager.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _is_embedding_function_conflict(err: Exception) -> bool:
7070
"conflict" in msg or "already exists" in msg
7171
)
7272

73+
7374
# ───────────────────────── Embedding Model ─────────────────────────
7475
# ChromaDB's default is sentence-transformers/all-MiniLM-L6-v2 (22M params,
7576
# 2021). Verbatim self-similarity scores ~0.65; topical matches sit at
@@ -86,6 +87,7 @@ def _is_embedding_function_conflict(err: Exception) -> bool:
8687
# sentence-transformers model. Set to "default" to use ChromaDB's
8788
# bundled ONNX MiniLM.
8889
import os as _os
90+
8991
MEMORY_EMBEDDING_MODEL = _os.environ.get(
9092
"MEMORY_EMBEDDING_MODEL", "BAAI/bge-small-en-v1.5"
9193
)
@@ -325,6 +327,7 @@ def _build_embedding_function():
325327
from chromadb.utils.embedding_functions import (
326328
SentenceTransformerEmbeddingFunction,
327329
)
330+
328331
return SentenceTransformerEmbeddingFunction(
329332
model_name=MEMORY_EMBEDDING_MODEL
330333
)
@@ -488,8 +491,7 @@ def retrieve(
488491
metadata={
489492
k: v
490493
for k, v in meta.items()
491-
if k
492-
not in ("file_path", "section_path", "title", "summary")
494+
if k not in ("file_path", "section_path", "title", "summary")
493495
},
494496
)
495497
)
@@ -753,9 +755,7 @@ def _chunk_markdown(self, content: str, file_path: str) -> List[MemoryChunk]:
753755
return self._chunk_memory_log(content, file_path)
754756
return self._chunk_by_sections(content, file_path)
755757

756-
def _chunk_memory_log(
757-
self, content: str, file_path: str
758-
) -> List[MemoryChunk]:
758+
def _chunk_memory_log(self, content: str, file_path: str) -> List[MemoryChunk]:
759759
"""One chunk per ``[ts] [cat] content`` line.
760760
761761
Each line is short enough on its own (memory items are capped at
@@ -813,9 +813,7 @@ def _chunk_memory_log(
813813

814814
return chunks
815815

816-
def _chunk_by_sections(
817-
self, content: str, file_path: str
818-
) -> List[MemoryChunk]:
816+
def _chunk_by_sections(self, content: str, file_path: str) -> List[MemoryChunk]:
819817
"""Original header-based chunker. Preserves existing behaviour for
820818
non-list markdown (AGENT.md, USER.md, PROACTIVE.md, ...).
821819
"""

agent_core/core/impl/task/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def create_task(
383383
# tasks it's the trigger description. inject_memory_event no-ops if
384384
# nothing passes min_relevance, so noise is filtered automatically.
385385
from agent_core.core.impl.memory.injector import inject_memory_event
386+
386387
inject_memory_event(query=task_instruction, session_id=task_id)
387388

388389
self._set_agent_property("current_task_id", task_id)

agent_core/core/impl/video_gen/interface.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ def _openai_generate(
524524

525525
if not paths:
526526
raise RuntimeError(
527-
_classify_error("openai", first_error or RuntimeError("no result"), self.model)
527+
_classify_error(
528+
"openai", first_error or RuntimeError("no result"), self.model
529+
)
528530
)
529531
return paths
530532

@@ -767,7 +769,9 @@ def _gemini_generate(
767769
try:
768770
data = self._gemini_client.download_video(uri, timeout=180)
769771
except Exception as exc:
770-
raise RuntimeError(_classify_error("gemini", exc, self.model)) from exc
772+
raise RuntimeError(
773+
_classify_error("gemini", exc, self.model)
774+
) from exc
771775
elif inline:
772776
data = base64.b64decode(inline)
773777
else:
@@ -944,7 +948,9 @@ def _byteplus_generate(
944948

945949
if not paths:
946950
raise RuntimeError(
947-
_classify_error("byteplus", first_error or RuntimeError("no result"), self.model)
951+
_classify_error(
952+
"byteplus", first_error or RuntimeError("no result"), self.model
953+
)
948954
)
949955
return paths
950956

@@ -1008,7 +1014,9 @@ def _byteplus_poll(
10081014
)
10091015
r.raise_for_status()
10101016
except Exception as exc:
1011-
raise RuntimeError(_classify_error("byteplus", exc, self.model)) from exc
1017+
raise RuntimeError(
1018+
_classify_error("byteplus", exc, self.model)
1019+
) from exc
10121020

10131021
data = r.json()
10141022
status = (data.get("status") or "").lower()

agent_core/core/models/chatgpt_subscription_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def __init__(
106106
class _Message:
107107
__slots__ = ("role", "content", "tool_calls")
108108

109-
def __init__(
110-
self, role: str = "assistant", content: str = "", tool_calls=None
111-
):
109+
def __init__(self, role: str = "assistant", content: str = "", tool_calls=None):
112110
self.role = role
113111
self.content = content
114112
self.tool_calls = tool_calls
@@ -319,7 +317,9 @@ def _consume_stream(stream: Any) -> Dict[str, Any]:
319317
elif etype == "response.failed":
320318
err_resp = getattr(event, "response", None)
321319
err = getattr(err_resp, "error", None) if err_resp else None
322-
failure_payload = err or f"response.failed (no error attached, event={event!r})"
320+
failure_payload = (
321+
err or f"response.failed (no error attached, event={event!r})"
322+
)
323323
elif etype == "error":
324324
failure_payload = getattr(event, "error", None) or repr(event)
325325
elif etype == "response.output_text.delta":
@@ -522,7 +522,9 @@ def _wrap_response(
522522
status = getattr(resp, "status", None)
523523
incomplete = getattr(resp, "incomplete_details", None)
524524
if embedded_error:
525-
raise RuntimeError(f"Codex returned an error in the response body: {embedded_error}")
525+
raise RuntimeError(
526+
f"Codex returned an error in the response body: {embedded_error}"
527+
)
526528
if status and status != "completed":
527529
raise RuntimeError(
528530
f"Codex response ended with status={status!r}"
@@ -566,6 +568,7 @@ def _translate_backend_error(exc: Exception, model: str) -> Exception:
566568
plan = ""
567569
try:
568570
from craftos_integrations.integrations.llm_oauth.chatgpt import load as _load
571+
569572
cred = _load()
570573
if cred is not None:
571574
plan = (getattr(cred, "plan", "") or "").lower()

0 commit comments

Comments
 (0)