coro-asr 1.0.3__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.
- coro_asr-1.0.3/.agents/skills/diagnose/SKILL.md +117 -0
- coro_asr-1.0.3/.agents/skills/diagnose/scripts/hitl-loop.template.sh +41 -0
- coro_asr-1.0.3/.agents/skills/grill-me/SKILL.md +7 -0
- coro_asr-1.0.3/.agents/skills/grill-with-docs/SKILL.md +7 -0
- coro_asr-1.0.3/.agents/skills/handoff/SKILL.md +19 -0
- coro_asr-1.0.3/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- coro_asr-1.0.3/.agents/skills/improve-codebase-architecture/SKILL.md +66 -0
- coro_asr-1.0.3/.agents/skills/journalist/SKILL.md +92 -0
- coro_asr-1.0.3/.agents/skills/journalist/scripts/query_journals.py +111 -0
- coro_asr-1.0.3/.agents/skills/journalist/scripts/update_journal_index.py +116 -0
- coro_asr-1.0.3/.agents/skills/prototype/LOGIC.md +79 -0
- coro_asr-1.0.3/.agents/skills/prototype/SKILL.md +31 -0
- coro_asr-1.0.3/.agents/skills/prototype/UI.md +112 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/SKILL.md +127 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +34 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +35 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +19 -0
- coro_asr-1.0.3/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
- coro_asr-1.0.3/.agents/skills/tdd/SKILL.md +108 -0
- coro_asr-1.0.3/.agents/skills/tdd/mocking.md +59 -0
- coro_asr-1.0.3/.agents/skills/tdd/refactoring.md +10 -0
- coro_asr-1.0.3/.agents/skills/tdd/tests.md +61 -0
- coro_asr-1.0.3/.agents/skills/to-issues/SKILL.md +84 -0
- coro_asr-1.0.3/.agents/skills/to-prd/SKILL.md +75 -0
- coro_asr-1.0.3/.agents/skills/triage/AGENT-BRIEF.md +207 -0
- coro_asr-1.0.3/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
- coro_asr-1.0.3/.agents/skills/triage/SKILL.md +112 -0
- coro_asr-1.0.3/.agents/skills/varlock/SKILL.md +361 -0
- coro_asr-1.0.3/.agents/skills/write-a-skill/SKILL.md +117 -0
- coro_asr-1.0.3/.agents/skills/zoom-out/SKILL.md +7 -0
- coro_asr-1.0.3/.devcontainer/Dockerfile +120 -0
- coro_asr-1.0.3/.devcontainer/devcontainer.json +53 -0
- coro_asr-1.0.3/.devcontainer/docker-compose.yml +46 -0
- coro_asr-1.0.3/.devcontainer/entrypoint.sh +14 -0
- coro_asr-1.0.3/.env.schema +23 -0
- coro_asr-1.0.3/.github/dependabot.yml +15 -0
- coro_asr-1.0.3/.github/workflows/ci.yml +44 -0
- coro_asr-1.0.3/.github/workflows/docker.yml +110 -0
- coro_asr-1.0.3/.github/workflows/pypi.yml +54 -0
- coro_asr-1.0.3/.github/workflows/release.yml +97 -0
- coro_asr-1.0.3/.gitignore +31 -0
- coro_asr-1.0.3/.python_version +1 -0
- coro_asr-1.0.3/.vscode/launch.json +24 -0
- coro_asr-1.0.3/AGENTS.md +126 -0
- coro_asr-1.0.3/CONTEXT.md +613 -0
- coro_asr-1.0.3/Dockerfile +138 -0
- coro_asr-1.0.3/LICENSE +21 -0
- coro_asr-1.0.3/PKG-INFO +32 -0
- coro_asr-1.0.3/README.md +709 -0
- coro_asr-1.0.3/assets/coro-logo.png +0 -0
- coro_asr-1.0.3/ast-grep/rules/no-dict-alias.yml +15 -0
- coro_asr-1.0.3/ast-grep/rules/no-dict-call-return.yml +7 -0
- coro_asr-1.0.3/ast-grep/rules/no-dict-literal-return.yml +9 -0
- coro_asr-1.0.3/ast-grep/rules/no-dict-return-annotation.yml +18 -0
- coro_asr-1.0.3/coro/__init__.py +1 -0
- coro_asr-1.0.3/coro/_version.py +24 -0
- coro_asr-1.0.3/coro/api/__init__.py +1 -0
- coro_asr-1.0.3/coro/api/dependencies.py +22 -0
- coro_asr-1.0.3/coro/api/errors.py +58 -0
- coro_asr-1.0.3/coro/api/exceptions.py +55 -0
- coro_asr-1.0.3/coro/api/health.py +45 -0
- coro_asr-1.0.3/coro/api/schemas.py +196 -0
- coro_asr-1.0.3/coro/api/sse.py +81 -0
- coro_asr-1.0.3/coro/api/v1/__init__.py +1 -0
- coro_asr-1.0.3/coro/api/v1/transcriptions.py +366 -0
- coro_asr-1.0.3/coro/app.py +149 -0
- coro_asr-1.0.3/coro/audio.py +292 -0
- coro_asr-1.0.3/coro/backends/__init__.py +8 -0
- coro_asr-1.0.3/coro/backends/asr/__init__.py +6 -0
- coro_asr-1.0.3/coro/backends/asr/factory.py +63 -0
- coro_asr-1.0.3/coro/backends/asr/faster_whisper.py +119 -0
- coro_asr-1.0.3/coro/backends/asr/onnx_asr.py +288 -0
- coro_asr-1.0.3/coro/backends/asr/onnx_genai.py +208 -0
- coro_asr-1.0.3/coro/backends/diarization/__init__.py +8 -0
- coro_asr-1.0.3/coro/backends/diarization/factory.py +98 -0
- coro_asr-1.0.3/coro/backends/diarization/nemo/__init__.py +7 -0
- coro_asr-1.0.3/coro/backends/diarization/nemo/diarization.py +83 -0
- coro_asr-1.0.3/coro/backends/diarization/nemo/streaming.py +327 -0
- coro_asr-1.0.3/coro/backends/diarization/pyannote.py +112 -0
- coro_asr-1.0.3/coro/backends/diarization/segments.py +78 -0
- coro_asr-1.0.3/coro/bench/__init__.py +9 -0
- coro_asr-1.0.3/coro/bench/ami.py +273 -0
- coro_asr-1.0.3/coro/bench/cli.py +366 -0
- coro_asr-1.0.3/coro/bench/clips.py +36 -0
- coro_asr-1.0.3/coro/bench/data/__init__.py +10 -0
- coro_asr-1.0.3/coro/bench/data/jfk.wav +0 -0
- coro_asr-1.0.3/coro/bench/errors.py +31 -0
- coro_asr-1.0.3/coro/bench/eval_diarization_quality.py +243 -0
- coro_asr-1.0.3/coro/bench/gpu.py +141 -0
- coro_asr-1.0.3/coro/bench/models/__init__.py +8 -0
- coro_asr-1.0.3/coro/bench/models/gpu.py +24 -0
- coro_asr-1.0.3/coro/bench/models/performance.py +81 -0
- coro_asr-1.0.3/coro/bench/models/quality.py +127 -0
- coro_asr-1.0.3/coro/bench/models/report.py +63 -0
- coro_asr-1.0.3/coro/bench/models/resource.py +37 -0
- coro_asr-1.0.3/coro/bench/orchestrate.py +580 -0
- coro_asr-1.0.3/coro/bench/performance.py +195 -0
- coro_asr-1.0.3/coro/bench/quality.py +316 -0
- coro_asr-1.0.3/coro/bench/report.py +602 -0
- coro_asr-1.0.3/coro/bench/run.py +184 -0
- coro_asr-1.0.3/coro/bench/sampling.py +176 -0
- coro_asr-1.0.3/coro/bench/schema.py +49 -0
- coro_asr-1.0.3/coro/bench/server_lifecycle.py +121 -0
- coro_asr-1.0.3/coro/bench/stm.py +339 -0
- coro_asr-1.0.3/coro/bench/transport.py +161 -0
- coro_asr-1.0.3/coro/bench/utils/ami_audios_download.py +144 -0
- coro_asr-1.0.3/coro/bench/utils/ami_xlm_to_stm.py +35 -0
- coro_asr-1.0.3/coro/bench/utils/make_ami_clip.py +83 -0
- coro_asr-1.0.3/coro/bench/utils/make_common_voice_clips.py +102 -0
- coro_asr-1.0.3/coro/bench/utils/make_rttm_clip.py +69 -0
- coro_asr-1.0.3/coro/bench/utils/openai_diarized_json_to_stm.py +38 -0
- coro_asr-1.0.3/coro/bench/utils/visualize_quality.py +56 -0
- coro_asr-1.0.3/coro/bench/viz.py +115 -0
- coro_asr-1.0.3/coro/cli.py +77 -0
- coro_asr-1.0.3/coro/core/__init__.py +5 -0
- coro_asr-1.0.3/coro/core/models/__init__.py +47 -0
- coro_asr-1.0.3/coro/core/models/events.py +44 -0
- coro_asr-1.0.3/coro/core/models/response.py +63 -0
- coro_asr-1.0.3/coro/core/models/transcript.py +62 -0
- coro_asr-1.0.3/coro/core/protocols.py +71 -0
- coro_asr-1.0.3/coro/core/response.py +265 -0
- coro_asr-1.0.3/coro/pipelines/__init__.py +4 -0
- coro_asr-1.0.3/coro/pipelines/done_frame.py +82 -0
- coro_asr-1.0.3/coro/pipelines/finalizer.py +155 -0
- coro_asr-1.0.3/coro/pipelines/full_memory.py +81 -0
- coro_asr-1.0.3/coro/pipelines/streaming.py +238 -0
- coro_asr-1.0.3/coro/pipelines/transcript_store.py +179 -0
- coro_asr-1.0.3/coro/pipelines/windowing.py +234 -0
- coro_asr-1.0.3/coro/runtime.py +43 -0
- coro_asr-1.0.3/coro/settings.py +132 -0
- coro_asr-1.0.3/docs/adr/0001-package-and-api-surface.md +15 -0
- coro_asr-1.0.3/docs/adr/0002-meeteval-for-quality-scoring.md +46 -0
- coro_asr-1.0.3/docs/adr/0002-replace-chunked-file-with-streaming-pipeline.md +5 -0
- coro_asr-1.0.3/docs/adr/0003-server-warmup-gates-health-readiness.md +45 -0
- coro_asr-1.0.3/docs/adr/0005-streaming-sortformer-internal-api.md +42 -0
- coro_asr-1.0.3/docs/adr/0006-data-model-module-tree.md +13 -0
- coro_asr-1.0.3/docs/adr/0007-capability-first-backend-layout.md +13 -0
- coro_asr-1.0.3/docs/agents/domain.md +51 -0
- coro_asr-1.0.3/docs/agents/issue-tracker.md +19 -0
- coro_asr-1.0.3/docs/agents/triage-labels.md +15 -0
- coro_asr-1.0.3/docs/benchmark.md +117 -0
- coro_asr-1.0.3/opencode.jsonc +90 -0
- coro_asr-1.0.3/prek.toml +115 -0
- coro_asr-1.0.3/pyproject.toml +272 -0
- coro_asr-1.0.3/sgconfig.yml +2 -0
- coro_asr-1.0.3/tests/test_app_factory.py +108 -0
- coro_asr-1.0.3/tests/test_asr_factory.py +65 -0
- coro_asr-1.0.3/tests/test_asr_windowing.py +214 -0
- coro_asr-1.0.3/tests/test_audio.py +249 -0
- coro_asr-1.0.3/tests/test_backends.py +105 -0
- coro_asr-1.0.3/tests/test_bench.py +186 -0
- coro_asr-1.0.3/tests/test_bench_ami.py +295 -0
- coro_asr-1.0.3/tests/test_bench_clips.py +50 -0
- coro_asr-1.0.3/tests/test_bench_common_voice.py +62 -0
- coro_asr-1.0.3/tests/test_bench_e2e.py +547 -0
- coro_asr-1.0.3/tests/test_bench_gpu.py +74 -0
- coro_asr-1.0.3/tests/test_bench_lifecycle.py +283 -0
- coro_asr-1.0.3/tests/test_bench_performance.py +649 -0
- coro_asr-1.0.3/tests/test_bench_quality.py +517 -0
- coro_asr-1.0.3/tests/test_bench_report.py +487 -0
- coro_asr-1.0.3/tests/test_bench_rttm_clip.py +84 -0
- coro_asr-1.0.3/tests/test_bench_transport.py +201 -0
- coro_asr-1.0.3/tests/test_bench_viz.py +94 -0
- coro_asr-1.0.3/tests/test_boundary_schemas.py +81 -0
- coro_asr-1.0.3/tests/test_core_response.py +119 -0
- coro_asr-1.0.3/tests/test_dependencies_runtime.py +34 -0
- coro_asr-1.0.3/tests/test_diarization_factory.py +66 -0
- coro_asr-1.0.3/tests/test_done_frame.py +87 -0
- coro_asr-1.0.3/tests/test_exception_handlers.py +32 -0
- coro_asr-1.0.3/tests/test_finalizer.py +147 -0
- coro_asr-1.0.3/tests/test_full_memory_pipeline.py +109 -0
- coro_asr-1.0.3/tests/test_health.py +112 -0
- coro_asr-1.0.3/tests/test_latency_factory.py +156 -0
- coro_asr-1.0.3/tests/test_onnx_asr_backend.py +276 -0
- coro_asr-1.0.3/tests/test_onnx_genai_backend.py +46 -0
- coro_asr-1.0.3/tests/test_openai_sdk_conformance.py +96 -0
- coro_asr-1.0.3/tests/test_pipelines.py +49 -0
- coro_asr-1.0.3/tests/test_pyannote_backend.py +180 -0
- coro_asr-1.0.3/tests/test_response_format.py +167 -0
- coro_asr-1.0.3/tests/test_settings.py +130 -0
- coro_asr-1.0.3/tests/test_sse_streaming.py +183 -0
- coro_asr-1.0.3/tests/test_stm.py +353 -0
- coro_asr-1.0.3/tests/test_streaming_diarizer.py +518 -0
- coro_asr-1.0.3/tests/test_streaming_memory.py +93 -0
- coro_asr-1.0.3/tests/test_streaming_pipeline.py +355 -0
- coro_asr-1.0.3/tests/test_streaming_pipeline_asr_only.py +169 -0
- coro_asr-1.0.3/tests/test_streaming_pipeline_real_model.py +165 -0
- coro_asr-1.0.3/tests/test_supported_endpoint_set.py +35 -0
- coro_asr-1.0.3/tests/test_transcript_store.py +81 -0
- coro_asr-1.0.3/tests/test_transcription_endpoint.py +259 -0
- coro_asr-1.0.3/uv.lock +3845 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: diagnose
|
|
3
|
+
description: Disciplined diagnosis loop for hard bugs and performance regressions. Reproduce → minimise → hypothesise → instrument → fix → regression-test. Use when user says "diagnose this" / "debug this", reports a bug, says something is broken/throwing/failing, or describes a performance regression.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Diagnose
|
|
7
|
+
|
|
8
|
+
A discipline for hard bugs. Skip phases only when explicitly justified.
|
|
9
|
+
|
|
10
|
+
When exploring the codebase, use the project's domain glossary to get a clear mental model of the relevant modules, and check ADRs in the area you're touching.
|
|
11
|
+
|
|
12
|
+
## Phase 1 — Build a feedback loop
|
|
13
|
+
|
|
14
|
+
**This is the skill.** Everything else is mechanical. If you have a fast, deterministic, agent-runnable pass/fail signal for the bug, you will find the cause — bisection, hypothesis-testing, and instrumentation all just consume that signal. If you don't have one, no amount of staring at code will save you.
|
|
15
|
+
|
|
16
|
+
Spend disproportionate effort here. **Be aggressive. Be creative. Refuse to give up.**
|
|
17
|
+
|
|
18
|
+
### Ways to construct one — try them in roughly this order
|
|
19
|
+
|
|
20
|
+
1. **Failing test** at whatever seam reaches the bug — unit, integration, e2e.
|
|
21
|
+
2. **Curl / HTTP script** against a running dev server.
|
|
22
|
+
3. **CLI invocation** with a fixture input, diffing stdout against a known-good snapshot.
|
|
23
|
+
4. **Headless browser script** (Playwright / Puppeteer) — drives the UI, asserts on DOM/console/network.
|
|
24
|
+
5. **Replay a captured trace.** Save a real network request / payload / event log to disk; replay it through the code path in isolation.
|
|
25
|
+
6. **Throwaway harness.** Spin up a minimal subset of the system (one service, mocked deps) that exercises the bug code path with a single function call.
|
|
26
|
+
7. **Property / fuzz loop.** If the bug is "sometimes wrong output", run 1000 random inputs and look for the failure mode.
|
|
27
|
+
8. **Bisection harness.** If the bug appeared between two known states (commit, dataset, version), automate "boot at state X, check, repeat" so you can `git bisect run` it.
|
|
28
|
+
9. **Differential loop.** Run the same input through old-version vs new-version (or two configs) and diff outputs.
|
|
29
|
+
10. **HITL bash script.** Last resort. If a human must click, drive _them_ with `scripts/hitl-loop.template.sh` so the loop is still structured. Captured output feeds back to you.
|
|
30
|
+
|
|
31
|
+
Build the right feedback loop, and the bug is 90% fixed.
|
|
32
|
+
|
|
33
|
+
### Iterate on the loop itself
|
|
34
|
+
|
|
35
|
+
Treat the loop as a product. Once you have _a_ loop, ask:
|
|
36
|
+
|
|
37
|
+
- Can I make it faster? (Cache setup, skip unrelated init, narrow the test scope.)
|
|
38
|
+
- Can I make the signal sharper? (Assert on the specific symptom, not "didn't crash".)
|
|
39
|
+
- Can I make it more deterministic? (Pin time, seed RNG, isolate filesystem, freeze network.)
|
|
40
|
+
|
|
41
|
+
A 30-second flaky loop is barely better than no loop. A 2-second deterministic loop is a debugging superpower.
|
|
42
|
+
|
|
43
|
+
### Non-deterministic bugs
|
|
44
|
+
|
|
45
|
+
The goal is not a clean repro but a **higher reproduction rate**. Loop the trigger 100×, parallelise, add stress, narrow timing windows, inject sleeps. A 50%-flake bug is debuggable; 1% is not — keep raising the rate until it's debuggable.
|
|
46
|
+
|
|
47
|
+
### When you genuinely cannot build a loop
|
|
48
|
+
|
|
49
|
+
Stop and say so explicitly. List what you tried. Ask the user for: (a) access to whatever environment reproduces it, (b) a captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do **not** proceed to hypothesise without a loop.
|
|
50
|
+
|
|
51
|
+
Do not proceed to Phase 2 until you have a loop you believe in.
|
|
52
|
+
|
|
53
|
+
## Phase 2 — Reproduce
|
|
54
|
+
|
|
55
|
+
Run the loop. Watch the bug appear.
|
|
56
|
+
|
|
57
|
+
Confirm:
|
|
58
|
+
|
|
59
|
+
- [ ] The loop produces the failure mode the **user** described — not a different failure that happens to be nearby. Wrong bug = wrong fix.
|
|
60
|
+
- [ ] The failure is reproducible across multiple runs (or, for non-deterministic bugs, reproducible at a high enough rate to debug against).
|
|
61
|
+
- [ ] You have captured the exact symptom (error message, wrong output, slow timing) so later phases can verify the fix actually addresses it.
|
|
62
|
+
|
|
63
|
+
Do not proceed until you reproduce the bug.
|
|
64
|
+
|
|
65
|
+
## Phase 3 — Hypothesise
|
|
66
|
+
|
|
67
|
+
Generate **3–5 ranked hypotheses** before testing any of them. Single-hypothesis generation anchors on the first plausible idea.
|
|
68
|
+
|
|
69
|
+
Each hypothesis must be **falsifiable**: state the prediction it makes.
|
|
70
|
+
|
|
71
|
+
> Format: "If <X> is the cause, then <changing Y> will make the bug disappear / <changing Z> will make it worse."
|
|
72
|
+
|
|
73
|
+
If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
|
|
74
|
+
|
|
75
|
+
**Show the ranked list to the user before testing.** They often have domain knowledge that re-ranks instantly ("we just deployed a change to #3"), or know hypotheses they've already ruled out. Cheap checkpoint, big time saver. Don't block on it — proceed with your ranking if the user is AFK.
|
|
76
|
+
|
|
77
|
+
## Phase 4 — Instrument
|
|
78
|
+
|
|
79
|
+
Each probe must map to a specific prediction from Phase 3. **Change one variable at a time.**
|
|
80
|
+
|
|
81
|
+
Tool preference:
|
|
82
|
+
|
|
83
|
+
1. **Debugger / REPL inspection** if the env supports it. One breakpoint beats ten logs.
|
|
84
|
+
2. **Targeted logs** at the boundaries that distinguish hypotheses.
|
|
85
|
+
3. Never "log everything and grep".
|
|
86
|
+
|
|
87
|
+
**Tag every debug log** with a unique prefix, e.g. `[DEBUG-a4f2]`. Cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
|
|
88
|
+
|
|
89
|
+
**Perf branch.** For performance regressions, logs are usually wrong. Instead: establish a baseline measurement (timing harness, `performance.now()`, profiler, query plan), then bisect. Measure first, fix second.
|
|
90
|
+
|
|
91
|
+
## Phase 5 — Fix + regression test
|
|
92
|
+
|
|
93
|
+
Write the regression test **before the fix** — but only if there is a **correct seam** for it.
|
|
94
|
+
|
|
95
|
+
A correct seam is one where the test exercises the **real bug pattern** as it occurs at the call site. If the only available seam is too shallow (single-caller test when the bug needs multiple callers, unit test that can't replicate the chain that triggered the bug), a regression test there gives false confidence.
|
|
96
|
+
|
|
97
|
+
**If no correct seam exists, that itself is the finding.** Note it. The codebase architecture is preventing the bug from being locked down. Flag this for the next phase.
|
|
98
|
+
|
|
99
|
+
If a correct seam exists:
|
|
100
|
+
|
|
101
|
+
1. Turn the minimised repro into a failing test at that seam.
|
|
102
|
+
2. Watch it fail.
|
|
103
|
+
3. Apply the fix.
|
|
104
|
+
4. Watch it pass.
|
|
105
|
+
5. Re-run the Phase 1 feedback loop against the original (un-minimised) scenario.
|
|
106
|
+
|
|
107
|
+
## Phase 6 — Cleanup + post-mortem
|
|
108
|
+
|
|
109
|
+
Required before declaring done:
|
|
110
|
+
|
|
111
|
+
- [ ] Original repro no longer reproduces (re-run the Phase 1 loop)
|
|
112
|
+
- [ ] Regression test passes (or absence of seam is documented)
|
|
113
|
+
- [ ] All `[DEBUG-...]` instrumentation removed (`grep` the prefix)
|
|
114
|
+
- [ ] Throwaway prototypes deleted (or moved to a clearly-marked debug location)
|
|
115
|
+
- [ ] The hypothesis that turned out correct is stated in the commit / PR message — so the next debugger learns
|
|
116
|
+
|
|
117
|
+
**Then ask: what would have prevented this bug?** If the answer involves architectural change (no good test seam, tangled callers, hidden coupling) hand off to the `/improve-codebase-architecture` skill with the specifics. Make the recommendation **after** the fix is in, not before — you have more information now than when you started.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Human-in-the-loop reproduction loop.
|
|
3
|
+
# Copy this file, edit the steps below, and run it.
|
|
4
|
+
# The agent runs the script; the user follows prompts in their terminal.
|
|
5
|
+
#
|
|
6
|
+
# Usage:
|
|
7
|
+
# bash hitl-loop.template.sh
|
|
8
|
+
#
|
|
9
|
+
# Two helpers:
|
|
10
|
+
# step "<instruction>" → show instruction, wait for Enter
|
|
11
|
+
# capture VAR "<question>" → show question, read response into VAR
|
|
12
|
+
#
|
|
13
|
+
# At the end, captured values are printed as KEY=VALUE for the agent to parse.
|
|
14
|
+
|
|
15
|
+
set -euo pipefail
|
|
16
|
+
|
|
17
|
+
step() {
|
|
18
|
+
printf '\n>>> %s\n' "$1"
|
|
19
|
+
read -r -p " [Enter when done] " _
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
capture() {
|
|
23
|
+
local var="$1" question="$2" answer
|
|
24
|
+
printf '\n>>> %s\n' "$question"
|
|
25
|
+
read -r -p " > " answer
|
|
26
|
+
printf -v "$var" '%s' "$answer"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# --- edit below ---------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
step "Open the app at http://localhost:3000 and sign in."
|
|
32
|
+
|
|
33
|
+
capture ERRORED "Click the 'Export' button. Did it throw an error? (y/n)"
|
|
34
|
+
|
|
35
|
+
capture ERROR_MSG "Paste the error message (or 'none'):"
|
|
36
|
+
|
|
37
|
+
# --- edit above ---------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
printf '\n--- Captured ---\n'
|
|
40
|
+
printf 'ERRORED=%s\n' "$ERRORED"
|
|
41
|
+
printf 'ERROR_MSG=%s\n' "$ERROR_MSG"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: handoff
|
|
3
|
+
description: Compact the current conversation into a handoff document for another agent to pick up.
|
|
4
|
+
argument-hint: "What will the next session be used for?"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Write a handoff document summarising the current conversation so a fresh agent can continue the work. Save to the temporary directory on the workspace .tmp/handoff/ and name the file with the current timestamp and a slugified version of the topic (e.g. `2024-01-01T12-00-00-fix-login-bug.md`).
|
|
8
|
+
|
|
9
|
+
Gather all the relevant context in order make the next task as easy as possible for the next agent.
|
|
10
|
+
|
|
11
|
+
Include a "suggested skills" section in the document, which suggests skills that the agent should invoke.
|
|
12
|
+
|
|
13
|
+
Do not duplicate content already captured in other artifacts (PRDs, plans, ADRs, issues, commits, diffs). Reference them by path or URL instead.
|
|
14
|
+
|
|
15
|
+
Redact any sensitive information, such as API keys, passwords, or personally identifiable information.
|
|
16
|
+
|
|
17
|
+
As output write a small handoff prompt on this chat to be copied and pasted into the next session, which references the handoff document and highlights the most important context for the next agent to know.
|
|
18
|
+
|
|
19
|
+
If the user passed arguments, treat them as a description of what the next session will focus on and tailor the doc accordingly.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# HTML Report Format
|
|
2
|
+
|
|
3
|
+
The architectural review is rendered as a single self-contained HTML file in the OS temp directory. Tailwind and Mermaid both come from CDNs. Mermaid handles graph-shaped diagrams reliably; hand-built divs and inline SVG handle the more editorial visuals (mass diagrams, cross-sections). Mix the two — don't lean on Mermaid for everything, it'll start to look generic.
|
|
4
|
+
|
|
5
|
+
## Scaffold
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<!doctype html>
|
|
9
|
+
<html lang="en">
|
|
10
|
+
<head>
|
|
11
|
+
<meta charset="utf-8" />
|
|
12
|
+
<title>Architecture review — {{repo name}}</title>
|
|
13
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
14
|
+
<script type="module">
|
|
15
|
+
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs";
|
|
16
|
+
mermaid.initialize({ startOnLoad: true, theme: "neutral", securityLevel: "loose" });
|
|
17
|
+
</script>
|
|
18
|
+
<style>
|
|
19
|
+
/* small custom layer for things Tailwind doesn't cover cleanly:
|
|
20
|
+
dashed seam lines, hand-drawn-feeling arrow heads, etc. */
|
|
21
|
+
.seam { stroke-dasharray: 4 4; }
|
|
22
|
+
.leak { stroke: #dc2626; }
|
|
23
|
+
.deep { background: linear-gradient(135deg, #0f172a, #1e293b); }
|
|
24
|
+
</style>
|
|
25
|
+
</head>
|
|
26
|
+
<body class="bg-stone-50 text-slate-900 font-sans">
|
|
27
|
+
<main class="max-w-5xl mx-auto px-6 py-12 space-y-12">
|
|
28
|
+
<header>...</header>
|
|
29
|
+
<section id="candidates" class="space-y-10">...</section>
|
|
30
|
+
<section id="top-recommendation">...</section>
|
|
31
|
+
</main>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Header
|
|
37
|
+
|
|
38
|
+
Repo name, date, and a compact legend: solid box = module, dashed line = seam, red arrow = leakage, thick dark box = deep module. No introduction paragraph — straight into the candidates.
|
|
39
|
+
|
|
40
|
+
## Candidate card
|
|
41
|
+
|
|
42
|
+
The diagrams carry the weight. Prose is sparse, plain, and uses the glossary terms (from the `/codebase-design` skill) without ceremony.
|
|
43
|
+
|
|
44
|
+
Each candidate is one `<article>`:
|
|
45
|
+
|
|
46
|
+
- **Title** — short, names the deepening (e.g. "Collapse the Order intake pipeline").
|
|
47
|
+
- **Badge row** — recommendation strength (`Strong` = emerald, `Worth exploring` = amber, `Speculative` = slate), plus a tag for the dependency category (`in-process`, `local-substitutable`, `ports & adapters`, `mock`).
|
|
48
|
+
- **Files** — monospaced list, `font-mono text-sm`.
|
|
49
|
+
- **Before / After diagram** — the centrepiece. Two columns, side by side. See patterns below.
|
|
50
|
+
- **Problem** — one sentence. What hurts.
|
|
51
|
+
- **Solution** — one sentence. What changes.
|
|
52
|
+
- **Wins** — bullets, ≤6 words each. e.g. "Tests hit one interface", "Pricing logic stops leaking", "Delete 4 shallow wrappers".
|
|
53
|
+
- **ADR callout** (if applicable) — one line in an amber-tinted box.
|
|
54
|
+
|
|
55
|
+
No paragraphs of explanation. If the diagram needs a paragraph to be understood, redraw the diagram.
|
|
56
|
+
|
|
57
|
+
## Diagram patterns
|
|
58
|
+
|
|
59
|
+
Pick the pattern that fits the candidate. Mix them. Don't make every diagram look the same — variety is part of the point.
|
|
60
|
+
|
|
61
|
+
### Mermaid graph (the workhorse for dependencies / call flow)
|
|
62
|
+
|
|
63
|
+
Use a Mermaid `flowchart` or `graph` when the point is "X calls Y calls Z, and look at the mess." Wrap it in a Tailwind-styled card so it doesn't feel parachuted in. Style with classDef to colour leakage edges red and the deep module dark. Sequence diagrams work well for "before: 6 round-trips; after: 1."
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<div class="rounded-lg border border-slate-200 bg-white p-4">
|
|
67
|
+
<pre class="mermaid">
|
|
68
|
+
flowchart LR
|
|
69
|
+
A[OrderHandler] --> B[OrderValidator]
|
|
70
|
+
B --> C[OrderRepo]
|
|
71
|
+
C -.leak.-> D[PricingClient]
|
|
72
|
+
classDef leak stroke:#dc2626,stroke-width:2px;
|
|
73
|
+
class C,D leak
|
|
74
|
+
</pre>
|
|
75
|
+
</div>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Hand-built boxes-and-arrows (when Mermaid's layout fights you)
|
|
79
|
+
|
|
80
|
+
Modules as `<div>`s with borders and labels. Arrows as inline SVG `<line>` or `<path>` elements positioned absolutely over a relative container. Reach for this when you want the "after" diagram to feel like one thick-bordered deep module with greyed-out internals — Mermaid won't render that with the right weight.
|
|
81
|
+
|
|
82
|
+
### Cross-section (good for layered shallowness)
|
|
83
|
+
|
|
84
|
+
Stack horizontal bands (`h-12 border-l-4`) to show layers a call passes through. Before: 6 thin layers each doing nothing. After: 1 thick band labelled with the consolidated responsibility.
|
|
85
|
+
|
|
86
|
+
### Mass diagram (good for "interface as wide as implementation")
|
|
87
|
+
|
|
88
|
+
Two rectangles per module — one for interface surface area, one for implementation. Before: interface rectangle is nearly as tall as the implementation rectangle (shallow). After: interface rectangle is short, implementation rectangle is tall (deep).
|
|
89
|
+
|
|
90
|
+
### Call-graph collapse
|
|
91
|
+
|
|
92
|
+
Before: a tree of function calls rendered as nested boxes. After: the same tree collapsed into one box, with the now-internal calls shown faded inside it.
|
|
93
|
+
|
|
94
|
+
## Style guidance
|
|
95
|
+
|
|
96
|
+
- Lean editorial, not corporate-dashboard. Generous whitespace. Serif optional for headings (`font-serif` works well with stone/slate).
|
|
97
|
+
- Colour sparingly: one accent (emerald or indigo) plus red for leakage and amber for warnings.
|
|
98
|
+
- Keep diagrams ~320px tall so before/after sits comfortably side by side without scrolling.
|
|
99
|
+
- Use `text-xs uppercase tracking-wider` for module labels inside diagrams — they should read as schematic, not as UI.
|
|
100
|
+
- The only scripts are the Tailwind CDN and the Mermaid ESM import. The report is otherwise static — no app code, no interactivity beyond Mermaid's own rendering.
|
|
101
|
+
|
|
102
|
+
## Top recommendation section
|
|
103
|
+
|
|
104
|
+
One larger card. Candidate name, one sentence on why, anchor link to its card. That's it.
|
|
105
|
+
|
|
106
|
+
## Tone
|
|
107
|
+
|
|
108
|
+
Plain English, concise — but the architectural nouns and verbs come straight from the `/codebase-design` skill. Concision is not an excuse to drift.
|
|
109
|
+
|
|
110
|
+
**Use exactly:** module, interface, implementation, depth, deep, shallow, seam, adapter, leverage, locality.
|
|
111
|
+
|
|
112
|
+
**Never substitute:** component, service, unit (for module) · API, signature (for interface) · boundary (for seam) · layer, wrapper (for module, when you mean module).
|
|
113
|
+
|
|
114
|
+
**Phrasings that fit the style:**
|
|
115
|
+
|
|
116
|
+
- "Order intake module is shallow — interface nearly matches the implementation."
|
|
117
|
+
- "Pricing leaks across the seam."
|
|
118
|
+
- "Deepen: one interface, one place to test."
|
|
119
|
+
- "Two adapters justify the seam: HTTP in prod, in-memory in tests."
|
|
120
|
+
|
|
121
|
+
**Wins bullets** name the gain in glossary terms: *"locality: bugs concentrate in one module"*, *"leverage: one interface, N call sites"*, *"interface shrinks; implementation absorbs the wrappers"*. Don't write *"easier to maintain"* or *"cleaner code"* — those terms aren't in the glossary and don't earn their place.
|
|
122
|
+
|
|
123
|
+
No hedging, no throat-clearing, no "it's worth noting that…". If a sentence could be a bullet, make it a bullet. If a bullet could be cut, cut it. If a term isn't in the `/codebase-design` glossary, reach for one that is before inventing a new one.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: improve-codebase-architecture
|
|
3
|
+
description: Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Improve Codebase Architecture
|
|
8
|
+
|
|
9
|
+
Surface architectural friction and propose **deepening opportunities** — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.
|
|
10
|
+
|
|
11
|
+
This command is _informed_ by the project's domain model and built on a shared design vocabulary:
|
|
12
|
+
|
|
13
|
+
- Run the `/codebase-design` skill for the architecture vocabulary (**module**, **interface**, **depth**, **seam**, **adapter**, **leverage**, **locality**) and its principles (the deletion test, "the interface is the test surface", "one adapter = hypothetical seam, two = real"). Use these terms exactly in every suggestion — don't drift into "component," "service," "API," or "boundary."
|
|
14
|
+
- The domain language in `CONTEXT.md` gives names to good seams; ADRs in `docs/adr/` record decisions this command should not re-litigate.
|
|
15
|
+
|
|
16
|
+
## Process
|
|
17
|
+
|
|
18
|
+
### 1. Explore
|
|
19
|
+
|
|
20
|
+
Read the project's domain glossary (`CONTEXT.md`) and any ADRs in the area you're touching first.
|
|
21
|
+
|
|
22
|
+
Then use the Agent tool with `subagent_type=Explore` to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:
|
|
23
|
+
|
|
24
|
+
- Where does understanding one concept require bouncing between many small modules?
|
|
25
|
+
- Where are modules **shallow** — interface nearly as complex as the implementation?
|
|
26
|
+
- Where have pure functions been extracted just for testability, but the real bugs hide in how they're called (no **locality**)?
|
|
27
|
+
- Where do tightly-coupled modules leak across their seams?
|
|
28
|
+
- Which parts of the codebase are untested, or hard to test through their current interface?
|
|
29
|
+
|
|
30
|
+
Apply the **deletion test** to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.
|
|
31
|
+
|
|
32
|
+
### 2. Present candidates as an HTML report
|
|
33
|
+
|
|
34
|
+
Write a self-contained HTML file to the OS temp directory so nothing lands in the repo. Resolve the temp dir from `$TMPDIR`, falling back to `/tmp` (or `%TEMP%` on Windows), and write to `<tmpdir>/architecture-review-<timestamp>.html` so each run gets a fresh file. Open it for the user — `xdg-open <path>` on Linux, `open <path>` on macOS, `start <path>` on Windows — and tell them the absolute path.
|
|
35
|
+
|
|
36
|
+
The report uses **Tailwind via CDN** for layout and styling, and **Mermaid via CDN** for diagrams where a graph/flow/sequence reliably communicates the structure. Mix Mermaid with hand-crafted CSS/SVG visuals — use Mermaid when relationships are graph-shaped (call graphs, dependencies, sequences), and hand-built divs/SVG when you want something more editorial (mass diagrams, cross-sections, collapse animations). Each candidate gets a **before/after visualisation**. Be visual.
|
|
37
|
+
|
|
38
|
+
For each candidate, render a card with:
|
|
39
|
+
|
|
40
|
+
- **Files** — which files/modules are involved
|
|
41
|
+
- **Problem** — why the current architecture is causing friction
|
|
42
|
+
- **Solution** — plain English description of what would change
|
|
43
|
+
- **Benefits** — explained in terms of locality and leverage, and how tests would improve
|
|
44
|
+
- **Before / After diagram** — side-by-side, custom-drawn, illustrating the shallowness and the deepening
|
|
45
|
+
- **Recommendation strength** — one of `Strong`, `Worth exploring`, `Speculative`, rendered as a badge
|
|
46
|
+
|
|
47
|
+
End the report with a **Top recommendation** section: which candidate you'd tackle first and why.
|
|
48
|
+
|
|
49
|
+
**Use CONTEXT.md vocabulary for the domain, and the `/codebase-design` vocabulary for the architecture.** If `CONTEXT.md` defines "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."
|
|
50
|
+
|
|
51
|
+
**ADR conflicts**: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly in the card (e.g. a warning callout: _"contradicts ADR-0007 — but worth reopening because…"_). Don't list every theoretical refactor an ADR forbids.
|
|
52
|
+
|
|
53
|
+
See [HTML-REPORT.md](HTML-REPORT.md) for the full HTML scaffold, diagram patterns, and styling guidance.
|
|
54
|
+
|
|
55
|
+
Do NOT propose interfaces yet. After the file is written, ask the user: "Which of these would you like to explore?"
|
|
56
|
+
|
|
57
|
+
### 3. Grilling loop
|
|
58
|
+
|
|
59
|
+
Once the user picks a candidate, run the `/grilling` skill to walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.
|
|
60
|
+
|
|
61
|
+
Side effects happen inline as decisions crystallize — run the `/domain-modeling` skill to keep the domain model current as you go:
|
|
62
|
+
|
|
63
|
+
- **Naming a deepened module after a concept not in `CONTEXT.md`?** Add the term to `CONTEXT.md`. Create the file lazily if it doesn't exist.
|
|
64
|
+
- **Sharpening a fuzzy term during the conversation?** Update `CONTEXT.md` right there.
|
|
65
|
+
- **User rejects the candidate with a load-bearing reason?** Offer an ADR, framed as: _"Want me to record this as an ADR so future architecture reviews don't re-suggest it?"_ Only offer when the reason would actually be needed by a future explorer to avoid re-suggesting the same thing — skip ephemeral reasons ("not worth it right now") and self-evident ones.
|
|
66
|
+
- **Want to explore alternative interfaces for the deepened module?** Run the `/codebase-design` skill and use its design-it-twice parallel sub-agent pattern.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: journalist
|
|
3
|
+
description: "Write short daily journal entries for the current session under .journals, maintain a metadata-driven index, and query prior entries by topic, date, or entry slug. Use when the user asks to journal, log, recap, record session notes, capture research notes, or search the project journal."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Journalist
|
|
7
|
+
|
|
8
|
+
Capture a concise, useful journal entry about the current session. The journal is local/private by default and lives under `.journals/`.
|
|
9
|
+
|
|
10
|
+
## Layout
|
|
11
|
+
|
|
12
|
+
Use this repo-local structure:
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
.journals/
|
|
16
|
+
index.md
|
|
17
|
+
<date>/
|
|
18
|
+
<date>_<topic-slug>_<title-slug>/
|
|
19
|
+
assets/
|
|
20
|
+
<date>_<topic-slug>_<title-slug>.md
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Example: `.journals/2026-06-13/2026-06-13_repo-tooling_setup-repo-skill/2026-06-13_repo-tooling_setup-repo-skill.md`.
|
|
24
|
+
|
|
25
|
+
## Entry Rules
|
|
26
|
+
|
|
27
|
+
- Do not record secrets, credentials, tokens, private keys, or sensitive personal data.
|
|
28
|
+
- Keep entries short, but preserve important context, decisions, evidence, links, and follow-ups.
|
|
29
|
+
- Support development journals, research journals, debugging notes, and design notes; do not force every entry into a development-only template.
|
|
30
|
+
- Use assets only when they materially help. Store them under the entry's `assets/` directory and link with relative paths.
|
|
31
|
+
- If an entry for the same date, topic, and title already exists, update it in place and refresh `updated_at`; otherwise create a new entry.
|
|
32
|
+
|
|
33
|
+
## Topic Selection
|
|
34
|
+
|
|
35
|
+
1. Read `.journals/index.md` if present, then scan journal frontmatter if needed.
|
|
36
|
+
2. Reuse an existing kebab-case topic when it fits the session.
|
|
37
|
+
3. Create a new kebab-case topic when no existing topic fits.
|
|
38
|
+
4. Ask the user only when multiple existing topics are plausible and the choice matters.
|
|
39
|
+
|
|
40
|
+
## Entry Template
|
|
41
|
+
|
|
42
|
+
Use YAML frontmatter exactly like this:
|
|
43
|
+
|
|
44
|
+
```markdown
|
|
45
|
+
---
|
|
46
|
+
created_at: <ISO-8601 timestamp>
|
|
47
|
+
updated_at: <ISO-8601 timestamp>
|
|
48
|
+
title: <short title>
|
|
49
|
+
topic: <kebab-case topic>
|
|
50
|
+
brief: <2-3 sentence summary>
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Notes
|
|
54
|
+
|
|
55
|
+
<Short narrative, bullets, research observations, decisions, links, or embedded tables/plots as appropriate.>
|
|
56
|
+
|
|
57
|
+
## Follow-ups
|
|
58
|
+
|
|
59
|
+
- <Open question or next action, if any.>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Adjust body sections to fit the session. Research entries may include tables, plots, quotes, methods, or findings inline instead of `Notes`/`Follow-ups` when that reads better.
|
|
63
|
+
|
|
64
|
+
## Index And Query Scripts
|
|
65
|
+
|
|
66
|
+
Use this skill's bundled scripts; do not copy them into `.journals/`:
|
|
67
|
+
|
|
68
|
+
- `scripts/update_journal_index.py <repo-root>` recompiles `.journals/index.md` from entry frontmatter.
|
|
69
|
+
- `scripts/query_journals.py <repo-root> [--topic TOPIC] [--date DATE] [--entry ENTRY] [--text TEXT] [--full]` searches entries.
|
|
70
|
+
|
|
71
|
+
After writing or updating an entry, always run `update_journal_index.py`.
|
|
72
|
+
|
|
73
|
+
## Index Format
|
|
74
|
+
|
|
75
|
+
The generated index is human-oriented, grouped by topic, and sorted by topic then newest entry first. It includes each entry's date, title, brief, and relative path.
|
|
76
|
+
|
|
77
|
+
Example:
|
|
78
|
+
|
|
79
|
+
```markdown
|
|
80
|
+
# Journal Index
|
|
81
|
+
|
|
82
|
+
Generated from journal entry frontmatter.
|
|
83
|
+
|
|
84
|
+
## Repo Tooling
|
|
85
|
+
|
|
86
|
+
- **2026-06-13** [Setup Repo Skill](.journals/2026-06-13/2026-06-13_repo-tooling_setup-repo-skill/2026-06-13_repo-tooling_setup-repo-skill.md)
|
|
87
|
+
- Updated repo setup defaults and non-destructive editing rules.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Setup Note
|
|
91
|
+
|
|
92
|
+
If `.journals/` is not gitignored, add `.journals/` to `.gitignore` without removing or rewriting existing ignore rules.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Query .journals entries by topic, date, entry slug, or text."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class Entry:
|
|
13
|
+
path: Path
|
|
14
|
+
created_at: str
|
|
15
|
+
title: str
|
|
16
|
+
topic: str
|
|
17
|
+
brief: str
|
|
18
|
+
text: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def parse_frontmatter(text: str) -> dict[str, str]:
|
|
22
|
+
metadata: dict[str, str] = {}
|
|
23
|
+
if not text.startswith("---\n"):
|
|
24
|
+
return metadata
|
|
25
|
+
end = text.find("\n---\n", 4)
|
|
26
|
+
if end == -1:
|
|
27
|
+
return metadata
|
|
28
|
+
for line in text[4:end].splitlines():
|
|
29
|
+
if not line.strip() or line.lstrip().startswith("#") or ":" not in line:
|
|
30
|
+
continue
|
|
31
|
+
key, value = line.split(":", 1)
|
|
32
|
+
metadata[key.strip()] = value.strip().strip('"').strip("'")
|
|
33
|
+
return metadata
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def collect_entries(journal_root: Path) -> list[Entry]:
|
|
37
|
+
entries: list[Entry] = []
|
|
38
|
+
for path in sorted(journal_root.glob("**/*.md")):
|
|
39
|
+
if path == journal_root / "index.md":
|
|
40
|
+
continue
|
|
41
|
+
text = path.read_text(encoding="utf-8")
|
|
42
|
+
metadata = parse_frontmatter(text)
|
|
43
|
+
if not metadata:
|
|
44
|
+
continue
|
|
45
|
+
entries.append(
|
|
46
|
+
Entry(
|
|
47
|
+
path=path,
|
|
48
|
+
created_at=metadata.get("created_at", ""),
|
|
49
|
+
title=metadata.get("title", ""),
|
|
50
|
+
topic=metadata.get("topic", ""),
|
|
51
|
+
brief=metadata.get("brief", ""),
|
|
52
|
+
text=text,
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
return entries
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def contains(value: str, needle: str | None) -> bool:
|
|
59
|
+
if not needle:
|
|
60
|
+
return True
|
|
61
|
+
return needle.lower() in value.lower()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def matches(entry: Entry, args: argparse.Namespace) -> bool:
|
|
65
|
+
if args.topic and not contains(entry.topic, args.topic):
|
|
66
|
+
return False
|
|
67
|
+
if args.date and not entry.created_at.startswith(args.date):
|
|
68
|
+
return False
|
|
69
|
+
if args.entry and args.entry.lower() not in entry.path.stem.lower():
|
|
70
|
+
return False
|
|
71
|
+
if args.text:
|
|
72
|
+
haystack = "\n".join([entry.title, entry.topic, entry.brief, entry.text])
|
|
73
|
+
if not contains(haystack, args.text):
|
|
74
|
+
return False
|
|
75
|
+
return True
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def main() -> int:
|
|
79
|
+
parser = argparse.ArgumentParser(description="Query .journals entries")
|
|
80
|
+
parser.add_argument("repo_root", help="Repository root path")
|
|
81
|
+
parser.add_argument("--topic", help="Match topic substring")
|
|
82
|
+
parser.add_argument("--date", help="Match date prefix, for example 2026-06-13 or 2026-06")
|
|
83
|
+
parser.add_argument("--entry", help="Match entry filename slug")
|
|
84
|
+
parser.add_argument("--text", help="Search title, brief, topic, and body text")
|
|
85
|
+
parser.add_argument("--full", action="store_true", help="Print full matching entries")
|
|
86
|
+
args = parser.parse_args()
|
|
87
|
+
|
|
88
|
+
repo_root = Path(args.repo_root).resolve()
|
|
89
|
+
journal_root = repo_root / ".journals"
|
|
90
|
+
entries = [entry for entry in collect_entries(journal_root) if matches(entry, args)]
|
|
91
|
+
entries.sort(key=lambda entry: entry.created_at, reverse=True)
|
|
92
|
+
|
|
93
|
+
if not entries:
|
|
94
|
+
print("No journal entries matched.")
|
|
95
|
+
return 1
|
|
96
|
+
|
|
97
|
+
for entry in entries:
|
|
98
|
+
rel_path = entry.path.relative_to(repo_root).as_posix()
|
|
99
|
+
if args.full:
|
|
100
|
+
print(f"<!-- {rel_path} -->")
|
|
101
|
+
print(entry.text.rstrip())
|
|
102
|
+
print()
|
|
103
|
+
else:
|
|
104
|
+
print(f"- {entry.created_at[:10]} [{entry.topic}] {entry.title} - {rel_path}")
|
|
105
|
+
if entry.brief:
|
|
106
|
+
print(f" {entry.brief}")
|
|
107
|
+
return 0
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
raise SystemExit(main())
|