repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

feat(skills): add checkhealth

a75fa7145c479cf3684e6a92b709d3f511dbaea3

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (4)

+343 / −0 text lines

Diff layout

mise.toml

Modified

+1 / −0 text lines

3434 "ruff check .",
3535 "dprint check",
3636 "python3 scripts/mdslw.py --mode check",
37 "python3 scripts/check_skills.py",
3738 "markdownlint-cli2",
3839 "yamlfmt -lint .",

scripts/check_skills.py

Added
new file mode 100644

+135 / −0 text lines

1#!/usr/bin/env python3
2"""Validate Agent Skill frontmatter."""
3
4from __future__ import annotations
5
6import re
7import shutil
8import subprocess
9import tempfile
10from pathlib import Path
11from typing import Any
13ROOT = Path(__file__).resolve().parents[1]
14SKILLS = ROOT / "skills"
15NAME_RE = re.compile(r"^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$")
18def skill_files() -> list[Path]:
19 return sorted(SKILLS.glob("*/SKILL.md"))
22def frontmatter(path: Path) -> str:
23 lines = path.read_text(encoding="utf-8").splitlines()
24 if not lines or lines[0] != "---":
25 raise ValueError("missing opening frontmatter fence")
26 for index, line in enumerate(lines[1:], start=2):
27 if line == "---":
28 return "\n".join(lines[1 : index - 1]) + "\n"
29 raise ValueError("missing closing frontmatter fence")
32def parse_yaml_with_pyyaml(text: str) -> dict[str, Any] | None:
33 try:
34 import yaml # type: ignore[import-untyped]
35 except ModuleNotFoundError:
36 return None
37 data = yaml.safe_load(text)
38 if not isinstance(data, dict):
39 raise ValueError("frontmatter is not a mapping")
40 return data
43def lint_yaml_with_yamlfmt(text: str) -> None:
44 yamlfmt = shutil.which("yamlfmt")
45 if not yamlfmt:
46 raise ValueError("install PyYAML or run under mise so yamlfmt is available")
47 with tempfile.TemporaryDirectory() as tmp:
48 path = Path(tmp) / "frontmatter.yaml"
49 path.write_text(text, encoding="utf-8")
50 result = subprocess.run(
51 [yamlfmt, "-lint", str(path)],
52 capture_output=True,
53 check=False,
54 text=True,
55 )
56 if result.returncode:
57 raise ValueError((result.stderr or result.stdout).strip())
60def parse_shallow_yaml(text: str) -> dict[str, str]:
61 data: dict[str, str] = {}
62 lines = text.splitlines()
63 index = 0
64 while index < len(lines):
65 line = lines[index]
66 index += 1
67 if not line or line.startswith(" "):
68 continue
69 match = re.match(r"^([A-Za-z0-9_-]+):(?:\s*(.*))?$", line)
70 if not match:
71 continue
72 key, value = match.groups()
73 value = value or ""
74 if value in {">", "|-", "|"}:
75 block: list[str] = []
76 while index < len(lines) and (not lines[index] or lines[index].startswith(" ")):
77 block.append(lines[index].strip())
78 index += 1
79 value = "\n".join(block).strip()
80 if (value.startswith('"') and value.endswith('"')) or (
81 value.startswith("'") and value.endswith("'")
82 ):
83 value = value[1:-1]
84 data[key] = value
85 return data
88def parse_frontmatter(text: str) -> dict[str, Any]:
89 data = parse_yaml_with_pyyaml(text)
90 if data is not None:
91 return data
92 lint_yaml_with_yamlfmt(text)
93 return parse_shallow_yaml(text)
96def validate(path: Path) -> list[str]:
97 errors: list[str] = []
98 try:
99 data = parse_frontmatter(frontmatter(path))
100 except Exception as error: # noqa: BLE001
101 return [str(error)]
103 name = data.get("name")
104 description = data.get("description")
106 if not isinstance(name, str) or not name:
107 errors.append("missing string field: name")
108 elif not NAME_RE.fullmatch(name):
109 errors.append(f"invalid skill name: {name!r}")
110 elif path.parent.name != name:
111 errors.append(f"directory/name mismatch: {path.parent.name!r} != {name!r}")
113 if not isinstance(description, str) or not description.strip():
114 errors.append("missing string field: description")
115 elif len(description) > 1024:
116 errors.append(f"description too long: {len(description)} > 1024")
118 return errors
121def main() -> int:
122 failed = False
123 for path in skill_files():
124 errors = validate(path)
125 if not errors:
126 continue
127 failed = True
128 rel = path.relative_to(ROOT)
129 for error in errors:
130 print(f"{rel}: {error}")
131 return int(failed)
134if __name__ == "__main__":
135 raise SystemExit(main())

skills/checkhealth/SKILL.md

Added
new file mode 100644

+88 / −0 text lines

1---
2name: checkhealth
3description: "Analyze current software project state: lifecycle stage, completion vs TODO, language/runtime versions, code style, deps, tooling, tests, build health, and what is going on in a repo/directory. Use when asked for project health, status, orientation, audit, inventory, roadmap, or 'what the hell is going on'."
4---
5
6# Checkhealth
7
8Analyze project state.
9Report facts first.
10No fixes unless asked.
12For command recipes, read `references/toolbox.md`.
14## Workflow
161. Map repo shape
17 - `ls`, `find` top-level files/dirs.
18 - Detect app/library/CLI/docs/config/monorepo.
19 - Note entrypoints, package/workspace files, lockfiles.
212. Identify stack
22 - Languages + versions from manifests, tool files, lockfiles, CI.
23 - Main deps/frameworks, build/test/lint tools.
24 - Style conventions from config + actual files.
263. Measure lifecycle
27 - README claims vs implementation.
28 - Tests present/runnable?
29 CI present?
30 release/build artifacts?
31 - Git state if available:
32 branch, dirty files, recent commits/tags.
33 - TODO/FIXME/HACK/XXX and issue-like docs.
354. Check health cheaply
36 - Prefer static inspection first.
37 - Run lightweight commands only when safe/obvious:
38 `git status`, manifest scripts, version commands, `test`/`lint` dry
39 equivalents.
40 - Do not install deps, migrate DBs, start servers, mutate files, or run
41 destructive commands.
435. Summarize
44 - Lifecycle:
45 idea/prototype/MVP/active-dev/maintenance/production/abandoned.
46 - Done vs TODO:
47 coarse percentage + evidence.
48 - Risks/blockers.
49 - Next 3-7 concrete actions.
51## Output
53Use this shape:
55```text
56## Checkhealth
58State: <one line>
59Lifecycle: <stage> (<confidence>)
60Done: <rough %>
61TODO: <rough %>
63Stack
64• Language/runtime: ...
65• Frameworks/deps: ...
66• Tooling: ...
67• Style: ...
69Repo map
70• ...
72Evidence
73• ...
75Health
76• Build/test/lint: ...
77• Git: ...
78• Docs: ...
79• Risks: ...
81Next
821. ...
832. ...
843. ...
85```
87Keep it blunt.
88Distinguish observed fact from inference.

skills/checkhealth/references/toolbox.md

Added
new file mode 100644

+119 / −0 text lines

1# Checkhealth Toolbox
2
3Use cheap, read-mostly commands.
4Respect repo ignores.
5No installs.
6No servers.
7
8## System snapshot
9
10```bash
11macchina --show host,kernel,distribution,shell,terminal,processor,memory,disk-space \
12 --long-kernel --memory-percentage --disk-space-percentage --disks /
13```
15Use only when host/runtime context matters.
16`macchina --show` values are lowercase.
17`macchina --doctor` diagnoses machine readouts, not project health.
19## File map
21```bash
22fd -d 3 -t f '^(package.json|mise.toml|pyproject.toml|README.md|SKILL.md)$' .
23fd -t f -e json -e toml -e yaml -e yml -e lock -e ts -e py .
24rg --files -g '!*.lock' -g '!node_modules/**'
25```
27`fd` and `rg` respect ignore files by default.
28Add `--hidden` deliberately.
29Avoid `--no-ignore` unless looking for generated/ignored project state.
31## Content search
33```bash
34rg -n 'TODO|FIXME|HACK|XXX|DEPRECATED|legacy|compat' .
35rg -n 'scripts|dependencies|devDependencies|engines' package.json extensions/*/package.json
36rg -n 'test|lint|build|fmt|format|ci' mise.toml package.json pyproject.toml .github
37```
39Use `rg -S` for smart case.
40Use globs to exclude noise:
42```bash
43rg -n --hidden --glob '!.git/**' --glob '!.jj/**' --glob '!node_modules/**' PATTERN .
44```
46## File preview
48```bash
49bat --style=plain --color=never --paging=never --line-range 1:80 README.md
50bat --style=plain --color=never --paging=never --diff
51```
53Use `bat` for human previews.
54Use `read` for exact agent file inspection.
56## Language / size profile
58```bash
59tokei . --exclude .git --exclude .jj --exclude node_modules
61tokei . --exclude .git --exclude .jj --exclude node_modules --output json > /tmp/tokei.json
62nu -c 'open /tmp/tokei.json | transpose lang data | where lang != Total | insert code {|r| $r.data.code } | insert files {|r| $r.data.reports | length } | sort-by code --reverse | first 12 | select lang files code'
63```
65`tokei` is good for stack/scale, not completion %.
66Markdown code counts may be unhelpful; inspect docs separately.
68## Nushell structured probes
70Learn local syntax first:
72```bash
73nu -c 'help commands | where name in [ls where open from sort-by transpose insert first select]'
74nu -c 'help from json'
75nu -c 'help sort-by'
76```
78Useful probes:
80```bash
81nu -c '^git ls-files | lines | each {|p| $p | path parse | get extension } | where $it != "" | reduce -f {} {|ext acc| $acc | upsert $ext (($acc | get --optional $ext | default 0) + 1)} | transpose ext files | sort-by files --reverse | first 15'
83nu -c '^git ls-files | lines | each {|p| $p | path split | first } | where $it != "" | reduce -f {} {|dir acc| $acc | upsert $dir (($acc | get --optional $dir | default 0) + 1)} | transpose dir files | sort-by files --reverse'
84```
86Put external producers inside `nu -c` (`^git ls-files`).
87Do not rely on piping Bash stdin into `nu -c`; `$in` may be `nothing`.
89## Git / Jujutsu
91```bash
92git status --short --branch
93git status --porcelain=v1 -b
94git log --oneline --decorate -5
95git tag --sort=-creatordate | head
96```
98For jj repos:
100```bash
101jj status --ignore-working-copy
102jj log -n 5 --no-graph --template 'change_id.short() ++ " " ++ commit_id.short() ++ " " ++ description.first_line() ++ "\n"'
103jj diff --summary
104```
106Edge case:
107`jj status` snapshots the working copy by default.
108Use `--ignore-working-copy` for non-mutating checks, but call out that it can be
109stale.
111## Man pages
113```bash
114MANWIDTH=100 MANPAGER=cat man rg | col -b | rg -n 'gitignore|--files|--glob'
115MANWIDTH=100 MANPAGER=cat man git-status | col -b | head -80
116```
118Use `man` for installed version truth.
119Some tools ship no man page (`tokei` here).