loopctl-mcp-server 3.13.1 → 3.14.1

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.
package/README.md CHANGED
@@ -277,7 +277,7 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
277
277
  | Tool | Description |
278
278
  |---|---|
279
279
  | `report_story` | Reviewer confirms the implementation is done. Transitions implementing -> reported_done. Accepts optional `token_usage` object. Under the LCP-1 §9.3 signed profile, pass the `claim` from `custody_sign_claim`. Refused 409 `chg_root_review_only` for a key descending from an intake source's `chg_root_dispatch_id`. |
280
- | `review_complete` | Record that a review has been completed for a story. Required before verify. Under the signed profile, pass the `claim` from `custody_sign_claim`. On a story bound to a chg change (loopctl US-47.5), after the existing custody gates: only a key chg-server minted for the review — a strict descendant of the intake source's `chg_root_dispatch_id` — may record it (409 `chg_reviewer_required`, the root key included); `commit_sha` is REQUIRED and must be the sha of a submitted revision of the story's current change (422 `commit_sha_not_bound`); one reviewer dispatch records one verdict (409 `chg_review_already_recorded`). `commit_sha` is ignored on any other story. |
280
+ | `review_complete` | Record that a review has been completed for a story. Required before verify. Under the signed profile, pass the `claim` from `custody_sign_claim`. On a story bound to a chg change (loopctl US-47.5), after the existing custody gates: only a key chg-server minted for the review — a strict descendant of the intake source's `chg_root_dispatch_id` — may record it (409 `chg_reviewer_required`, the root key included); `commit_sha` is REQUIRED and must be the sha of a submitted revision of the story's current change (422 `commit_sha_not_bound`); one reviewer dispatch records one verdict (409 `chg_review_already_recorded`); a key the intake source minted (`review_dispatch`, US-50.3) reviews only the revision it was minted for, while its dispatch is live (409 `chg_review_dispatch_mismatch`). `commit_sha` is ignored on any other story. |
281
281
 
282
282
  ### Verification Tools (orchestrator key)
283
283
 
@@ -538,13 +538,14 @@ The order to wire it up, the stage machine these tools move a story through, and
538
538
  | `place_dispatch` | **Place a queued story on a runner** (`POST /api/v1/runners/:runner_id/dispatches`): claims it under a freshly minted custody dispatch and pushes the work. The control-side trigger of the delivery loop. 409 `runner_declines_work` when the machine declares `draining` or `max_sessions` 0 — refused before the mint, so nothing was claimed; a retry carrying a `dispatch_id` loopctl already holds is re-sent anyway, because its claim is already standing. 409 `runner_exhausted` when the machine's subscription (its own, or one it shares an account with) is exhausted — also refused before the mint, and the body carries `usage_exhausted_until`, when it clears on its own. Required: `story_id`, `runner_id` (from `runner_pool`). Optional: `kind` (`implement`, the only kind this tool sends — `triage` is dispatchable on the contract but placement CLAIMS the story, which triage must not do; the server refuses any kind whose agent spec is not a `:build` with 422 `not_placeable_kind`, before anything is minted or claimed), `dispatch_id` (the idempotency key — generated when absent; pass the SAME one to retry rather than start a second session), `base_branch`, `wall_clock_seconds`, `max_turns`, and `branch` — **which you should not send**. Since runner contract 1.14.0 loopctl DERIVES the branch from the story number and an id fragment, behind a prefix the target runner declared it accepts (`branch_prefixes`, visible on `runner_pool`), which is a per-machine fact only the server can read. A branch you name is never rewritten, only judged, and it must satisfy three things: it must be a valid git ref name (422 `invalid_branch_name`, which also refuses a non-string such as `null`), it must start with one of that machine's declared prefixes (422 `branch_not_allowed`), and it must END WITH THIS STORY'S OWN SUFFIX (422 `branch_not_unique`) so that two stories on one repository can never be given one branch — you may choose the prefix, you may not drop the suffix. Nothing is claimed on any of them, and the fix is to drop the field. `base_branch` is judged as a git ref name too (422 `invalid_branch_name`): it reaches git on the runner just as `branch` does. It is NOT story-unique — every dispatch cutting from `master` is the normal case. A retry naming a different `branch` from the one this dispatch was already sent on is 422 `branch_conflict`: the branch is recorded at the first push and re-sent verbatim, because a session may be running on it right now, and a retry naming a different `base_branch` from the recorded one is 422 `base_branch_conflict`, because the merge gate judges against the recorded base. 409 `no_conforming_branch` is the machine's problem rather than the request's: it declares prefixes and none of them can produce a valid branch name carrying the story number and id fragment that keeps two stories off one branch, so nothing was claimed and an operator has to fix `branch_prefixes` on that box — the body echoes the declared prefixes. A retry carrying a `dispatch_id` loopctl already holds is never refused for either prefix reason: its claim is already standing, so the declaration only steers the name. The story object is NOT a parameter: loopctl builds it from its own rows and refuses a caller-supplied one. The story must be `pending` or `contracted` (a pending one is contracted by the placement), its dependencies met, with its stage at `queued`. A retry also moves the claim's deadline to now + its `wall_clock_seconds` + `DISPATCH_LEASE_GRACE_SECONDS` (never earlier than the one already sent), and 409 `dispatch_claim_ended` means the claim that `dispatch_id` was placed under has ended — nothing was pushed or written; place again with a new `dispatch_id`. Requires `LOOPCTL_USER_KEY`. |
539
539
  | `story_stage` | **Where a story is in the delivery machine** (`GET /api/v1/stories/:id/stage`): stage, `claim_epoch`, `lock_version`, `attempts`, the runner holding it, and the escalation reason when parked. `stage: null` means the loop has never touched it. This is how you watch a run, and the only way to see why a stage report was refused `stale_stage`. `escalation_reason` is untrusted session text. Required: `story_id`. |
540
540
  | `agent_outcomes` | **An agent spec's track record, per version** (`GET /api/v1/agent_specs/:spec_id/outcomes`, loopctl US-48.12): every runner dispatch ends in one outcome row keyed by its spec `{id, version}`, and this summarises one spec's rows recorded in the last `window_days` (default 30, at most 365), newest version first — `runs`, `ended`, `successes` (a build whose work merged, a triage verdict no human overrode, a verify verdict loopctl recorded, a reply draft stored `drafted`, a spec_tuner run whose draft loopctl judged `proposed`), `human_overrides`, `budget_exhausted` (sessions ended `wall_clock_exceeded` / `max_turns_exceeded`), each also as a rate, and `median_elapsed_s` / `median_turns` (null when no run carries one; turns come from the runner's session-end report, runner contract 1.27.0, so a run on an older runner has none). Every figure is from an event loopctl recorded, never session text. Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for a malformed `spec_id` or a `window_days` outside 1..365 (both also refused locally), 401 without a valid key; no role is refused. Required: `spec_id` (`triage`, `implement`, `reply_draft`, `verify`, `spec_tuner`). |
541
+ | `chg_ledger_summary` | **The chg audit questions, answered** (`GET /api/v1/chg_ledger/summary`, loopctl US-50.6): what the `/chg` dashboard shows, computed by the same functions, from the ledger rows the fleet's chg outboxes sent — `gate_outcomes` (per day and kind, counts per verdict), `fallbacks` (checks that ran mode `all`, the rate, the top reasons), `selection` (stats and misses: a chg check that passed on a commit whose gate failed), `phase_times` (hydrate, static, affected, tests, lock_wait), `flaky`, `runner_samples`, `review_outcomes` (merged PRs' findings by severity and disposition, and how many merged without a counted round, totalled over EVERY merged PR in range) and `attention` (changes flagged gap or stale and still flagged: current state, so `since` and `until` do not apply). Lists cap at 50 rows; a panel shed under load is the string `unavailable`. Optional: `repo`, `host` (review outcomes and flagged changes ignore it), `since` (ISO 8601, default 7 days before `until`), `until` (default now). 422 for a malformed timestamp, a `since` not before `until`, or a period over 90 days (all also refused locally); 401 without a valid key; no role is refused. Any tenant key: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. |
541
542
  | `change_binding_get` | **The chg changes bound to a story** (`GET /api/v1/stories/:id/changes`, loopctl US-47.7): every change a chg `submitted` event bound to the story, OLDEST FIRST so the current one is last, each with `repo`, `change_id`, `current`, `superseded_at`, `submitter_not_claimant`, `inserted_at`, and its APPLIED events in `event_seq` order (`event_seq`, `kind`, `revision`, `sha`, `occurred_at`, `applied_at`; never the event `data` payload). Bounded by the server, bounds in `meta` (`max_bindings`, `max_events_per_change`): the newest of each are kept, so the current binding is always listed, and `binding_count` / `applied_event_count` / `events_truncated` say when more exist. Any tenant key reads it (`role: :agent` with the hierarchy), so nothing is pinned: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 404 when the story is not your tenant's — another tenant's id answers exactly like an unknown one; 401 without a valid key; 400 for a superadmin key without `X-Impersonate-Tenant`; no role is refused. Required: `story_id` (refused locally if not a UUID). |
542
543
  | `resolve_escalation` | **Move an escalated story off `escalated`, as a human** (`POST /api/v1/stories/:id/stage/resolve`): `to` is `detected` (triage it again), `queued` (work it again), `done` or `failed`. `detected` is for a story triage escalated, such as `triage_verdict:verdict_invalid`. It is refused 409 `not_retriageable`, with what the story holds in `held`, for a story an implementer was assigned or worked. `queued` on a triage escalation skips triage. The other half of `escalate_story` — without it a parked story stays parked for ever. Requires `LOOPCTL_USER_KEY` on a key no dispatch minted: a session cannot resolve the escalation it raised. Optional: `reason`. |
543
544
  | `escalation_list` | **The escalation inbox** (`GET /api/v1/escalations`, loopctl US-48.11): every story of your tenant parked at `escalated`, newest escalation first, so a timed-out or failed implementation can be found and worked again. **Reads only** — `resolve_escalation` with `to: "queued"` is what works a row again. Each row: `story_id`, `project_id`, `escalated_at`, `edge`, `reason_class`, `spec` (`{id, version}` of the dispatch that parked it, or null), `dispatch_id`, and `escalation_reason`, which is untrusted session text: read `escalation_reason_fenced`. `reason_class` comes from the stage-machine edge, never from text: `budget_exhausted`, `session_failed`, `triage_escalated`, `gate_refused`, `operator_released`, `other`. A `budget_exhausted` row carries `run`: `elapsed_seconds`, `wall_clock_seconds`, `turns_used` against `max_turns` (the budget it was placed under), `branch`, `session_ended_reason`, `work_left_behind` (from the ledger and the runner's session-end report: `"true"` or `"false"` as the runner reported unpushed commits at exit, `"unknown"` when it did not say — a runner older than contract 1.27.0, or one that could not tell; `turns_used` is then null too). Optional: `reason_class`, `project_id` (UUID), `since` (ISO8601), `cursor` (a page's `next_cursor`, verbatim), `limit` (default 50, at most 100). Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for an unknown `reason_class`, a bad `since` or `limit`, or a foreign or tampered cursor; 422 for a malformed `project_id`; no role is refused. The MCP server adds `remedies` to the page, holding each present `reason_class`'s text once (`meaning`, `options`: which `resolve_escalation` target fits, in order, and `take_over`), and a `remedy` to every row: `see` (its `remedies` key), a `warning` when the change already merged, and `salvage` when the runner left unpushed commits. |
544
545
  | `escalation_playbook` | **What to do with a stuck story**, from finding it to closing it: what each `reason_class` means, which `resolve_escalation` target fits (`queued` run again, `detected` triage again, `done` accept, `failed` drop), and the steps to take a story over in this session: leave it escalated, do not `claim_story`, salvage the runner's branch when `run.work_left_behind` is `"true"`, fix it through the normal delivery loop with a PR that says `Fixes #<issue>`, then `resolve_escalation` `to: "done"` citing the PR. Optional: `reason_class`. Local: sends nothing, needs no key. Same text as the `stuck_story` prompt. |
545
546
  | `force_unclaim_story` | **Take a story back from the agent holding it** (`POST /api/v1/stories/:id/force-unclaim`). Resets it to `agent_status: pending` with `assigned_agent_id` cleared AND makes the delivery stage row follow the release back to `queued`. **A delivery story then goes to `escalated`, not back to the queue** (loopctl US-44.4): an operator taking a story back is a human decision, so a release that leaves the stage row at `queued` escalates it over `operator_released` in the same transaction, spending no attempt against the retry ceiling — it is not left in the queue behind the human's back. Put it back to work with `resolve_escalation` `to: queued`, which releases (a no-op by then) AND re-contracts. A story with no delivery stage row is simply left `pending`. A story parked at `claimed` with nobody on it is the residue of a compensation that did not complete, not what a refused dispatch normally leaves: placement releases the claim inline when a runner refuses, and the claim lease releases it unattended once `claimed_until` passes — reach for this to get it back now, or when both of those left it held. Requeues from any stage a claim holds; a stage no claim holds keeps its stage and is rebound to the new epoch; `done` and `failed` are untouched. For an ESCALATED story use `resolve_escalation` instead — that one releases AND re-contracts, so its `queued` really is placeable. Requires an orchestrator-ROLE key: the action is `exact_role: :orchestrator`, so a user or superadmin key is 403'd like any other non-member. Put it in `LOOPCTL_ORCH_KEY` (which is then the key sent, and a global `LOOPCTL_API_KEY` does not displace it) or, with no orchestrator key set, in `LOOPCTL_API_KEY`. The orchestrator key must be linked to a registered agent (400 otherwise) and the tenant must be human-anchored (403 `custody_tier_required` otherwise). Does not touch `verified_status`. Run again on an already-pending story it is still an operator's release: a row stranded behind the story's claim epoch is rebound, an in-flight row is requeued, and a row then at `queued` — including one already sitting there — is escalated over `operator_released`, as on the first run; a row already escalated, or anywhere else at that epoch, is left alone. Every 500 means the whole release rolled back and the story is still claimed: `audit_chain_append_failed` (the escalation's chain entry was refused) is a server-side condition a re-run meets again until an operator acts; `force_unclaim_failed` (the server log names the step) — call it again. A 422 means the release write itself was rejected. No request body. Required: `story_id` (refused locally if it is not a UUID). |
546
547
  | `merge_precondition` | **Run the merge gate over a story's real pull request** (`POST /api/v1/stories/:id/merge-precondition`). Both delivery gates run again over the diff that exists, plus custody, the 12-file / 1000-line hard bound, the head-has-not-moved check and the self-deploy exclusion; the story must be at stage `ci`. **Gate A reads what triage persisted, never the caller**: the lens verdicts recorded with the story's most recent triage, or a human's re-queue of a Gate A escalation — `gate_a_inputs` on the answer says which, and `missing` refuses with `gate_a_inputs_missing`. This tool sends no trio. Decisions: `allow` (recorded against the head; the only thing that licenses a merge), `refuse` (the story is escalated before this returns), `already_merged`, `head_moved`, `unevaluated` (503 with `Retry-After`). Requires an orchestrator- or user-ROLE key (`exact_role: [:orchestrator, :user]`, so an agent key is 403'd); `LOOPCTL_ORCH_KEY` is sent when set, else `LOOPCTL_API_KEY`. 403 `custody_tier_required` without a human anchor, 404 for an unknown story, 409 `change_protocol_enrolled` when the story's intake source is in mode `chg` (the PR route is closed; land with `chg submit` — decided before any GitHub read, nothing escalated), 422 when the story is not at `ci`. Required: `story_id` (refused locally if not a UUID) and `claim_epoch` (a non-negative integer, refused locally otherwise); optional `effect_proof`. |
547
- | `intake_source_enroll` | **Bind a GitHub repository to a work project and mint its webhook secret** (`POST /api/v1/intake/sources`) — the step that gives the delivery loop an input, and the row `place_dispatch` reads `repo` and `base_branch` from (its 409 `no_intake_source` means this has not been done; 409 `ambiguous_intake_source` means it has been done twice). **The secret is returned ONCE and can never be read again** — the column is encrypted at rest and redacted on the schema, so no other tool carries it and losing it costs a revoke, a re-enrolment and a reconfigured GitHub webhook. **This tool does not return it either:** a tool result lands in the transcript and the audit log, so it is written to the required `secret_file` with mode 0600 (the handling `runner_enroll` gives a runner credential) and the result carries the source row, the `webhook_url` and that path. The path is reserved before the request, so an existing file or an unwritable directory is refused with nothing enrolled, and any outcome that is not a clean creation withholds the response body — an unparsed 2xx body IS the secret. A 2xx carrying the source and the secret but no webhook path is RECOVERED rather than discarded (the path is derived from the source id, flagged `webhook_url_derived`), and an outcome that proves a source id but no usable secret REVOKES that source rather than leaving it holding the repository's unique slot. Then configure GitHub: Payload URL = the returned `webhook_url`, content type `application/json`, Secret = the contents of the file, and the **Issues** event only — `gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f config[content_type]=json -f config[secret]="$(cat <secret_file>)" -f 'events[]=issues'`. Every later delivery failure is the SAME 401 `invalid_signature` — unknown or revoked source, suspended tenant, missing or wrong signature, or a payload whose `repository.full_name` does not match — so the webhook's Recent Deliveries tab cannot tell you which. `base_branch` is set HERE: it defaults to `master` when the body does not name it, so name `main` for a repository created on GitHub since 2020 or every dispatch is cut from a trunk that does not exist. It is not nullable (a dispatch must name a branch), so null or blank is refused rather than falling back to the default, and `intake_source_update` changes it afterwards. Refusals: 403 `api_key_mint_forbidden` if your key was minted by a dispatch (this mints a credential belonging to no lineage, so only an unlineaged operator key may), 403 `custody_tier_required` on an agent-rooted tenant, 422 for a repository that is not `owner/name`, an ACTIVE source already binding it, a project that is missing / archived / not a work project, or a `target_epic_id` outside that project. `mode` is the merge route: `pr` (the default when omitted; the merge gate reads a pull request) or `chg` (Epic 47: the change protocol lands the repository's changes with `chg submit`, and `merge_precondition` refuses every story on the source with 409 `change_protocol_enrolled`); any other value, null included, is refused. A `chg` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND `chg_root_dispatch_id` in the same call — refused locally and 422 at the server without them — and a root that is not a parentless, unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid` (a child, a revoked or agent-role dispatch, another tenant's and an unknown id all alike). The change-events secret is write-only: no response and no tool result ever carries it. `required_checks` are the CI checks story verification judges a story's commit by, GitHub Actions job names, bounded in number and length by the server; `local-gate` is refused because whoever pushed posts it. Story verification judges a story's commit against the same `required_checks` in EITHER mode, satisfied only by a job of a push run of the story's branch; it first needs a GitHub credential for this tenant, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise, whatever the list holds); then a `pr` source that names none records `no_required_checks` and reads nothing, so naming them is how a pr source opts in, and a source that names some has its (tenant, repository) credential resolved before any GitHub read (`credential_unavailable` if there is none). Required: `repo_full_name`, `project_id`, `secret_file`. `triage_requires_ticket` decides which issues are triaged at all: false (the default), every issue the webhook delivers; true, only an issue HomeCareBilling filed from a support ticket (its single `#HCB-xxxxxxxx` Ticket line confirmed by the HomeCareBilling footer, which intake records as `ticket_id`), and every other issue stays an intake record with no story until it gains a ticket; anything but a boolean is refused. It filters on the format, it does not authenticate: anyone who can open an issue can type it. Optional: `base_branch`, `mode`, `required_checks`, `triage_requires_ticket`, `change_events_secret` / `change_events_secret_file`, `chg_root_dispatch_id`, and `target_epic_id` — **omitting the epic is not a neutral default**: with no epic every triaged report is escalated to a human and every record stays `pending_triage` until `intake_source_update` names one. Requires `LOOPCTL_USER_KEY`. |
548
+ | `intake_source_enroll` | **Bind a GitHub repository to a work project and mint its webhook secret** (`POST /api/v1/intake/sources`) — the step that gives the delivery loop an input, and the row `place_dispatch` reads `repo` and `base_branch` from (its 409 `no_intake_source` means this has not been done; 409 `ambiguous_intake_source` means it has been done twice). **The secret is returned ONCE and can never be read again** — the column is encrypted at rest and redacted on the schema, so no other tool carries it and losing it costs a revoke, a re-enrolment and a reconfigured GitHub webhook. **This tool does not return it either:** a tool result lands in the transcript and the audit log, so it is written to the required `secret_file` with mode 0600 (the handling `runner_enroll` gives a runner credential) and the result carries the source row, the `webhook_url` and that path. The path is reserved before the request, so an existing file or an unwritable directory is refused with nothing enrolled, and any outcome that is not a clean creation withholds the response body — an unparsed 2xx body IS the secret. A 2xx carrying the source and the secret but no webhook path is RECOVERED rather than discarded (the path is derived from the source id, flagged `webhook_url_derived`), and an outcome that proves a source id but no usable secret REVOKES that source rather than leaving it holding the repository's unique slot. Then configure GitHub: Payload URL = the returned `webhook_url`, content type `application/json`, Secret = the contents of the file, and the **Issues** and **Pull requests** events (a merged pull request queues a read of its `## Review findings` section) — `gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f config[content_type]=json -f config[secret]="$(cat <secret_file>)" -f 'events[]=issues' -f 'events[]=pull_request'`. Every later delivery failure is the SAME 401 `invalid_signature` — unknown or revoked source, suspended tenant, missing or wrong signature, or a payload whose `repository.full_name` does not match — so the webhook's Recent Deliveries tab cannot tell you which. `base_branch` is set HERE: it defaults to `master` when the body does not name it, so name `main` for a repository created on GitHub since 2020 or every dispatch is cut from a trunk that does not exist. It is not nullable (a dispatch must name a branch), so null or blank is refused rather than falling back to the default, and `intake_source_update` changes it afterwards. Refusals: 403 `api_key_mint_forbidden` if your key was minted by a dispatch (this mints a credential belonging to no lineage, so only an unlineaged operator key may), 403 `custody_tier_required` on an agent-rooted tenant, 422 for a repository that is not `owner/name`, an ACTIVE source already binding it, a project that is missing / archived / not a work project, or a `target_epic_id` outside that project. `mode` is the merge route: `pr` (the default when omitted; the merge gate reads a pull request) or `chg` (Epic 47: the change protocol lands the repository's changes with `chg submit`, and `merge_precondition` refuses every story on the source with 409 `change_protocol_enrolled`); any other value, null included, is refused. A `chg` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND `chg_root_dispatch_id` in the same call — refused locally and 422 at the server without them — and a root that is not a parentless, unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid` (a child, a revoked or agent-role dispatch, another tenant's and an unknown id all alike). The change-events secret is write-only: no response and no tool result ever carries it. `required_checks` are the CI checks story verification judges a story's commit by, GitHub Actions job names, bounded in number and length by the server; `local-gate` is refused because whoever pushed posts it. Story verification judges a story's commit against the same `required_checks` in EITHER mode, satisfied only by a job of a push run of the story's branch; it first needs a GitHub credential for this tenant, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise, whatever the list holds); then a `pr` source that names none records `no_required_checks` and reads nothing, so naming them is how a pr source opts in, and a source that names some has its (tenant, repository) credential resolved before any GitHub read (`credential_unavailable` if there is none). Required: `repo_full_name`, `project_id`, `secret_file`. `triage_requires_ticket` decides which issues are triaged at all: false (the default), every issue the webhook delivers; true, only an issue HomeCareBilling filed from a support ticket (its single `#HCB-xxxxxxxx` Ticket line confirmed by the HomeCareBilling footer, which intake records as `ticket_id`), and every other issue stays an intake record with no story until it gains a ticket; anything but a boolean is refused. It filters on the format, it does not authenticate: anyone who can open an issue can type it. Optional: `base_branch`, `mode`, `required_checks`, `triage_requires_ticket`, `change_events_secret` / `change_events_secret_file`, `chg_root_dispatch_id`, and `target_epic_id` — **omitting the epic is not a neutral default**: with no epic every triaged report is escalated to a human and every record stays `pending_triage` until `intake_source_update` names one. Requires `LOOPCTL_USER_KEY`. |
548
549
  | `intake_source_list` | List the tenant's intake sources (`GET /api/v1/intake/sources`): `id` (the webhook URL is `/api/v1/intake/github/<id>`), `project_id`, `repo_full_name`, `base_branch`, `mode` (`pr` or `chg`), `required_checks`, `triage_requires_ticket`, `chg_root_dispatch_id`, `target_epic_id`, `revoked_at`, timestamps. **The webhook secret is not here and is not anywhere**, and neither is a `chg` source's change-events secret — it is returned once by `intake_source_enroll`, so this is not how to recover one. Use it to find the source behind a 409 `no_intake_source` or `ambiguous_intake_source`, to check a repository's `base_branch` before placing work, and to identify a source left behind by an enrolment whose outcome was unknown. Optional: `include_revoked`. Requires `LOOPCTL_USER_KEY`; the only one of the four that does not also need a human-anchored tenant. |
549
550
  | `intake_source_update` | **Set where a source's work lands** (`PATCH /api/v1/intake/sources/:id`): `target_epic_id`, the epic triaged stories are created in, `base_branch`, the branch every dispatch for this repository is cut from, `mode` (`pr` or `chg`), a `chg` source's `change_events_secret` / `change_events_secret_file` and `chg_root_dispatch_id`, and `required_checks`, the checks story verification judges a story's commit by — once the tenant has a GitHub credential, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise), a source naming none records `no_required_checks` and reads nothing, and one naming some has its (tenant, repository) credential resolved before any GitHub read (`local-gate` is refused), and `triage_requires_ticket`, which issues are triaged at all (true: only issues HomeCareBilling filed from a support ticket; read at dispatch time, so it reaches stories already waiting at `detected`; null is refused). Presence decides — a field you do not name is left exactly as it was, and naming none of them is 422 `nothing_to_update`. `mode` has no cleared state either, and a null or unknown value is refused locally. Each implement dispatch records the base branch it was placed under, and the merge gate reads that; `mode` is not bound that way — the gate reads the source's current mode. **Switching to `chg` closes the PR route for every story on the source at once** (409 `change_protocol_enrolled`; land with `chg submit`), and the switch itself is 409 `pr_route_in_flight`, naming `story_ids`, while a story of the project sits at `ci` holding a merge allow it has not merged on. The resulting source must carry both credentials, named here or kept from an earlier `chg` stint (422 naming the missing one), and the root is re-checked on every write that leaves the source `chg`, a secret rotation or a base-branch edit included (422 `chg_root_invalid`; switching to `pr` is never blocked by it). Switching to `pr` KEEPS both and ignores them; on a `pr` source an explicit null clears either, on a `chg` source it is a 422. Naming either credential, or setting `mode` to `chg` (which re-activates the kept ones), needs the tenant's operator key, one no dispatch minted (403 `chg_registration_forbidden` otherwise — a key minted by a dispatch beneath yours is refused the same way), and the secret never comes back. **Do not send `target_epic_id: null` to mean "not changing this":** an explicit null is the only way to CLEAR the epic, which returns the source to escalating every report instead of filing a story. `base_branch` has no cleared state and a null there is refused locally. This is how a source already pointed at the wrong trunk is corrected — `intake_source_enroll` takes `base_branch` itself, so a `main` repository no longer needs a second call — and the remedy for a source with no epic — every record from it stays `pending_triage` and is retried until one is named, then they promote on the next run with nothing lost. Revoked sources are 404, not a no-op: revoking clears the target so the epic can be deleted, and repointing one would put that block back. 422 when the epic is not in this source's project. Required: `source_id` (refused locally if it is not a UUID — the server answers the same 404 for malformed and unknown). Requires `LOOPCTL_USER_KEY` and a human-anchored tenant. |
550
551
  | `intake_source_revoke` | **Revoke an intake source** (`DELETE /api/v1/intake/sources/:id`). The verb is DELETE and the action is a revoke: `revoked_at` is stamped, the row is kept, and `intake_source_list` still returns it with `include_revoked`; nothing already received is discarded. Afterwards every delivery to that URL is refused 401 `invalid_signature` exactly as a wrong secret is, so the GitHub webhook does not know it has been cut off and should be deleted on the repository too. Idempotent — a second revoke answers 200 with the original `revoked_at`. It frees the repository's uniqueness slot (the index is partial on not-yet-revoked), so a source with a lost secret, a wrong project or a typo'd repository is corrected by revoking and enrolling again; and it clears `target_epic_id`, which is what makes that epic deletable and is the remedy an epic-delete refusal names. Required: `source_id` (refused locally if it is not a UUID). Requires `LOOPCTL_USER_KEY` and a human-anchored tenant. |
package/index.js CHANGED
@@ -90,6 +90,7 @@ import { mcpVersion as mcpVersionRequest, packageVersion } from "./lib/mcp-versi
90
90
  import { revokeDispatch as revokeDispatchRequest } from "./lib/dispatch-revoke.js";
91
91
  import { changeBindingGet as changeBindingGetRequest } from "./lib/change-bindings.js";
92
92
  import { agentOutcomes } from "./lib/agent-outcomes.js";
93
+ import { chgLedgerSummary } from "./lib/chg-ledger-summary.js";
93
94
  import {
94
95
  clearGithubCredential as clearGithubCredentialRequest,
95
96
  githubCredential as githubCredentialRequest,
@@ -3504,6 +3505,18 @@ async function agentOutcomesRead(args) {
3504
3505
  );
3505
3506
  }
3506
3507
 
3508
+ // US-50.6: a READ of the chg ledger summary, `role: :agent` with the hierarchy — keyed as
3509
+ // agentOutcomesRead is, LOOPCTL_AGENT_KEY as an OVERRIDE so `resolveKey`'s order holds.
3510
+ async function chgLedgerSummaryRead(args) {
3511
+ const key = process.env.LOOPCTL_AGENT_KEY;
3512
+
3513
+ return toContent(
3514
+ await chgLedgerSummary(args, {
3515
+ apiCall: (method, path, body) => apiCall(method, path, body, key),
3516
+ }),
3517
+ );
3518
+ }
3519
+
3507
3520
  async function resolveEscalation(args) {
3508
3521
  return toContent(await resolveEscalationRequest(args, deliveryDeps()));
3509
3522
  }
@@ -5026,7 +5039,10 @@ const TOOLS = [
5026
5039
  "chg_root_dispatch_id — else 409 chg_reviewer_required (chg-server's root key is " +
5027
5040
  "refused too); commit_sha is REQUIRED and must be the sha of a submitted revision of " +
5028
5041
  "the story's current change, else 422 commit_sha_not_bound; and one reviewer dispatch " +
5029
- "records one verdict, a second is 409 chg_review_already_recorded. On any other story " +
5042
+ "records one verdict, a second is 409 chg_review_already_recorded. A key the intake " +
5043
+ "source minted (review_dispatch, loopctl US-50.3) reviews only the revision it was " +
5044
+ "minted for, and only while its dispatch is live, else 409 " +
5045
+ "chg_review_dispatch_mismatch. On any other story " +
5030
5046
  "commit_sha is ignored and not stored. On a PULL-REQUEST-ROUTE story (loopctl " +
5031
5047
  "US-48.18) only the key of the story's bound verify@1 dispatch may record the review, " +
5032
5048
  "else 409 pr_route_verifier_only — a user key included.",
@@ -8949,6 +8965,45 @@ const TOOLS = [
8949
8965
  required: ["spec_id"],
8950
8966
  },
8951
8967
  },
8968
+ {
8969
+ name: "chg_ledger_summary",
8970
+ description:
8971
+ "THE CHG AUDIT QUESTIONS, ANSWERED (GET /api/v1/chg_ledger/summary, loopctl US-50.6): " +
8972
+ "what the /chg dashboard shows, computed server-side by the same functions, from the " +
8973
+ "ledger rows the fleet's chg outboxes sent. Panels: `gate_outcomes` (per day and kind " +
8974
+ "`chg`/`gate`, counts per verdict), `fallbacks` (checks that ran mode all, the rate, " +
8975
+ "the top reasons), `selection` (stats, plus misses: a chg check that passed on a " +
8976
+ "commit whose gate failed), `phase_times` (hydrate, static, affected, tests, " +
8977
+ "lock_wait: rows, mean and max ms), `flaky`, `runner_samples`, `review_outcomes` " +
8978
+ "(merged PRs' findings by severity and disposition, and how many merged without a " +
8979
+ "counted review round), `attention` (changes flagged gap or stale). Lists are capped " +
8980
+ "at 50 rows. A panel whose read was shed under load is the string `unavailable`; " +
8981
+ "retry later, the others are unaffected.\n\n" +
8982
+ "Filters, all optional: `repo` (owner/name), `host` (a fleet host; review outcomes " +
8983
+ "and flagged changes carry none and ignore it), `since` (ISO 8601, inclusive; default " +
8984
+ "7 days before `until`), `until` (ISO 8601, exclusive; default now). Any key of the " +
8985
+ "tenant may read it (`role: :agent` with the hierarchy), so the key is the usual " +
8986
+ "order with LOOPCTL_AGENT_KEY as this tool's own: LOOPCTL_API_KEY when set, else " +
8987
+ "LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY. REFUSES: 422 for a timestamp that is not " +
8988
+ "ISO 8601, a `since` not before `until`, or a period over 90 days; 401 for no key or " +
8989
+ "one that does not authenticate; 429 when rate limited. No 403: every key role " +
8990
+ "clears the gate. Those 422 cases are refused locally too (status 0, nothing sent).",
8991
+ inputSchema: {
8992
+ type: "object",
8993
+ properties: {
8994
+ repo: { type: "string", description: "Only this repository, owner/name." },
8995
+ host: { type: "string", description: "Only rows from this fleet host." },
8996
+ since: {
8997
+ type: "string",
8998
+ description: "ISO 8601 start, inclusive. Default 7 days before `until`.",
8999
+ },
9000
+ until: {
9001
+ type: "string",
9002
+ description: "ISO 8601 end, exclusive. Default now. At most 90 days after `since`.",
9003
+ },
9004
+ },
9005
+ },
9006
+ },
8952
9007
  {
8953
9008
  name: "change_binding_get",
8954
9009
  description:
@@ -9234,11 +9289,14 @@ const TOOLS = [
9234
9289
  "THEN CONFIGURE GITHUB — the tool stops at the loopctl end and this is the other half. " +
9235
9290
  "On the repository: Settings > Webhooks > Add webhook, Payload URL = the `webhook_url` " +
9236
9291
  "returned, Content type = application/json, Secret = the contents of `secret_file`, and " +
9237
- "under 'Let me select individual events' tick ISSUES ONLY. The secret is the HMAC key " +
9292
+ "under 'Let me select individual events' tick ISSUES and PULL REQUESTS (a merged pull " +
9293
+ "request queues a read of its `## Review findings` section; every other pull-request " +
9294
+ "action is recorded as ignored). The secret is the HMAC key " +
9238
9295
  "GitHub signs the RAW body with as `X-Hub-Signature-256`; loopctl verifies it before " +
9239
9296
  "trusting a byte. In one command, without the secret ever passing through this " +
9240
9297
  "transcript: gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f " +
9241
- "config[content_type]=json -f config[secret]=\"$(cat <secret_file>)\" -f 'events[]=issues'\n\n" +
9298
+ "config[content_type]=json -f config[secret]=\"$(cat <secret_file>)\" -f 'events[]=issues' " +
9299
+ "-f 'events[]=pull_request'\n\n" +
9242
9300
  "EVERY delivery failure afterwards is the SAME 401 `invalid_signature` — an unknown or " +
9243
9301
  "revoked source, a suspended tenant, a missing or wrong signature, and a payload whose " +
9244
9302
  "`repository.full_name` does not match this source's repository. That is deliberate (a " +
@@ -10665,6 +10723,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
10665
10723
 
10666
10724
  case "agent_outcomes":
10667
10725
  return await agentOutcomesRead(args);
10726
+ case "chg_ledger_summary":
10727
+ return await chgLedgerSummaryRead(args);
10668
10728
 
10669
10729
  case "resolve_escalation":
10670
10730
  return await resolveEscalation(args);
@@ -0,0 +1,69 @@
1
+ /**
2
+ * `chg_ledger_summary` (loopctl US-50.6): the chg audit questions the /chg dashboard answers,
3
+ * for a session with no browser — `GET /api/v1/chg_ledger/summary`.
4
+ *
5
+ * Gate outcomes per day, the fallback rate and its reasons, selection quality and misses,
6
+ * time per gate phase, flaky tests, runner samples, merged-PR review outcomes, and changes
7
+ * flagged gap or stale; computed server-side by the same functions the page renders.
8
+ *
9
+ * A READ, `role: :agent` with the hierarchy, so any role's key clears the gate and nothing is
10
+ * pinned: the handler passes LOOPCTL_AGENT_KEY as an override, so `resolveKey`'s order holds
11
+ * (LOOPCTL_API_KEY when set, else LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY).
12
+ */
13
+
14
+ export const MAX_PERIOD_DAYS = 90;
15
+
16
+ const DAY_MS = 86_400_000;
17
+
18
+ function refuse(body) {
19
+ return { error: true, status: 0, body };
20
+ }
21
+
22
+ function parseTime(value) {
23
+ if (typeof value !== "string" || value === "") return null;
24
+ const ms = Date.parse(value);
25
+ return Number.isNaN(ms) ? NaN : ms;
26
+ }
27
+
28
+ /** `GET /api/v1/chg_ledger/summary`, with the optional `repo`, `host`, `since`, `until`. */
29
+ export async function chgLedgerSummary(args = {}, { apiCall, now = Date.now } = {}) {
30
+ const { repo, host, since, until } = args;
31
+
32
+ for (const [name, value] of [
33
+ ["repo", repo],
34
+ ["host", host],
35
+ ]) {
36
+ if (value !== undefined && value !== null && typeof value !== "string") {
37
+ return refuse(`\`${name}\` must be a string.`);
38
+ }
39
+ }
40
+
41
+ const sinceMs = parseTime(since);
42
+ const untilMs = parseTime(until);
43
+
44
+ if (Number.isNaN(sinceMs)) return refuse("`since` must be an ISO 8601 timestamp.");
45
+ if (Number.isNaN(untilMs)) return refuse("`until` must be an ISO 8601 timestamp.");
46
+
47
+ // Mirrors the server's defaults only to refuse locally what it would refuse anyway; the
48
+ // server stays the judge.
49
+ const end = untilMs ?? now();
50
+ const start = sinceMs ?? end - 7 * DAY_MS;
51
+
52
+ if (start >= end) return refuse("`since` must be before `until`.");
53
+ if (end - start > MAX_PERIOD_DAYS * DAY_MS) {
54
+ return refuse(`The period may be at most ${MAX_PERIOD_DAYS} days (since to until).`);
55
+ }
56
+
57
+ const qs = new URLSearchParams();
58
+ for (const [name, value] of [
59
+ ["repo", repo],
60
+ ["host", host],
61
+ ["since", since],
62
+ ["until", until],
63
+ ]) {
64
+ if (typeof value === "string" && value !== "") qs.set(name, value);
65
+ }
66
+
67
+ const query = qs.toString();
68
+ return apiCall("GET", `/api/v1/chg_ledger/summary${query ? `?${query}` : ""}`, null);
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.13.1",
3
+ "version": "3.14.1",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",