loopctl-mcp-server 3.15.0 → 3.17.0
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 +5 -3
- package/index.js +109 -11
- package/lib/chg-findings.js +76 -0
- package/lib/intake-sources.js +45 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -538,16 +538,18 @@ 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)
|
|
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), `attention` (changes flagged gap or stale and still flagged: current state, so `since` and `until` do not apply) and `findings` (the feedback loop's findings: `by_state` and `by_kind` counts and the escalated ones; current state, only `repo` applies). 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`. |
|
|
542
|
+
| `chg_findings` | **What the chg feedback loop is working on** (`GET /api/v1/chg_findings`, loopctl US-51.6): the problems the nightly sweep derived from the chg ledger and filed as GitHub issues for the delivery loop to fix (`selection_miss`, `flaky_test`, `missing_review`, `stuck_change`, `source_silent`), newest sighting first, each with its `state` (queued, filed, fixed, closed, escalated), `occurrences`, `fix_attempts`, `loop_depth`, `cycle`, `issue_url` and `escalated_reason`. Optional: `state`, `kind`, `repo`, `limit` (default 50, at most 200). 422 for an unknown `state` or `kind` or a `limit` out of range (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`. |
|
|
543
|
+
| `chg_finding_clear` | **Send an escalated finding round the loop again** (`POST /api/v1/chg_findings/:id/clear`, loopctl US-51.6): back to `queued`, fix attempts reset, issue number dropped, so the next sweep files a fresh issue; the escalated issue stays open for you to close. Audited (`chg_finding_cleared`). Required: `finding_id`. 409 `not_escalated` for any other state; 404 for a finding the tenant does not hold; 403 for a non-user key or a tenant with no human anchor. Requires `LOOPCTL_USER_KEY`, used exactly. |
|
|
542
544
|
| `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). |
|
|
543
545
|
| `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`. |
|
|
544
546
|
| `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. |
|
|
545
547
|
| `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. |
|
|
546
548
|
| `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). |
|
|
547
549
|
| `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`. |
|
|
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 / the wrong kind for the mode, 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`), both on a work project; or `ledger` (loopctl #1047), which enrols a repository that has no work project for the chg ledger alone: `project_id` is then an active KB scope (`create_kb_scope`), the source is never a dispatch binding (`place_dispatch` and candidate selection skip it), and GitHub deliveries to it are refused. Any other value, null included, is refused. **Sending is not routing:** the two chg credentials authenticate the ledger and change-event endpoints in every mode, so a `pr` source holding them sends its ledger too and stays `pr` — its events are recorded and move no story. A `chg` or `ledger` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND `
|
|
550
|
+
| `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 / the wrong kind for the mode, 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`), both on a work project; or `ledger` (loopctl #1047), which enrols a repository that has no work project for the chg ledger alone: `project_id` is then an active KB scope (`create_kb_scope`), the source is never a dispatch binding (`place_dispatch` and candidate selection skip it), and GitHub deliveries to it are refused. Any other value, null included, is refused. **Sending is not routing:** the two chg credentials authenticate the ledger and change-event endpoints in every mode, so a `pr` source holding them sends its ledger too and stays `pr` — its events are recorded and move no story. A `chg` or `ledger` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND a root in the same call — `mint_chg_root: true` (preferred: loopctl mints a keyless, agentless root in the same write and returns its id) or `chg_root_dispatch_id` — refused locally and 422 at the server without them, and 422 with both. A root minted with `dispatch` takes its agent's one orchestrator-key slot, so it is 422 when that agent already holds a live key; the expiry sweep never revokes the row of a root a live source names. A named root that is not a parentless, unrevoked, orchestrator-role dispatch of this tenant with more than 300 s left before it expires 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` or `mint_chg_root`, 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`. |
|
|
549
551
|
| `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`, `chg` or `ledger`), `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. |
|
|
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` on a work project, `ledger` on a KB scope; a switch across project kinds is 422), the `change_events_secret` / `change_events_secret_file` and `chg_root_dispatch_id` that authenticate the source's chg ledger and change events (on a `pr` source they let chg send the ledger while the source stays `pr` and its merge gate still reads the PR — do not switch to `chg` for that), 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
|
|
552
|
+
| `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` on a work project, `ledger` on a KB scope; a switch across project kinds is 422), the `change_events_secret` / `change_events_secret_file` and `chg_root_dispatch_id` that authenticate the source's chg ledger and change events (or `mint_chg_root: true`, which has loopctl mint a new keyless root in the write: the fix for a source with no root or a revoked one, 422 beside a named root) (on a `pr` source they let chg send the ledger while the source stays `pr` and its merge gate still reads the PR — do not switch to `chg` for that), 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`, also for a named root with 300 s or less left; switching to `pr` is never blocked by it). Switching to `pr` KEEPS both and they stay LIVE: the sender's ledger and its new changes' events are still accepted (recorded, routing nothing), while an event for a change the `chg` route already acted on is 401 until the source is `chg` again, so send an explicit null to refuse the sender; on a `pr` source an explicit null clears either, on a `chg` or `ledger` source it is a 422. Naming either credential, or setting `mode` to `chg` or `ledger` (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. |
|
|
551
553
|
| `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. |
|
|
552
554
|
|
|
553
555
|
### Dispatch & Chain of Custody (v2) Tools
|
package/index.js
CHANGED
|
@@ -91,6 +91,7 @@ import { revokeDispatch as revokeDispatchRequest } from "./lib/dispatch-revoke.j
|
|
|
91
91
|
import { changeBindingGet as changeBindingGetRequest } from "./lib/change-bindings.js";
|
|
92
92
|
import { agentOutcomes } from "./lib/agent-outcomes.js";
|
|
93
93
|
import { chgLedgerSummary } from "./lib/chg-ledger-summary.js";
|
|
94
|
+
import { chgFindings, chgFindingClear } from "./lib/chg-findings.js";
|
|
94
95
|
import {
|
|
95
96
|
clearGithubCredential as clearGithubCredentialRequest,
|
|
96
97
|
githubCredential as githubCredentialRequest,
|
|
@@ -3517,6 +3518,22 @@ async function chgLedgerSummaryRead(args) {
|
|
|
3517
3518
|
);
|
|
3518
3519
|
}
|
|
3519
3520
|
|
|
3521
|
+
// US-51.6: the findings list is a READ keyed as chgLedgerSummaryRead is; clearing one is a
|
|
3522
|
+
// person's act and takes the EXACT user key through runnerDeps().
|
|
3523
|
+
async function chgFindingsRead(args) {
|
|
3524
|
+
const key = process.env.LOOPCTL_AGENT_KEY;
|
|
3525
|
+
|
|
3526
|
+
return toContent(
|
|
3527
|
+
await chgFindings(args, {
|
|
3528
|
+
apiCall: (method, path, body) => apiCall(method, path, body, key),
|
|
3529
|
+
}),
|
|
3530
|
+
);
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3533
|
+
async function chgFindingClearCall(args) {
|
|
3534
|
+
return toContent(await chgFindingClear(args, runnerDeps()));
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3520
3537
|
async function resolveEscalation(args) {
|
|
3521
3538
|
return toContent(await resolveEscalationRequest(args, deliveryDeps()));
|
|
3522
3539
|
}
|
|
@@ -9004,6 +9021,61 @@ const TOOLS = [
|
|
|
9004
9021
|
},
|
|
9005
9022
|
},
|
|
9006
9023
|
},
|
|
9024
|
+
{
|
|
9025
|
+
name: "chg_findings",
|
|
9026
|
+
description:
|
|
9027
|
+
"THE CHG FEEDBACK LOOP'S FINDINGS (GET /api/v1/chg_findings, loopctl US-51.6): the " +
|
|
9028
|
+
"problems the nightly sweep derived from the chg ledger and files as GitHub issues for " +
|
|
9029
|
+
"the delivery loop to fix — `selection_miss`, `flaky_test`, `missing_review`, " +
|
|
9030
|
+
"`stuck_change`, `source_silent` — newest sighting first. Each row: `id`, `kind`, " +
|
|
9031
|
+
"`fingerprint`, `repo`, `state` (queued, filed, fixed, closed, escalated), " +
|
|
9032
|
+
"`occurrences`, `fix_attempts`, `loop_depth`, `cycle`, `issue_number`, `issue_url`, " +
|
|
9033
|
+
"`escalated_reason` and the timestamps.\n\n" +
|
|
9034
|
+
"Filters, all optional: `state`, `kind`, `repo` (owner/name, any case), `limit` " +
|
|
9035
|
+
"(default 50, at most 200). Any key of the tenant may read it (`role: :agent` with the " +
|
|
9036
|
+
"hierarchy): LOOPCTL_API_KEY when set, else LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY. " +
|
|
9037
|
+
"REFUSES: 422 for an unknown `state` or `kind` or a `limit` outside 1..200 (also " +
|
|
9038
|
+
"refused locally, status 0, nothing sent); 401 for no key or one that does not " +
|
|
9039
|
+
"authenticate. No 403: every key role clears the gate.",
|
|
9040
|
+
inputSchema: {
|
|
9041
|
+
type: "object",
|
|
9042
|
+
properties: {
|
|
9043
|
+
state: {
|
|
9044
|
+
type: "string",
|
|
9045
|
+
enum: ["queued", "filed", "fixed", "closed", "escalated"],
|
|
9046
|
+
description: "Only findings in this state.",
|
|
9047
|
+
},
|
|
9048
|
+
kind: {
|
|
9049
|
+
type: "string",
|
|
9050
|
+
enum: ["selection_miss", "flaky_test", "missing_review", "stuck_change", "source_silent"],
|
|
9051
|
+
description: "Only findings of this kind.",
|
|
9052
|
+
},
|
|
9053
|
+
repo: { type: "string", description: "Only findings filed on this repository." },
|
|
9054
|
+
limit: { type: "integer", description: "Default 50, at most 200." },
|
|
9055
|
+
},
|
|
9056
|
+
},
|
|
9057
|
+
},
|
|
9058
|
+
{
|
|
9059
|
+
name: "chg_finding_clear",
|
|
9060
|
+
description:
|
|
9061
|
+
"SEND AN ESCALATED CHG FINDING ROUND THE LOOP AGAIN (POST " +
|
|
9062
|
+
"/api/v1/chg_findings/:id/clear, loopctl US-51.6). The finding goes back to `queued` " +
|
|
9063
|
+
"with its fix attempts reset and its issue number dropped, so the next nightly sweep " +
|
|
9064
|
+
"files a fresh issue. The escalated issue is left open for you to close. Audited as " +
|
|
9065
|
+
"`chg_finding_cleared`. Use it after a person has looked at why the loop escalated " +
|
|
9066
|
+
"(depth 2, or two fixes that did not hold) and decided the loop should try again. " +
|
|
9067
|
+
"REFUSES: 409 not_escalated for a finding in any other state; 404 for a finding the " +
|
|
9068
|
+
"tenant does not hold; 403 for any key that is not user-role; 403 " +
|
|
9069
|
+
"custody_tier_required on a tenant with no human anchor. Requires LOOPCTL_USER_KEY " +
|
|
9070
|
+
"(user role), used exactly; refused locally when it is not set.",
|
|
9071
|
+
inputSchema: {
|
|
9072
|
+
type: "object",
|
|
9073
|
+
properties: {
|
|
9074
|
+
finding_id: { type: "string", description: "The finding's id, from chg_findings." },
|
|
9075
|
+
},
|
|
9076
|
+
required: ["finding_id"],
|
|
9077
|
+
},
|
|
9078
|
+
},
|
|
9007
9079
|
{
|
|
9008
9080
|
name: "change_binding_get",
|
|
9009
9081
|
description:
|
|
@@ -9324,9 +9396,11 @@ const TOOLS = [
|
|
|
9324
9396
|
"number. `chg` (Epic 47): the change protocol lands the repository's changes with " +
|
|
9325
9397
|
"`chg submit`, and merge_precondition refuses every story on the source with 409 " +
|
|
9326
9398
|
"`change_protocol_enrolled`. A `chg` enrolment needs `change_events_secret` (or " +
|
|
9327
|
-
"`change_events_secret_file`) AND
|
|
9328
|
-
"
|
|
9329
|
-
"
|
|
9399
|
+
"`change_events_secret_file`) AND a root in the same call — `mint_chg_root: true` " +
|
|
9400
|
+
"(preferred: loopctl mints a keyless root in the same write) or `chg_root_dispatch_id` " +
|
|
9401
|
+
"— refused here, and 422 at the server, without them; a named root that is not a " +
|
|
9402
|
+
"parentless, unrevoked, orchestrator-role dispatch of this tenant with more than 300 s " +
|
|
9403
|
+
"left is 422 `chg_root_invalid`. The " +
|
|
9330
9404
|
"change-events secret is write-only: no response and no tool result ever carries it. " +
|
|
9331
9405
|
"Any other mode, null included, is refused.\n\n" +
|
|
9332
9406
|
"SENDING IS NOT ROUTING (loopctl #1047). The two chg credentials authenticate the " +
|
|
@@ -9406,12 +9480,21 @@ const TOOLS = [
|
|
|
9406
9480
|
chg_root_dispatch_id: {
|
|
9407
9481
|
type: "string",
|
|
9408
9482
|
description:
|
|
9409
|
-
"
|
|
9410
|
-
"
|
|
9411
|
-
"
|
|
9412
|
-
"
|
|
9413
|
-
"or agent-role dispatch, another tenant's or an unknown id — is
|
|
9414
|
-
"`chg_root_invalid`, all alike.",
|
|
9483
|
+
"Alternative to `mint_chg_root` (prefer that). With `mode: chg` or `mode: ledger`, " +
|
|
9484
|
+
"and with the secret on a `pr` source, a root is required (a signed request is " +
|
|
9485
|
+
"refused without both). A PARENTLESS, UNREVOKED, ORCHESTRATOR-role dispatch (UUID) " +
|
|
9486
|
+
"of this tenant with more than 300 s left before it expires. Anything else — a " +
|
|
9487
|
+
"child, a revoked or agent-role dispatch, another tenant's or an unknown id — is " +
|
|
9488
|
+
"refused 422 `chg_root_invalid`, all alike. Not with `mint_chg_root`.",
|
|
9489
|
+
},
|
|
9490
|
+
mint_chg_root: {
|
|
9491
|
+
type: "boolean",
|
|
9492
|
+
description:
|
|
9493
|
+
"true: loopctl mints the source's chg root in this write, keyless and agentless, " +
|
|
9494
|
+
"and returns its id as `chg_root_dispatch_id`. The way to get a root: one minted " +
|
|
9495
|
+
"with `dispatch` takes its agent's one orchestrator-key slot (422 when the agent " +
|
|
9496
|
+
"already holds one). The expiry sweep never revokes a root a live source names. " +
|
|
9497
|
+
"Not with `chg_root_dispatch_id` (422). Needs the operator key, like the secret.",
|
|
9415
9498
|
},
|
|
9416
9499
|
required_checks: {
|
|
9417
9500
|
type: "array",
|
|
@@ -9511,7 +9594,8 @@ const TOOLS = [
|
|
|
9511
9594
|
"write that leaves the source `chg` — a secret rotation or a base-branch edit included " +
|
|
9512
9595
|
"— and whenever one is named (422 `chg_root_invalid` unless it is a parentless, " +
|
|
9513
9596
|
"unrevoked, orchestrator-role dispatch of this tenant; a revoked root blocks every such " +
|
|
9514
|
-
"write until a live one is named
|
|
9597
|
+
"write until a live one is named or `mint_chg_root: true` mints one, while switching " +
|
|
9598
|
+
"to `pr` is never blocked). Switching " +
|
|
9515
9599
|
"to `pr` KEEPS both and they stay LIVE: the sender's ledger and its new changes' events " +
|
|
9516
9600
|
"are still accepted (recorded, routing nothing), while an event for a change the `chg` " +
|
|
9517
9601
|
"route already acted on is 401 until the source is `chg` again. Send an explicit null " +
|
|
@@ -9587,7 +9671,17 @@ const TOOLS = [
|
|
|
9587
9671
|
"The parentless, unrevoked, orchestrator-role dispatch of this tenant chg-server's " +
|
|
9588
9672
|
"key was minted from; anything else is 422 `chg_root_invalid`, and the root a `chg` " +
|
|
9589
9673
|
"or `ledger` source keeps is re-checked on every write to it. Null clears it on a " +
|
|
9590
|
-
"`pr` source (422 on a `chg` or `ledger` one). Omit to leave it alone."
|
|
9674
|
+
"`pr` source (422 on a `chg` or `ledger` one). Omit to leave it alone. A named " +
|
|
9675
|
+
"root needs more than 300 s left before it expires. Prefer `mint_chg_root`.",
|
|
9676
|
+
},
|
|
9677
|
+
mint_chg_root: {
|
|
9678
|
+
type: "boolean",
|
|
9679
|
+
description:
|
|
9680
|
+
"true: loopctl mints a NEW keyless, agentless chg root in this write and the source " +
|
|
9681
|
+
"names it from then on (the result's `chg_root_dispatch_id`). The fix for a source " +
|
|
9682
|
+
"with no root, or with a revoked one. A root minted with `dispatch` takes its " +
|
|
9683
|
+
"agent's one orchestrator-key slot. The expiry sweep never revokes a root a live " +
|
|
9684
|
+
"source names. Not with `chg_root_dispatch_id` (422). Needs the operator key.",
|
|
9591
9685
|
},
|
|
9592
9686
|
required_checks: {
|
|
9593
9687
|
type: "array",
|
|
@@ -10752,6 +10846,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
10752
10846
|
return await agentOutcomesRead(args);
|
|
10753
10847
|
case "chg_ledger_summary":
|
|
10754
10848
|
return await chgLedgerSummaryRead(args);
|
|
10849
|
+
case "chg_findings":
|
|
10850
|
+
return await chgFindingsRead(args);
|
|
10851
|
+
case "chg_finding_clear":
|
|
10852
|
+
return await chgFindingClearCall(args);
|
|
10755
10853
|
|
|
10756
10854
|
case "resolve_escalation":
|
|
10757
10855
|
return await resolveEscalation(args);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chg_findings` and `chg_finding_clear` (loopctl US-51.6): the chg feedback loop's findings —
|
|
3
|
+
* `GET /api/v1/chg_findings` and `POST /api/v1/chg_findings/:id/clear`.
|
|
4
|
+
*
|
|
5
|
+
* A finding is a problem the nightly sweep derived from the chg ledger (a selection miss, a
|
|
6
|
+
* flaky test, a merge with no review, a stuck change, a silent ledger sender), filed as a
|
|
7
|
+
* GitHub issue that the delivery loop then fixes.
|
|
8
|
+
*
|
|
9
|
+
* The list is a READ, `role: :agent` with the hierarchy, so the handler passes
|
|
10
|
+
* LOOPCTL_AGENT_KEY as an override and `resolveKey`'s order holds. Clearing an ESCALATED
|
|
11
|
+
* finding sends it round the loop again, so it is `role: :user` on a human-anchored tenant and
|
|
12
|
+
* takes the EXACT user key, like the runner tools.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const STATES = ["queued", "filed", "fixed", "closed", "escalated"];
|
|
16
|
+
export const KINDS = [
|
|
17
|
+
"selection_miss",
|
|
18
|
+
"flaky_test",
|
|
19
|
+
"missing_review",
|
|
20
|
+
"stuck_change",
|
|
21
|
+
"source_silent",
|
|
22
|
+
];
|
|
23
|
+
export const LIST_CAP = 200;
|
|
24
|
+
|
|
25
|
+
export const MISSING_USER_KEY =
|
|
26
|
+
"No user-role API key configured. Set LOOPCTL_USER_KEY to a user-role key to clear a chg " +
|
|
27
|
+
"finding: clearing sends an escalated problem back to the loop, so it is a person's act and " +
|
|
28
|
+
"the endpoint refuses agent and orchestrator keys.";
|
|
29
|
+
|
|
30
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
31
|
+
|
|
32
|
+
function refuse(body) {
|
|
33
|
+
return { error: true, status: 0, body };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `GET /api/v1/chg_findings`, with the optional `state`, `kind`, `repo`, `limit`. */
|
|
37
|
+
export async function chgFindings(args = {}, { apiCall } = {}) {
|
|
38
|
+
const { state, kind, repo, limit } = args;
|
|
39
|
+
|
|
40
|
+
if (state !== undefined && state !== null && !STATES.includes(state)) {
|
|
41
|
+
return refuse(`\`state\` must be one of ${STATES.join(", ")}.`);
|
|
42
|
+
}
|
|
43
|
+
if (kind !== undefined && kind !== null && !KINDS.includes(kind)) {
|
|
44
|
+
return refuse(`\`kind\` must be one of ${KINDS.join(", ")}.`);
|
|
45
|
+
}
|
|
46
|
+
if (repo !== undefined && repo !== null && typeof repo !== "string") {
|
|
47
|
+
return refuse("`repo` must be a string.");
|
|
48
|
+
}
|
|
49
|
+
if (
|
|
50
|
+
limit !== undefined &&
|
|
51
|
+
limit !== null &&
|
|
52
|
+
!(Number.isInteger(limit) && limit >= 1 && limit <= LIST_CAP)
|
|
53
|
+
) {
|
|
54
|
+
return refuse(`\`limit\` must be an integer from 1 to ${LIST_CAP}.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const qs = new URLSearchParams();
|
|
58
|
+
if (typeof state === "string") qs.set("state", state);
|
|
59
|
+
if (typeof kind === "string") qs.set("kind", kind);
|
|
60
|
+
if (typeof repo === "string" && repo !== "") qs.set("repo", repo);
|
|
61
|
+
if (Number.isInteger(limit)) qs.set("limit", String(limit));
|
|
62
|
+
|
|
63
|
+
const query = qs.toString();
|
|
64
|
+
return apiCall("GET", `/api/v1/chg_findings${query ? `?${query}` : ""}`, null);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `POST /api/v1/chg_findings/:id/clear` with the exact user key. */
|
|
68
|
+
export async function chgFindingClear({ finding_id } = {}, { userKey, apiCall } = {}) {
|
|
69
|
+
if (!userKey) return refuse(MISSING_USER_KEY);
|
|
70
|
+
|
|
71
|
+
if (typeof finding_id !== "string" || !UUID.test(finding_id)) {
|
|
72
|
+
return refuse("`finding_id` is required: the finding's UUID, from chg_findings.");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return apiCall("POST", `/api/v1/chg_findings/${encodeURIComponent(finding_id)}/clear`, {});
|
|
76
|
+
}
|
package/lib/intake-sources.js
CHANGED
|
@@ -90,6 +90,12 @@
|
|
|
90
90
|
* `chg_root_dispatch_id`, the parentless orchestrator-role dispatch chg-server's key was minted
|
|
91
91
|
* from (`422 chg_root_invalid` for anything else, another tenant's included).
|
|
92
92
|
*
|
|
93
|
+
* `mint_chg_root: true` in place of a root id has loopctl insert the root itself, keyless and
|
|
94
|
+
* agentless, in the source's own write. It is the way to get one: a root minted with `dispatch`
|
|
95
|
+
* takes its agent's one orchestrator-key slot (422 when the agent already holds a live key),
|
|
96
|
+
* and the expiry sweep keeps the ROW of a root a live source names, whichever way it was made.
|
|
97
|
+
* A named root must have more than 300 s left before it expires.
|
|
98
|
+
*
|
|
93
99
|
* The secret is WRITE-ONLY on both sides: the server never serialises it, and `publicSource`
|
|
94
100
|
* below never names it, so no tool result carries it. A tool INPUT is recorded in the
|
|
95
101
|
* transcript too, so `change_events_secret_file` is offered beside it: the tool reads the
|
|
@@ -248,6 +254,32 @@ export async function chgCredentials(args, { clearable, fs = defaultFs, homedir
|
|
|
248
254
|
}
|
|
249
255
|
}
|
|
250
256
|
|
|
257
|
+
// `mint_chg_root: true` has loopctl insert a keyless, agentless root in the same write. It is
|
|
258
|
+
// the way to get a root: one minted with `dispatch` takes its agent's one orchestrator-key
|
|
259
|
+
// slot. Only `true` is sent; `false` is the same as leaving it out.
|
|
260
|
+
const mint = args.mint_chg_root;
|
|
261
|
+
|
|
262
|
+
if (mint !== undefined) {
|
|
263
|
+
if (typeof mint !== "boolean") {
|
|
264
|
+
return {
|
|
265
|
+
refusal: refuse("`mint_chg_root` must be true (mint a root in this write) or left out."),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (mint === true) {
|
|
270
|
+
if (root !== undefined) {
|
|
271
|
+
return {
|
|
272
|
+
refusal: refuse(
|
|
273
|
+
"Send `chg_root_dispatch_id` OR `mint_chg_root: true`, not both; the server " +
|
|
274
|
+
"answers 422. Prefer `mint_chg_root`.",
|
|
275
|
+
),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fields.mint_chg_root = true;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
251
283
|
return { fields };
|
|
252
284
|
}
|
|
253
285
|
|
|
@@ -295,18 +327,19 @@ async function readSecretFile(secretFile, { fs, homedir }) {
|
|
|
295
327
|
function chgEnrolmentRefusal(mode, fields) {
|
|
296
328
|
if (!CREDENTIALED_MODES.includes(mode)) return null;
|
|
297
329
|
|
|
298
|
-
const missing = [
|
|
299
|
-
|
|
300
|
-
)
|
|
330
|
+
const missing = [];
|
|
331
|
+
if (fields.change_events_secret === undefined) missing.push("`change_events_secret`");
|
|
332
|
+
if (fields.chg_root_dispatch_id === undefined && fields.mint_chg_root !== true) {
|
|
333
|
+
missing.push("`mint_chg_root: true` (or `chg_root_dispatch_id`)");
|
|
334
|
+
}
|
|
301
335
|
|
|
302
336
|
if (missing.length === 0) return null;
|
|
303
337
|
|
|
304
338
|
return refuse(
|
|
305
|
-
`\`mode: ${mode}\` needs ${missing.
|
|
306
|
-
"
|
|
307
|
-
"
|
|
308
|
-
"
|
|
309
|
-
"events with (`change_events_secret_file` keeps it out of the transcript).",
|
|
339
|
+
`\`mode: ${mode}\` needs ${missing.join(" and ")} in the same call; the server answers ` +
|
|
340
|
+
"422 without them. `mint_chg_root: true` has loopctl mint the source's root, keyless, " +
|
|
341
|
+
"in the same write. The secret is the HMAC key the sender signs with " +
|
|
342
|
+
"(`change_events_secret_file` keeps it out of the transcript).",
|
|
310
343
|
);
|
|
311
344
|
}
|
|
312
345
|
|
|
@@ -426,6 +459,7 @@ export async function enrollIntakeSource(
|
|
|
426
459
|
change_events_secret,
|
|
427
460
|
change_events_secret_file,
|
|
428
461
|
chg_root_dispatch_id,
|
|
462
|
+
mint_chg_root,
|
|
429
463
|
} = {},
|
|
430
464
|
{ userKey, apiCall, baseUrl, fs = defaultFs, homedir = os.homedir() } = {},
|
|
431
465
|
) {
|
|
@@ -487,7 +521,7 @@ export async function enrollIntakeSource(
|
|
|
487
521
|
|
|
488
522
|
// The `chg` credentials (US-47.2), resolved and judged before a secret file is reserved.
|
|
489
523
|
const chg = await chgCredentials(
|
|
490
|
-
{ change_events_secret, change_events_secret_file, chg_root_dispatch_id },
|
|
524
|
+
{ change_events_secret, change_events_secret_file, chg_root_dispatch_id, mint_chg_root },
|
|
491
525
|
{ clearable: false, fs, homedir },
|
|
492
526
|
);
|
|
493
527
|
if (chg.refusal) return chg.refusal;
|
|
@@ -762,7 +796,8 @@ export async function updateIntakeSource(
|
|
|
762
796
|
"Nothing to update. Name at least one of `target_epic_id` (null clears it), " +
|
|
763
797
|
"`base_branch`, `mode`, `required_checks`, `triage_requires_ticket`, " +
|
|
764
798
|
"`change_events_secret` (or " +
|
|
765
|
-
"`change_events_secret_file`) or `
|
|
799
|
+
"`change_events_secret_file`), `chg_root_dispatch_id` or `mint_chg_root`. A body " +
|
|
800
|
+
"carrying none of them " +
|
|
766
801
|
"is refused 422 `nothing_to_update`, because a field you do not send is left exactly " +
|
|
767
802
|
"as it was.",
|
|
768
803
|
);
|