{"id":50974357,"url":"https://github.com/broomva/p9","last_synced_at":"2026-06-19T06:02:00.204Z","repository":{"id":355833581,"uuid":"1229227697","full_name":"broomva/p9","owner":"broomva","description":"bstack P9 — CI watcher + productive-wait primitive. Replaces sleep-based CI waits with an event-driven control loop, drains a context-scoped wait-queue while CI runs, classifies failures, and self-heals known categories. Merge authorization stays with the control metalayer.","archived":false,"fork":false,"pushed_at":"2026-06-12T01:10:36.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-12T03:07:29.199Z","etag":null,"topics":["agent-skill","broomva","bstack","ci-cd","claude-code","productive-wait","self-heal"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/broomva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-04T20:40:22.000Z","updated_at":"2026-06-12T01:10:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/broomva/p9","commit_stats":null,"previous_names":["broomva/p9"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/broomva/p9","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broomva%2Fp9","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broomva%2Fp9/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broomva%2Fp9/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broomva%2Fp9/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/broomva","download_url":"https://codeload.github.com/broomva/p9/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broomva%2Fp9/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34519052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-skill","broomva","bstack","ci-cd","claude-code","productive-wait","self-heal"],"created_at":"2026-06-19T06:01:59.310Z","updated_at":"2026-06-19T06:02:00.198Z","avatar_url":"https://github.com/broomva.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# p9 — bstack P9: productive-wait primitive (the wait optimizer)\n\n\u003e **Never `sleep` on a blocking wait.** P9 is a wait optimizer — turn any blocking external operation (PR CI, push-triggered deploys, builds, long indexing) into work on the next priority. PR CI is the canonical implementation today; the primitive is broader.\n\n## Why P9 exists\n\nWhen an agent kicks off a long external operation and waits for it, the dumb pattern is `sleep`. P9 replaces it with productive-wait discipline:\n\n1. **Notification via `run_in_background`** — for PR CI, the observer is `gh pr checks --watch`. No polling.\n2. **Productive wait** — the agent drains a context-scoped queue (session → memory → graph → docs → Linear) while the operation runs.\n3. **Self-heal** — when CI fails for known categories (lint, format, codegen drift, flaky tests), P9 classifies and applies the heal command. Unknown failures escalate to a Linear ticket.\n4. **Merge stays governed** — P9 emits `MERGE_READY`; the existing `.control/policy.yaml` + control-gate-hook authorizes the actual merge. P9 owns mechanism, not policy.\n\n## Scope today vs. on roadmap\n\nP9 currently tracks **PR-scoped waits** through the `p9 watch \u003cpr\u003e` CLI. That covers ~95% of agent waits in a typical session.\n\nThe remaining 5% — **non-PR waits** — are not yet wired into `p9 watch`. These include:\n\n- **Push-triggered deploys** — a push to `main` that fires a Vercel/Cloudflare deploy hook without opening a PR\n- **Long-running test suites or builds** — outside the CI surface\n- **External index / sync operations** — content pipelines, embeddings, search-index rebuilds\n\nFor these, the productive-wait *discipline* still applies: kick off next-priority work, then do **one direct check** on the operation's completion. Never `sleep`. Wiring these into `p9 watch \u003ckind\u003e \u003cref\u003e` is on the roadmap.\n\n## Quick start\n\n```bash\n# 1. Install dependencies (stdlib-only at runtime; pytest for tests)\npython3 -m venv .venv \u0026\u0026 source .venv/bin/activate\npip install -r tests/requirements-dev.txt\n\n# 2. Wire policy blocks\n# Add ci_watch: and ci_heal: to your .control/policy.yaml. See\n# tests/fixtures/policy-good.yaml for a complete example.\n\n# 3. Verify install\npython3 scripts/p9.py doctor\n# → p9 doctor: ok\n\n# 4. Use it\ngh pr create ... ; PR=42\npython3 scripts/p9.py watch $PR --background\n# In parallel: pull productive work while CI runs\npython3 scripts/p9.py wait-queue pop\n# When the bg-task notification fires, check terminal state:\npython3 scripts/p9.py status --pr $PR --json\n```\n\n## Subcommands\n\n| Command | Purpose |\n|---|---|\n| `p9 watch \u003cpr\u003e` | Spawn `gh pr checks --watch` in background, transition to `WATCHING`. |\n| `p9 status [--pr N]` | Show in-flight PRs and their state-machine position. |\n| `p9 wait-queue {push,pop,list,clear}` | Manage the productive-wait queue (5 sources, priority-ordered). |\n| `p9 heal \u003cpr\u003e --classify` | Read failure log, classify against the rubric (read-only — does not execute heals). |\n| `p9 events tail` | Stream P9 events (P1 conversation-bridge consumes these). |\n| `p9 merge-ready \u003cpr\u003e` | Mark a green PR as ready for metalayer-authorized merge. |\n| `p9 doctor` | Health-check: gh auth, state directory, policy blocks, rubric. |\n\n## Architecture (one paragraph)\n\nPure Python, stdlib-only at runtime. State lives in `~/.config/broomva/p9/state.jsonl` (append-only, JSONL with `flock` serialization, partial-write recovery on read). Failure classification is regex-only — no LLM in the hot path — driven by `references/scoring-rubric.md` (markdown is human-canonical; `_builtin_rubric()` in `scripts/p9.py` is code-canonical; a unit test asserts they stay in sync). The evaluator scores progress with a four-term weighted sum (signature change + failures decreased + budget remaining + classifier confidence) and forces escalation after two consecutive sub-floor cycles. Multi-PR concurrency is bounded by `ci_watch.max_concurrent_prs` (default 1). Everything fails closed on missing or malformed policy blocks.\n\n## Cardinal invariant\n\n\u003e **P9 never silently drops state.** Every failure produces (a) a `state.jsonl` event, (b) a Linear ticket via the escalation channel, or (c) both. If neither write succeeds, P9 crashes loudly (exit 99) — degraded silent operation is forbidden.\n\n## Where it fits in the bstack\n\n```\nP3 (Linear ticket) → P4 (PR pipeline) → P9 (CI watcher + heal) → metalayer authorizes merge\n                                              ↓ drains during wait\n                                      {context queue, P5 worktree, P6 bookkeeping}\n```\n\nComposes with — does not duplicate — existing primitives. See `AGENTS.md` in the workspace repo for the full bstack specification.\n\n## Spec \u0026 design\n\nThe full design lives at [`broomva/workspace`](https://github.com/broomva/workspace) under `docs/superpowers/specs/2026-05-04-p9-ci-watcher-design.md`. Seven rounds of clarifying Q\u0026A locked the architecture before a line of code was written.\n\n## Tests\n\n```bash\npython3 -m pytest tests/\n# 46 passed\n```\n\n## License\n\nMIT — see [LICENSE](LICENSE).\n\n## Related\n\n- [broomva/bookkeeping](https://github.com/broomva/bookkeeping) — bstack P8 (knowledge graph engine)\n- [broomva/workspace](https://github.com/broomva/workspace) — unified workspace + governance\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroomva%2Fp9","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbroomva%2Fp9","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroomva%2Fp9/lists"}