kanso-runner 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.
File without changes
kanso_runner/cli.py ADDED
@@ -0,0 +1,35 @@
1
+ import argparse
2
+ import json
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ from kanso_runner.plans import PLAN_PATH, Progress, chosen, read_plans, request
7
+
8
+ NOTHING_OPEN = 3
9
+
10
+
11
+ def parser() -> argparse.ArgumentParser:
12
+ found = argparse.ArgumentParser(prog="kanso-runner", description="Work Kanso implementation plans step by step.")
13
+ commands = found.add_subparsers(dest="command", required=True)
14
+ step = commands.add_parser("next", help="print the next open step and its session prompt as JSON")
15
+ step.add_argument("--repository", type=Path, required=True, help="a git repository or bare mirror")
16
+ step.add_argument("--ref", required=True, help="the branch the plans are read from, such as main")
17
+ step.add_argument("--first", help="a plan the owner asked to go first")
18
+ step.add_argument("--current", help="the plan in work, which goes on before older ones")
19
+ step.add_argument("--stopped", nargs="*", default=[], help="plans paused after failing steps")
20
+ return found
21
+
22
+
23
+ def main() -> int:
24
+ arguments = parser().parse_args()
25
+ progress = Progress(arguments.first, arguments.current, arguments.stopped)
26
+ found = chosen(read_plans(arguments.repository, arguments.ref), progress)
27
+ if found is None:
28
+ return NOTHING_OPEN
29
+ name, step = found
30
+ print(json.dumps({"plan": name, "path": PLAN_PATH.format(name=name), "step": step, "prompt": request(name, step)}))
31
+ return 0
32
+
33
+
34
+ if __name__ == "__main__":
35
+ sys.exit(main())
kanso_runner/plans.py ADDED
@@ -0,0 +1,83 @@
1
+ import re
2
+ import subprocess
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+
6
+ PLAN_PATH = "docs/{name}-implementation-plan.md"
7
+ PLAN_FILE = re.compile(r"docs/(?P<name>[\w-]+)-implementation-plan\.md")
8
+ HEADING = re.compile(r"^#{1,2} ")
9
+ STEPS = re.compile(r"^## (?:Steps|Open work)\b")
10
+ DESIGN = "## Design"
11
+ ITEM = re.compile(r"^(?:\d+\.|-) ")
12
+ OWNER_ITEM = re.compile(r"^(?:\d+\.|-) \(owner\)")
13
+ SPLIT = (
14
+ "Split the plan's Design into a `## Steps` list of numbered items, each small enough for one session and with "
15
+ "its next action, then implement the first of them."
16
+ )
17
+ REQUEST = """Work on the implementation plan {path} with the Kanso skill, one step per session. Implement exactly
18
+ this step of it and nothing else:
19
+
20
+ {step}
21
+
22
+ Keep every check green. In the same commit, remove the step from the plan, or narrow it to what is left with a new
23
+ next action. When the step is too big for one session, split it in the plan into smaller steps and implement the
24
+ first. When no open item is left, delete the plan and move the decisions that still matter into the project docs.
25
+ Never work on an item tagged (owner): it is the owner's."""
26
+
27
+
28
+ @dataclass(slots=True)
29
+ class Progress:
30
+ first: str | None
31
+ current: str | None
32
+ stopped: list[str]
33
+
34
+
35
+ def listed(lines: list[str]) -> list[str]:
36
+ found: list[str] = []
37
+ inside = False
38
+ for line in lines:
39
+ if HEADING.match(line):
40
+ inside = bool(STEPS.match(line))
41
+ elif inside and ITEM.match(line):
42
+ found.append(line)
43
+ elif inside and found and line.startswith(" "):
44
+ found[-1] += f"\n{line}"
45
+ return found
46
+
47
+
48
+ def open_steps(text: str) -> list[str]:
49
+ lines = text.splitlines()
50
+ if not any(STEPS.match(line) for line in lines):
51
+ return [SPLIT] if DESIGN in lines else []
52
+ return [step for step in listed(lines) if not OWNER_ITEM.match(step)]
53
+
54
+
55
+ def chosen(texts: dict[str, str], progress: Progress) -> tuple[str, str] | None:
56
+ ready = {
57
+ name: steps[0] for name, text in texts.items() if name not in progress.stopped and (steps := open_steps(text))
58
+ }
59
+ for name in (progress.first, progress.current, *ready):
60
+ if name is not None and name in ready:
61
+ return name, ready[name]
62
+ return None
63
+
64
+
65
+ def request(name: str, step: str) -> str:
66
+ return REQUEST.format(path=PLAN_PATH.format(name=name), step=step)
67
+
68
+
69
+ def git(repository: Path, *arguments: str) -> str:
70
+ return subprocess.run(["git", "-C", str(repository), *arguments], check=True, capture_output=True, text=True).stdout
71
+
72
+
73
+ def read_plans(repository: Path, ref: str) -> dict[str, str]:
74
+ entries = git(repository, "ls-tree", "--name-only", ref, "docs/").split()
75
+ names = {path: found["name"] for path in entries if (found := PLAN_FILE.fullmatch(path)) is not None}
76
+ born = {
77
+ path: int(git(repository, "log", "--diff-filter=A", "--format=%ct", ref, "--", path).split()[-1])
78
+ for path in names
79
+ }
80
+ return {
81
+ names[path]: git(repository, "show", f"{ref}:{path}")
82
+ for path in sorted(names, key=lambda path: (born[path], path))
83
+ }
kanso_runner/py.typed ADDED
File without changes
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: kanso-runner
3
+ Version: 0.1.0
4
+ Summary: Let a coding agent work your Kanso implementation plans step by step, one pull request per step
5
+ Keywords: ai-agents,claude-code,codex,planning,kanso,automation
6
+ Author: datenwissenschaften
7
+ Author-email: datenwissenschaften <martin.franke@datenwissenschaften.com>
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Software Development
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.12, <4.0
16
+ Project-URL: Repository, https://github.com/datenwissenschaften/kanso
17
+ Project-URL: Used by, https://github.com/datenwissenschaften/retro-speedlab-suite
18
+ Description-Content-Type: text/markdown
19
+
20
+ # kanso-runner
21
+
22
+ **Let a coding agent work through your plan, one reviewed pull request per step.**
23
+
24
+ Kanso asks agents to write a plan before risky work: `docs/<task>-implementation-plan.md`, with numbered steps that each name their next action. `kanso-runner` turns that plan into a queue. It reads the plans on your main branch, picks the next open step, and gives your agent the exact prompt for that one step. The agent implements it, removes it from the plan in the same commit, and opens a pull request. Once CI is green, the next step follows.
25
+
26
+ - **One step, one pull request.** Every change stays small enough to review and to revert.
27
+ - **The plan is the state.** Finished steps leave the plan in the same commit, so no step is worked twice.
28
+ - **You stay in charge.** Steps tagged `(owner)` are never picked. You can name a plan to go first, and a plan whose step failed waits until you restart it.
29
+
30
+ ## Used in production by RetroSpeedLab
31
+
32
+ [RetroSpeedLab](https://www.retrospeedlab.com) is a game studio run by AI agents ([suite](https://github.com/datenwissenschaften/retro-speedlab-suite)). Its maintainer agent works the suite's [implementation plans](https://github.com/datenwissenschaften/retro-speedlab-suite/tree/main/docs) with `kanso-runner`, one step per session, and the owner steers it from Discord with `work on suite`, `pause plans` and `resume plans`.
33
+
34
+ ```markdown
35
+ ## Open work, in order
36
+
37
+ 1. **Typed backend:** pyright excludes the backend. Next action: TypedDicts for the Twitch payloads.
38
+ 2. (owner) **Old repos:** delete the archived repos after 7 days.
39
+ ```
40
+
41
+ ```console
42
+ $ kanso-runner next --repository . --ref main
43
+ {"plan": "suite", "path": "docs/suite-implementation-plan.md", "step": "1. **Typed backend:** …", "prompt": "Work on the implementation plan …"}
44
+ ```
45
+
46
+ ## How it picks
47
+
48
+ 1. Only `## Steps` and `## Open work` hold work; notes under `## Open` are never picked.
49
+ 2. A plan with a `## Design` but no steps is first split into steps.
50
+ 3. The plan you named goes first, then the plan in work, then the oldest plan by the commit that added it.
51
+ 4. `kanso-runner next` exits with code 3 when nothing is open.
52
+
53
+ ## Use it
54
+
55
+ ```bash
56
+ uvx kanso-runner next --repository . --ref main --current suite --stopped music-ab
57
+ ```
58
+
59
+ From Python, as RetroSpeedLab's maintainer does:
60
+
61
+ ```python
62
+ from kanso_runner.plans import Progress, chosen, read_plans, request
63
+
64
+ found = chosen(read_plans(mirror, "main"), Progress(first=None, current="suite", stopped=[]))
65
+ if found is not None:
66
+ run_agent_session(request(*found))
67
+ ```
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ cd runner && uv sync && uv run ruff check && uv run mypy && uv run pytest
73
+ ```
74
+
75
+ MIT © datenwissenschaften. Part of [Kanso](https://github.com/datenwissenschaften/kanso).
@@ -0,0 +1,8 @@
1
+ kanso_runner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ kanso_runner/cli.py,sha256=lsjiZMBUlbhFdDqEA7sCja9XBDdCN-UDRVhjpgvnb_A,1458
3
+ kanso_runner/plans.py,sha256=D-57FhwsyA0xCDsbxfVaaXcn-BmXqcWHIVe0byo5_h0,3099
4
+ kanso_runner/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ kanso_runner-0.1.0.dist-info/WHEEL,sha256=xTCBFIZIIyRSxyowOv5Wqg_jFU6KsdIffuulBB09Ph8,80
6
+ kanso_runner-0.1.0.dist-info/entry_points.txt,sha256=4djpo3KBAIebrQ-mfUOu-B4eIjv7J-1L3RcgNJi0yHU,56
7
+ kanso_runner-0.1.0.dist-info/METADATA,sha256=8hXcGitEpOV1XZ4WDlQrQJFMhj4WVnQRxX5lCNqms74,3548
8
+ kanso_runner-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ kanso-runner = kanso_runner.cli:main
3
+