重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。

同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。

Made-with: Cursor
This commit is contained in:
oliver 2026-04-26 08:34:33 +08:00
parent 4a23b715a2
commit dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions

View file

@ -4,8 +4,7 @@ from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple
from .frontmatter import resolve_hook_key
HookSource = Literal["oclaw-bundled", "oclaw-plugin", "oclaw-managed", "oclaw-workspace"]
from .hook_types import HookEntry, HookSource, ensure_entry_dict, ensure_hook_entry
@dataclass(frozen=True, slots=True)
@ -63,22 +62,27 @@ def resolve_hook_config(config: Optional[Dict[str, Any]], hook_key: str) -> Opti
return entry if isinstance(entry, dict) else None
def resolve_hook_enable_state(entry: Dict[str, Any], config: Optional[Dict[str, Any]]) -> Dict[str, Any]:
def resolve_hook_enable_state(entry: HookEntry | Dict[str, Any], config: Optional[Dict[str, Any]]) -> Dict[str, Any]:
"""
Returns { enabled: bool, reason?: str }
"""
hook = entry.get("hook") if isinstance(entry, dict) else None
entry_dict = ensure_entry_dict(entry)
hook = entry_dict.get("hook") if isinstance(entry_dict, dict) else None
name = (hook or {}).get("name") if isinstance(hook, dict) else None
source = (hook or {}).get("source") if isinstance(hook, dict) else None
if not isinstance(name, str) or not isinstance(source, str):
return {"enabled": False, "reason": "invalid hook entry"}
hook_key = resolve_hook_key(name, entry)
hook_key = resolve_hook_key(name, entry_dict)
hook_cfg = resolve_hook_config(config, hook_key)
invocation = entry_dict.get("invocation") if isinstance(entry_dict.get("invocation"), dict) else {}
if source == "oclaw-plugin":
return {"enabled": True}
if invocation.get("enabled") is False:
return {"enabled": False, "reason": "disabled by hook invocation policy"}
if isinstance(hook_cfg, dict) and hook_cfg.get("enabled") is False:
return {"enabled": False, "reason": "disabled in config"}
@ -89,9 +93,11 @@ def resolve_hook_enable_state(entry: Dict[str, Any], config: Optional[Dict[str,
return {"enabled": True}
def _can_override(candidate: Dict[str, Any], existing: Dict[str, Any]) -> bool:
c_source = ((candidate.get("hook") or {}).get("source")) if isinstance(candidate, dict) else None
e_source = ((existing.get("hook") or {}).get("source")) if isinstance(existing, dict) else None
def _can_override(candidate: HookEntry | Dict[str, Any], existing: HookEntry | Dict[str, Any]) -> bool:
c_dict = ensure_entry_dict(candidate)
e_dict = ensure_entry_dict(existing)
c_source = ((c_dict.get("hook") or {}).get("source")) if isinstance(c_dict, dict) else None
e_source = ((e_dict.get("hook") or {}).get("source")) if isinstance(e_dict, dict) else None
if c_source not in HOOK_SOURCE_POLICIES or e_source not in HOOK_SOURCE_POLICIES:
return False
c_pol = get_hook_source_policy(c_source) # type: ignore[arg-type]
@ -100,26 +106,41 @@ def _can_override(candidate: Dict[str, Any], existing: Dict[str, Any]) -> bool:
def resolve_hook_entries(
entries: Sequence[Dict[str, Any]],
entries: Sequence[HookEntry | Dict[str, Any]],
on_collision_ignored: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> List[Dict[str, Any]]:
) -> List[HookEntry]:
ordered = sorted(
list(enumerate(entries)),
key=lambda x: (get_hook_source_policy(x[1]["hook"]["source"]).precedence, x[0]), # type: ignore[index]
key=lambda x: (
get_hook_source_policy(
str((ensure_entry_dict(x[1]).get("hook") or {}).get("source") or "oclaw-managed") # type: ignore[arg-type]
).precedence,
x[0],
),
)
merged: Dict[str, Dict[str, Any]] = {}
merged: Dict[str, HookEntry] = {}
for _, entry in ordered:
name = entry.get("hook", {}).get("name")
name = ensure_entry_dict(entry).get("hook", {}).get("name")
if not isinstance(name, str):
continue
existing = merged.get(name)
if not existing:
merged[name] = entry
merged[name] = ensure_hook_entry(entry)
continue
if _can_override(entry, existing):
merged[name] = entry
merged[name] = ensure_hook_entry(entry)
continue
if on_collision_ignored:
on_collision_ignored({"name": name, "kept": existing, "ignored": entry})
on_collision_ignored(
{"name": name, "kept": ensure_entry_dict(existing), "ignored": ensure_entry_dict(entry)}
)
return list(merged.values())
def resolve_hook_entries_compat(
entries: Sequence[HookEntry | Dict[str, Any]],
on_collision_ignored: Optional[Callable[[Dict[str, Any]], None]] = None,
) -> List[Dict[str, Any]]:
resolved = resolve_hook_entries(entries, on_collision_ignored=on_collision_ignored)
return [ensure_entry_dict(e) for e in resolved]