graftkit 0.1.0__py3-none-any.whl
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.
- graftkit/__init__.py +40 -0
- graftkit/__main__.py +7 -0
- graftkit/_core/__init__.py +4 -0
- graftkit/_core/agent.py +41 -0
- graftkit/_core/app.py +32 -0
- graftkit/_core/commands/__init__.py +1 -0
- graftkit/_core/commands/describe.py +45 -0
- graftkit/_core/commands/doctor.py +35 -0
- graftkit/_core/commands/extension.py +109 -0
- graftkit/_core/commands/init.py +84 -0
- graftkit/_core/commands/skills.py +361 -0
- graftkit/_core/config.py +195 -0
- graftkit/_core/conformance.py +69 -0
- graftkit/_core/context.py +79 -0
- graftkit/_core/errors.py +13 -0
- graftkit/_core/extension.py +163 -0
- graftkit/_core/identity.py +32 -0
- graftkit/_core/launcher.py +106 -0
- graftkit/_core/models.py +19 -0
- graftkit/_core/patterns.py +18 -0
- graftkit/_core/root.py +69 -0
- graftkit/_core/settings.py +83 -0
- graftkit/_core/skills/__init__.py +5 -0
- graftkit/_core/skills/catalog.py +238 -0
- graftkit/_core/skills/content.py +59 -0
- graftkit/_core/skills/edit.py +54 -0
- graftkit/_core/skills/fetch.py +155 -0
- graftkit/_core/skills/generate.py +63 -0
- graftkit/_core/skills/harness.py +49 -0
- graftkit/_core/skills/install.py +109 -0
- graftkit/_core/skills/links.py +124 -0
- graftkit/_core/skills/lock.py +98 -0
- graftkit/_core/skills/publish.py +126 -0
- graftkit/_core/skills/resolve.py +221 -0
- graftkit/_core/skills/spec.py +161 -0
- graftkit/_core/templates/__init__.py +1 -0
- graftkit/_core/templates/extension/package/_cli_/__init__.py.tmpl +5 -0
- graftkit/_core/templates/extension/package/_cli_/commands/__init__.py.tmpl +1 -0
- graftkit/_core/templates/extension/package/_cli_/commands/hello.py.tmpl +45 -0
- graftkit/_core/templates/extension/package/_cli_/workflows/__init__.py.tmpl +1 -0
- graftkit/_core/templates/extension/package/_cli_/workflows/hello.py.tmpl +18 -0
- graftkit/_core/templates/extension/tests/_cli_/test__cli__conformance.py.tmpl +13 -0
- graftkit/_core/templates/extension/tests/_cli_/test_hello_command.py.tmpl +18 -0
- graftkit/_core/templates/init/workflow.yml.tmpl +26 -0
- graftkit/_core/workflows/__init__.py +1 -0
- graftkit/_core/workflows/content.py +218 -0
- graftkit/_core/workflows/describe.py +75 -0
- graftkit/_core/workflows/doctor.py +85 -0
- graftkit/_core/workflows/extension.py +129 -0
- graftkit/_core/workflows/init.py +44 -0
- graftkit/_core/workflows/skills.py +567 -0
- graftkit/py.typed +0 -0
- graftkit/testing/__init__.py +260 -0
- graftkit/testing/plugin.py +58 -0
- graftkit-0.1.0.dist-info/METADATA +183 -0
- graftkit-0.1.0.dist-info/RECORD +59 -0
- graftkit-0.1.0.dist-info/WHEEL +4 -0
- graftkit-0.1.0.dist-info/entry_points.txt +5 -0
- graftkit-0.1.0.dist-info/licenses/LICENSE +21 -0
graftkit/__init__.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""graftkit's public API: extensions, command declarations, and ``__version__``.
|
|
2
|
+
|
|
3
|
+
``graftkit.testing`` is public too; ``graftkit._core`` is internal. Semantic versioning applies.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from importlib.metadata import version as _version
|
|
7
|
+
|
|
8
|
+
from cli_interview_kit import (
|
|
9
|
+
CliError,
|
|
10
|
+
Command,
|
|
11
|
+
Consent,
|
|
12
|
+
Console,
|
|
13
|
+
Interview,
|
|
14
|
+
Invocation,
|
|
15
|
+
Option,
|
|
16
|
+
Question,
|
|
17
|
+
non_empty,
|
|
18
|
+
when,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
from graftkit._core.extension import Extension
|
|
22
|
+
from graftkit._core.root import Repo
|
|
23
|
+
|
|
24
|
+
__version__ = _version("graftkit")
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"CliError",
|
|
28
|
+
"Command",
|
|
29
|
+
"Consent",
|
|
30
|
+
"Console",
|
|
31
|
+
"Extension",
|
|
32
|
+
"Interview",
|
|
33
|
+
"Invocation",
|
|
34
|
+
"Option",
|
|
35
|
+
"Question",
|
|
36
|
+
"Repo",
|
|
37
|
+
"__version__",
|
|
38
|
+
"non_empty",
|
|
39
|
+
"when",
|
|
40
|
+
]
|
graftkit/__main__.py
ADDED
graftkit/_core/agent.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""The agent policy: whether an AI agent may run a command itself, or hands it to the user.
|
|
2
|
+
|
|
3
|
+
A command declares ``annotations={"graftkit.agent": "run"}``; without it, it is ``hand-off``.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Literal, get_args
|
|
9
|
+
|
|
10
|
+
from cli_interview_kit import Command
|
|
11
|
+
|
|
12
|
+
from graftkit._core.identity import CLI_NAME
|
|
13
|
+
|
|
14
|
+
AGENT_KEY = f"{CLI_NAME}.agent"
|
|
15
|
+
"""The annotation that holds a command's agent policy."""
|
|
16
|
+
|
|
17
|
+
AgentPolicy = Literal["run", "hand-off"]
|
|
18
|
+
|
|
19
|
+
RUN = {AGENT_KEY: "run"}
|
|
20
|
+
"""The annotations of a command an agent may run itself."""
|
|
21
|
+
|
|
22
|
+
_PREFIX = f"{CLI_NAME}."
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def policy(command: Command) -> AgentPolicy:
|
|
26
|
+
"""Return a command's agent policy; ``hand-off`` unless it declares ``run``."""
|
|
27
|
+
return "run" if command.annotations.get(AGENT_KEY) == "run" else "hand-off"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def annotation_problems(command: Command) -> list[str]:
|
|
31
|
+
"""Return what is wrong with a command's ``graftkit.*`` annotations."""
|
|
32
|
+
problems = [
|
|
33
|
+
f"unknown annotation `{key}`"
|
|
34
|
+
for key in sorted(command.annotations)
|
|
35
|
+
if key.startswith(_PREFIX) and key != AGENT_KEY
|
|
36
|
+
]
|
|
37
|
+
value = command.annotations.get(AGENT_KEY)
|
|
38
|
+
if value is not None and value not in get_args(AgentPolicy):
|
|
39
|
+
allowed = " or ".join(f"`{p}`" for p in get_args(AgentPolicy))
|
|
40
|
+
problems.append(f"`{AGENT_KEY}` is `{value}`; use {allowed}")
|
|
41
|
+
return problems
|
graftkit/_core/app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Assembling one cli-interview-kit App from the core commands and the root's extension."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from cli_interview_kit import App, Command
|
|
6
|
+
|
|
7
|
+
from graftkit import __version__
|
|
8
|
+
from graftkit._core.commands import describe, doctor, extension, init, skills
|
|
9
|
+
from graftkit._core.context import Context
|
|
10
|
+
from graftkit._core.identity import CLI_NAME
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_app(context: Context) -> App:
|
|
14
|
+
"""Return the app for a context: the core commands, then the extension's."""
|
|
15
|
+
catalog: list[tuple[str, Command]] = []
|
|
16
|
+
core = (
|
|
17
|
+
describe.command(context, lambda: tuple(catalog)),
|
|
18
|
+
doctor.command(context),
|
|
19
|
+
extension.command(context),
|
|
20
|
+
init.command(context),
|
|
21
|
+
skills.command(context, lambda: tuple(catalog)),
|
|
22
|
+
)
|
|
23
|
+
origin = context.extension.name if context.extension else "core"
|
|
24
|
+
catalog.extend(("core", command) for command in core)
|
|
25
|
+
catalog.extend((origin, command) for command in context.commands)
|
|
26
|
+
where = f" in {context.root}" if context.root else ""
|
|
27
|
+
return App(
|
|
28
|
+
name=CLI_NAME,
|
|
29
|
+
description=f"Root-aware developer tooling and agent skills{where}.",
|
|
30
|
+
version=__version__,
|
|
31
|
+
commands=tuple(command for _, command in catalog),
|
|
32
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The core commands, present in every repository."""
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""``describe``: every command available in this root, for people and for agents.
|
|
2
|
+
|
|
3
|
+
Declarations and rendering only; ``workflows.describe`` does the work.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from cli_interview_kit import Command, Invocation, Option
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
|
|
14
|
+
from graftkit._core.agent import RUN
|
|
15
|
+
from graftkit._core.context import Context
|
|
16
|
+
from graftkit._core.workflows.describe import Catalog, describe
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def command(context: Context, catalog: Catalog) -> Command:
|
|
20
|
+
"""Return the ``describe`` command."""
|
|
21
|
+
|
|
22
|
+
def run(invocation: Invocation) -> None:
|
|
23
|
+
"""Print the commands as a table, or as JSON with ``--json``."""
|
|
24
|
+
document = describe(context, catalog())
|
|
25
|
+
if invocation.options["json"]:
|
|
26
|
+
_ = sys.stdout.write(json.dumps(document.model_dump(mode="json"), indent=2) + "\n")
|
|
27
|
+
return
|
|
28
|
+
table = Table("Command", "From", "Help")
|
|
29
|
+
for entry in document.commands:
|
|
30
|
+
table.add_row(entry.command, entry.origin, entry.help)
|
|
31
|
+
invocation.console.print(table)
|
|
32
|
+
|
|
33
|
+
return Command(
|
|
34
|
+
name="describe",
|
|
35
|
+
annotations=RUN,
|
|
36
|
+
help="List every command available in this root.",
|
|
37
|
+
options=(
|
|
38
|
+
Option(
|
|
39
|
+
dest="json",
|
|
40
|
+
kind="switch",
|
|
41
|
+
help="Print a JSON document with each command's options and questions.",
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
run=run,
|
|
45
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""``doctor``: check the machine and the root the CLI runs in.
|
|
2
|
+
|
|
3
|
+
Declarations and rendering only; ``workflows.doctor`` does the work.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from cli_interview_kit import CliError, Command, Invocation
|
|
9
|
+
from rich.table import Table
|
|
10
|
+
|
|
11
|
+
from graftkit._core.agent import RUN
|
|
12
|
+
from graftkit._core.context import Context
|
|
13
|
+
from graftkit._core.workflows.doctor import run_checks
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def command(context: Context) -> Command:
|
|
17
|
+
"""Return the ``doctor`` command."""
|
|
18
|
+
|
|
19
|
+
def run(invocation: Invocation) -> None:
|
|
20
|
+
"""Run every check and fail if any failed."""
|
|
21
|
+
checks = run_checks(context)
|
|
22
|
+
table = Table("Check", "Result", "Detail")
|
|
23
|
+
for check in checks:
|
|
24
|
+
result = "[green]ok[/]" if check.ok else "[red]failed[/]"
|
|
25
|
+
table.add_row(check.name, result, check.detail)
|
|
26
|
+
invocation.console.print(table)
|
|
27
|
+
if failed := [check.name for check in checks if not check.ok]:
|
|
28
|
+
raise CliError(f"doctor found problems: {', '.join(failed)}.")
|
|
29
|
+
|
|
30
|
+
return Command(
|
|
31
|
+
name="doctor",
|
|
32
|
+
help="Check the tools this CLI needs and this root.",
|
|
33
|
+
annotations=RUN,
|
|
34
|
+
run=run,
|
|
35
|
+
)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""``extension``: scaffold a repository's extension in the standard shape, and check it.
|
|
2
|
+
|
|
3
|
+
Declarations and rendering only; ``workflows.extension`` does the work.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from cli_interview_kit import CliError, Command, Interview, Invocation, Question
|
|
9
|
+
|
|
10
|
+
from graftkit._core.agent import RUN
|
|
11
|
+
from graftkit._core.conformance import check_extension
|
|
12
|
+
from graftkit._core.context import Context
|
|
13
|
+
from graftkit._core.identity import CLI_NAME, CONFIG_FILE
|
|
14
|
+
from graftkit._core.workflows.extension import (
|
|
15
|
+
NAME,
|
|
16
|
+
PACKAGE,
|
|
17
|
+
default_name,
|
|
18
|
+
default_package,
|
|
19
|
+
scaffold,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def command(context: Context) -> Command:
|
|
24
|
+
"""Return the ``extension`` command group."""
|
|
25
|
+
return Command(
|
|
26
|
+
name="extension",
|
|
27
|
+
help="Scaffold this repository's extension in the standard shape, or check it.",
|
|
28
|
+
subcommands=(
|
|
29
|
+
Command(
|
|
30
|
+
name="new",
|
|
31
|
+
annotations=RUN,
|
|
32
|
+
help="Scaffold an extension with one example command and its tests.",
|
|
33
|
+
interview=Interview(
|
|
34
|
+
questions=(
|
|
35
|
+
Question(
|
|
36
|
+
key="name",
|
|
37
|
+
section="extension",
|
|
38
|
+
kind="text",
|
|
39
|
+
prompt="Extension name",
|
|
40
|
+
help="Lowercase words joined by hyphens, usually the repository's.",
|
|
41
|
+
default=default_name(context.root),
|
|
42
|
+
validator=_valid_name,
|
|
43
|
+
),
|
|
44
|
+
Question(
|
|
45
|
+
key="package",
|
|
46
|
+
section="extension",
|
|
47
|
+
kind="text",
|
|
48
|
+
prompt="Package",
|
|
49
|
+
help="The importable package the extension goes in.",
|
|
50
|
+
default=default_package(context.root),
|
|
51
|
+
validator=_valid_package,
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
),
|
|
55
|
+
run=lambda i: _new(context, i),
|
|
56
|
+
),
|
|
57
|
+
Command(
|
|
58
|
+
name="check",
|
|
59
|
+
annotations=RUN,
|
|
60
|
+
help="Check this root's extension against the command standard.",
|
|
61
|
+
run=lambda i: _check(context, i),
|
|
62
|
+
),
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _valid_name(value: str) -> str:
|
|
68
|
+
"""Validate an extension name."""
|
|
69
|
+
name = value.strip()
|
|
70
|
+
if not NAME.fullmatch(name):
|
|
71
|
+
raise ValueError("Use lowercase words joined by single hyphens.")
|
|
72
|
+
return name
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _valid_package(value: str) -> str:
|
|
76
|
+
"""Validate a dotted package name."""
|
|
77
|
+
package = value.strip()
|
|
78
|
+
if not PACKAGE.fullmatch(package):
|
|
79
|
+
raise ValueError("Use a dotted Python package name, e.g. `mypackage`.")
|
|
80
|
+
return package
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _new(context: Context, invocation: Invocation) -> None:
|
|
84
|
+
"""Scaffold an extension in the current root."""
|
|
85
|
+
if context.root is None:
|
|
86
|
+
raise CliError(f"Run this inside a repository with a {CONFIG_FILE}.")
|
|
87
|
+
written = scaffold(context.root, invocation.answers["name"], invocation.answers["package"])
|
|
88
|
+
console = invocation.console
|
|
89
|
+
for path in written:
|
|
90
|
+
console.info(f"created {path}")
|
|
91
|
+
console.info(
|
|
92
|
+
f"registered the entry point in pyproject.toml and set [cli] extension in {CONFIG_FILE}"
|
|
93
|
+
)
|
|
94
|
+
console.success(
|
|
95
|
+
f"Next: `uv sync`, then `{CLI_NAME} hello` and `uv run pytest tests/{CLI_NAME}`."
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _check(context: Context, invocation: Invocation) -> None:
|
|
100
|
+
"""Check the root's extension against the command standard."""
|
|
101
|
+
if context.repo is None or context.extension is None:
|
|
102
|
+
detail = " ".join(context.problems) or "this root names no [cli] extension."
|
|
103
|
+
raise CliError(f"No extension to check: {detail}")
|
|
104
|
+
problems = check_extension(context.extension, context.repo)
|
|
105
|
+
for problem in problems:
|
|
106
|
+
invocation.console.error(problem)
|
|
107
|
+
if problems:
|
|
108
|
+
raise CliError(f"{len(problems)} conformance problem(s).")
|
|
109
|
+
invocation.console.success(f"Extension `{context.extension.name}` follows the standard.")
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""``init``: onboard a repository.
|
|
2
|
+
|
|
3
|
+
Declarations and rendering only; ``workflows.init`` does the work.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import re
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from cli_interview_kit import CliError, Command, Interview, Invocation, Question
|
|
12
|
+
|
|
13
|
+
from graftkit._core.agent import RUN
|
|
14
|
+
from graftkit._core.context import Context
|
|
15
|
+
from graftkit._core.identity import CLI_NAME, CONFIG_FILE
|
|
16
|
+
from graftkit._core.patterns import REPOSITORY
|
|
17
|
+
from graftkit._core.skills.harness import HARNESSES
|
|
18
|
+
from graftkit._core.workflows.init import init
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def command(context: Context) -> Command:
|
|
22
|
+
"""Return the ``init`` command."""
|
|
23
|
+
settings = context.settings
|
|
24
|
+
return Command(
|
|
25
|
+
name="init",
|
|
26
|
+
annotations=RUN,
|
|
27
|
+
help=f"Make the current folder a root: {CONFIG_FILE}, settings and a CI check.",
|
|
28
|
+
interview=Interview(
|
|
29
|
+
questions=(
|
|
30
|
+
Question(
|
|
31
|
+
key="harnesses",
|
|
32
|
+
section="skills",
|
|
33
|
+
kind="multiselect",
|
|
34
|
+
prompt="Harnesses",
|
|
35
|
+
help="The coding-agent harnesses this repository's skills serve.",
|
|
36
|
+
choices=tuple(HARNESSES),
|
|
37
|
+
),
|
|
38
|
+
Question(
|
|
39
|
+
key="content_repository",
|
|
40
|
+
section="settings",
|
|
41
|
+
kind="text",
|
|
42
|
+
prompt="Content repository",
|
|
43
|
+
help="Shared skills, bundles and allow-list, `owner/name`; blank for none.",
|
|
44
|
+
default=settings.content_repository or "",
|
|
45
|
+
validator=_optional_repository,
|
|
46
|
+
),
|
|
47
|
+
Question(
|
|
48
|
+
key="workflow",
|
|
49
|
+
section="ci",
|
|
50
|
+
kind="confirm",
|
|
51
|
+
prompt="Add the CI check workflow?",
|
|
52
|
+
help="Write the CI check that runs `skills sync --check` on every change.",
|
|
53
|
+
default=True,
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
),
|
|
57
|
+
run=lambda i: _init(context, i),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _optional_repository(value: str) -> str:
|
|
62
|
+
"""Validate an ``owner/name`` repository, allowing blank for none."""
|
|
63
|
+
repository = value.strip()
|
|
64
|
+
if repository and not re.fullmatch(REPOSITORY, repository):
|
|
65
|
+
raise ValueError("Use `owner/name`.")
|
|
66
|
+
return repository
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _init(context: Context, invocation: Invocation) -> None:
|
|
70
|
+
"""Make the current folder a root."""
|
|
71
|
+
# One root per repository: nested roots are not supported.
|
|
72
|
+
if context.root is not None:
|
|
73
|
+
raise CliError(f"This folder is inside the root {context.root}; it cannot hold another.")
|
|
74
|
+
answers = invocation.answers
|
|
75
|
+
written = init(
|
|
76
|
+
Path.cwd(),
|
|
77
|
+
list(answers["harnesses"]),
|
|
78
|
+
answers["content_repository"] or None,
|
|
79
|
+
workflow=bool(answers["workflow"]),
|
|
80
|
+
)
|
|
81
|
+
console = invocation.console
|
|
82
|
+
for path in written:
|
|
83
|
+
console.info(f"created {path}")
|
|
84
|
+
console.success(f"Next: `{CLI_NAME} skills add …` or `{CLI_NAME} skills new`.")
|