seed-kernel 1.0.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- seed/__init__.py +125 -0
- seed/cli.py +102 -0
- seed/core/__init__.py +8 -0
- seed/core/_session_cache.py +41 -0
- seed/core/agent_context.py +163 -0
- seed/core/agent_registry.py +180 -0
- seed/core/agent_runtime.py +2384 -0
- seed/core/chat_events.py +70 -0
- seed/core/commands.py +149 -0
- seed/core/config_plane.py +537 -0
- seed/core/engine.py +150 -0
- seed/core/env_access.py +168 -0
- seed/core/execution.py +148 -0
- seed/core/llm_exec.py +1652 -0
- seed/core/llm_presets.py +305 -0
- seed/core/llm_sess.py +1094 -0
- seed/core/media_store.py +84 -0
- seed/core/mem_bridge.py +294 -0
- seed/core/mem_sys.py +409 -0
- seed/core/model_providers.py +88 -0
- seed/core/models.py +211 -0
- seed/core/paths.py +109 -0
- seed/core/persistence.py +133 -0
- seed/core/proj_reg.py +609 -0
- seed/core/proj_todos.py +141 -0
- seed/core/projection_audit.py +317 -0
- seed/core/routing.py +192 -0
- seed/core/sess_store.py +44 -0
- seed/core/tool_output_cap.py +122 -0
- seed/core/tool_runtime.py +330 -0
- seed/core/trace_audit.py +123 -0
- seed/core/turn_loop.py +750 -0
- seed/core/usage_accumulator.py +72 -0
- seed/integrations/__init__.py +33 -0
- seed/integrations/agent_tools.py +160 -0
- seed/integrations/cron_sched.py +773 -0
- seed/integrations/env_config.py +77 -0
- seed/integrations/exec_backend.py +432 -0
- seed/integrations/hooks.py +61 -0
- seed/integrations/hooks_config.py +109 -0
- seed/integrations/instruction_release.py +256 -0
- seed/integrations/lsp_client.py +219 -0
- seed/integrations/lsp_config.py +99 -0
- seed/integrations/mcp_client.py +1283 -0
- seed/integrations/mcp_config.py +208 -0
- seed/integrations/mcp_registry.py +154 -0
- seed/integrations/message_api.py +16 -0
- seed/integrations/prompt_task.py +39 -0
- seed/integrations/safety.py +331 -0
- seed/integrations/session_title.py +211 -0
- seed/integrations/symbol_index.py +311 -0
- seed/integrations/task_runner.py +275 -0
- seed/integrations/webhook_auth.py +33 -0
- seed/integrations/webhook_dedup.py +132 -0
- seed/models.py +31 -0
- seed_kernel-1.0.11.dist-info/METADATA +17 -0
- seed_kernel-1.0.11.dist-info/RECORD +60 -0
- seed_kernel-1.0.11.dist-info/WHEEL +5 -0
- seed_kernel-1.0.11.dist-info/entry_points.txt +2 -0
- seed_kernel-1.0.11.dist-info/top_level.txt +1 -0
seed/core/chat_events.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextvars import ContextVar, Token
|
|
4
|
+
from typing import Any, Callable, Dict, Optional
|
|
5
|
+
|
|
6
|
+
_EMITTER: ContextVar[Optional[Callable[[Dict[str, Any]], None]]] = ContextVar(
|
|
7
|
+
"seed_chat_event_emitter",
|
|
8
|
+
default=None,
|
|
9
|
+
)
|
|
10
|
+
_CURRENT_TOOL: ContextVar[Optional[Dict[str, Any]]] = ContextVar(
|
|
11
|
+
"seed_current_tool_context",
|
|
12
|
+
default=None,
|
|
13
|
+
)
|
|
14
|
+
_CANCEL_CHECKER: ContextVar[Optional[Callable[[], bool]]] = ContextVar(
|
|
15
|
+
"seed_chat_cancel_checker",
|
|
16
|
+
default=None,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def set_chat_event_emitter(
|
|
21
|
+
emitter: Optional[Callable[[Dict[str, Any]], None]]
|
|
22
|
+
) -> Token[Optional[Callable[[Dict[str, Any]], None]]]:
|
|
23
|
+
return _EMITTER.set(emitter)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def reset_chat_event_emitter(token: Token[Optional[Callable[[Dict[str, Any]], None]]]) -> None:
|
|
27
|
+
_EMITTER.reset(token)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def emit_chat_event(event: Dict[str, Any]) -> None:
|
|
31
|
+
emitter = _EMITTER.get()
|
|
32
|
+
if not emitter:
|
|
33
|
+
return
|
|
34
|
+
try:
|
|
35
|
+
emitter(dict(event))
|
|
36
|
+
except Exception:
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def set_current_tool_context(ctx: Optional[Dict[str, Any]]) -> Token[Optional[Dict[str, Any]]]:
|
|
41
|
+
return _CURRENT_TOOL.set(ctx)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def reset_current_tool_context(token: Token[Optional[Dict[str, Any]]]) -> None:
|
|
45
|
+
_CURRENT_TOOL.reset(token)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_current_tool_context() -> Optional[Dict[str, Any]]:
|
|
49
|
+
ctx = _CURRENT_TOOL.get()
|
|
50
|
+
return dict(ctx) if isinstance(ctx, dict) else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def set_chat_cancel_checker(
|
|
54
|
+
checker: Optional[Callable[[], bool]]
|
|
55
|
+
) -> Token[Optional[Callable[[], bool]]]:
|
|
56
|
+
return _CANCEL_CHECKER.set(checker)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def reset_chat_cancel_checker(token: Token[Optional[Callable[[], bool]]]) -> None:
|
|
60
|
+
_CANCEL_CHECKER.reset(token)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def is_chat_cancelled() -> bool:
|
|
64
|
+
checker = _CANCEL_CHECKER.get()
|
|
65
|
+
if checker is None:
|
|
66
|
+
return False
|
|
67
|
+
try:
|
|
68
|
+
return bool(checker())
|
|
69
|
+
except Exception:
|
|
70
|
+
return False
|
seed/core/commands.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Command routing engine."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
from typing import List, Optional, Tuple
|
|
6
|
+
|
|
7
|
+
from seed.core.models import Command, CommandRoutingResult
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def tokenize_input(input_string: str) -> Tuple[str, List[str]]:
|
|
13
|
+
tokens = input_string.strip().split()
|
|
14
|
+
if not tokens:
|
|
15
|
+
return "", []
|
|
16
|
+
command_name = tokens[0]
|
|
17
|
+
arguments = tokens[1:] if len(tokens) > 1 else []
|
|
18
|
+
return command_name, arguments
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def edit_distance(s1: str, s2: str) -> int:
|
|
22
|
+
if len(s1) < len(s2):
|
|
23
|
+
return edit_distance(s2, s1)
|
|
24
|
+
if len(s2) == 0:
|
|
25
|
+
return len(s1)
|
|
26
|
+
previous_row = range(len(s2) + 1)
|
|
27
|
+
for i, c1 in enumerate(s1):
|
|
28
|
+
current_row = [i + 1]
|
|
29
|
+
for j, c2 in enumerate(s2):
|
|
30
|
+
insertions = previous_row[j + 1] + 1
|
|
31
|
+
deletions = current_row[j] + 1
|
|
32
|
+
substitutions = previous_row[j] + (c1 != c2)
|
|
33
|
+
current_row.append(min(insertions, deletions, substitutions))
|
|
34
|
+
previous_row = current_row
|
|
35
|
+
return previous_row[-1]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def fuzzy_match(input_cmd: str, commands: List[Command], threshold: int = 3) -> List[str]:
|
|
39
|
+
suggestions: List[Tuple[int, str]] = []
|
|
40
|
+
input_lower = input_cmd.lower()
|
|
41
|
+
for cmd in commands:
|
|
42
|
+
if cmd.name.lower() == input_lower or any(
|
|
43
|
+
alias.lower() == input_lower for alias in cmd.aliases
|
|
44
|
+
):
|
|
45
|
+
return [cmd.name]
|
|
46
|
+
distance = edit_distance(input_lower, cmd.name.lower())
|
|
47
|
+
if distance <= threshold:
|
|
48
|
+
suggestions.append((distance, cmd.name))
|
|
49
|
+
suggestions.sort(key=lambda x: x[0])
|
|
50
|
+
return [name for _, name in suggestions[:3]] if suggestions else []
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def find_command(input_cmd: str, commands: List[Command], fuzzy_threshold: int = 3) -> CommandRoutingResult:
|
|
54
|
+
input_lower = input_cmd.lower().strip()
|
|
55
|
+
for cmd in commands:
|
|
56
|
+
if cmd.name.lower() == input_lower:
|
|
57
|
+
return CommandRoutingResult(matched=True, command=cmd, command_args=[])
|
|
58
|
+
for alias in cmd.aliases:
|
|
59
|
+
if alias.lower() == input_lower:
|
|
60
|
+
return CommandRoutingResult(
|
|
61
|
+
matched=True,
|
|
62
|
+
command=cmd,
|
|
63
|
+
command_args=[],
|
|
64
|
+
suggestions=[cmd.name],
|
|
65
|
+
)
|
|
66
|
+
prefix_matches = [
|
|
67
|
+
cmd
|
|
68
|
+
for cmd in commands
|
|
69
|
+
if cmd.name.lower().startswith(input_lower)
|
|
70
|
+
or any(alias.lower().startswith(input_lower) for alias in cmd.aliases)
|
|
71
|
+
]
|
|
72
|
+
if len(prefix_matches) == 1:
|
|
73
|
+
return CommandRoutingResult(matched=True, command=prefix_matches[0], command_args=[])
|
|
74
|
+
|
|
75
|
+
suggestions = fuzzy_match(input_cmd, commands, fuzzy_threshold)
|
|
76
|
+
|
|
77
|
+
if prefix_matches:
|
|
78
|
+
names = [cmd.name for cmd in prefix_matches[:3]]
|
|
79
|
+
return CommandRoutingResult(
|
|
80
|
+
matched=False,
|
|
81
|
+
command=None,
|
|
82
|
+
command_args=[],
|
|
83
|
+
suggestions=names,
|
|
84
|
+
error=f"Ambiguous prefix match. Did you mean one of: {', '.join(names)}?",
|
|
85
|
+
)
|
|
86
|
+
if suggestions:
|
|
87
|
+
return CommandRoutingResult(
|
|
88
|
+
matched=False,
|
|
89
|
+
command=None,
|
|
90
|
+
command_args=[],
|
|
91
|
+
suggestions=suggestions,
|
|
92
|
+
error=f"Command not found. Did you mean: {', '.join(suggestions)}?",
|
|
93
|
+
)
|
|
94
|
+
return CommandRoutingResult(
|
|
95
|
+
matched=False,
|
|
96
|
+
command=None,
|
|
97
|
+
command_args=[],
|
|
98
|
+
suggestions=[],
|
|
99
|
+
error=f"Command '{input_cmd}' not found. Use 'commands' to see available commands.",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class CommandRouter:
|
|
104
|
+
"""Register commands and route raw input strings."""
|
|
105
|
+
|
|
106
|
+
def __init__(self) -> None:
|
|
107
|
+
self.commands: List[Command] = []
|
|
108
|
+
|
|
109
|
+
def add_command(self, command: Command) -> None:
|
|
110
|
+
self.commands.append(command)
|
|
111
|
+
|
|
112
|
+
def add_commands(self, commands: List[Command]) -> None:
|
|
113
|
+
self.commands.extend(commands)
|
|
114
|
+
|
|
115
|
+
def remove_command(self, name: str) -> bool:
|
|
116
|
+
for i, cmd in enumerate(self.commands):
|
|
117
|
+
if cmd.name.lower() == name.lower() or any(
|
|
118
|
+
alias.lower() == name.lower() for alias in cmd.aliases
|
|
119
|
+
):
|
|
120
|
+
self.commands.pop(i)
|
|
121
|
+
return True
|
|
122
|
+
return False
|
|
123
|
+
|
|
124
|
+
def get_command(self, name: str) -> Optional[Command]:
|
|
125
|
+
for cmd in self.commands:
|
|
126
|
+
if cmd.name.lower() == name.lower() or any(
|
|
127
|
+
alias.lower() == name.lower() for alias in cmd.aliases
|
|
128
|
+
):
|
|
129
|
+
return cmd
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
def list_commands(self) -> List[Command]:
|
|
133
|
+
return self.commands.copy()
|
|
134
|
+
|
|
135
|
+
def count_commands(self) -> int:
|
|
136
|
+
return len(self.commands)
|
|
137
|
+
|
|
138
|
+
def route(self, input_string: str, fuzzy_threshold: int = 3) -> CommandRoutingResult:
|
|
139
|
+
command_name, arguments = tokenize_input(input_string)
|
|
140
|
+
if not command_name:
|
|
141
|
+
return CommandRoutingResult(
|
|
142
|
+
matched=False,
|
|
143
|
+
command=None,
|
|
144
|
+
command_args=[],
|
|
145
|
+
error="Empty input",
|
|
146
|
+
)
|
|
147
|
+
result = find_command(command_name, self.commands, fuzzy_threshold)
|
|
148
|
+
result.command_args = arguments
|
|
149
|
+
return result
|