Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(skills): a portable skill can never promote itself by being unreadable
Harald7269d7549d9c
diff --git a/docs/marketplace/portable-skills.md b/docs/marketplace/portable-skills.mdindex 51f8ab1be2..3897cff7ca 100644--- a/docs/marketplace/portable-skills.md+++ b/docs/marketplace/portable-skills.md@@ -63,6 +63,12 @@ schema, so a typo in a hand-written skill is caught where it is made.`description`, `when_to_use`, `version`, `author`, `license`, `category`,`tags`, the three URLs, `token_budget_estimate`. Dashed spellings(`when-to-use`) fold onto the underscored ones.+* **`state` is adopted, for the opposite of the usual reason.** The loader+ reads a missing `state` as VALIDATED — the active pool — so dropping an+ author's (or the import route's, AP-15) `state: draft` would *promote* the+ file by discarding its own restriction. It is read so it can only hold a+ skill back: a value in a vocabulary Jarvis does not share (`state:+ published`) falls to DRAFT rather than being ignored.* **Nothing that grants behaviour crosses over** — not even when a foreignfile spells it exactly the way Jarvis does: `triggers` (fires by itself),`risk_policy` (lowers the confirmation tier), `auto_fire` (promotes into thediff --git a/jarvis/skills/portable.py b/jarvis/skills/portable.pyindex e574d3c245..d84e900b23 100644--- a/jarvis/skills/portable.py+++ b/jarvis/skills/portable.py@@ -37,13 +37,20 @@ from typing import Anyfrom pydantic import ValidationError-from .schema import SkillFrontmatter+from .schema import SkillFrontmatter, SkillLifecycleStatelog = logging.getLogger(__name__)#: The frontmatter fields a foreign skill may contribute. Descriptive only —#: identity, prose, provenance. See the module docstring for why the#: behaviour-granting fields are absent.+#:+#: ``state`` is the one apparent exception, and it is here for the opposite of+#: the usual reason: dropping it would be the PERMISSIVE choice. The loader+#: reads a missing ``state`` as VALIDATED — the active pool — so ignoring an+#: author's (or the import route's) ``state: draft`` would silently promote the+#: file. It is adopted so it can only ever hold the skill back, never let it+#: through: an unreadable value falls to DRAFT rather than being dropped.ADOPTED_FIELDS: frozenset[str] = frozenset({"name",@@ -58,6 +65,7 @@ ADOPTED_FIELDS: frozenset[str] = frozenset("source_url","docs_url","token_budget_estimate",+ "state",})@@ -87,6 +95,28 @@ def _normalise_key(key: Any) -> str:return str(key).strip().replace("-", "_").lower()+def _fail_closed_state(+ frontmatter: SkillFrontmatter, meta: Mapping[str, Any]+) -> SkillFrontmatter:+ """A ``state:`` the adapter could not read means DRAFT, never "active".++ The loader reads an absent ``state`` as VALIDATED, so a foreign file+ spelling it in a vocabulary Jarvis does not share (``state: published``)+ would otherwise be *promoted* by having its own restriction dropped. The+ file said something about its readiness; not understanding it is a reason+ to hold it back, not to wave it through.+ """+ if frontmatter.state is not None:+ return frontmatter+ if not any(_normalise_key(key) == "state" for key in meta):+ return frontmatter+ log.warning(+ "portable skill %r declared an unreadable state — holding it as draft",+ frontmatter.name,+ )+ return frontmatter.model_copy(update={"state": SkillLifecycleState.DRAFT})++def adapt_portable_frontmatter(meta: Mapping[str, Any]) -> PortableAdaptation | None:"""Adapt a foreign frontmatter mapping, or return None if it is not one.@@ -143,7 +173,7 @@ def adapt_portable_frontmatter(meta: Mapping[str, Any]) -> PortableAdaptation |return Nonecontinuereturn PortableAdaptation(- frontmatter=frontmatter,+ frontmatter=_fail_closed_state(frontmatter, meta),ignored=tuple(sorted(ignored)),)diff --git a/tests/unit/skills/test_portable_skills.py b/tests/unit/skills/test_portable_skills.pyindex 2c4a26c6b7..f822cf2bb8 100644--- a/tests/unit/skills/test_portable_skills.py+++ b/tests/unit/skills/test_portable_skills.py@@ -185,6 +185,52 @@ Body.assert skill.portable is False+def test_a_declared_draft_is_honoured(tmp_path: Path) -> None:+ """AP-15: the import route stamps ``state: draft`` into the file it stores.++ Dropping that key in portable mode would PROMOTE the skill — the loader+ reads an absent state as VALIDATED, which is the active pool. So a+ downloaded file that says draft stays a draft.+ """+ text = """---+name: imported+description: downloaded from the internet+allowed-tools: Read+state: draft+---++Body.+"""+ skill = parse_skill(_write(tmp_path, "imported", text))++ assert skill.portable is True+ assert skill.state == SkillLifecycleState.DRAFT+++def test_an_unreadable_state_holds_the_skill_back(tmp_path: Path) -> None:+ # A word from another agent's vocabulary. Not understanding it is a reason+ # to hold the skill, not to wave it through.+ text = """---+name: mystery+description: says something about its own readiness+allowed-tools: Read+state: published+---++Body.+"""+ skill = parse_skill(_write(tmp_path, "mystery", text))++ assert skill.portable is True+ assert skill.state == SkillLifecycleState.DRAFT+++def test_a_state_free_portable_skill_still_loads_normally(tmp_path: Path) -> None:+ skill = parse_skill(_write(tmp_path, "three-point-check", CLAUDE_CODE_SKILL))++ assert skill.state == SkillLifecycleState.VALIDATED++def test_non_mapping_frontmatter_is_refused() -> None:assert adapt_portable_frontmatter({"name": 42}) is Noneassert adapt_portable_frontmatter({"name": " "}) is Nonediff --git a/tests/unit/web/test_skills_import_route.py b/tests/unit/web/test_skills_import_route.pyindex 499ee2eaa2..cdcef78baa 100644--- a/tests/unit/web/test_skills_import_route.py+++ b/tests/unit/web/test_skills_import_route.py@@ -129,6 +129,36 @@ async def test_import_preserves_the_body(assert "description: a skill downloaded from the internet" in stored+_FOREIGN_FORMAT = (+ "---\n"+ "name: remote-skill\n"+ "description: written for another agent\n"+ "allowed-tools: Read, Grep\n"+ "model: inherit\n"+ "---\n\n"+ "## Body\n\nJust a marker body.\n"+)+++async def test_import_accepts_a_skill_written_for_another_agent(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A SKILL.md in the open Agent Skills format imports — and stays a draft.++ The portable adapter (jarvis/skills/portable.py) is what makes the first+ half work; the second half is the guard above it: the adapter must not+ drop the stamped ``state: draft`` and thereby promote the file into the+ active pool.+ """+ detail, frontmatter = await _import(_FOREIGN_FORMAT, tmp_path, monkeypatch)++ assert frontmatter["state"] == "draft"+ assert detail["state"] == "draft"+ assert detail["portable"] is True+ assert set(detail["ignored_fields"]) == {"allowed-tools", "model"}++@pytest.mark.asyncioasync def test_import_refuses_a_traversal_name(tmp_path: Path, monkeypatch: pytest.MonkeyPatch