swarmkit-schema 1.0.0__tar.gz

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.
@@ -0,0 +1,66 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ .venv/
8
+ venv/
9
+ env/
10
+ .eggs/
11
+ *.egg-info/
12
+ *.egg
13
+ build/
14
+ dist/
15
+ .pytest_cache/
16
+ .mypy_cache/
17
+ .ruff_cache/
18
+ .pyre/
19
+ .pytype/
20
+ .coverage
21
+ .coverage.*
22
+ htmlcov/
23
+ coverage.xml
24
+ *.cover
25
+ .hypothesis/
26
+ .tox/
27
+ .nox/
28
+
29
+ # Node / TypeScript
30
+ node_modules/
31
+ .next/
32
+ out/
33
+ .turbo/
34
+ .nx/
35
+ dist/
36
+ *.tsbuildinfo
37
+ .pnpm-store/
38
+ .yarn/
39
+
40
+ # Editors / OS
41
+ .vscode/
42
+ .idea/
43
+ *.swp
44
+ *.swo
45
+ .DS_Store
46
+ Thumbs.db
47
+ *~
48
+
49
+ # Env / secrets
50
+ .env
51
+ .env.local
52
+ .env.*.local
53
+ *.pem
54
+
55
+ # SwarmKit runtime artifacts (per design §9.3)
56
+ .swarmkit/
57
+ *.sqlite
58
+ *.sqlite-journal
59
+
60
+ # Claude Code
61
+ .claude/settings.local.json
62
+
63
+ # Build / logs
64
+ *.log
65
+ .cache/
66
+ _site/
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmkit-schema
3
+ Version: 1.0.0
4
+ Summary: SwarmKit JSON Schemas + Python validator.
5
+ Author: Srijith Kartha
6
+ License: MIT
7
+ Keywords: json-schema,schema,swarmkit
8
+ Requires-Python: >=3.11
9
+ Requires-Dist: jsonschema>=4.23
10
+ Requires-Dist: pydantic>=2.8
11
+ Requires-Dist: pyyaml>=6.0
12
+ Requires-Dist: referencing>=0.35
13
+ Provides-Extra: dev
14
+ Requires-Dist: mypy>=1.11; extra == 'dev'
15
+ Requires-Dist: pytest>=8.0; extra == 'dev'
16
+ Requires-Dist: ruff>=0.6; extra == 'dev'
17
+ Requires-Dist: types-jsonschema; extra == 'dev'
18
+ Requires-Dist: types-pyyaml; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ SwarmKit canonical JSON Schemas + Python validator. See https://github.com/delivstat/swarmkit
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "swarmkit-schema"
3
+ version = "1.0.0"
4
+ description = "SwarmKit JSON Schemas + Python validator."
5
+ readme = {text = "SwarmKit canonical JSON Schemas + Python validator. See https://github.com/delivstat/swarmkit", content-type = "text/markdown"}
6
+ requires-python = ">=3.11"
7
+ license = { text = "MIT" }
8
+ authors = [{ name = "Srijith Kartha" }]
9
+ keywords = ["swarmkit", "schema", "json-schema"]
10
+
11
+ dependencies = [
12
+ "jsonschema>=4.23",
13
+ "pydantic>=2.8",
14
+ "pyyaml>=6.0",
15
+ "referencing>=0.35",
16
+ ]
17
+
18
+ [project.optional-dependencies]
19
+ dev = [
20
+ "pytest>=8.0",
21
+ "mypy>=1.11",
22
+ "ruff>=0.6",
23
+ "types-pyyaml",
24
+ "types-jsonschema",
25
+ ]
26
+
27
+ [build-system]
28
+ requires = ["hatchling"]
29
+ build-backend = "hatchling.build"
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ packages = ["src/swarmkit_schema"]
@@ -0,0 +1,56 @@
1
+ """SwarmKit schema validators (Python).
2
+
3
+ The JSON Schema files under `packages/schema/schemas/` are the source of truth —
4
+ this package only validates against them. See `packages/schema/CLAUDE.md` for
5
+ the dual-surface rule.
6
+
7
+ Resolution order:
8
+ 1. `_schemas/` inside the installed package (wheel builds via hatch
9
+ `force-include`).
10
+ 2. `packages/schema/schemas/` relative to this file (editable / dev mode).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import json
16
+ from pathlib import Path
17
+ from typing import Any, Literal
18
+
19
+ import jsonschema
20
+
21
+ __version__ = "0.0.1"
22
+
23
+ SchemaName = Literal["topology", "skill", "archetype", "workspace", "trigger"]
24
+
25
+ _HERE = Path(__file__).resolve().parent
26
+
27
+
28
+ def _schema_root() -> Path:
29
+ installed = _HERE / "_schemas"
30
+ if installed.is_dir():
31
+ return installed
32
+ # Editable dev mode: packages/schema/python/src/swarmkit_schema → ../../../schemas
33
+ dev = _HERE.parent.parent.parent / "schemas"
34
+ if dev.is_dir():
35
+ return dev
36
+ raise RuntimeError(f"Canonical JSON Schemas not found. Looked in:\n {installed}\n {dev}")
37
+
38
+
39
+ def _load(name: SchemaName) -> dict[str, Any]:
40
+ path = _schema_root() / f"{name}.schema.json"
41
+ data: dict[str, Any] = json.loads(path.read_text(encoding="utf-8"))
42
+ return data
43
+
44
+
45
+ def get_schema(name: SchemaName) -> dict[str, Any]:
46
+ """Return the canonical JSON Schema for the given artifact type."""
47
+ return _load(name)
48
+
49
+
50
+ def validate(name: SchemaName, instance: Any) -> None:
51
+ """Validate `instance` against the named schema. Raises `ValidationError` on failure."""
52
+ schema = _load(name)
53
+ jsonschema.validate(instance=instance, schema=schema)
54
+
55
+
56
+ __all__ = ["SchemaName", "__version__", "get_schema", "validate"]
@@ -0,0 +1,126 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.swarmkit.dev/v1/archetype.schema.json",
4
+ "title": "SwarmKit Archetype",
5
+ "description": "A kind of agent (noun). See design §6.6, §13 and design/details/archetype-schema-v1.md.",
6
+ "type": "object",
7
+ "required": ["apiVersion", "kind", "metadata", "role", "defaults", "provenance"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "apiVersion": { "const": "swarmkit/v1" },
11
+ "kind": { "const": "Archetype" },
12
+ "metadata": { "$ref": "#/$defs/metadata" },
13
+ "role": {
14
+ "enum": ["root", "leader", "worker"],
15
+ "description": "Must match the agent role where this archetype is instantiated."
16
+ },
17
+ "defaults": { "$ref": "#/$defs/defaults" },
18
+ "provenance": { "$ref": "#/$defs/provenance" }
19
+ },
20
+ "$defs": {
21
+ "identifier": {
22
+ "type": "string",
23
+ "pattern": "^[a-z][a-z0-9-]*$"
24
+ },
25
+ "semver": {
26
+ "type": "string",
27
+ "pattern": "^\\d+\\.\\d+\\.\\d+$"
28
+ },
29
+ "metadata": {
30
+ "type": "object",
31
+ "additionalProperties": false,
32
+ "required": ["id", "name", "description"],
33
+ "properties": {
34
+ "id": { "$ref": "#/$defs/identifier" },
35
+ "name": { "type": "string", "minLength": 1 },
36
+ "description": { "type": "string", "minLength": 10 }
37
+ }
38
+ },
39
+ "defaults": {
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "properties": {
43
+ "model": { "$ref": "#/$defs/model" },
44
+ "prompt": { "$ref": "#/$defs/prompt" },
45
+ "skills": {
46
+ "type": "array",
47
+ "items": { "$ref": "#/$defs/skill_entry" }
48
+ },
49
+ "iam": { "$ref": "#/$defs/iam" }
50
+ }
51
+ },
52
+ "model": {
53
+ "type": "object",
54
+ "additionalProperties": true,
55
+ "properties": {
56
+ "provider": { "type": "string" },
57
+ "name": { "type": "string" },
58
+ "temperature": { "type": "number", "minimum": 0, "maximum": 2 },
59
+ "max_tokens": { "type": "integer", "minimum": 1 }
60
+ }
61
+ },
62
+ "prompt": {
63
+ "type": "object",
64
+ "additionalProperties": true,
65
+ "properties": {
66
+ "system": { "type": "string" },
67
+ "persona": { "type": "string" }
68
+ }
69
+ },
70
+ "skill_entry": {
71
+ "$comment": "Concrete skill ID (string) or abstract-skill placeholder (§6.6 edge case).",
72
+ "oneOf": [
73
+ { "$ref": "#/$defs/identifier" },
74
+ {
75
+ "type": "object",
76
+ "additionalProperties": false,
77
+ "required": ["abstract"],
78
+ "properties": {
79
+ "abstract": {
80
+ "type": "object",
81
+ "additionalProperties": false,
82
+ "required": ["category"],
83
+ "properties": {
84
+ "category": {
85
+ "enum": ["capability", "decision", "coordination", "persistence"]
86
+ },
87
+ "capability": {
88
+ "type": "string",
89
+ "description": "Free-text tag matched by the topology resolver."
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ ]
96
+ },
97
+ "iam": {
98
+ "type": "object",
99
+ "additionalProperties": false,
100
+ "properties": {
101
+ "base_scope": { "type": "array", "items": { "type": "string" } },
102
+ "elevated_scopes": { "type": "array", "items": { "type": "string" } }
103
+ }
104
+ },
105
+ "provenance": {
106
+ "type": "object",
107
+ "additionalProperties": false,
108
+ "required": ["authored_by", "version"],
109
+ "properties": {
110
+ "authored_by": {
111
+ "enum": [
112
+ "human",
113
+ "authored_by_swarm",
114
+ "derived_from_template",
115
+ "imported_from_registry",
116
+ "vendor_published"
117
+ ]
118
+ },
119
+ "authored_date": { "type": "string", "format": "date" },
120
+ "version": { "$ref": "#/$defs/semver" },
121
+ "registry": { "type": "string" },
122
+ "vendor": { "type": "string" }
123
+ }
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,213 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.swarmkit.dev/v1/skill.schema.json",
4
+ "title": "SwarmKit Skill",
5
+ "description": "A discrete capability an agent can exercise. See design §6 and design/details/skill-schema-v1.md.",
6
+ "type": "object",
7
+ "required": ["apiVersion", "kind", "metadata", "category", "implementation", "provenance"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "apiVersion": { "const": "swarmkit/v1" },
11
+ "kind": { "const": "Skill" },
12
+ "metadata": { "$ref": "#/$defs/metadata" },
13
+ "category": {
14
+ "enum": ["capability", "decision", "coordination", "persistence"],
15
+ "description": "Runtime semantics differ by category (design §6.2)."
16
+ },
17
+ "inputs": {
18
+ "type": "object",
19
+ "description": "JSON Schema (draft 2020-12) defining the skill's input shape.",
20
+ "additionalProperties": true
21
+ },
22
+ "outputs": {
23
+ "type": "object",
24
+ "description": "JSON Schema defining the skill's output shape. Passed to providers for structured generation (Tier 0) and used for deterministic validation (Tier 1). See design/details/structured-output-governance.md.",
25
+ "additionalProperties": true
26
+ },
27
+ "implementation": { "$ref": "#/$defs/implementation" },
28
+ "iam": { "$ref": "#/$defs/iam" },
29
+ "constraints": { "$ref": "#/$defs/constraints" },
30
+ "provenance": { "$ref": "#/$defs/provenance" }
31
+ },
32
+ "allOf": [
33
+ {
34
+ "$comment": "Decision skills must emit a human-readable reasoning string so audits and reviews have a rationale alongside the verdict. See design/details/skill-schema-v1.md §'Decision-category output contract'.",
35
+ "if": {
36
+ "properties": { "category": { "const": "decision" } },
37
+ "required": ["category"]
38
+ },
39
+ "then": {
40
+ "required": ["outputs"],
41
+ "properties": {
42
+ "outputs": {
43
+ "required": ["properties"],
44
+ "properties": {
45
+ "properties": {
46
+ "required": ["reasoning"]
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ ],
54
+ "$defs": {
55
+ "identifier": {
56
+ "type": "string",
57
+ "pattern": "^[a-z][a-z0-9-]*$"
58
+ },
59
+ "semver": {
60
+ "type": "string",
61
+ "pattern": "^\\d+\\.\\d+\\.\\d+$"
62
+ },
63
+ "iam_scope": {
64
+ "type": "string",
65
+ "pattern": "^[a-z][a-z0-9_-]*:[a-z*][a-z0-9_*-]*$",
66
+ "description": "namespace:action — e.g. repo:read, github:write, skills:activate, mcp_servers:*"
67
+ },
68
+ "metadata": {
69
+ "type": "object",
70
+ "additionalProperties": false,
71
+ "required": ["id", "name", "description"],
72
+ "properties": {
73
+ "id": { "$ref": "#/$defs/identifier" },
74
+ "name": { "type": "string", "minLength": 1 },
75
+ "description": { "type": "string", "minLength": 10 }
76
+ }
77
+ },
78
+ "fields": {
79
+ "type": "object",
80
+ "additionalProperties": { "$ref": "#/$defs/field" }
81
+ },
82
+ "field": {
83
+ "type": "object",
84
+ "required": ["type"],
85
+ "additionalProperties": false,
86
+ "properties": {
87
+ "type": {
88
+ "enum": ["string", "number", "integer", "boolean", "enum", "object", "array"]
89
+ },
90
+ "required": { "type": "boolean" },
91
+ "description": { "type": "string" },
92
+ "values": {
93
+ "type": "array",
94
+ "minItems": 1,
95
+ "description": "Required when type=enum."
96
+ },
97
+ "range": {
98
+ "type": "array",
99
+ "items": { "type": "number" },
100
+ "minItems": 2,
101
+ "maxItems": 2,
102
+ "description": "[min, max] — only for number/integer."
103
+ },
104
+ "items": {
105
+ "$ref": "#/$defs/field",
106
+ "description": "Required when type=array."
107
+ },
108
+ "properties": {
109
+ "$ref": "#/$defs/fields",
110
+ "description": "Optional when type=object."
111
+ }
112
+ },
113
+ "allOf": [
114
+ {
115
+ "if": { "properties": { "type": { "const": "enum" } }, "required": ["type"] },
116
+ "then": { "required": ["values"] }
117
+ },
118
+ {
119
+ "if": { "properties": { "type": { "const": "array" } }, "required": ["type"] },
120
+ "then": { "required": ["items"] }
121
+ }
122
+ ]
123
+ },
124
+ "implementation": {
125
+ "oneOf": [
126
+ {
127
+ "type": "object",
128
+ "additionalProperties": false,
129
+ "required": ["type", "server", "tool"],
130
+ "properties": {
131
+ "type": { "const": "mcp_tool" },
132
+ "server": { "type": "string", "minLength": 1 },
133
+ "tool": { "type": "string", "minLength": 1 },
134
+ "arguments": { "type": "object" }
135
+ }
136
+ },
137
+ {
138
+ "type": "object",
139
+ "additionalProperties": false,
140
+ "required": ["type", "prompt"],
141
+ "properties": {
142
+ "type": { "const": "llm_prompt" },
143
+ "model": { "type": "object", "additionalProperties": true },
144
+ "prompt": { "type": "string", "minLength": 1 }
145
+ }
146
+ },
147
+ {
148
+ "type": "object",
149
+ "additionalProperties": false,
150
+ "required": ["type", "composes"],
151
+ "properties": {
152
+ "type": { "const": "composed" },
153
+ "composes": {
154
+ "type": "array",
155
+ "minItems": 1,
156
+ "items": { "$ref": "#/$defs/identifier" }
157
+ },
158
+ "strategy": {
159
+ "enum": ["parallel-consensus", "sequential", "custom"]
160
+ }
161
+ }
162
+ }
163
+ ]
164
+ },
165
+ "iam": {
166
+ "type": "object",
167
+ "additionalProperties": false,
168
+ "properties": {
169
+ "required_scopes": {
170
+ "type": "array",
171
+ "items": { "$ref": "#/$defs/iam_scope" }
172
+ }
173
+ }
174
+ },
175
+ "constraints": {
176
+ "type": "object",
177
+ "additionalProperties": false,
178
+ "properties": {
179
+ "max_latency_ms": { "type": "integer", "minimum": 1 },
180
+ "timeout_seconds": { "type": "integer", "minimum": 1 },
181
+ "retry": {
182
+ "type": "object",
183
+ "additionalProperties": false,
184
+ "properties": {
185
+ "attempts": { "type": "integer", "minimum": 0 },
186
+ "backoff": { "enum": ["exponential", "linear", "none"] }
187
+ }
188
+ },
189
+ "on_failure": { "enum": ["escalate_to_human", "fail", "retry", "fallback"] }
190
+ }
191
+ },
192
+ "provenance": {
193
+ "type": "object",
194
+ "additionalProperties": false,
195
+ "required": ["authored_by", "version"],
196
+ "properties": {
197
+ "authored_by": {
198
+ "enum": [
199
+ "human",
200
+ "authored_by_swarm",
201
+ "derived_from_template",
202
+ "imported_from_registry",
203
+ "vendor_published"
204
+ ]
205
+ },
206
+ "authored_date": { "type": "string", "format": "date" },
207
+ "version": { "$ref": "#/$defs/semver" },
208
+ "registry": { "type": "string" },
209
+ "vendor": { "type": "string" }
210
+ }
211
+ }
212
+ }
213
+ }