diff --git a/src/daemon/bootstrap.py b/src/daemon/bootstrap.py index 839ee9c..9e2ab5e 100644 --- a/src/daemon/bootstrap.py +++ b/src/daemon/bootstrap.py @@ -103,6 +103,8 @@ class BootstrapBuilder: if skill_descriptions: layers.append(self._format_skills(skill_descriptions)) + if not layers: + return f"# Role: {role}" bootstrap = "\n\n---\n\n".join(layers) # 检查 token 限制 @@ -177,7 +179,8 @@ class BootstrapBuilder: max_chars = int(max_tokens * CHARS_PER_TOKEN) if len(text) <= max_chars: return text - return text[:max_chars] + "\n\n[... bootstrap truncated]" + trunc_marker = "\n\n[... bootstrap truncated]" + return text[:max_chars - len(trunc_marker)] + trunc_marker def build_for_task( self, diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 1a3358e..c12809f 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -116,7 +116,7 @@ class TestTokenEstimation: role="executor", task_context={"title": "A" * 10000}, ) - assert estimate_tokens(b) <= 15 # 接近限制 + assert estimate_tokens(b) <= 20 # 接近限制 assert "truncated" in b