dynamic-skill-compiler 0.1.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.
Files changed (28) hide show
  1. dynamic_skill_compiler-0.1.0/LICENSE +21 -0
  2. dynamic_skill_compiler-0.1.0/MANIFEST.in +12 -0
  3. dynamic_skill_compiler-0.1.0/PKG-INFO +155 -0
  4. dynamic_skill_compiler-0.1.0/README.md +119 -0
  5. dynamic_skill_compiler-0.1.0/pyproject.toml +63 -0
  6. dynamic_skill_compiler-0.1.0/reports/dynamic_skill_compiler_design.md +99 -0
  7. dynamic_skill_compiler-0.1.0/setup.cfg +4 -0
  8. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/__init__.py +66 -0
  9. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/cli.py +141 -0
  10. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/decompose.py +207 -0
  11. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/fragments.py +205 -0
  12. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/graph.py +2036 -0
  13. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/grounding.py +55 -0
  14. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/models.py +175 -0
  15. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/pipeline.py +558 -0
  16. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/py.typed +1 -0
  17. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/query.py +254 -0
  18. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/retriever.py +280 -0
  19. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler/semantic.py +280 -0
  20. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/PKG-INFO +155 -0
  21. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/SOURCES.txt +26 -0
  22. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/dependency_links.txt +1 -0
  23. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/entry_points.txt +2 -0
  24. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/requires.txt +12 -0
  25. dynamic_skill_compiler-0.1.0/src/dynamic_skill_compiler.egg-info/top_level.txt +1 -0
  26. dynamic_skill_compiler-0.1.0/tests/test_cli.py +47 -0
  27. dynamic_skill_compiler-0.1.0/tests/test_dynamic_skill_compiler.py +1325 -0
  28. dynamic_skill_compiler-0.1.0/tests/test_experiment_skill_module.py +256 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZJUNLP
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include src/dynamic_skill_compiler *.py py.typed
5
+ recursive-include tests *.py
6
+ recursive-include reports *.md
7
+ prune experiments/results
8
+ prune results
9
+ prune .cache
10
+ prune .venv-experiments
11
+ prune skillnet-ai
12
+ global-exclude __pycache__ *.py[cod] .DS_Store
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: dynamic-skill-compiler
3
+ Version: 0.1.0
4
+ Summary: Task-driven compiler for agent skill libraries.
5
+ Author: ZJUNLP
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/taomiao/DynamicSkillCompiler
8
+ Project-URL: Repository, https://github.com/taomiao/DynamicSkillCompiler
9
+ Project-URL: Issues, https://github.com/taomiao/DynamicSkillCompiler/issues
10
+ Keywords: agent,skills,compiler,retrieval,planning
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: semantic
27
+ Requires-Dist: numpy>=1.24; extra == "semantic"
28
+ Requires-Dist: openai>=1.109.1; extra == "semantic"
29
+ Provides-Extra: dev
30
+ Requires-Dist: build>=1.2.1; extra == "dev"
31
+ Requires-Dist: twine>=5.1.1; extra == "dev"
32
+ Provides-Extra: all
33
+ Requires-Dist: numpy>=1.24; extra == "all"
34
+ Requires-Dist: openai>=1.109.1; extra == "all"
35
+ Dynamic: license-file
36
+
37
+ # Dynamic Skill Compiler
38
+
39
+ Dynamic Skill Compiler (DSC) is a task-driven compiler for agent skills. It takes a natural-language task, retrieves candidate skills from a local skill library, builds a skill graph, and emits a compact, dependency-aware skill package for execution.
40
+
41
+ ## What DSC Does
42
+
43
+ - Decomposes a task into subgoals and required capabilities.
44
+ - Retrieves local skill assets and their declared relationships.
45
+ - Extracts relevant skill fragments instead of passing whole skill files.
46
+ - Builds a graph over `similar_to`, `belong_to`, `compose_with`, and `depend_on` relationships.
47
+ - Runs compiler passes to select, repair, augment, and prune the skill set.
48
+ - Produces a `CompiledSkillPackage` with selected skills, execution order, coverage metrics, and pass traces.
49
+
50
+ ## Repository Layout
51
+
52
+ ```text
53
+ src/dynamic_skill_compiler/ Core DSC compiler package
54
+ tests/ Compiler and experiment integration tests
55
+ experiments/ Benchmark runners and local skill libraries
56
+ reports/ DSC design notes
57
+ ```
58
+
59
+ The benchmark runners under `experiments/` are kept as evaluation harnesses for ScienceWorld, ALFWorld, and WebShop. They are intentionally separate from the core compiler package.
60
+
61
+ ## Quick Start
62
+
63
+ Install from a local checkout:
64
+
65
+ ```bash
66
+ python -m pip install -e .
67
+ ```
68
+
69
+ After the package is published to PyPI, users can install it with:
70
+
71
+ ```bash
72
+ python -m pip install dynamic-skill-compiler
73
+ ```
74
+
75
+ Semantic embedding support is optional:
76
+
77
+ ```bash
78
+ python -m pip install "dynamic-skill-compiler[semantic]"
79
+ ```
80
+
81
+ ```python
82
+ from dynamic_skill_compiler import (
83
+ CompilerConfig,
84
+ DynamicSkillCompiler,
85
+ LocalEnvironment,
86
+ LocalSkillLibraryRetriever,
87
+ )
88
+
89
+ retriever = LocalSkillLibraryRetriever("experiments/src/skills/scienceworld")
90
+ compiler = DynamicSkillCompiler(
91
+ retriever=retriever,
92
+ config=CompilerConfig(),
93
+ )
94
+
95
+ compiled = compiler.compile(
96
+ "Your task is to measure the temperature of an unknown substance.",
97
+ environment=LocalEnvironment(benchmark="scienceworld"),
98
+ )
99
+
100
+ print([skill.asset.name for skill in compiled.compiled_skills])
101
+ print(compiled.execution_order)
102
+ print(compiled.metrics.coverage_score)
103
+ ```
104
+
105
+ ## CLI
106
+
107
+ The package installs a `dsc` command for quick local compilation:
108
+
109
+ ```bash
110
+ dsc "Measure the temperature of the unknown object." \
111
+ --skills-dir experiments/src/skills/scienceworld \
112
+ --pretty
113
+ ```
114
+
115
+ The command prints a JSON summary containing selected skills, execution order,
116
+ coverage metrics, compiler pass traces, and dropped-skill reasons.
117
+
118
+ ## Build And Publish
119
+
120
+ Build source and wheel distributions:
121
+
122
+ ```bash
123
+ python -m pip install ".[dev]"
124
+ python -m build
125
+ python -m twine check dist/*
126
+ ```
127
+
128
+ Publish to TestPyPI first:
129
+
130
+ ```bash
131
+ python -m twine upload --repository testpypi dist/*
132
+ ```
133
+
134
+ Publish to PyPI:
135
+
136
+ ```bash
137
+ python -m twine upload dist/*
138
+ ```
139
+
140
+ Use a PyPI API token via `TWINE_USERNAME=__token__` and
141
+ `TWINE_PASSWORD=pypi-...` or through your local `.pypirc`.
142
+
143
+ ## Tests
144
+
145
+ ```bash
146
+ PYTHONPATH=src python -m unittest discover -s tests -p "test_*.py"
147
+
148
+ PYTHONPATH=src:experiments/src .venv-experiments/bin/python \
149
+ experiments/test_runtime_execution_guard.py
150
+ ```
151
+
152
+ ## Branches
153
+
154
+ - `main`: standalone DSC codebase.
155
+ - `codex/v0321`: latest DSC development branch mirrored into `main`.
@@ -0,0 +1,119 @@
1
+ # Dynamic Skill Compiler
2
+
3
+ Dynamic Skill Compiler (DSC) is a task-driven compiler for agent skills. It takes a natural-language task, retrieves candidate skills from a local skill library, builds a skill graph, and emits a compact, dependency-aware skill package for execution.
4
+
5
+ ## What DSC Does
6
+
7
+ - Decomposes a task into subgoals and required capabilities.
8
+ - Retrieves local skill assets and their declared relationships.
9
+ - Extracts relevant skill fragments instead of passing whole skill files.
10
+ - Builds a graph over `similar_to`, `belong_to`, `compose_with`, and `depend_on` relationships.
11
+ - Runs compiler passes to select, repair, augment, and prune the skill set.
12
+ - Produces a `CompiledSkillPackage` with selected skills, execution order, coverage metrics, and pass traces.
13
+
14
+ ## Repository Layout
15
+
16
+ ```text
17
+ src/dynamic_skill_compiler/ Core DSC compiler package
18
+ tests/ Compiler and experiment integration tests
19
+ experiments/ Benchmark runners and local skill libraries
20
+ reports/ DSC design notes
21
+ ```
22
+
23
+ The benchmark runners under `experiments/` are kept as evaluation harnesses for ScienceWorld, ALFWorld, and WebShop. They are intentionally separate from the core compiler package.
24
+
25
+ ## Quick Start
26
+
27
+ Install from a local checkout:
28
+
29
+ ```bash
30
+ python -m pip install -e .
31
+ ```
32
+
33
+ After the package is published to PyPI, users can install it with:
34
+
35
+ ```bash
36
+ python -m pip install dynamic-skill-compiler
37
+ ```
38
+
39
+ Semantic embedding support is optional:
40
+
41
+ ```bash
42
+ python -m pip install "dynamic-skill-compiler[semantic]"
43
+ ```
44
+
45
+ ```python
46
+ from dynamic_skill_compiler import (
47
+ CompilerConfig,
48
+ DynamicSkillCompiler,
49
+ LocalEnvironment,
50
+ LocalSkillLibraryRetriever,
51
+ )
52
+
53
+ retriever = LocalSkillLibraryRetriever("experiments/src/skills/scienceworld")
54
+ compiler = DynamicSkillCompiler(
55
+ retriever=retriever,
56
+ config=CompilerConfig(),
57
+ )
58
+
59
+ compiled = compiler.compile(
60
+ "Your task is to measure the temperature of an unknown substance.",
61
+ environment=LocalEnvironment(benchmark="scienceworld"),
62
+ )
63
+
64
+ print([skill.asset.name for skill in compiled.compiled_skills])
65
+ print(compiled.execution_order)
66
+ print(compiled.metrics.coverage_score)
67
+ ```
68
+
69
+ ## CLI
70
+
71
+ The package installs a `dsc` command for quick local compilation:
72
+
73
+ ```bash
74
+ dsc "Measure the temperature of the unknown object." \
75
+ --skills-dir experiments/src/skills/scienceworld \
76
+ --pretty
77
+ ```
78
+
79
+ The command prints a JSON summary containing selected skills, execution order,
80
+ coverage metrics, compiler pass traces, and dropped-skill reasons.
81
+
82
+ ## Build And Publish
83
+
84
+ Build source and wheel distributions:
85
+
86
+ ```bash
87
+ python -m pip install ".[dev]"
88
+ python -m build
89
+ python -m twine check dist/*
90
+ ```
91
+
92
+ Publish to TestPyPI first:
93
+
94
+ ```bash
95
+ python -m twine upload --repository testpypi dist/*
96
+ ```
97
+
98
+ Publish to PyPI:
99
+
100
+ ```bash
101
+ python -m twine upload dist/*
102
+ ```
103
+
104
+ Use a PyPI API token via `TWINE_USERNAME=__token__` and
105
+ `TWINE_PASSWORD=pypi-...` or through your local `.pypirc`.
106
+
107
+ ## Tests
108
+
109
+ ```bash
110
+ PYTHONPATH=src python -m unittest discover -s tests -p "test_*.py"
111
+
112
+ PYTHONPATH=src:experiments/src .venv-experiments/bin/python \
113
+ experiments/test_runtime_execution_guard.py
114
+ ```
115
+
116
+ ## Branches
117
+
118
+ - `main`: standalone DSC codebase.
119
+ - `codex/v0321`: latest DSC development branch mirrored into `main`.
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dynamic-skill-compiler"
7
+ version = "0.1.0"
8
+ description = "Task-driven compiler for agent skill libraries."
9
+ readme = "README.md"
10
+ authors = [{ name = "ZJUNLP" }]
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ requires-python = ">=3.9"
14
+ keywords = [
15
+ "agent",
16
+ "skills",
17
+ "compiler",
18
+ "retrieval",
19
+ "planning",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 3 - Alpha",
23
+ "Intended Audience :: Developers",
24
+ "Intended Audience :: Science/Research",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
33
+ "Topic :: Software Development :: Libraries :: Python Modules",
34
+ ]
35
+ dependencies = []
36
+
37
+ [project.optional-dependencies]
38
+ semantic = [
39
+ "numpy>=1.24",
40
+ "openai>=1.109.1",
41
+ ]
42
+ dev = [
43
+ "build>=1.2.1",
44
+ "twine>=5.1.1",
45
+ ]
46
+ all = [
47
+ "numpy>=1.24",
48
+ "openai>=1.109.1",
49
+ ]
50
+
51
+ [project.urls]
52
+ Homepage = "https://github.com/taomiao/DynamicSkillCompiler"
53
+ Repository = "https://github.com/taomiao/DynamicSkillCompiler"
54
+ Issues = "https://github.com/taomiao/DynamicSkillCompiler/issues"
55
+
56
+ [project.scripts]
57
+ dsc = "dynamic_skill_compiler.cli:main"
58
+
59
+ [tool.setuptools.packages.find]
60
+ where = ["src"]
61
+
62
+ [tool.setuptools.package-data]
63
+ dynamic_skill_compiler = ["py.typed"]
@@ -0,0 +1,99 @@
1
+ # Dynamic Skill Compiler Design
2
+
3
+ ## Goal
4
+
5
+ Dynamic Skill Compiler (DSC) is a task-driven compiler for local agent skill libraries. Instead of passing a raw top-k skill list into the agent, DSC builds a task-specific skill graph and emits a compact, dependency-aware package that is easier for the executor to use.
6
+
7
+ ## Compiler Pipeline
8
+
9
+ 1. Query optimization
10
+ - Normalize the raw task.
11
+ - Extract compact retrieval queries.
12
+ - Generate semantic queries for broader recall.
13
+ - Infer constraints such as low-token, local-only, or evaluation-heavy tasks.
14
+
15
+ 2. Query understanding
16
+ - Convert the task into a `QueryPlan`.
17
+ - Separate required capabilities from optional capabilities.
18
+ - Preserve benchmark and environment constraints for downstream scoring.
19
+
20
+ 3. Skill retrieval
21
+ - Retrieve candidates from local skill libraries.
22
+ - Merge and deduplicate candidates into a unified pool.
23
+ - Use semantic and lexical signals when embeddings are available.
24
+
25
+ 4. Skill graph construction
26
+ - Preserve declared `depend_on`, `belong_to`, `compose_with`, and `similar_to` edges.
27
+ - Infer extra `similar_to` edges from capability overlap.
28
+ - Build a multi-relational graph over all candidates.
29
+
30
+ 5. Task-aware compilation
31
+ - Score each candidate by task coverage, quality, cost, and latency.
32
+ - Remove low-relevance nodes.
33
+ - Collapse redundant `similar_to` clusters while keeping the best utility path.
34
+ - Prune broad parent skills when more specific children satisfy the task.
35
+ - Reintroduce required dependencies to maintain executability.
36
+ - Trim isolated low-value nodes.
37
+
38
+ 6. Localization and compression
39
+ - Rewrite generic commands and placeholders against the active workspace.
40
+ - Resolve `{cwd}`, `{workspace_root}`, and Python binary selection.
41
+ - Select relevant fragments instead of always passing whole skill files.
42
+ - Preserve authoritative reference guidance when quality-first mode is enabled.
43
+
44
+ 7. Compilation output
45
+ - A compiled subgraph.
46
+ - An execution order.
47
+ - A dropped-skill audit trail.
48
+ - Coverage, redundancy, token-cost, and pass-trace metrics.
49
+
50
+ ## Intended Gains Over Direct Retrieval
51
+
52
+ DSC targets gains in:
53
+
54
+ - Safety and executability
55
+ - Dependency closure after pruning prevents broken packages.
56
+ - Completeness
57
+ - Task coverage is explicitly measured before finalizing the package.
58
+ - Maintainability
59
+ - Redundant overlapping skills are removed, reducing graph sprawl.
60
+ - Cost awareness
61
+ - Candidate selection prefers lower token and lower execution cost skills when coverage is similar.
62
+ - Token efficiency
63
+ - The compiler removes unrelated, overlapping, and overly broad skills before packaging.
64
+
65
+ ## Current Implementation Scope
66
+
67
+ The current implementation provides:
68
+
69
+ - Query optimizer
70
+ - In-memory and local-library retrievers
71
+ - Optional semantic retrieval cache
72
+ - Multi-relational graph builder
73
+ - Heuristic compiler with redundancy pruning and dependency repair
74
+ - Environment localization
75
+ - Fragment-level skill compression
76
+ - Unit tests for the core compiler logic
77
+
78
+ ## Experimental Upgrades
79
+
80
+ The benchmark harness can evaluate DSC on ScienceWorld, ALFWorld, and WebShop with these ablations:
81
+
82
+ - no query optimization
83
+ - no graph pruning
84
+ - no localization
85
+ - no dependency repair
86
+ - no fragment compression
87
+ - direct retrieval baseline
88
+
89
+ ## Suggested Paper Framing
90
+
91
+ - Baseline: direct retrieval plus raw top-k skill use
92
+ - Method: Dynamic Skill Compiler
93
+ - Main claim: compile-time optimization of skill graphs improves task success and token efficiency
94
+ - Key measured outcomes:
95
+ - task success
96
+ - prompt token usage
97
+ - selected skill count
98
+ - graph density after compilation
99
+ - execution latency
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,66 @@
1
+ from dynamic_skill_compiler.models import (
2
+ CompilationMetrics,
3
+ CompiledSkill,
4
+ CompiledSkillPackage,
5
+ CompilerPassTrace,
6
+ LocalEnvironment,
7
+ QueryPlan,
8
+ SkillAsset,
9
+ SkillFragment,
10
+ SkillGraph,
11
+ SkillRelation,
12
+ Subgoal,
13
+ )
14
+ from dynamic_skill_compiler.decompose import TaskDecomposer
15
+ from dynamic_skill_compiler.fragments import FragmentMatcher, SkillFragmentExtractor
16
+ from dynamic_skill_compiler.graph import (
17
+ DEFAULT_GRAPH_PASSES,
18
+ GRAPH_PASS_PRESETS,
19
+ LEGACY_DEFAULT_GRAPH_PASSES,
20
+ SLIM_GRAPH_PASSES,
21
+ SUPPORTED_GRAPH_PASSES,
22
+ )
23
+ from dynamic_skill_compiler.grounding import EnvironmentGrounder
24
+ from dynamic_skill_compiler.pipeline import CompilerConfig, DynamicSkillCompiler
25
+ from dynamic_skill_compiler.semantic import SemanticSoftMatcher
26
+ from dynamic_skill_compiler.query import QueryOptimizer
27
+ from dynamic_skill_compiler.retriever import (
28
+ CompositeSkillRetriever,
29
+ InMemorySkillRetriever,
30
+ LocalSkillLibraryRetriever,
31
+ SkillRetriever,
32
+ )
33
+
34
+ __version__ = "0.1.0"
35
+
36
+ __all__ = [
37
+ "CompilationMetrics",
38
+ "CompiledSkill",
39
+ "CompiledSkillPackage",
40
+ "CompilerPassTrace",
41
+ "CompilerConfig",
42
+ "CompositeSkillRetriever",
43
+ "DEFAULT_GRAPH_PASSES",
44
+ "DynamicSkillCompiler",
45
+ "EnvironmentGrounder",
46
+ "FragmentMatcher",
47
+ "GRAPH_PASS_PRESETS",
48
+ "InMemorySkillRetriever",
49
+ "LEGACY_DEFAULT_GRAPH_PASSES",
50
+ "LocalSkillLibraryRetriever",
51
+ "LocalEnvironment",
52
+ "QueryOptimizer",
53
+ "QueryPlan",
54
+ "SkillAsset",
55
+ "SkillFragment",
56
+ "SkillFragmentExtractor",
57
+ "SkillGraph",
58
+ "SkillRelation",
59
+ "SkillRetriever",
60
+ "SLIM_GRAPH_PASSES",
61
+ "Subgoal",
62
+ "SemanticSoftMatcher",
63
+ "SUPPORTED_GRAPH_PASSES",
64
+ "TaskDecomposer",
65
+ "__version__",
66
+ ]
@@ -0,0 +1,141 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from dataclasses import asdict, is_dataclass
7
+ from typing import Any
8
+
9
+ from dynamic_skill_compiler.models import LocalEnvironment
10
+ from dynamic_skill_compiler.pipeline import CompilerConfig, DynamicSkillCompiler
11
+ from dynamic_skill_compiler.retriever import LocalSkillLibraryRetriever
12
+
13
+
14
+ def build_parser() -> argparse.ArgumentParser:
15
+ parser = argparse.ArgumentParser(
16
+ prog="dsc",
17
+ description="Compile a local skill library into a task-specific DSC package.",
18
+ )
19
+ parser.add_argument(
20
+ "query",
21
+ nargs="?",
22
+ help="Task query to compile. If omitted, the query is read from stdin.",
23
+ )
24
+ parser.add_argument(
25
+ "--skills-dir",
26
+ required=True,
27
+ help="Directory containing local skill folders with SKILL.md files.",
28
+ )
29
+ parser.add_argument(
30
+ "--benchmark",
31
+ default="generic",
32
+ help="Optional environment/benchmark label used by adaptive compiler profiles.",
33
+ )
34
+ parser.add_argument(
35
+ "--cwd",
36
+ default=".",
37
+ help="Execution working directory used for localization.",
38
+ )
39
+ parser.add_argument(
40
+ "--workspace-root",
41
+ default=".",
42
+ help="Workspace root used for localization.",
43
+ )
44
+ parser.add_argument(
45
+ "--python-bin",
46
+ default=sys.executable or "python",
47
+ help="Python executable name/path used for localization.",
48
+ )
49
+ parser.add_argument(
50
+ "--min-relevance",
51
+ type=float,
52
+ default=CompilerConfig.min_relevance,
53
+ help="Minimum utility score required for skill selection.",
54
+ )
55
+ parser.add_argument(
56
+ "--preserve-top-k",
57
+ type=int,
58
+ default=CompilerConfig.preserve_top_k,
59
+ help="Always preserve at least this many top-scored skills.",
60
+ )
61
+ parser.add_argument(
62
+ "--max-selected-skills",
63
+ type=int,
64
+ default=CompilerConfig.max_selected_skills,
65
+ help="Hard cap for selected skills. Use 0 for no explicit cap.",
66
+ )
67
+ parser.add_argument(
68
+ "--pretty",
69
+ action="store_true",
70
+ help="Pretty-print JSON output.",
71
+ )
72
+ parser.add_argument(
73
+ "--include-instructions",
74
+ action="store_true",
75
+ help="Include localized selected instructions in the JSON output.",
76
+ )
77
+ return parser
78
+
79
+
80
+ def compile_from_args(args: argparse.Namespace) -> dict[str, Any]:
81
+ query = args.query if args.query is not None else sys.stdin.read().strip()
82
+ if not query:
83
+ raise SystemExit("A task query is required, either as an argument or on stdin.")
84
+
85
+ compiler = DynamicSkillCompiler(
86
+ retriever=LocalSkillLibraryRetriever(args.skills_dir),
87
+ config=CompilerConfig(
88
+ min_relevance=args.min_relevance,
89
+ preserve_top_k=args.preserve_top_k,
90
+ max_selected_skills=args.max_selected_skills,
91
+ ),
92
+ )
93
+ compiled = compiler.compile(
94
+ query,
95
+ environment=LocalEnvironment(
96
+ cwd=args.cwd,
97
+ workspace_root=args.workspace_root,
98
+ python_bin=args.python_bin,
99
+ benchmark=args.benchmark,
100
+ ),
101
+ )
102
+ summary = compiler.summarize(compiled)
103
+ summary["metrics"] = _to_jsonable(compiled.metrics)
104
+ if args.include_instructions:
105
+ summary["compiled_skills"] = [
106
+ {
107
+ "name": item.asset.name,
108
+ "skill_id": item.asset.skill_id,
109
+ "selected_reason": item.selected_reason,
110
+ "utility_score": item.utility_score,
111
+ "localized_instructions": item.localized_instructions,
112
+ "selected_fragments": [_to_jsonable(fragment) for fragment in item.selected_fragments],
113
+ }
114
+ for item in compiled.compiled_skills
115
+ ]
116
+ return summary
117
+
118
+
119
+ def main(argv: list[str] | None = None) -> int:
120
+ parser = build_parser()
121
+ args = parser.parse_args(argv)
122
+ summary = compile_from_args(args)
123
+ indent = 2 if args.pretty else None
124
+ print(json.dumps(summary, ensure_ascii=False, indent=indent))
125
+ return 0
126
+
127
+
128
+ def _to_jsonable(value: Any) -> Any:
129
+ if is_dataclass(value):
130
+ return _to_jsonable(asdict(value))
131
+ if isinstance(value, dict):
132
+ return {str(key): _to_jsonable(item) for key, item in value.items()}
133
+ if isinstance(value, (list, tuple)):
134
+ return [_to_jsonable(item) for item in value]
135
+ if isinstance(value, set):
136
+ return sorted(_to_jsonable(item) for item in value)
137
+ return value
138
+
139
+
140
+ if __name__ == "__main__":
141
+ raise SystemExit(main())