loopctl-mcp-server 3.16.0 → 3.17.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
@@ -547,9 +547,9 @@ The order to wire it up, the stage machine these tools move a story through, and
547
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. |
548
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). |
549
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`. |
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 `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`. |
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 for the chg ledger alone: `project_id` is then its active KB scope (`create_kb_scope`), or its active work project when that project has no intake route (its stories stay unbound), 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`. |
551
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. |
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 (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`; 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. |
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 or a work project; a switch into or out of `ledger` 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. |
553
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. |
554
554
 
555
555
  ### Dispatch & Chain of Custody (v2) Tools
package/index.js CHANGED
@@ -9383,7 +9383,7 @@ const TOOLS = [
9383
9383
  "on). 422 when the repository is not `owner/name`, when an ACTIVE source already binds " +
9384
9384
  "that repository (revoke it first — the uniqueness is partial on not-yet-revoked), when " +
9385
9385
  "the project is missing, archived or the wrong kind for the mode (a work project for " +
9386
- "`pr`/`chg`, a KB scope for `ledger`), or when `target_epic_id` names " +
9386
+ "`pr`/`chg`; a KB scope or a work project for `ledger`), or when `target_epic_id` names " +
9387
9387
  "an epic outside that project. 429 when rate limited.\n\n" +
9388
9388
  "NAME `base_branch` AT ENROLMENT for a repository whose trunk is not `master`. It is the " +
9389
9389
  "branch every dispatch for this repository is cut FROM, it defaults to `master` when the " +
@@ -9396,20 +9396,23 @@ const TOOLS = [
9396
9396
  "number. `chg` (Epic 47): the change protocol lands the repository's changes with " +
9397
9397
  "`chg submit`, and merge_precondition refuses every story on the source with 409 " +
9398
9398
  "`change_protocol_enrolled`. A `chg` enrolment needs `change_events_secret` (or " +
9399
- "`change_events_secret_file`) AND `chg_root_dispatch_id` in the same call — refused " +
9400
- "here, and 422 at the server, without them — and a root that is not a parentless, " +
9401
- "unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid`. The " +
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 " +
9402
9404
  "change-events secret is write-only: no response and no tool result ever carries it. " +
9403
9405
  "Any other mode, null included, is refused.\n\n" +
9404
9406
  "SENDING IS NOT ROUTING (loopctl #1047). The two chg credentials authenticate the " +
9405
9407
  "ledger (POST /api/v1/chg_ledger/:source_id) and change-event endpoints in EVERY mode. " +
9406
9408
  "A `pr` source that holds them stays `pr`: its merge precondition still reads the PR, " +
9407
9409
  "and its change events are recorded without binding or moving any story. `ledger` " +
9408
- "enrols a repository that has NO work project for the ledger alone: `project_id` must " +
9409
- "then be an active KB scope (create_kb_scope), both credentials are required as for " +
9410
- "`chg`, the source is never a dispatch binding (place_dispatch and candidate selection " +
9411
- "skip it), and GitHub deliveries to it are refused. `ledger` on a work project, or " +
9412
- "`pr`/`chg` on a kb scope, is 422 at the server.",
9410
+ "enrols a repository for the ledger alone: `project_id` is its active KB scope " +
9411
+ "(create_kb_scope), or its active work project when that project has no intake route " +
9412
+ "(reportex, cron_books). Both credentials are required as for `chg`, the source is " +
9413
+ "never a dispatch binding (place_dispatch and candidate selection skip it), so the " +
9414
+ "project's stories stay unbound, and GitHub deliveries to it are refused. `pr`/`chg` " +
9415
+ "on a kb scope is 422 at the server.",
9413
9416
  inputSchema: {
9414
9417
  type: "object",
9415
9418
  properties: {
@@ -9423,8 +9426,8 @@ const TOOLS = [
9423
9426
  type: "string",
9424
9427
  description:
9425
9428
  "The ACTIVE WORK project (UUID) whose queue this repository's issues feed — or, " +
9426
- "with `mode: ledger`, the active KB scope the ledger-only source belongs to. The " +
9427
- "wrong kind for the mode, or an archived project, is a 422.",
9429
+ "with `mode: ledger`, the active KB scope or work project the ledger-only source " +
9430
+ "belongs to. A kb scope for `pr`/`chg`, or an archived project, is a 422.",
9428
9431
  },
9429
9432
  target_epic_id: {
9430
9433
  type: "string",
@@ -9454,8 +9457,8 @@ const TOOLS = [
9454
9457
  "Optional. How this repository's changes reach its base branch: `pr` (the " +
9455
9458
  "default; the merge gate reads a pull request by number) or `chg` (the change " +
9456
9459
  "protocol lands them and the PR route is closed, 409 `change_protocol_enrolled`; " +
9457
- "needs the two fields below). `ledger` routes nothing: a KB scope's ledger-only " +
9458
- "source, which also needs the two fields below. Not nullable.",
9460
+ "needs the two fields below). `ledger` routes nothing: a ledger-only source on a KB " +
9461
+ "scope or a work project, which also needs the two fields below. Not nullable.",
9459
9462
  },
9460
9463
  change_events_secret: {
9461
9464
  type: "string",
@@ -9478,12 +9481,21 @@ const TOOLS = [
9478
9481
  chg_root_dispatch_id: {
9479
9482
  type: "string",
9480
9483
  description:
9481
- "Required with `mode: chg` or `mode: ledger`, and with the secret on a `pr` source " +
9482
- "(a signed request is refused without both). The dispatch (UUID) chg's key was minted from: " +
9483
- "a PARENTLESS, UNREVOKED, ORCHESTRATOR-role dispatch of this tenant, minted by the " +
9484
- "operator key with `dispatch` and no parent. Anything else — a child, a revoked " +
9485
- "or agent-role dispatch, another tenant's or an unknown id — is refused 422 " +
9486
- "`chg_root_invalid`, all alike.",
9484
+ "Alternative to `mint_chg_root` (prefer that). With `mode: chg` or `mode: ledger`, " +
9485
+ "and with the secret on a `pr` source, a root is required (a signed request is " +
9486
+ "refused without both). A PARENTLESS, UNREVOKED, ORCHESTRATOR-role dispatch (UUID) " +
9487
+ "of this tenant with more than 300 s left before it expires. Anything else — a " +
9488
+ "child, a revoked or agent-role dispatch, another tenant's or an unknown id — is " +
9489
+ "refused 422 `chg_root_invalid`, all alike. Not with `mint_chg_root`.",
9490
+ },
9491
+ mint_chg_root: {
9492
+ type: "boolean",
9493
+ description:
9494
+ "true: loopctl mints the source's chg root in this write, keyless and agentless, " +
9495
+ "and returns its id as `chg_root_dispatch_id`. The way to get a root: one minted " +
9496
+ "with `dispatch` takes its agent's one orchestrator-key slot (422 when the agent " +
9497
+ "already holds one). The expiry sweep never revokes a root a live source names. " +
9498
+ "Not with `chg_root_dispatch_id` (422). Needs the operator key, like the secret.",
9487
9499
  },
9488
9500
  required_checks: {
9489
9501
  type: "array",
@@ -9556,13 +9568,14 @@ const TOOLS = [
9556
9568
  "SET WHERE A SOURCE'S WORK LANDS (PATCH /api/v1/intake/sources/:id): `target_epic_id`, " +
9557
9569
  "the epic triaged stories are created in, `base_branch`, the branch every dispatch " +
9558
9570
  "for this repository is cut FROM and carries, `mode`, the merge route (`pr` or `chg`, " +
9559
- "or `ledger` on a KB scope), and the `change_events_secret` and `chg_root_dispatch_id` " +
9571
+ "or `ledger` on a KB scope or a work project), and the `change_events_secret` and " +
9572
+ "`chg_root_dispatch_id` " +
9560
9573
  "that authenticate a source's chg ledger and change events.\n\n" +
9561
9574
  "LEDGER FROM A `pr` SOURCE (loopctl #1047): naming both credentials on a `pr` source " +
9562
9575
  "lets chg send its ledger and change events for that repository while the source STAYS " +
9563
9576
  "`pr` — the merge precondition still reads the PR, and the events move no story. Do not " +
9564
- "switch to `chg` for that. A mode change between a work project's modes (`pr`, `chg`) " +
9565
- "and `ledger` is 422: a source never moves between a work project and a KB scope.\n\n" +
9577
+ "switch to `chg` for that. A mode change into or out of `ledger` is 422: a ledger " +
9578
+ "source is a credential, `pr`/`chg` its project's merge route; revoke and enrol anew.\n\n" +
9566
9579
  "PRESENCE DECIDES, AND A FIELD YOU DO NOT NAME IS LEFT EXACTLY AS IT WAS. Naming " +
9567
9580
  "none of them is refused 422 `nothing_to_update` rather than being a silent no-op. DO NOT " +
9568
9581
  "SEND `target_epic_id: null` TO MEAN 'I AM NOT CHANGING THIS' — an explicit null is the " +
@@ -9583,7 +9596,8 @@ const TOOLS = [
9583
9596
  "write that leaves the source `chg` — a secret rotation or a base-branch edit included " +
9584
9597
  "— and whenever one is named (422 `chg_root_invalid` unless it is a parentless, " +
9585
9598
  "unrevoked, orchestrator-role dispatch of this tenant; a revoked root blocks every such " +
9586
- "write until a live one is named, while switching to `pr` is never blocked). Switching " +
9599
+ "write until a live one is named or `mint_chg_root: true` mints one, while switching " +
9600
+ "to `pr` is never blocked). Switching " +
9587
9601
  "to `pr` KEEPS both and they stay LIVE: the sender's ledger and its new changes' events " +
9588
9602
  "are still accepted (recorded, routing nothing), while an event for a change the `chg` " +
9589
9603
  "route already acted on is 401 until the source is `chg` again. Send an explicit null " +
@@ -9633,8 +9647,8 @@ const TOOLS = [
9633
9647
  enum: ["pr", "chg", "ledger"],
9634
9648
  description:
9635
9649
  "`pr` (the merge gate reads a pull request) or `chg` (the change protocol lands " +
9636
- "changes; the PR route is closed) on a work project; `ledger` on a KB scope. A " +
9637
- "switch across project kinds is 422. Not nullable. Omit to leave the current " +
9650
+ "changes; the PR route is closed) on a work project; `ledger` on either kind. A " +
9651
+ "switch into or out of `ledger` is 422. Not nullable. Omit to leave the current " +
9638
9652
  "value alone.",
9639
9653
  },
9640
9654
  change_events_secret: {
@@ -9659,7 +9673,17 @@ const TOOLS = [
9659
9673
  "The parentless, unrevoked, orchestrator-role dispatch of this tenant chg-server's " +
9660
9674
  "key was minted from; anything else is 422 `chg_root_invalid`, and the root a `chg` " +
9661
9675
  "or `ledger` source keeps is re-checked on every write to it. Null clears it on a " +
9662
- "`pr` source (422 on a `chg` or `ledger` one). Omit to leave it alone.",
9676
+ "`pr` source (422 on a `chg` or `ledger` one). Omit to leave it alone. A named " +
9677
+ "root needs more than 300 s left before it expires. Prefer `mint_chg_root`.",
9678
+ },
9679
+ mint_chg_root: {
9680
+ type: "boolean",
9681
+ description:
9682
+ "true: loopctl mints a NEW keyless, agentless chg root in this write and the source " +
9683
+ "names it from then on (the result's `chg_root_dispatch_id`). The fix for a source " +
9684
+ "with no root, or with a revoked one. A root minted with `dispatch` takes its " +
9685
+ "agent's one orchestrator-key slot. The expiry sweep never revokes a root a live " +
9686
+ "source names. Not with `chg_root_dispatch_id` (422). Needs the operator key.",
9663
9687
  },
9664
9688
  required_checks: {
9665
9689
  type: "array",
@@ -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
@@ -102,10 +108,10 @@
102
108
  * The two credentials authenticate the ledger and change-event endpoints in EVERY mode, so a
103
109
  * `pr` source that holds them sends its ledger rows and change events too: it stays `pr`, its
104
110
  * merge precondition still answers from the PR, and its events are recorded without moving
105
- * any story. `mode: "ledger"` is the same credential pair on a KB scope (a repo with no work
106
- * project): enrolled for the ledger alone, never a dispatch binding, and refused every GitHub
107
- * delivery. Its enrolment needs both credentials in the same call, like `chg`; a mode change
108
- * between a work project's modes and `ledger` is a 422.
111
+ * any story. `mode: "ledger"` is the same credential pair on a KB scope or on a work project
112
+ * with no intake route: enrolled for the ledger alone, never a dispatch binding, and refused
113
+ * every GitHub delivery. Its enrolment needs both credentials in the same call, like `chg`; a
114
+ * mode change into or out of `ledger` is a 422.
109
115
  *
110
116
  * ## `repo_full_name` IS NOT SHAPE-CHECKED HERE, AND THAT IS A DECISION
111
117
  *
@@ -174,7 +180,7 @@ function epicRefusal(value, { clearable }) {
174
180
  /**
175
181
  * The modes a source may take: `pr`, the default, and `chg` (US-47.2), where the change
176
182
  * protocol lands the repository's changes and the PR route is closed — both on a WORK project
177
- * — and `ledger` (issue #1047), a KB scope's ledger-only credential that routes nothing. NOT
183
+ * — and `ledger` (issue #1047), a ledger-only credential, on either kind, that routes nothing. NOT
178
184
  * nullable — the server answers 422 — so a null is refused here where the reason can be
179
185
  * stated.
180
186
  */
@@ -188,8 +194,8 @@ export function modeRefusal(mode) {
188
194
 
189
195
  return refuse(
190
196
  "`mode` must be `pr`, `chg` or `ledger`, or must be left out entirely (enrolment then " +
191
- "takes `pr`, and an update keeps the current value). It cannot be null. `ledger` is a " +
192
- "kb scope's mode; `pr` and `chg` belong to a work project.",
197
+ "takes `pr`, and an update keeps the current value). It cannot be null. `pr` and `chg` " +
198
+ "belong to a work project; `ledger` sits on a kb scope or a work project.",
193
199
  );
194
200
  }
195
201
 
@@ -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 = ["change_events_secret", "chg_root_dispatch_id"].filter(
299
- (field) => fields[field] === undefined,
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.map((f) => `\`${f}\``).join(" and ")} in the same call; ` +
306
- "the server answers 422 without them. `chg_root_dispatch_id` is the parentless " +
307
- "orchestrator-role dispatch chg-server's key was minted from (the operator mints it " +
308
- "with `dispatch`, no parent), and the secret is the HMAC key chg-server signs its " +
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 `chg_root_dispatch_id`. A body carrying none of them " +
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
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.16.0",
3
+ "version": "3.17.1",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",