-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodec_dispatch.py
More file actions
51 lines (40 loc) · 1.48 KB
/
codec_dispatch.py
File metadata and controls
51 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""CODEC Skill Dispatch — load and match skills from ~/.codec/skills/
Uses SkillRegistry for lazy loading: only metadata (name, triggers,
description) is parsed at startup via AST. The actual module import
happens on first invocation of a skill.
"""
import logging
from codec_config import SKILLS_DIR
from codec_skill_registry import SkillRegistry
log = logging.getLogger('codec')
# Global registry instance shared across codec.py
registry = SkillRegistry(SKILLS_DIR)
def load_skills():
"""Scan skill plugins from SKILLS_DIR — extracts metadata only (fast)."""
registry.scan()
def check_skill(task):
"""Return a skill-like dict for the matching skill, or None.
The dict has 'name' and a lazy 'run' key that triggers the actual
module import on first call.
"""
name = registry.match_trigger(task)
if name is None:
return None
return {
'name': name,
'triggers': registry.get_triggers(name),
'run': lambda task, app="", **kw: registry.run(name, task, app),
}
def run_skill(skill, task, app=""):
"""Execute a skill and return its result."""
try:
result = skill['run'](task, app)
skill_name = skill.get('name', 'unknown')
try:
with open("/tmp/codec_overlay_events.jsonl", "a") as _f:
_f.write(f'{{"type":"skill_fired","name":"{skill_name}"}}\n')
except Exception:
pass
return result
except Exception as e:
return f"Skill error: {e}"