Skip to content

Commit efc1b6e

Browse files
committed
feat: improve logging skill guidance and validation
Clarify task scope, preserve event contracts, and align logging examples. Update installation docs, add portable validation, CI checks, and behavioral eval scenarios.
1 parent 161c383 commit efc1b6e

23 files changed

Lines changed: 678 additions & 420 deletions

File tree

‎.github/pull_request_template.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Describe what this PR changes and why.
1616
- [ ] `examples/stdlib/`
1717
- [ ] plugin metadata
1818
- [ ] `README.md`
19-
- [ ] `_.github/`
19+
- [ ] `.github/`
2020

2121
## Behavior impact
2222
Explain any user-visible change in skill triggering, recommendations, examples, or installation flow.
@@ -37,7 +37,7 @@ Notes (include details if you could not run something):
3737
- [ ] Updated examples to match the guidance
3838

3939
## Checklist
40-
- [ ] I kept the repo aligned with a `structlog`-first but Python-wide logging stance
40+
- [ ] I kept the repo aligned with the existing logging stack and user-requested scope
4141
- [ ] I did not silently contradict the bundled reference guide
4242
- [ ] I preserved the split between `structlog` and stdlib examples where applicable
4343
- [ ] I kept installation and metadata paths consistent with the current repo layout

‎.github/workflows/quality.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Quality
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ['**']
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.12'
19+
cache: pip
20+
- run: python -m pip install -r requirements-dev.txt
21+
- run: python scripts/validate_repo.py
22+
- run: python -m unittest discover -s tests -v
23+
- run: python scripts/check_release_state.py

‎.github/workflows/release.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ jobs:
2323
with:
2424
python-version: '3.12'
2525

26+
- name: Install validation dependencies
27+
run: python -m pip install -r requirements-dev.txt
28+
29+
- name: Validate skill and examples
30+
run: |
31+
python scripts/validate_repo.py
32+
python -m unittest discover -s tests -v
33+
2634
- name: Validate release state
2735
run: |
2836
python3 scripts/check_release_state.py --expected-version "${GITHUB_REF_NAME}"

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
venv
55
.uv*
66
.DS_Store
7+
__pycache__/
8+
*.py[cod]

‎README.md‎

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,26 @@ npx skills add https://github.com/mrKazzila/python-structured-logging-skill
2929

3030
### Manual install
3131

32-
#### Claude Code
32+
Copy the inner `plugins/python-structured-logging/skills/python-structured-logging` directory, including its examples and references. Run these commands from the repository root; choose the location for your client.
3333

34-
Copy this repository into the target project's `/.claude` folder.
34+
| Client / scope | Destination |
35+
| --- | --- |
36+
| Claude Code / project | `<project>/.claude/skills/python-structured-logging` |
37+
| Codex / user | `~/.agents/skills/python-structured-logging` |
38+
| OpenCode / user | `~/.config/opencode/skills/python-structured-logging` |
3539

36-
See the [official Claude Skills documentation](https://platform.claude.com/docs/en/agents-and-tools/agent-skills/overview).
37-
38-
#### Codex CLI
39-
40-
Copy [`plugins/python-structured-logging/skills/python-structured-logging`](plugins/python-structured-logging/skills/python-structured-logging) into your Codex skills path, typically `~/.codex/skills/python-structured-logging`.
41-
42-
See the [Agent Skills specification](https://agentskills.io/specification) for the standard skill format.
43-
44-
#### OpenCode
45-
46-
Clone the entire repo into the OpenCode skills directory:
40+
For example, for Codex:
4741

4842
```sh
49-
git clone https://github.com/mrKazzila/python-structured-logging-skill.git ~/.opencode/skills/python-structured-logging-skill
43+
mkdir -p ~/.agents/skills
44+
cp -R plugins/python-structured-logging/skills/python-structured-logging ~/.agents/skills/
5045
```
5146

52-
Do not copy only the inner `skills/` folder. OpenCode auto-discovers `SKILL.md` files under `~/.opencode/skills/`.
47+
For an existing installation, update its contents rather than nesting another copy. Do not copy the entire repository into a skill directory.
48+
49+
Verify discovery in a fresh client session: use `/python-structured-logging` for a manually installed Claude Code skill, `/skills` or `$python-structured-logging` in Codex, or ask OpenCode to list available skills. For Claude plugin installation, the command is namespaced as `/python-structured-logging:python-structured-logging`.
50+
51+
See the official [Claude Code](https://code.claude.com/docs/en/skills), [Codex](https://learn.chatgpt.com/docs/build-skills), and [OpenCode](https://opencode.ai/docs/skills/) documentation. Paths were checked against documentation on 2026-09-18; discovery still needs a smoke test in your client version.
5352

5453
The skill inspects the logging stack already in use before changing anything. If the project already uses `structlog`, it leans into bound context and structured fields. If the project intentionally uses stdlib `logging`, it improves event names, `extra` payloads, and traceback handling without forcing a migration.
5554

@@ -71,24 +70,33 @@ The skill inspects the logging stack already in use before changing anything. If
7170

7271
## When Not to Use
7372

74-
- The user explicitly asked not to change logging behavior.
73+
- The task is unrelated to logging. Review-only requests are supported and must not change files.
7574
- The task is a one-off throwaway script where logging would add more noise than value.
7675
- The project has strict logging conventions and the current task is unrelated to logging or observability.
7776

7877
## Verify / Contribute
7978

80-
- Edit the skill or reference guide.
81-
- Update examples if the recommended behavior changes.
82-
- Run checks before finishing:
79+
Requires Python 3.12+ and either `uv` with `just`, or a Python virtual environment. No local Codex installation is needed.
8380

8481
```sh
85-
just validate
86-
python scripts/check_release_state.py
82+
just check
8783
```
8884

89-
- `just validate` uses `uv` plus `pyyaml`. If `pyyaml` is not already available, `uv` may need a writable cache and network access to fetch it.
90-
- `uv run python scripts/check_release_state.py` is an equivalent release-state check if you prefer to keep the command under `uv`.
91-
- Keep the skill concise, direct, and usable by agents during review and refactoring.
85+
Equivalent commands without `just` or `uv`:
86+
87+
```sh
88+
python3 -m venv .venv
89+
.venv/bin/python -m pip install -r requirements-dev.txt
90+
.venv/bin/python scripts/validate_repo.py
91+
.venv/bin/python -m unittest discover -s tests -v
92+
.venv/bin/python scripts/check_release_state.py
93+
```
94+
95+
Dependencies are pinned in `requirements-dev.txt`. The first installation requires access to a package index. `just validate` runs structural validation; `just test` runs executable example and validator regression checks. CI runs these checks on pull requests, branch pushes, and before a release.
96+
97+
Behavioral agent evaluation is separate: see [evals/README.md](evals/README.md) for fixtures, prompts, acceptance criteria, and skill/no-skill comparisons. Passing structural checks does not establish agent quality.
98+
99+
Keep changes scoped and update examples or eval cases when the recommended behavior changes.
92100

93101
## License
94102

‎evals/README.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Behavioral evaluations
2+
3+
These cases evaluate agent decisions separately from deterministic repository checks. They have not been benchmarked yet. `cases.json` contains prompts, input files, expected implicit activation, and outcome criteria. Keep cases and results outside the installed skill so the agent does not see the grading answers.
4+
5+
## Run a case
6+
7+
1. Create a fresh temporary project and copy only the listed fixtures into it, keeping their basenames. Install any fixture dependencies in an isolated environment. Record initial file checksums.
8+
2. Start a fresh agent session with no prior discussion of the expected solution. Use the exact prompt from the case. For activation tests, make the skill discoverable without naming it in the prompt. Inspect the trace to determine whether it was loaded.
9+
3. Allow local edits and tests only in the temporary project. These cases need no production services, real credentials, publishing, or network access beyond dependency setup.
10+
4. Save the trace, final response, diff, emitted logs, and test output. Score each criterion with evidence; do not grade exact wording or prescribed code structure. Use runtime checks for output and behavior, and human review for scope and diagnostic usefulness.
11+
5. Repeat in a separate clean context without the skill installed or available through another plugin. Do not force skill invocation in the baseline. Use the same model, runtime, prompt, dependencies, and permissions.
12+
13+
Run at least three trials per case and condition when making quality claims. Also compare the old and new skill revisions if evaluating an instruction change. Explicit invocation can be tested separately, but cannot establish implicit activation accuracy. Models may need different amounts of guidance; report results per model instead of pooling them.
14+
15+
## Record results
16+
17+
Use a JSONL row per trial with these fields:
18+
19+
```json
20+
{"case_id":"stdlib_refactor","condition":"with_skill","skill_commit":"<sha>","model":"<exact-model>","runtime":"<client-version>","trial":1,"skill_loaded":true,"criteria":[{"index":0,"passed":true,"evidence":"<artifact-path-and-observation>"}],"elapsed_seconds":0,"input_tokens":null,"output_tokens":null,"artifacts":"<temporary-run-directory>"}
21+
```
22+
23+
Use null for unavailable metrics; do not infer them. Mark unresolved criteria as null with an explanation, rather than passing them. Summarize per-case pass rates, activation misses/false positives, latency, and token usage where available. Compare paired outcomes with and without the skill. Store results outside the skill package; no generated results are committed by the deterministic checks.
24+
25+
The unit tests in `tests/` verify the bundled examples and repository validator. They do not execute an agent or prove that it passes these scenarios.

‎evals/cases.json‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"cases": [
3+
{
4+
"id": "stdlib_refactor",
5+
"should_trigger": true,
6+
"fixtures": [
7+
"plugins/python-structured-logging/skills/python-structured-logging/examples/stdlib/bad.py"
8+
],
9+
"prompt": "Improve logging in bad.py using the existing stdlib stack. Preserve its signature and business behavior. Demonstrate fields in rendered output with a test formatter.",
10+
"criteria": [
11+
"No structlog dependency or arbitrary keyword fields are introduced.",
12+
"Success returns None; negative amount raises PaymentGatewayError with the original message.",
13+
"Rendered output contains invoice and request IDs; the failure has one traceback record.",
14+
"No module-level handler installation or global logging reconfiguration is introduced."
15+
]
16+
},
17+
{
18+
"id": "structlog_refactor",
19+
"should_trigger": true,
20+
"fixtures": [
21+
"plugins/python-structured-logging/skills/python-structured-logging/examples/structlog/bad.py"
22+
],
23+
"prompt": "Improve logging in bad.py while preserving the current stack, function signature, and exception behavior.",
24+
"criteria": [
25+
"A stable event and structured fields replace interpolated variable event names.",
26+
"Successful input returns None and negative input still raises PaymentGatewayError.",
27+
"A failure produces one record with traceback; negative input is not marked retryable."
28+
]
29+
},
30+
{
31+
"id": "review_only",
32+
"should_trigger": true,
33+
"fixtures": [
34+
"plugins/python-structured-logging/skills/python-structured-logging/examples/stdlib/bad.py"
35+
],
36+
"prompt": "Review the logging in bad.py. Report issues and concrete effects. Do not modify files.",
37+
"criteria": [
38+
"Fixture checksums are unchanged and no new project files appear.",
39+
"Findings identify dynamic events and missing traceback with file locations.",
40+
"No migration or code edit is performed."
41+
]
42+
},
43+
{
44+
"id": "event_contract",
45+
"should_trigger": true,
46+
"fixtures": [
47+
"evals/fixtures/service.py"
48+
],
49+
"prompt": "Add amount_cents to the success log in service.py. Existing dotted event names are consumed by production alerts and must remain unchanged.",
50+
"criteria": [
51+
"Both dotted event names remain unchanged.",
52+
"The success LogRecord contains amount_cents.",
53+
"Function signatures, return values and exception behavior remain unchanged."
54+
]
55+
},
56+
{
57+
"id": "exception_owner",
58+
"should_trigger": true,
59+
"fixtures": [
60+
"evals/fixtures/service.py"
61+
],
62+
"prompt": "Review exception logging across charge and handle_invoice. Change it only if necessary to prevent duplicate failure records.",
63+
"criteria": [
64+
"One call with negative input produces exactly one failure record with traceback.",
65+
"The ValueError still propagates.",
66+
"No failure log is added to charge; leaving correct logging unchanged is acceptable."
67+
]
68+
},
69+
{
70+
"id": "context_lifecycle",
71+
"should_trigger": true,
72+
"fixtures": [
73+
"evals/fixtures/async_jobs.py"
74+
],
75+
"prompt": "Fix job context leaking into worker_idle in async_jobs.py. Preserve event names and ensure overlapping jobs retain their own IDs.",
76+
"criteria": [
77+
"Run the program and decode every JSON line.",
78+
"Each job_processed event has its own job_id: one, two, three.",
79+
"worker_idle has no job_id.",
80+
"Cleanup also executes if processing raises; demonstrate that path with a focused test."
81+
]
82+
},
83+
{
84+
"id": "unrelated_cli",
85+
"should_trigger": false,
86+
"fixtures": [
87+
"evals/fixtures/cli.py"
88+
],
89+
"prompt": "Change render_total to include currency USD in its JSON output. Preserve stdout as the result stream.",
90+
"criteria": [
91+
"The logging skill is not implicitly selected.",
92+
"JSON on stdout contains amount_cents and currency USD.",
93+
"No logging dependency, configuration, or conversion of print to logging is introduced."
94+
]
95+
},
96+
{
97+
"id": "sensitive_output",
98+
"should_trigger": true,
99+
"fixtures": [
100+
"evals/fixtures/sensitive.py"
101+
],
102+
"prompt": "Make logging in sensitive.py safe for payloads containing synthetic credentials. Preserve exception propagation. Verify the rendered failure output.",
103+
"criteria": [
104+
"Neither the synthetic marker nor payload credentials occur anywhere in rendered logs.",
105+
"The original ValueError still propagates with its original message.",
106+
"The solution checks exception text as well as structured fields.",
107+
"The record retains enough operation and error-type information to diagnose the failure."
108+
]
109+
}
110+
]
111+
}

‎evals/fixtures/async_jobs.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import asyncio
2+
3+
import structlog
4+
5+
structlog.configure(processors=[
6+
structlog.contextvars.merge_contextvars,
7+
structlog.processors.JSONRenderer(),
8+
])
9+
logger = structlog.get_logger()
10+
11+
12+
async def run_job(job_id):
13+
structlog.contextvars.bind_contextvars(job_id=job_id)
14+
await asyncio.sleep(0)
15+
logger.info('job_processed')
16+
17+
18+
async def main():
19+
await asyncio.gather(run_job('one'), run_job('two'))
20+
await run_job('three')
21+
logger.info('worker_idle')
22+
23+
24+
if __name__ == '__main__':
25+
asyncio.run(main())

‎evals/fixtures/cli.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import json
2+
3+
4+
def render_total(amount_cents):
5+
print(json.dumps({'amount_cents': amount_cents}))

‎evals/fixtures/sensitive.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import logging
2+
3+
logger = logging.getLogger(__name__)
4+
5+
6+
def process_request(payload):
7+
try:
8+
raise ValueError('upstream rejected token=TEST_SECRET_DO_NOT_USE')
9+
except ValueError:
10+
logger.exception('request_failed', extra={'payload': payload})
11+
raise

0 commit comments

Comments
 (0)