chaincompiler-market 0.4.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.
- chaincompiler_market-0.4.0/LICENSE +21 -0
- chaincompiler_market-0.4.0/PKG-INFO +33 -0
- chaincompiler_market-0.4.0/README.md +20 -0
- chaincompiler_market-0.4.0/pyproject.toml +18 -0
- chaincompiler_market-0.4.0/setup.cfg +4 -0
- chaincompiler_market-0.4.0/src/ccmarket/__init__.py +33 -0
- chaincompiler_market-0.4.0/src/ccmarket/cli.py +169 -0
- chaincompiler_market-0.4.0/src/ccmarket/exchange.py +122 -0
- chaincompiler_market-0.4.0/src/ccmarket/federation.py +109 -0
- chaincompiler_market-0.4.0/src/ccmarket/marketplace.py +60 -0
- chaincompiler_market-0.4.0/src/ccmarket/registry.py +128 -0
- chaincompiler_market-0.4.0/src/ccmarket/reports.py +97 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/PKG-INFO +33 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/SOURCES.txt +22 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/dependency_links.txt +1 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/entry_points.txt +2 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/requires.txt +3 -0
- chaincompiler_market-0.4.0/src/chaincompiler_market.egg-info/top_level.txt +1 -0
- chaincompiler_market-0.4.0/tests/test_cli.py +34 -0
- chaincompiler_market-0.4.0/tests/test_exchange.py +75 -0
- chaincompiler_market-0.4.0/tests/test_federation.py +76 -0
- chaincompiler_market-0.4.0/tests/test_marketplace.py +49 -0
- chaincompiler_market-0.4.0/tests/test_registry.py +77 -0
- chaincompiler_market-0.4.0/tests/test_reports.py +32 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sancovp
|
|
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,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chaincompiler-market
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: ChainCompiler's marketplace: the exchange (several skill trees under one master), the reports queue, and the registry with its trust levels, contribution gate and federation walk
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: agent-skilltree>=0.5.0
|
|
10
|
+
Requires-Dist: click
|
|
11
|
+
Requires-Dist: pyyaml
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# chaincompiler-market
|
|
15
|
+
|
|
16
|
+
ChainCompiler's marketplace (import `ccmarket`, command `ccmarket`): the exchange, the reports queue, and the registry
|
|
17
|
+
with its federation. Part of [ChainCompiler](https://github.com/sancovp/chaincompiler); its design is that repository's
|
|
18
|
+
`DESIGN.md` §15.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
pip install chaincompiler-market
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- **An exchange** holds several skill trees in one repository under one master: `ccmarket exchange build <manifest>
|
|
25
|
+
<repo>`, `ccmarket exchange validate <manifest> <repo>` (exits 1 on any error). A manifest is JSON or YAML.
|
|
26
|
+
- **The reports queue** records a skill that was needed and missing, or should have been used: `ccmarket report-missed`,
|
|
27
|
+
`ccmarket mark-problem`, `ccmarket reports`, `ccmarket resolve`.
|
|
28
|
+
- **The registry** is the marketplace's one list (`registry.json`): entries that point at what was made, each
|
|
29
|
+
`unverified`, `verified` or `featured`. It takes a skill, a tree, an exchange, a tool server, a child registry, and
|
|
30
|
+
the five kinds an instance of ChainCompiler makes: an AIOS, a skillchain, a chain of reasoning, an attention chain and
|
|
31
|
+
a syntax. `ccmarket registry publish|search|validate|promote`. A contribution may only add `unverified` entries; a
|
|
32
|
+
maintainer promotes. A registry that lists child registries federates into a tree (`walk_federation`), and a child's
|
|
33
|
+
parent is checked by name.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# chaincompiler-market
|
|
2
|
+
|
|
3
|
+
ChainCompiler's marketplace (import `ccmarket`, command `ccmarket`): the exchange, the reports queue, and the registry
|
|
4
|
+
with its federation. Part of [ChainCompiler](https://github.com/sancovp/chaincompiler); its design is that repository's
|
|
5
|
+
`DESIGN.md` §15.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pip install chaincompiler-market
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **An exchange** holds several skill trees in one repository under one master: `ccmarket exchange build <manifest>
|
|
12
|
+
<repo>`, `ccmarket exchange validate <manifest> <repo>` (exits 1 on any error). A manifest is JSON or YAML.
|
|
13
|
+
- **The reports queue** records a skill that was needed and missing, or should have been used: `ccmarket report-missed`,
|
|
14
|
+
`ccmarket mark-problem`, `ccmarket reports`, `ccmarket resolve`.
|
|
15
|
+
- **The registry** is the marketplace's one list (`registry.json`): entries that point at what was made, each
|
|
16
|
+
`unverified`, `verified` or `featured`. It takes a skill, a tree, an exchange, a tool server, a child registry, and
|
|
17
|
+
the five kinds an instance of ChainCompiler makes: an AIOS, a skillchain, a chain of reasoning, an attention chain and
|
|
18
|
+
a syntax. `ccmarket registry publish|search|validate|promote`. A contribution may only add `unverified` entries; a
|
|
19
|
+
maintainer promotes. A registry that lists child registries federates into a tree (`walk_federation`), and a child's
|
|
20
|
+
parent is checked by name.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "chaincompiler-market"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "ChainCompiler's marketplace: the exchange (several skill trees under one master), the reports queue, and the registry with its trust levels, contribution gate and federation walk"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["agent-skilltree>=0.5.0", "click", "pyyaml"]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
ccmarket = "ccmarket.cli:main"
|
|
16
|
+
|
|
17
|
+
[tool.setuptools.packages.find]
|
|
18
|
+
where = ["src"]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""ccmarket — ChainCompiler's marketplace: the exchange, the reports queue, the registry and its federation.
|
|
2
|
+
|
|
3
|
+
An exchange holds several skill trees in one repository under one master. The reports queue records a skill that was
|
|
4
|
+
needed and missing, or should have been used, for whoever improves a tree to read and close. The registry is the
|
|
5
|
+
marketplace's one list: entries pointing at what was made, each with a trust level, a contribution gate and a
|
|
6
|
+
maintainer's promotion; a registry can list child registries, so marketplaces federate into a tree.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
__version__ = "0.4.0"
|
|
11
|
+
|
|
12
|
+
from .exchange import Exchange, Member, load_exchange
|
|
13
|
+
from .exchange import build as build_exchange
|
|
14
|
+
from .exchange import is_valid as exchange_is_valid
|
|
15
|
+
from .exchange import validate as validate_exchange
|
|
16
|
+
from .federation import (flatten_federation, local_resolver, register_child, validate_federation,
|
|
17
|
+
walk_federation)
|
|
18
|
+
from .marketplace import log_notify, publish
|
|
19
|
+
from .marketplace import search as search_marketplace
|
|
20
|
+
from .registry import (KINDS, MADE_KINDS, TRUST, Entry, load_registry, new_registry, promote,
|
|
21
|
+
validate_contribution, validate_registry)
|
|
22
|
+
from .registry import search as search_registry
|
|
23
|
+
from .reports import DEFAULT_REPORTS, list_reports, mark_problem, report_missed, resolve
|
|
24
|
+
from .reports import summary as reports_summary
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"Exchange", "Member", "load_exchange", "build_exchange", "exchange_is_valid", "validate_exchange",
|
|
28
|
+
"flatten_federation", "local_resolver", "register_child", "validate_federation", "walk_federation",
|
|
29
|
+
"log_notify", "publish", "search_marketplace",
|
|
30
|
+
"KINDS", "MADE_KINDS", "TRUST", "Entry", "load_registry", "new_registry", "promote", "validate_contribution",
|
|
31
|
+
"validate_registry", "search_registry",
|
|
32
|
+
"DEFAULT_REPORTS", "list_reports", "mark_problem", "report_missed", "resolve", "reports_summary", "__version__",
|
|
33
|
+
]
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""The `ccmarket` command: an exchange, the reports queue, and a registry."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@click.group()
|
|
14
|
+
@click.version_option(__version__, prog_name="ccmarket")
|
|
15
|
+
def main() -> None:
|
|
16
|
+
"""ChainCompiler's marketplace: exchanges, the reports queue, the registry."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@main.group()
|
|
20
|
+
def exchange() -> None:
|
|
21
|
+
"""Several skill trees in one repository, under one master."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@exchange.command(name="build")
|
|
25
|
+
@click.argument("manifest", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
26
|
+
@click.argument("repo", type=click.Path(file_okay=False, path_type=Path))
|
|
27
|
+
def exchange_build(manifest: Path, repo: Path) -> None:
|
|
28
|
+
"""Materialize every member tree and the master from an exchange MANIFEST into REPO."""
|
|
29
|
+
from .exchange import build, load_exchange
|
|
30
|
+
ex = load_exchange(manifest)
|
|
31
|
+
master = build(ex, repo)
|
|
32
|
+
click.echo(f"built exchange '{ex.name}' — {len(ex.trees)} tree(s) + master at {master}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@exchange.command(name="validate")
|
|
36
|
+
@click.argument("manifest", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
37
|
+
@click.argument("repo", type=click.Path(exists=True, file_okay=False, path_type=Path))
|
|
38
|
+
def exchange_validate(manifest: Path, repo: Path) -> None:
|
|
39
|
+
"""Validate a built exchange REPO against its MANIFEST; exits 1 on any error."""
|
|
40
|
+
from .exchange import load_exchange, validate
|
|
41
|
+
found = validate(repo, load_exchange(manifest))
|
|
42
|
+
for v in found:
|
|
43
|
+
click.echo(str(v))
|
|
44
|
+
errors = [v for v in found if v.severity == "error"]
|
|
45
|
+
click.echo("✓ exchange valid" if not errors else f"✗ {len(errors)} error(s)")
|
|
46
|
+
if errors:
|
|
47
|
+
sys.exit(1)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@main.command(name="report-missed")
|
|
51
|
+
@click.option("--needed", required=True, help="the capability that was needed")
|
|
52
|
+
@click.option("--happened", required=True, help="what happened without it")
|
|
53
|
+
@click.option("--suggests", default=None, help="what skill would have helped")
|
|
54
|
+
@click.option("--by", default="agent")
|
|
55
|
+
@click.option("--reports", "reports_path", default=None, help="the reports file (default: Claude Code's own folder)")
|
|
56
|
+
def report_missed_cmd(needed, happened, suggests, by, reports_path) -> None:
|
|
57
|
+
"""File a report that a needed skill did not exist."""
|
|
58
|
+
from .reports import DEFAULT_REPORTS, report_missed
|
|
59
|
+
e = report_missed(reports_path or DEFAULT_REPORTS, needed=needed, happened=happened, suggests=suggests, by=by)
|
|
60
|
+
click.echo(f"✓ filed {e['id']} (missed_skill): {needed}")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@main.command(name="mark-problem")
|
|
64
|
+
@click.option("--skill", required=True, help="the skill that should have been used")
|
|
65
|
+
@click.option("--expected", required=True)
|
|
66
|
+
@click.option("--happened", required=True)
|
|
67
|
+
@click.option("--by", default="user")
|
|
68
|
+
@click.option("--reports", "reports_path", default=None)
|
|
69
|
+
def mark_problem_cmd(skill, expected, happened, by, reports_path) -> None:
|
|
70
|
+
"""File a report that a skill should have been used and was not."""
|
|
71
|
+
from .reports import DEFAULT_REPORTS, mark_problem
|
|
72
|
+
e = mark_problem(reports_path or DEFAULT_REPORTS, skill=skill, expected=expected, happened=happened, by=by)
|
|
73
|
+
click.echo(f"✓ filed {e['id']} (expected_not_used): {skill}")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@main.command(name="reports")
|
|
77
|
+
@click.option("--reports", "reports_path", default=None)
|
|
78
|
+
@click.option("--kind", default=None)
|
|
79
|
+
def reports_cmd(reports_path, kind) -> None:
|
|
80
|
+
"""Show the open reports: the queue of whoever improves a tree."""
|
|
81
|
+
from .reports import DEFAULT_REPORTS, list_reports, summary
|
|
82
|
+
rp = reports_path or DEFAULT_REPORTS
|
|
83
|
+
s = summary(rp)
|
|
84
|
+
click.echo(f"reports: {s['open']} open / {s['total']} total {s['open_by_kind']}")
|
|
85
|
+
for r in list_reports(rp, kind=kind):
|
|
86
|
+
what = r.get("needed") or r.get("skill") or ""
|
|
87
|
+
click.echo(f" {r['id']} [{r['kind']}] {what} — {r.get('happened', '')}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@main.command(name="resolve")
|
|
91
|
+
@click.argument("report_id")
|
|
92
|
+
@click.option("--resolution", required=True)
|
|
93
|
+
@click.option("--reports", "reports_path", default=None)
|
|
94
|
+
def resolve_cmd(report_id, resolution, reports_path) -> None:
|
|
95
|
+
"""Close a report, naming what was made or improved for it."""
|
|
96
|
+
from .reports import DEFAULT_REPORTS, resolve
|
|
97
|
+
try:
|
|
98
|
+
resolve(reports_path or DEFAULT_REPORTS, report_id, resolution=resolution)
|
|
99
|
+
except KeyError as exc:
|
|
100
|
+
click.echo(f"✗ {exc.args[0]}")
|
|
101
|
+
sys.exit(1)
|
|
102
|
+
click.echo(f"✓ resolved {report_id}")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@main.group()
|
|
106
|
+
def registry() -> None:
|
|
107
|
+
"""The marketplace's one list."""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@registry.command(name="validate")
|
|
111
|
+
@click.argument("path", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
112
|
+
def registry_validate(path: Path) -> None:
|
|
113
|
+
"""Check a registry document; exits 1 on any error."""
|
|
114
|
+
from .registry import load_registry, validate_registry
|
|
115
|
+
errs = validate_registry(load_registry(path))
|
|
116
|
+
for e in errs:
|
|
117
|
+
click.echo(f"✗ {e}")
|
|
118
|
+
click.echo("✓ registry valid" if not errs else f"✗ {len(errs)} error(s)")
|
|
119
|
+
if errs:
|
|
120
|
+
sys.exit(1)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@registry.command(name="publish")
|
|
124
|
+
@click.argument("path", type=click.Path(dir_okay=False, path_type=Path))
|
|
125
|
+
@click.argument("name")
|
|
126
|
+
@click.argument("target")
|
|
127
|
+
@click.option("--kind", default="skill")
|
|
128
|
+
@click.option("--public/--private", default=False)
|
|
129
|
+
@click.option("--tag", "tags", multiple=True)
|
|
130
|
+
@click.option("--by", default="author")
|
|
131
|
+
def registry_publish(path: Path, name, target, kind, public, tags, by) -> None:
|
|
132
|
+
"""Add or update NAME, pointing at TARGET, in the registry at PATH."""
|
|
133
|
+
from .marketplace import publish
|
|
134
|
+
try:
|
|
135
|
+
e = publish(path, name, target, kind=kind, public=public, tags=list(tags), by=by)
|
|
136
|
+
except ValueError as exc:
|
|
137
|
+
click.echo(f"✗ {exc}")
|
|
138
|
+
sys.exit(1)
|
|
139
|
+
click.echo(f"✓ published {e['name']} ({e['kind']}, {e['trust']}) in {path}")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@registry.command(name="search")
|
|
143
|
+
@click.argument("path", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
144
|
+
@click.argument("query", required=False)
|
|
145
|
+
@click.option("--min-trust", default="unverified")
|
|
146
|
+
def registry_search(path: Path, query, min_trust) -> None:
|
|
147
|
+
"""List the entries of the registry at PATH whose name or tags hold QUERY."""
|
|
148
|
+
from .registry import search
|
|
149
|
+
click.echo(json.dumps(search(path, query, min_trust=min_trust), indent=2))
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@registry.command(name="promote")
|
|
153
|
+
@click.argument("path", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
154
|
+
@click.argument("name")
|
|
155
|
+
@click.option("--to", default="verified")
|
|
156
|
+
@click.option("--by", default=None)
|
|
157
|
+
def registry_promote(path: Path, name, to, by) -> None:
|
|
158
|
+
"""Maintainer only: raise an entry's trust."""
|
|
159
|
+
from .registry import promote
|
|
160
|
+
try:
|
|
161
|
+
e = promote(path, name, to=to, by=by)
|
|
162
|
+
except (KeyError, ValueError) as exc:
|
|
163
|
+
click.echo(f"✗ {exc.args[0]}")
|
|
164
|
+
sys.exit(1)
|
|
165
|
+
click.echo(f"✓ {e.name} → {e.trust}")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
main()
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Exchange — many skill trees in one repo, under a master.
|
|
2
|
+
|
|
3
|
+
An exchange manifest (JSON or YAML) lists member skill trees and a master name:
|
|
4
|
+
|
|
5
|
+
name: my-exchange
|
|
6
|
+
master: cc-master
|
|
7
|
+
trees:
|
|
8
|
+
- name: cognition
|
|
9
|
+
manifest: trees/cognition.skilltree.json
|
|
10
|
+
- name: writing
|
|
11
|
+
manifest: trees/writing.skilltree.json
|
|
12
|
+
|
|
13
|
+
`build` materializes each member tree under `<repo>/trees/<name>/`, then writes a
|
|
14
|
+
MASTER root whose Read-breadcrumbs point into each member tree's root. The master
|
|
15
|
+
is itself a SkillTree-of-trees — the closure again: a tree whose first layer is
|
|
16
|
+
the set of member roots. `validate` checks every member tree AND the master's
|
|
17
|
+
cross-tree breadcrumbs.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
import json
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from skilltree import SkillTree, Violation, materialize
|
|
26
|
+
from skilltree import validate as validate_tree
|
|
27
|
+
from skilltree.materialize import _front, node_skill_md # _front: SkillTree's one frontmatter writer
|
|
28
|
+
from skilltree.validate import _CRUMB_RE, _has_frontmatter
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class Member:
|
|
33
|
+
name: str
|
|
34
|
+
manifest: str
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class Exchange:
|
|
39
|
+
name: str
|
|
40
|
+
master: str
|
|
41
|
+
trees: list[Member]
|
|
42
|
+
base: Path # dir the manifest paths resolve against
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def load_exchange(path: str | Path) -> Exchange:
|
|
46
|
+
p = Path(path)
|
|
47
|
+
text = p.read_text(encoding="utf-8")
|
|
48
|
+
if p.suffix in (".yaml", ".yml"):
|
|
49
|
+
import yaml
|
|
50
|
+
data = yaml.safe_load(text)
|
|
51
|
+
else:
|
|
52
|
+
data = json.loads(text)
|
|
53
|
+
return Exchange(
|
|
54
|
+
name=data["name"],
|
|
55
|
+
master=data.get("master", "master"),
|
|
56
|
+
trees=[Member(m["name"], m["manifest"]) for m in data.get("trees", [])],
|
|
57
|
+
base=p.resolve().parent,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def build(exchange: Exchange, repo_dir: str | Path, *, localize: bool = False) -> Path:
|
|
62
|
+
"""Materialize every member tree + the master. Returns the master SKILL.md path.
|
|
63
|
+
Breadcrumbs are portable (relative to the repo) unless `localize=True`."""
|
|
64
|
+
repo = Path(repo_dir)
|
|
65
|
+
members: list[tuple[str, Path]] = [] # (member name, member root SKILL.md)
|
|
66
|
+
for m in exchange.trees:
|
|
67
|
+
tree = SkillTree.load((exchange.base / m.manifest).resolve())
|
|
68
|
+
tree_dir = repo / "trees" / m.name
|
|
69
|
+
materialize(tree, tree_dir, localize=localize)
|
|
70
|
+
members.append((m.name, node_skill_md(tree_dir, tree.root.name).resolve()))
|
|
71
|
+
|
|
72
|
+
master_md = node_skill_md(repo, exchange.master)
|
|
73
|
+
master_md.parent.mkdir(parents=True, exist_ok=True)
|
|
74
|
+
from skilltree.model import PORTABLE_NOTE, crumb_path
|
|
75
|
+
crumbs = [f"- {name} (tree): Read `{crumb_path(root_md, repo, localize=localize)}`"
|
|
76
|
+
for name, root_md in members]
|
|
77
|
+
body = (f"Master of the **{exchange.name}** exchange — {len(members)} skill tree(s).\n\n"
|
|
78
|
+
"## Trees — pick one and **Read** (the Read tool) into its root\n"
|
|
79
|
+
"Only this master is loaded. Read a tree's root below to load it (a Bash `cat` won't); "
|
|
80
|
+
"each tree then walks its own breadcrumbs." + ("" if localize else f" {PORTABLE_NOTE}")
|
|
81
|
+
+ "\n\n"
|
|
82
|
+
+ "\n".join(crumbs))
|
|
83
|
+
master_md.write_text(_front(exchange.master, f"master of the {exchange.name} exchange", body),
|
|
84
|
+
encoding="utf-8")
|
|
85
|
+
|
|
86
|
+
(repo / "exchange.lock.json").write_text(json.dumps(
|
|
87
|
+
{"name": exchange.name, "master": exchange.master,
|
|
88
|
+
"trees": [{"name": n, "root": crumb_path(r, repo, localize=localize)} for n, r in members]},
|
|
89
|
+
indent=2), encoding="utf-8")
|
|
90
|
+
return master_md
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def validate(repo_dir: str | Path, exchange: Exchange) -> list[Violation]:
|
|
94
|
+
repo = Path(repo_dir)
|
|
95
|
+
out: list[Violation] = []
|
|
96
|
+
# 1. each member tree validates on its own
|
|
97
|
+
for m in exchange.trees:
|
|
98
|
+
for v in validate_tree(repo / "trees" / m.name):
|
|
99
|
+
out.append(Violation(v.severity, f"{m.name}/{v.where}", v.message))
|
|
100
|
+
# 2. the master root + its cross-tree breadcrumbs
|
|
101
|
+
master_md = node_skill_md(repo, exchange.master)
|
|
102
|
+
if not master_md.is_file():
|
|
103
|
+
out.append(Violation("error", exchange.master, f"missing master SKILL.md at {master_md}"))
|
|
104
|
+
return out
|
|
105
|
+
if not _has_frontmatter(master_md):
|
|
106
|
+
out.append(Violation("error", exchange.master, "master SKILL.md lacks frontmatter"))
|
|
107
|
+
found = {(Path(p) if Path(p).is_absolute() else repo / p).resolve()
|
|
108
|
+
for p in _CRUMB_RE.findall(master_md.read_text(encoding="utf-8"))}
|
|
109
|
+
expected = {
|
|
110
|
+
node_skill_md(repo / "trees" / m.name, SkillTree.load((exchange.base / m.manifest).resolve()).root.name).resolve()
|
|
111
|
+
for m in exchange.trees
|
|
112
|
+
}
|
|
113
|
+
for missing in expected - found:
|
|
114
|
+
out.append(Violation("error", exchange.master, f"no master breadcrumb for tree root → {missing}"))
|
|
115
|
+
for p in found:
|
|
116
|
+
if not Path(p).is_file():
|
|
117
|
+
out.append(Violation("error", exchange.master, f"dead master breadcrumb: `{p}` does not resolve"))
|
|
118
|
+
return out
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def is_valid(repo_dir: str | Path, exchange: Exchange) -> bool:
|
|
122
|
+
return not any(v.severity == "error" for v in validate(repo_dir, exchange))
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Walk the federation: a tree of marketplaces under a root.
|
|
2
|
+
|
|
3
|
+
A child marketplace joins by contributing a `registry`-kind entry to its parent's
|
|
4
|
+
registry.json (pointing at the child's own registry.json). Federation is then a
|
|
5
|
+
walk: from the root registry, resolve each `registry` entry to the child's
|
|
6
|
+
registry and recurse — a tree of marketplaces mirroring the tree of repos.
|
|
7
|
+
|
|
8
|
+
`resolve` is pluggable so this works offline: it maps a `registry` entry to a
|
|
9
|
+
registry dict (a local map for tests; a fetch-by-repo-ref for the real network).
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import datetime as _dt
|
|
14
|
+
import json
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Callable
|
|
17
|
+
|
|
18
|
+
from .registry import load_registry, validate_registry
|
|
19
|
+
|
|
20
|
+
Resolver = Callable[[dict], "dict | None"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def local_resolver(name_to_registry: dict[str, dict]) -> Resolver:
|
|
24
|
+
"""Resolve a `registry` entry to a child registry from an in-memory/local map."""
|
|
25
|
+
def _resolve(entry: dict) -> dict | None:
|
|
26
|
+
target = name_to_registry.get(entry["name"]) or name_to_registry.get(entry.get("repo", ""))
|
|
27
|
+
if isinstance(target, (str, Path)):
|
|
28
|
+
return load_registry(target)
|
|
29
|
+
return target
|
|
30
|
+
return _resolve
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _children(registry: dict) -> list[dict]:
|
|
34
|
+
return [e for e in registry.get("entries", []) if e.get("kind") == "registry"]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def walk_federation(registry: dict, resolve: Resolver, *, _seen: frozenset[str] | None = None) -> dict:
|
|
38
|
+
"""Return the nested federation tree rooted at `registry`."""
|
|
39
|
+
_seen = _seen or frozenset()
|
|
40
|
+
name = registry.get("name")
|
|
41
|
+
node = {
|
|
42
|
+
"name": name,
|
|
43
|
+
"entries": [e for e in registry.get("entries", []) if e.get("kind") != "registry"],
|
|
44
|
+
"children": [],
|
|
45
|
+
}
|
|
46
|
+
if name in _seen: # cycle guard
|
|
47
|
+
node["cycle"] = True
|
|
48
|
+
return node
|
|
49
|
+
seen = _seen | {name}
|
|
50
|
+
for entry in _children(registry):
|
|
51
|
+
child = resolve(entry)
|
|
52
|
+
if child is None:
|
|
53
|
+
node["children"].append({"name": entry["name"], "unresolved": True})
|
|
54
|
+
else:
|
|
55
|
+
node["children"].append(walk_federation(child, resolve, _seen=seen))
|
|
56
|
+
return node
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def flatten_federation(registry: dict, resolve: Resolver) -> list[dict]:
|
|
60
|
+
"""Every leaf entry across the federation, tagged with the registry path it came through."""
|
|
61
|
+
out: list[dict] = []
|
|
62
|
+
|
|
63
|
+
def rec(node: dict, path: tuple[str, ...]) -> None:
|
|
64
|
+
here = path + (node["name"],)
|
|
65
|
+
for e in node.get("entries", []):
|
|
66
|
+
out.append({**e, "_path": list(here)})
|
|
67
|
+
for c in node.get("children", []):
|
|
68
|
+
if not c.get("unresolved") and not c.get("cycle"):
|
|
69
|
+
rec(c, here)
|
|
70
|
+
rec(walk_federation(registry, resolve), ())
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def validate_federation(registry: dict, resolve: Resolver) -> list[str]:
|
|
75
|
+
"""Check the federation: child schemas valid, parent backrefs consistent, no cycles."""
|
|
76
|
+
errs: list[str] = []
|
|
77
|
+
|
|
78
|
+
def rec(reg: dict, seen: frozenset[str]) -> None:
|
|
79
|
+
errs.extend(f"{reg.get('name')}: {e}" for e in validate_registry(reg))
|
|
80
|
+
if reg.get("name") in seen:
|
|
81
|
+
errs.append(f"federation cycle at {reg.get('name')!r}")
|
|
82
|
+
return
|
|
83
|
+
s = seen | {reg.get("name")}
|
|
84
|
+
for entry in _children(reg):
|
|
85
|
+
child = resolve(entry)
|
|
86
|
+
if child is None:
|
|
87
|
+
errs.append(f"{reg.get('name')}: unresolved child registry {entry['name']!r}")
|
|
88
|
+
continue
|
|
89
|
+
if child.get("parent") not in (None, reg.get("name")):
|
|
90
|
+
errs.append(f"{child.get('name')!r}: parent backref {child.get('parent')!r} "
|
|
91
|
+
f"does not match {reg.get('name')!r}")
|
|
92
|
+
rec(child, s)
|
|
93
|
+
rec(registry, frozenset())
|
|
94
|
+
return errs
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def register_child(parent_path: str | Path, name: str, repo: str, *,
|
|
98
|
+
manifest: str = "registry.json", by: str = "maintainer",
|
|
99
|
+
now: str | None = None) -> dict:
|
|
100
|
+
"""Add a `registry`-kind child to a parent registry (federation link, unverified)."""
|
|
101
|
+
p = Path(parent_path)
|
|
102
|
+
data = load_registry(p)
|
|
103
|
+
data.setdefault("entries", []).append({
|
|
104
|
+
"name": name, "kind": "registry", "repo": repo, "manifest": manifest,
|
|
105
|
+
"version": "0.1.0", "trust": "unverified",
|
|
106
|
+
"provenance": {"by": by, "at": now or _dt.datetime.now().isoformat(timespec="seconds")},
|
|
107
|
+
})
|
|
108
|
+
p.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
109
|
+
return data
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Publishing to a registry — the one list a marketplace is.
|
|
2
|
+
|
|
3
|
+
`publish()` adds or updates an entry of a registry document (`registry.json`: a name, a parent, entries), the same
|
|
4
|
+
document the contribution gate checks and the federation walk reads: there is no second, local list. A published entry
|
|
5
|
+
lands `unverified` with its provenance; marked `public`, it fires the `notify` hook, where a hosted service plugs in.
|
|
6
|
+
This module holds no network code of its own.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import datetime as _dt
|
|
11
|
+
import json
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Callable
|
|
14
|
+
|
|
15
|
+
from .registry import KINDS, load_registry, new_registry
|
|
16
|
+
from .registry import search as _search
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def publish(registry: str | Path, name: str, path: str | Path, *, kind: str = "skill", public: bool = False,
|
|
20
|
+
version: str = "0.1.0", tags: list[str] | None = None, repo: str | None = None, by: str = "author",
|
|
21
|
+
notify: Callable[[dict], None] | None = None, now: str | None = None,
|
|
22
|
+
registry_name: str | None = None) -> dict:
|
|
23
|
+
"""Add (or update, by name) an entry in the registry at `registry`, making the document when it is absent. A
|
|
24
|
+
republished entry keeps the trust it had: only `promote` raises it. Fires `notify` when the entry is public."""
|
|
25
|
+
if kind not in KINDS:
|
|
26
|
+
raise ValueError(f"kind must be one of {KINDS}, got {kind!r}")
|
|
27
|
+
registry = Path(registry)
|
|
28
|
+
data = load_registry(registry) if registry.is_file() else new_registry(registry_name or registry.resolve().parent.name)
|
|
29
|
+
old = next((e for e in data["entries"] if e.get("name") == name), {})
|
|
30
|
+
at = now or _dt.datetime.now().isoformat(timespec="seconds")
|
|
31
|
+
entry = {"name": name, "kind": kind, "repo": repo or old.get("repo") or str(Path(path)),
|
|
32
|
+
"manifest": str(Path(path)), "version": version, "trust": old.get("trust", "unverified"),
|
|
33
|
+
"public": public, "tags": list(tags or []),
|
|
34
|
+
"provenance": {**old.get("provenance", {}), "by": old.get("provenance", {}).get("by", by),
|
|
35
|
+
"published_at": at}}
|
|
36
|
+
data["entries"] = [e for e in data["entries"] if e.get("name") != name] + [entry]
|
|
37
|
+
registry.parent.mkdir(parents=True, exist_ok=True)
|
|
38
|
+
registry.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
39
|
+
if public and notify is not None:
|
|
40
|
+
notify(entry)
|
|
41
|
+
return entry
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def search(registry: str | Path, query: str | None = None, *, public_only: bool = False,
|
|
45
|
+
min_trust: str = "unverified") -> list[dict]:
|
|
46
|
+
"""The entries of a registry whose name or tags hold `query`, at or above a trust floor."""
|
|
47
|
+
if not Path(registry).is_file():
|
|
48
|
+
return []
|
|
49
|
+
rows = _search(registry, query, min_trust=min_trust)
|
|
50
|
+
return [r for r in rows if r.get("public")] if public_only else rows
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def log_notify(log_path: str | Path) -> Callable[[dict], None]:
|
|
54
|
+
"""A local stand-in for a hosted notifier: append each public publish to a log."""
|
|
55
|
+
def _notify(entry: dict) -> None:
|
|
56
|
+
p = Path(log_path)
|
|
57
|
+
p.parent.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
with p.open("a", encoding="utf-8") as fh:
|
|
59
|
+
fh.write(json.dumps(entry) + "\n")
|
|
60
|
+
return _notify
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""The marketplace as a git repo: registry.json + a contribution gate.
|
|
2
|
+
|
|
3
|
+
The registry is DATA (pointers), never code we run. A contribution is a PR that
|
|
4
|
+
ADDS entries — and the gate enforces the locked policy:
|
|
5
|
+
|
|
6
|
+
- new entries must land `unverified` (promotion is maintainer-only)
|
|
7
|
+
- contributions may not change another entry's trust, remove others' entries,
|
|
8
|
+
or rename/re-parent the registry
|
|
9
|
+
- every entry carries provenance
|
|
10
|
+
|
|
11
|
+
`promote()` is the separate, maintainer-only step that flips trust upward. This
|
|
12
|
+
is "validate → queue → gated promote" — no auto-merge of agent-loadable content.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
import datetime as _dt
|
|
18
|
+
import json
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
# what a registry lists: the kinds it has always taken, a federated child marketplace (`registry`), and the five
|
|
23
|
+
# kinds an instance of ChainCompiler makes — an AIOS, a skillchain, a chain of reasoning, an attention chain, a syntax
|
|
24
|
+
KINDS = ("skill", "tree", "exchange", "mcp", "registry", "aios", "skillchain", "cor", "ac", "syntax")
|
|
25
|
+
MADE_KINDS = ("aios", "skillchain", "cor", "ac", "syntax")
|
|
26
|
+
TRUST = ("unverified", "verified", "featured")
|
|
27
|
+
_REQUIRED = ("name", "kind", "repo")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class Entry:
|
|
32
|
+
name: str
|
|
33
|
+
kind: str
|
|
34
|
+
repo: str
|
|
35
|
+
manifest: str = ""
|
|
36
|
+
version: str = "0.1.0"
|
|
37
|
+
trust: str = "unverified"
|
|
38
|
+
provenance: dict = field(default_factory=dict)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def load_registry(path: str | Path) -> dict:
|
|
42
|
+
return json.loads(Path(path).read_text(encoding="utf-8"))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _by_name(data: dict) -> dict[str, dict]:
|
|
46
|
+
return {e["name"]: e for e in data.get("entries", [])}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def validate_registry(data: dict) -> list[str]:
|
|
50
|
+
"""Schema check on a registry document."""
|
|
51
|
+
errs: list[str] = []
|
|
52
|
+
if not isinstance(data.get("name"), str):
|
|
53
|
+
errs.append("registry: missing string `name`")
|
|
54
|
+
if "parent" not in data:
|
|
55
|
+
errs.append("registry: missing `parent` (use null at the root)")
|
|
56
|
+
if not isinstance(data.get("entries"), list):
|
|
57
|
+
errs.append("registry: `entries` must be a list")
|
|
58
|
+
return errs
|
|
59
|
+
seen: set[str] = set()
|
|
60
|
+
for i, e in enumerate(data["entries"]):
|
|
61
|
+
tag = e.get("name", f"#{i}")
|
|
62
|
+
for f in _REQUIRED:
|
|
63
|
+
if not e.get(f):
|
|
64
|
+
errs.append(f"entry {tag}: missing `{f}`")
|
|
65
|
+
if e.get("kind") not in KINDS:
|
|
66
|
+
errs.append(f"entry {tag}: kind must be one of {KINDS}")
|
|
67
|
+
if e.get("trust", "unverified") not in TRUST:
|
|
68
|
+
errs.append(f"entry {tag}: trust must be one of {TRUST}")
|
|
69
|
+
if e.get("name") in seen:
|
|
70
|
+
errs.append(f"entry {tag}: duplicate name")
|
|
71
|
+
seen.add(e.get("name"))
|
|
72
|
+
return errs
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def validate_contribution(base: dict, head: dict, *, actor: str | None = None) -> list[str]:
|
|
76
|
+
"""Gate a PR's registry change. Empty list = a valid (queued, unverified) contribution."""
|
|
77
|
+
errs = validate_registry(head)
|
|
78
|
+
if errs:
|
|
79
|
+
return errs
|
|
80
|
+
if head.get("name") != base.get("name"):
|
|
81
|
+
errs.append("contribution may not rename the registry")
|
|
82
|
+
if head.get("parent") != base.get("parent"):
|
|
83
|
+
errs.append("contribution may not change the registry parent")
|
|
84
|
+
b, h = _by_name(base), _by_name(head)
|
|
85
|
+
for name in h.keys() - b.keys(): # ADDED
|
|
86
|
+
e = h[name]
|
|
87
|
+
if e.get("trust", "unverified") != "unverified":
|
|
88
|
+
errs.append(f"new entry {name!r} must be `unverified` (promotion is maintainer-only)")
|
|
89
|
+
if not (e.get("provenance") or {}).get("by"):
|
|
90
|
+
errs.append(f"new entry {name!r} must carry provenance.by")
|
|
91
|
+
for name in b.keys() - h.keys(): # REMOVED
|
|
92
|
+
errs.append(f"contribution removes existing entry {name!r} (maintainer-only)")
|
|
93
|
+
for name in b.keys() & h.keys(): # MODIFIED
|
|
94
|
+
if h[name].get("trust") != b[name].get("trust"):
|
|
95
|
+
errs.append(f"contribution changes trust of {name!r} (maintainer-only — use promote)")
|
|
96
|
+
return errs
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def promote(path: str | Path, name: str, *, to: str = "verified", by: str | None = None,
|
|
100
|
+
now: str | None = None) -> Entry:
|
|
101
|
+
"""Maintainer-only: flip an entry's trust. Direct (not via PR)."""
|
|
102
|
+
if to not in TRUST:
|
|
103
|
+
raise ValueError(f"trust must be one of {TRUST}")
|
|
104
|
+
p = Path(path)
|
|
105
|
+
data = load_registry(p)
|
|
106
|
+
for e in data.get("entries", []):
|
|
107
|
+
if e["name"] == name:
|
|
108
|
+
e["trust"] = to
|
|
109
|
+
e.setdefault("provenance", {})["promoted_by"] = by or "maintainer"
|
|
110
|
+
e["provenance"]["promoted_at"] = now or _dt.datetime.now().isoformat(timespec="seconds")
|
|
111
|
+
p.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")
|
|
112
|
+
return Entry(**{k: e.get(k) for k in ("name", "kind", "repo", "manifest", "version", "trust", "provenance")})
|
|
113
|
+
raise KeyError(f"no entry named {name!r}")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def search(path: str | Path, query: str | None = None, *, min_trust: str = "unverified") -> list[dict]:
|
|
117
|
+
"""Consumer view with a trust floor."""
|
|
118
|
+
floor = TRUST.index(min_trust)
|
|
119
|
+
rows = [e for e in load_registry(path).get("entries", []) if TRUST.index(e.get("trust", "unverified")) >= floor]
|
|
120
|
+
if query:
|
|
121
|
+
q = query.lower()
|
|
122
|
+
rows = [e for e in rows if q in e["name"].lower() or any(q in t.lower() for t in e.get("tags", []))]
|
|
123
|
+
return rows
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def new_registry(name: str, parent: str | None = None) -> dict:
|
|
127
|
+
"""An empty registry document."""
|
|
128
|
+
return {"name": name, "parent": parent, "entries": []}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""The feedback store — the observe→improve half of keeping a skill tree.
|
|
2
|
+
|
|
3
|
+
Reports accumulate the gaps and problems found *in use*, so an improver can act
|
|
4
|
+
on them later. Two report kinds to start:
|
|
5
|
+
|
|
6
|
+
- `missed_skill` — a needed skill didn't exist (filed by the agent, or by
|
|
7
|
+
the user telling the agent "you missed X").
|
|
8
|
+
- `expected_not_used` — a skill SHOULD have fired for a task but didn't
|
|
9
|
+
("expected xyz but the skill wasn't used").
|
|
10
|
+
|
|
11
|
+
An agent files a report through the CLI (`ccmarket report-missed`). An
|
|
12
|
+
improver agent reads the open reports, then creates/improves skills and calls
|
|
13
|
+
`resolve` to close them.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import datetime as _dt
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
# Claude Code's own configuration folder: the one `CLAUDE_CONFIG_DIR` names, else the home's `.claude`
|
|
24
|
+
DEFAULT_REPORTS = Path(os.environ.get("CLAUDE_CONFIG_DIR") or Path.home() / ".claude") / "skill-reports.json"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _now() -> str:
|
|
28
|
+
return _dt.datetime.now().isoformat(timespec="seconds")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _load(path: Path) -> list[dict]:
|
|
32
|
+
return json.loads(path.read_text(encoding="utf-8")) if path.is_file() else []
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _save(path: Path, rows: list[dict]) -> None:
|
|
36
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
path.write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def file_report(reports_path: str | Path, *, kind: str, by: str, now: str | None = None,
|
|
41
|
+
**fields: Any) -> dict:
|
|
42
|
+
path = Path(reports_path)
|
|
43
|
+
rows = _load(path)
|
|
44
|
+
entry = {"id": f"r{len(rows) + 1}", "kind": kind, "by": by, "at": now or _now(),
|
|
45
|
+
"status": "open", **fields}
|
|
46
|
+
rows.append(entry)
|
|
47
|
+
_save(path, rows)
|
|
48
|
+
return entry
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def report_missed(reports_path: str | Path = DEFAULT_REPORTS, *, needed: str, happened: str,
|
|
52
|
+
suggests: str | None = None, by: str = "agent", now: str | None = None) -> dict:
|
|
53
|
+
"""File a missed-skill report: a capability was needed but no skill existed."""
|
|
54
|
+
return file_report(reports_path, kind="missed_skill", by=by, now=now,
|
|
55
|
+
needed=needed, happened=happened, suggests=suggests)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def mark_problem(reports_path: str | Path = DEFAULT_REPORTS, *, skill: str, expected: str,
|
|
59
|
+
happened: str, by: str = "user", now: str | None = None) -> dict:
|
|
60
|
+
"""Mark 'expected this skill to be used, but it wasn't' — feeds the improver."""
|
|
61
|
+
return file_report(reports_path, kind="expected_not_used", by=by, now=now,
|
|
62
|
+
skill=skill, expected=expected, happened=happened)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def list_reports(reports_path: str | Path = DEFAULT_REPORTS, *, kind: str | None = None,
|
|
66
|
+
status: str | None = "open") -> list[dict]:
|
|
67
|
+
rows = _load(Path(reports_path))
|
|
68
|
+
if kind:
|
|
69
|
+
rows = [r for r in rows if r.get("kind") == kind]
|
|
70
|
+
if status:
|
|
71
|
+
rows = [r for r in rows if r.get("status") == status]
|
|
72
|
+
return rows
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def summary(reports_path: str | Path = DEFAULT_REPORTS) -> dict:
|
|
76
|
+
rows = _load(Path(reports_path))
|
|
77
|
+
open_rows = [r for r in rows if r.get("status") == "open"]
|
|
78
|
+
by_kind: dict[str, int] = {}
|
|
79
|
+
for r in open_rows:
|
|
80
|
+
by_kind[r["kind"]] = by_kind.get(r["kind"], 0) + 1
|
|
81
|
+
return {"total": len(rows), "open": len(open_rows), "open_by_kind": by_kind}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def resolve(reports_path: str | Path, report_id: str, *, resolution: str,
|
|
85
|
+
by: str = "improver", now: str | None = None) -> dict:
|
|
86
|
+
"""Close a report (after creating/improving the skill it asked for)."""
|
|
87
|
+
path = Path(reports_path)
|
|
88
|
+
rows = _load(path)
|
|
89
|
+
for r in rows:
|
|
90
|
+
if r["id"] == report_id:
|
|
91
|
+
r["status"] = "resolved"
|
|
92
|
+
r["resolution"] = resolution
|
|
93
|
+
r["resolved_by"] = by
|
|
94
|
+
r["resolved_at"] = now or _now()
|
|
95
|
+
_save(path, rows)
|
|
96
|
+
return r
|
|
97
|
+
raise KeyError(f"no report {report_id!r}")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chaincompiler-market
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: ChainCompiler's marketplace: the exchange (several skill trees under one master), the reports queue, and the registry with its trust levels, contribution gate and federation walk
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: agent-skilltree>=0.5.0
|
|
10
|
+
Requires-Dist: click
|
|
11
|
+
Requires-Dist: pyyaml
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# chaincompiler-market
|
|
15
|
+
|
|
16
|
+
ChainCompiler's marketplace (import `ccmarket`, command `ccmarket`): the exchange, the reports queue, and the registry
|
|
17
|
+
with its federation. Part of [ChainCompiler](https://github.com/sancovp/chaincompiler); its design is that repository's
|
|
18
|
+
`DESIGN.md` §15.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
pip install chaincompiler-market
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- **An exchange** holds several skill trees in one repository under one master: `ccmarket exchange build <manifest>
|
|
25
|
+
<repo>`, `ccmarket exchange validate <manifest> <repo>` (exits 1 on any error). A manifest is JSON or YAML.
|
|
26
|
+
- **The reports queue** records a skill that was needed and missing, or should have been used: `ccmarket report-missed`,
|
|
27
|
+
`ccmarket mark-problem`, `ccmarket reports`, `ccmarket resolve`.
|
|
28
|
+
- **The registry** is the marketplace's one list (`registry.json`): entries that point at what was made, each
|
|
29
|
+
`unverified`, `verified` or `featured`. It takes a skill, a tree, an exchange, a tool server, a child registry, and
|
|
30
|
+
the five kinds an instance of ChainCompiler makes: an AIOS, a skillchain, a chain of reasoning, an attention chain and
|
|
31
|
+
a syntax. `ccmarket registry publish|search|validate|promote`. A contribution may only add `unverified` entries; a
|
|
32
|
+
maintainer promotes. A registry that lists child registries federates into a tree (`walk_federation`), and a child's
|
|
33
|
+
parent is checked by name.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/ccmarket/__init__.py
|
|
5
|
+
src/ccmarket/cli.py
|
|
6
|
+
src/ccmarket/exchange.py
|
|
7
|
+
src/ccmarket/federation.py
|
|
8
|
+
src/ccmarket/marketplace.py
|
|
9
|
+
src/ccmarket/registry.py
|
|
10
|
+
src/ccmarket/reports.py
|
|
11
|
+
src/chaincompiler_market.egg-info/PKG-INFO
|
|
12
|
+
src/chaincompiler_market.egg-info/SOURCES.txt
|
|
13
|
+
src/chaincompiler_market.egg-info/dependency_links.txt
|
|
14
|
+
src/chaincompiler_market.egg-info/entry_points.txt
|
|
15
|
+
src/chaincompiler_market.egg-info/requires.txt
|
|
16
|
+
src/chaincompiler_market.egg-info/top_level.txt
|
|
17
|
+
tests/test_cli.py
|
|
18
|
+
tests/test_exchange.py
|
|
19
|
+
tests/test_federation.py
|
|
20
|
+
tests/test_marketplace.py
|
|
21
|
+
tests/test_registry.py
|
|
22
|
+
tests/test_reports.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ccmarket
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""The `ccmarket` command: reports filed, listed and closed; a registry published to, searched, validated, promoted."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from click.testing import CliRunner
|
|
8
|
+
|
|
9
|
+
from ccmarket.cli import main
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_reports_are_filed_listed_and_closed(tmp_path: Path):
|
|
13
|
+
rp, run = str(tmp_path / "reports.json"), CliRunner().invoke
|
|
14
|
+
assert run(main, ["report-missed", "--needed", "a csv skill", "--happened", "wrote it by hand",
|
|
15
|
+
"--reports", rp]).exit_code == 0
|
|
16
|
+
assert run(main, ["mark-problem", "--skill", "deploy", "--expected", "used", "--happened", "skipped",
|
|
17
|
+
"--reports", rp]).exit_code == 0
|
|
18
|
+
out = run(main, ["reports", "--reports", rp]).output
|
|
19
|
+
assert "2 open / 2 total" in out and "a csv skill" in out and "deploy" in out
|
|
20
|
+
assert run(main, ["resolve", "r1", "--resolution", "made the skill", "--reports", rp]).exit_code == 0
|
|
21
|
+
assert "1 open / 2 total" in run(main, ["reports", "--reports", rp]).output
|
|
22
|
+
assert run(main, ["resolve", "r9", "--resolution", "x", "--reports", rp]).exit_code == 1
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_a_registry_is_published_to_searched_validated_and_promoted(tmp_path: Path):
|
|
26
|
+
reg, run = str(tmp_path / "registry.json"), CliRunner().invoke
|
|
27
|
+
assert run(main, ["registry", "publish", reg, "my-agent", str(tmp_path / "agent"), "--kind", "aios",
|
|
28
|
+
"--tag", "writing"]).exit_code == 0
|
|
29
|
+
assert run(main, ["registry", "publish", reg, "x", str(tmp_path / "x"), "--kind", "widget"]).exit_code == 1
|
|
30
|
+
assert run(main, ["registry", "validate", reg]).exit_code == 0
|
|
31
|
+
assert [e["name"] for e in json.loads(run(main, ["registry", "search", reg, "writing"]).output)] == ["my-agent"]
|
|
32
|
+
assert run(main, ["registry", "promote", reg, "my-agent"]).exit_code == 0
|
|
33
|
+
assert json.loads(run(main, ["registry", "search", reg, "--min-trust", "verified"]).output)[0]["trust"] == "verified"
|
|
34
|
+
assert run(main, ["registry", "promote", reg, "absent"]).exit_code == 1
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Exchange tests: many trees + a master, built and validated."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from skilltree import SkillTree, TreeNode
|
|
8
|
+
from ccmarket import build_exchange, exchange_is_valid, load_exchange
|
|
9
|
+
from skilltree.materialize import node_skill_md
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _two_tree_exchange(tmp_path: Path) -> Path:
|
|
13
|
+
# two member tree manifests
|
|
14
|
+
cog = SkillTree(TreeNode("cognition", "sc", children=[TreeNode("reason", "cor")]))
|
|
15
|
+
wri = SkillTree(TreeNode("writing", "sc", children=[TreeNode("draft", "cor")]))
|
|
16
|
+
cog.save(tmp_path / "cognition.skilltree.json")
|
|
17
|
+
wri.save(tmp_path / "writing.skilltree.json")
|
|
18
|
+
manifest = {
|
|
19
|
+
"name": "my-exchange", "master": "cc-master",
|
|
20
|
+
"trees": [
|
|
21
|
+
{"name": "cognition", "manifest": "cognition.skilltree.json"},
|
|
22
|
+
{"name": "writing", "manifest": "writing.skilltree.json"},
|
|
23
|
+
],
|
|
24
|
+
}
|
|
25
|
+
mpath = tmp_path / "exchange.json"
|
|
26
|
+
mpath.write_text(json.dumps(manifest))
|
|
27
|
+
return mpath
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_build_exchange_master_and_members(tmp_path: Path):
|
|
31
|
+
mpath = _two_tree_exchange(tmp_path)
|
|
32
|
+
ex = load_exchange(mpath)
|
|
33
|
+
repo = tmp_path / "repo"
|
|
34
|
+
master = build_exchange(ex, repo)
|
|
35
|
+
assert master.is_file()
|
|
36
|
+
assert exchange_is_valid(repo, ex)
|
|
37
|
+
# master breadcrumbs into each member tree's root
|
|
38
|
+
body = master.read_text()
|
|
39
|
+
# portable by default: relative to the master's folder (the repo), no machine path
|
|
40
|
+
assert "trees/cognition/.claude/skills/cognition/SKILL.md" in body
|
|
41
|
+
assert "trees/writing/.claude/skills/writing/SKILL.md" in body
|
|
42
|
+
assert str(tmp_path) not in body
|
|
43
|
+
# each member tree is materialized + valid on its own
|
|
44
|
+
assert node_skill_md(repo / "trees" / "cognition" / "reason", "reason").is_file()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_dead_master_breadcrumb_caught(tmp_path: Path):
|
|
48
|
+
from ccmarket import validate_exchange
|
|
49
|
+
mpath = _two_tree_exchange(tmp_path)
|
|
50
|
+
ex = load_exchange(mpath)
|
|
51
|
+
repo = tmp_path / "repo"
|
|
52
|
+
build_exchange(ex, repo)
|
|
53
|
+
# nuke a member tree → master breadcrumb to it now dies
|
|
54
|
+
import shutil
|
|
55
|
+
shutil.rmtree(repo / "trees" / "writing")
|
|
56
|
+
issues = [v for v in validate_exchange(repo, ex) if v.severity == "error"]
|
|
57
|
+
assert issues
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_the_command_exits_1_on_an_invalid_exchange_and_reads_a_yaml_manifest(tmp_path: Path):
|
|
61
|
+
from click.testing import CliRunner
|
|
62
|
+
from skilltree import SkillTree, TreeNode
|
|
63
|
+
from ccmarket.cli import main
|
|
64
|
+
tree = tmp_path / "t.skilltree.json"
|
|
65
|
+
SkillTree(TreeNode("alpha", "sc", description="a", children=[TreeNode("leaf", "skill", description="l")])).save(tree)
|
|
66
|
+
manifest = tmp_path / "ex.yaml"
|
|
67
|
+
manifest.write_text("name: ex\nmaster: m\ntrees:\n - name: alpha\n manifest: t.skilltree.json\n")
|
|
68
|
+
repo = tmp_path / "repo"
|
|
69
|
+
run = CliRunner().invoke
|
|
70
|
+
assert run(main, ["exchange", "build", str(manifest), str(repo)]).exit_code == 0
|
|
71
|
+
assert run(main, ["exchange", "validate", str(manifest), str(repo)]).exit_code == 0
|
|
72
|
+
master = next(repo.glob(".claude/skills/*/SKILL.md"))
|
|
73
|
+
master.write_text(master.read_text().replace("alpha (tree)", "alpha (tree) gone").replace("trees/alpha", "trees/nope"))
|
|
74
|
+
bad = run(main, ["exchange", "validate", str(manifest), str(repo)])
|
|
75
|
+
assert bad.exit_code == 1 and "error" in bad.output
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Federation tests: walking a federation of marketplaces, with cycle/backref checks."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from ccmarket import (
|
|
5
|
+
flatten_federation,
|
|
6
|
+
local_resolver,
|
|
7
|
+
validate_federation,
|
|
8
|
+
walk_federation,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _reg(name, parent, entries):
|
|
13
|
+
return {"name": name, "parent": parent, "entries": entries}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _skill(name, by="x"):
|
|
17
|
+
return {"name": name, "kind": "skill", "repo": f"github:{by}/{name}",
|
|
18
|
+
"trust": "verified", "provenance": {"by": by}}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _child_ref(name):
|
|
22
|
+
return {"name": name, "kind": "registry", "repo": f"github:o/{name}",
|
|
23
|
+
"trust": "verified", "provenance": {"by": "o"}}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _world():
|
|
27
|
+
root = _reg("root", None, [_skill("root-skill"), _child_ref("alpha"), _child_ref("beta")])
|
|
28
|
+
alpha = _reg("alpha", "root", [_skill("alpha-skill"), _child_ref("gamma")])
|
|
29
|
+
beta = _reg("beta", "root", [_skill("beta-skill")])
|
|
30
|
+
gamma = _reg("gamma", "alpha", [_skill("gamma-skill")])
|
|
31
|
+
resolve = local_resolver({"alpha": alpha, "beta": beta, "gamma": gamma})
|
|
32
|
+
return root, resolve
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_walk_nests_the_federation():
|
|
36
|
+
root, resolve = _world()
|
|
37
|
+
tree = walk_federation(root, resolve)
|
|
38
|
+
assert tree["name"] == "root"
|
|
39
|
+
kids = {c["name"] for c in tree["children"]}
|
|
40
|
+
assert kids == {"alpha", "beta"}
|
|
41
|
+
alpha = next(c for c in tree["children"] if c["name"] == "alpha")
|
|
42
|
+
assert {c["name"] for c in alpha["children"]} == {"gamma"}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_flatten_tags_each_entry_with_its_path():
|
|
46
|
+
root, resolve = _world()
|
|
47
|
+
flat = {e["name"]: e["_path"] for e in flatten_federation(root, resolve)}
|
|
48
|
+
assert flat["gamma-skill"] == ["root", "alpha", "gamma"]
|
|
49
|
+
assert flat["beta-skill"] == ["root", "beta"]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_unresolved_child_is_flagged():
|
|
53
|
+
root = _reg("root", None, [_child_ref("missing")])
|
|
54
|
+
resolve = local_resolver({}) # nothing resolves
|
|
55
|
+
tree = walk_federation(root, resolve)
|
|
56
|
+
assert tree["children"][0]["unresolved"]
|
|
57
|
+
assert any("unresolved" in e for e in validate_federation(root, resolve))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_cycle_is_caught():
|
|
61
|
+
a = _reg("a", None, [_child_ref("b")])
|
|
62
|
+
b = _reg("b", "a", [_child_ref("a")]) # b points back to a → cycle
|
|
63
|
+
resolve = local_resolver({"a": a, "b": b})
|
|
64
|
+
assert any("cycle" in e for e in validate_federation(a, resolve))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_validate_federation_clean_world():
|
|
68
|
+
root, resolve = _world()
|
|
69
|
+
assert validate_federation(root, resolve) == []
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_a_child_whose_parent_is_another_registry_is_refused_whatever_its_parent_is_called():
|
|
73
|
+
root = _reg("root", None, [_child_ref("alpha")])
|
|
74
|
+
alpha = _reg("alpha", "github:someone/else", [_skill("alpha-skill")]) # a parent that is not `root`
|
|
75
|
+
errs = validate_federation(root, local_resolver({"alpha": alpha}))
|
|
76
|
+
assert any("parent backref" in e and "does not match 'root'" in e for e in errs)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Publishing: one registry, an entry upserted by name, public entries notified, the five made kinds taken."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from ccmarket import (MADE_KINDS, load_registry, log_notify, promote, publish, search_marketplace,
|
|
10
|
+
validate_registry)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_publish_writes_the_registry_document_and_search_reads_it(tmp_path: Path):
|
|
14
|
+
reg = tmp_path / "registry.json"
|
|
15
|
+
publish(reg, "debug-attn", tmp_path / "skills" / "debug-attn", kind="skill", tags=["debug"])
|
|
16
|
+
publish(reg, "cc-master", tmp_path / "repo", kind="exchange", public=True)
|
|
17
|
+
data = load_registry(reg)
|
|
18
|
+
assert set(data) == {"name", "parent", "entries"} and validate_registry(data) == [] # the one registry, valid
|
|
19
|
+
assert len(search_marketplace(reg)) == 2
|
|
20
|
+
assert [r["name"] for r in search_marketplace(reg, "debug")] == ["debug-attn"] # by tag or name
|
|
21
|
+
assert [r["name"] for r in search_marketplace(reg, public_only=True)] == ["cc-master"]
|
|
22
|
+
assert all(e["trust"] == "unverified" and e["provenance"]["by"] for e in data["entries"])
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_a_republish_updates_by_name_and_keeps_the_trust_a_maintainer_gave(tmp_path: Path):
|
|
26
|
+
reg = tmp_path / "registry.json"
|
|
27
|
+
publish(reg, "x", tmp_path / "a", version="0.1.0")
|
|
28
|
+
promote(reg, "x", to="verified", by="m")
|
|
29
|
+
publish(reg, "x", tmp_path / "a", version="0.2.0")
|
|
30
|
+
rows = search_marketplace(reg)
|
|
31
|
+
assert len(rows) == 1 and rows[0]["version"] == "0.2.0" and rows[0]["trust"] == "verified"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_notify_fires_only_when_public(tmp_path: Path):
|
|
35
|
+
reg, log = tmp_path / "registry.json", tmp_path / "notify.log"
|
|
36
|
+
publish(reg, "private-one", tmp_path / "p", public=False, notify=log_notify(log))
|
|
37
|
+
assert not log.exists()
|
|
38
|
+
publish(reg, "public-one", tmp_path / "q", public=True, notify=log_notify(log))
|
|
39
|
+
assert json.loads(log.read_text().splitlines()[0])["name"] == "public-one"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_the_registry_takes_the_five_kinds_an_instance_makes_and_refuses_another(tmp_path: Path):
|
|
43
|
+
reg = tmp_path / "registry.json"
|
|
44
|
+
for kind in MADE_KINDS:
|
|
45
|
+
publish(reg, f"a-{kind}", tmp_path / kind, kind=kind)
|
|
46
|
+
assert MADE_KINDS == ("aios", "skillchain", "cor", "ac", "syntax")
|
|
47
|
+
assert validate_registry(load_registry(reg)) == [] and len(search_marketplace(reg)) == 5
|
|
48
|
+
with pytest.raises(ValueError):
|
|
49
|
+
publish(reg, "nope", tmp_path / "n", kind="widget")
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Registry tests: registry schema, the contribution gate, gated promotion."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from ccmarket import (
|
|
8
|
+
load_registry,
|
|
9
|
+
promote,
|
|
10
|
+
search_registry,
|
|
11
|
+
validate_contribution,
|
|
12
|
+
validate_registry,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
ROOT = {"name": "m", "parent": None, "entries": [
|
|
16
|
+
{"name": "owned", "kind": "skill", "repo": "github:me/x", "trust": "verified",
|
|
17
|
+
"provenance": {"by": "me"}},
|
|
18
|
+
]}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _add(entry):
|
|
22
|
+
head = json.loads(json.dumps(ROOT))
|
|
23
|
+
head["entries"].append(entry)
|
|
24
|
+
return head
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_schema_valid_and_invalid():
|
|
28
|
+
assert validate_registry(ROOT) == []
|
|
29
|
+
bad = {"name": "m", "parent": None, "entries": [{"name": "x", "kind": "nope", "repo": "r"}]}
|
|
30
|
+
assert any("kind" in e for e in validate_registry(bad))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_valid_contribution_adds_unverified():
|
|
34
|
+
head = _add({"name": "new", "kind": "skill", "repo": "github:a/b", "trust": "unverified",
|
|
35
|
+
"provenance": {"by": "alice"}})
|
|
36
|
+
assert validate_contribution(ROOT, head) == []
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_contribution_cannot_self_promote():
|
|
40
|
+
head = _add({"name": "new", "kind": "skill", "repo": "github:a/b", "trust": "verified",
|
|
41
|
+
"provenance": {"by": "alice"}})
|
|
42
|
+
assert any("unverified" in e for e in validate_contribution(ROOT, head))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_contribution_needs_provenance():
|
|
46
|
+
head = _add({"name": "new", "kind": "skill", "repo": "github:a/b", "trust": "unverified"})
|
|
47
|
+
assert any("provenance" in e for e in validate_contribution(ROOT, head))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_contribution_cannot_tamper_others():
|
|
51
|
+
# change an existing entry's trust
|
|
52
|
+
head = json.loads(json.dumps(ROOT))
|
|
53
|
+
head["entries"][0]["trust"] = "unverified"
|
|
54
|
+
assert any("trust" in e for e in validate_contribution(ROOT, head))
|
|
55
|
+
# remove an existing entry
|
|
56
|
+
head2 = {"name": "m", "parent": None, "entries": []}
|
|
57
|
+
assert any("removes" in e for e in validate_contribution(ROOT, head2))
|
|
58
|
+
# re-parent / rename
|
|
59
|
+
head3 = json.loads(json.dumps(ROOT)); head3["parent"] = "github:evil/x"
|
|
60
|
+
assert any("parent" in e for e in validate_contribution(ROOT, head3))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_promote_is_the_gated_step(tmp_path: Path):
|
|
64
|
+
reg = tmp_path / "registry.json"
|
|
65
|
+
reg.write_text(json.dumps(_add({"name": "new", "kind": "skill", "repo": "github:a/b",
|
|
66
|
+
"trust": "unverified", "provenance": {"by": "alice"}})))
|
|
67
|
+
entry = promote(reg, "new", to="verified", by="sancovp", now="2026-06-16T00:00:00")
|
|
68
|
+
assert entry.trust == "verified"
|
|
69
|
+
assert load_registry(reg)["entries"][-1]["provenance"]["promoted_by"] == "sancovp"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_search_trust_floor(tmp_path: Path):
|
|
73
|
+
reg = tmp_path / "registry.json"
|
|
74
|
+
reg.write_text(json.dumps(_add({"name": "new", "kind": "skill", "repo": "github:a/b",
|
|
75
|
+
"trust": "unverified", "provenance": {"by": "alice"}})))
|
|
76
|
+
assert {e["name"] for e in search_registry(reg, min_trust="verified")} == {"owned"}
|
|
77
|
+
assert {e["name"] for e in search_registry(reg, min_trust="unverified")} == {"owned", "new"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Tests: the skill-reports store (the observe→improve queue)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from ccmarket import list_reports, mark_problem, report_missed, reports_summary, resolve
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_report_missed_and_list(tmp_path: Path):
|
|
10
|
+
rp = tmp_path / "reports.json"
|
|
11
|
+
e = report_missed(rp, needed="a CSV linter", happened="hand-rolled it", suggests="csv-lint: validate CSVs", by="agent")
|
|
12
|
+
assert e["id"] == "r1" and e["kind"] == "missed_skill" and e["status"] == "open"
|
|
13
|
+
rows = list_reports(rp)
|
|
14
|
+
assert len(rows) == 1 and rows[0]["needed"] == "a CSV linter"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_mark_problem(tmp_path: Path):
|
|
18
|
+
rp = tmp_path / "reports.json"
|
|
19
|
+
mark_problem(rp, skill="deep-research", expected="should have triggered", happened="answered from memory")
|
|
20
|
+
assert list_reports(rp, kind="expected_not_used")[0]["skill"] == "deep-research"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_summary_and_resolve(tmp_path: Path):
|
|
24
|
+
rp = tmp_path / "reports.json"
|
|
25
|
+
report_missed(rp, needed="x", happened="y")
|
|
26
|
+
mark_problem(rp, skill="s", expected="e", happened="h")
|
|
27
|
+
s = reports_summary(rp)
|
|
28
|
+
assert s == {"total": 2, "open": 2, "open_by_kind": {"missed_skill": 1, "expected_not_used": 1}}
|
|
29
|
+
resolve(rp, "r1", resolution="created csv-lint skill")
|
|
30
|
+
assert reports_summary(rp)["open"] == 1 # r1 closed
|
|
31
|
+
assert list_reports(rp) == [r for r in list_reports(rp) if r["status"] == "open"]
|
|
32
|
+
assert "r1" not in {r["id"] for r in list_reports(rp)} # open list excludes resolved
|