loopctl-mcp-server 3.14.1 → 3.15.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 CHANGED
@@ -545,9 +545,9 @@ The order to wire it up, the stage machine these tools move a story through, and
545
545
  | `escalation_playbook` | **What to do with a stuck story**, from finding it to closing it: what each `reason_class` means, which `resolve_escalation` target fits (`queued` run again, `detected` triage again, `done` accept, `failed` drop), and the steps to take a story over in this session: leave it escalated, do not `claim_story`, salvage the runner's branch when `run.work_left_behind` is `"true"`, fix it through the normal delivery loop with a PR that says `Fixes #<issue>`, then `resolve_escalation` `to: "done"` citing the PR. Optional: `reason_class`. Local: sends nothing, needs no key. Same text as the `stuck_story` prompt. |
546
546
  | `force_unclaim_story` | **Take a story back from the agent holding it** (`POST /api/v1/stories/:id/force-unclaim`). Resets it to `agent_status: pending` with `assigned_agent_id` cleared AND makes the delivery stage row follow the release back to `queued`. **A delivery story then goes to `escalated`, not back to the queue** (loopctl US-44.4): an operator taking a story back is a human decision, so a release that leaves the stage row at `queued` escalates it over `operator_released` in the same transaction, spending no attempt against the retry ceiling — it is not left in the queue behind the human's back. Put it back to work with `resolve_escalation` `to: queued`, which releases (a no-op by then) AND re-contracts. A story with no delivery stage row is simply left `pending`. A story parked at `claimed` with nobody on it is the residue of a compensation that did not complete, not what a refused dispatch normally leaves: placement releases the claim inline when a runner refuses, and the claim lease releases it unattended once `claimed_until` passes — reach for this to get it back now, or when both of those left it held. Requeues from any stage a claim holds; a stage no claim holds keeps its stage and is rebound to the new epoch; `done` and `failed` are untouched. For an ESCALATED story use `resolve_escalation` instead — that one releases AND re-contracts, so its `queued` really is placeable. Requires an orchestrator-ROLE key: the action is `exact_role: :orchestrator`, so a user or superadmin key is 403'd like any other non-member. Put it in `LOOPCTL_ORCH_KEY` (which is then the key sent, and a global `LOOPCTL_API_KEY` does not displace it) or, with no orchestrator key set, in `LOOPCTL_API_KEY`. The orchestrator key must be linked to a registered agent (400 otherwise) and the tenant must be human-anchored (403 `custody_tier_required` otherwise). Does not touch `verified_status`. Run again on an already-pending story it is still an operator's release: a row stranded behind the story's claim epoch is rebound, an in-flight row is requeued, and a row then at `queued` — including one already sitting there — is escalated over `operator_released`, as on the first run; a row already escalated, or anywhere else at that epoch, is left alone. Every 500 means the whole release rolled back and the story is still claimed: `audit_chain_append_failed` (the escalation's chain entry was refused) is a server-side condition a re-run meets again until an operator acts; `force_unclaim_failed` (the server log names the step) — call it again. A 422 means the release write itself was rejected. No request body. Required: `story_id` (refused locally if it is not a UUID). |
547
547
  | `merge_precondition` | **Run the merge gate over a story's real pull request** (`POST /api/v1/stories/:id/merge-precondition`). Both delivery gates run again over the diff that exists, plus custody, the 12-file / 1000-line hard bound, the head-has-not-moved check and the self-deploy exclusion; the story must be at stage `ci`. **Gate A reads what triage persisted, never the caller**: the lens verdicts recorded with the story's most recent triage, or a human's re-queue of a Gate A escalation — `gate_a_inputs` on the answer says which, and `missing` refuses with `gate_a_inputs_missing`. This tool sends no trio. Decisions: `allow` (recorded against the head; the only thing that licenses a merge), `refuse` (the story is escalated before this returns), `already_merged`, `head_moved`, `unevaluated` (503 with `Retry-After`). Requires an orchestrator- or user-ROLE key (`exact_role: [:orchestrator, :user]`, so an agent key is 403'd); `LOOPCTL_ORCH_KEY` is sent when set, else `LOOPCTL_API_KEY`. 403 `custody_tier_required` without a human anchor, 404 for an unknown story, 409 `change_protocol_enrolled` when the story's intake source is in mode `chg` (the PR route is closed; land with `chg submit` — decided before any GitHub read, nothing escalated), 422 when the story is not at `ci`. Required: `story_id` (refused locally if not a UUID) and `claim_epoch` (a non-negative integer, refused locally otherwise); optional `effect_proof`. |
548
- | `intake_source_enroll` | **Bind a GitHub repository to a work project and mint its webhook secret** (`POST /api/v1/intake/sources`) — the step that gives the delivery loop an input, and the row `place_dispatch` reads `repo` and `base_branch` from (its 409 `no_intake_source` means this has not been done; 409 `ambiguous_intake_source` means it has been done twice). **The secret is returned ONCE and can never be read again** — the column is encrypted at rest and redacted on the schema, so no other tool carries it and losing it costs a revoke, a re-enrolment and a reconfigured GitHub webhook. **This tool does not return it either:** a tool result lands in the transcript and the audit log, so it is written to the required `secret_file` with mode 0600 (the handling `runner_enroll` gives a runner credential) and the result carries the source row, the `webhook_url` and that path. The path is reserved before the request, so an existing file or an unwritable directory is refused with nothing enrolled, and any outcome that is not a clean creation withholds the response body — an unparsed 2xx body IS the secret. A 2xx carrying the source and the secret but no webhook path is RECOVERED rather than discarded (the path is derived from the source id, flagged `webhook_url_derived`), and an outcome that proves a source id but no usable secret REVOKES that source rather than leaving it holding the repository's unique slot. Then configure GitHub: Payload URL = the returned `webhook_url`, content type `application/json`, Secret = the contents of the file, and the **Issues** and **Pull requests** events (a merged pull request queues a read of its `## Review findings` section) — `gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f config[content_type]=json -f config[secret]="$(cat <secret_file>)" -f 'events[]=issues' -f 'events[]=pull_request'`. Every later delivery failure is the SAME 401 `invalid_signature` — unknown or revoked source, suspended tenant, missing or wrong signature, or a payload whose `repository.full_name` does not match — so the webhook's Recent Deliveries tab cannot tell you which. `base_branch` is set HERE: it defaults to `master` when the body does not name it, so name `main` for a repository created on GitHub since 2020 or every dispatch is cut from a trunk that does not exist. It is not nullable (a dispatch must name a branch), so null or blank is refused rather than falling back to the default, and `intake_source_update` changes it afterwards. Refusals: 403 `api_key_mint_forbidden` if your key was minted by a dispatch (this mints a credential belonging to no lineage, so only an unlineaged operator key may), 403 `custody_tier_required` on an agent-rooted tenant, 422 for a repository that is not `owner/name`, an ACTIVE source already binding it, a project that is missing / archived / not a work project, or a `target_epic_id` outside that project. `mode` is the merge route: `pr` (the default when omitted; the merge gate reads a pull request) or `chg` (Epic 47: the change protocol lands the repository's changes with `chg submit`, and `merge_precondition` refuses every story on the source with 409 `change_protocol_enrolled`); any other value, null included, is refused. A `chg` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND `chg_root_dispatch_id` in the same call — refused locally and 422 at the server without them — and a root that is not a parentless, unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid` (a child, a revoked or agent-role dispatch, another tenant's and an unknown id all alike). The change-events secret is write-only: no response and no tool result ever carries it. `required_checks` are the CI checks story verification judges a story's commit by, GitHub Actions job names, bounded in number and length by the server; `local-gate` is refused because whoever pushed posts it. Story verification judges a story's commit against the same `required_checks` in EITHER mode, satisfied only by a job of a push run of the story's branch; it first needs a GitHub credential for this tenant, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise, whatever the list holds); then a `pr` source that names none records `no_required_checks` and reads nothing, so naming them is how a pr source opts in, and a source that names some has its (tenant, repository) credential resolved before any GitHub read (`credential_unavailable` if there is none). Required: `repo_full_name`, `project_id`, `secret_file`. `triage_requires_ticket` decides which issues are triaged at all: false (the default), every issue the webhook delivers; true, only an issue HomeCareBilling filed from a support ticket (its single `#HCB-xxxxxxxx` Ticket line confirmed by the HomeCareBilling footer, which intake records as `ticket_id`), and every other issue stays an intake record with no story until it gains a ticket; anything but a boolean is refused. It filters on the format, it does not authenticate: anyone who can open an issue can type it. Optional: `base_branch`, `mode`, `required_checks`, `triage_requires_ticket`, `change_events_secret` / `change_events_secret_file`, `chg_root_dispatch_id`, and `target_epic_id` — **omitting the epic is not a neutral default**: with no epic every triaged report is escalated to a human and every record stays `pending_triage` until `intake_source_update` names one. Requires `LOOPCTL_USER_KEY`. |
549
- | `intake_source_list` | List the tenant's intake sources (`GET /api/v1/intake/sources`): `id` (the webhook URL is `/api/v1/intake/github/<id>`), `project_id`, `repo_full_name`, `base_branch`, `mode` (`pr` or `chg`), `required_checks`, `triage_requires_ticket`, `chg_root_dispatch_id`, `target_epic_id`, `revoked_at`, timestamps. **The webhook secret is not here and is not anywhere**, and neither is a `chg` source's change-events secret — it is returned once by `intake_source_enroll`, so this is not how to recover one. Use it to find the source behind a 409 `no_intake_source` or `ambiguous_intake_source`, to check a repository's `base_branch` before placing work, and to identify a source left behind by an enrolment whose outcome was unknown. Optional: `include_revoked`. Requires `LOOPCTL_USER_KEY`; the only one of the four that does not also need a human-anchored tenant. |
550
- | `intake_source_update` | **Set where a source's work lands** (`PATCH /api/v1/intake/sources/:id`): `target_epic_id`, the epic triaged stories are created in, `base_branch`, the branch every dispatch for this repository is cut from, `mode` (`pr` or `chg`), a `chg` source's `change_events_secret` / `change_events_secret_file` and `chg_root_dispatch_id`, and `required_checks`, the checks story verification judges a story's commit by — once the tenant has a GitHub credential, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise), a source naming none records `no_required_checks` and reads nothing, and one naming some has its (tenant, repository) credential resolved before any GitHub read (`local-gate` is refused), and `triage_requires_ticket`, which issues are triaged at all (true: only issues HomeCareBilling filed from a support ticket; read at dispatch time, so it reaches stories already waiting at `detected`; null is refused). Presence decides — a field you do not name is left exactly as it was, and naming none of them is 422 `nothing_to_update`. `mode` has no cleared state either, and a null or unknown value is refused locally. Each implement dispatch records the base branch it was placed under, and the merge gate reads that; `mode` is not bound that way — the gate reads the source's current mode. **Switching to `chg` closes the PR route for every story on the source at once** (409 `change_protocol_enrolled`; land with `chg submit`), and the switch itself is 409 `pr_route_in_flight`, naming `story_ids`, while a story of the project sits at `ci` holding a merge allow it has not merged on. The resulting source must carry both credentials, named here or kept from an earlier `chg` stint (422 naming the missing one), and the root is re-checked on every write that leaves the source `chg`, a secret rotation or a base-branch edit included (422 `chg_root_invalid`; switching to `pr` is never blocked by it). Switching to `pr` KEEPS both and ignores them; on a `pr` source an explicit null clears either, on a `chg` source it is a 422. Naming either credential, or setting `mode` to `chg` (which re-activates the kept ones), needs the tenant's operator key, one no dispatch minted (403 `chg_registration_forbidden` otherwise — a key minted by a dispatch beneath yours is refused the same way), and the secret never comes back. **Do not send `target_epic_id: null` to mean "not changing this":** an explicit null is the only way to CLEAR the epic, which returns the source to escalating every report instead of filing a story. `base_branch` has no cleared state and a null there is refused locally. This is how a source already pointed at the wrong trunk is corrected — `intake_source_enroll` takes `base_branch` itself, so a `main` repository no longer needs a second call — and the remedy for a source with no epic — every record from it stays `pending_triage` and is retried until one is named, then they promote on the next run with nothing lost. Revoked sources are 404, not a no-op: revoking clears the target so the epic can be deleted, and repointing one would put that block back. 422 when the epic is not in this source's project. Required: `source_id` (refused locally if it is not a UUID — the server answers the same 404 for malformed and unknown). Requires `LOOPCTL_USER_KEY` and a human-anchored tenant. |
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 `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`. |
549
+ | `intake_source_list` | List the tenant's intake sources (`GET /api/v1/intake/sources`): `id` (the webhook URL is `/api/v1/intake/github/<id>`), `project_id`, `repo_full_name`, `base_branch`, `mode` (`pr`, `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`; 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
551
  | `intake_source_revoke` | **Revoke an intake source** (`DELETE /api/v1/intake/sources/:id`). The verb is DELETE and the action is a revoke: `revoked_at` is stamped, the row is kept, and `intake_source_list` still returns it with `include_revoked`; nothing already received is discarded. Afterwards every delivery to that URL is refused 401 `invalid_signature` exactly as a wrong secret is, so the GitHub webhook does not know it has been cut off and should be deleted on the repository too. Idempotent — a second revoke answers 200 with the original `revoked_at`. It frees the repository's uniqueness slot (the index is partial on not-yet-revoked), so a source with a lost secret, a wrong project or a typo'd repository is corrected by revoking and enrolling again; and it clears `target_epic_id`, which is what makes that epic deletable and is the remedy an epic-delete refusal names. Required: `source_id` (refused locally if it is not a UUID). Requires `LOOPCTL_USER_KEY` and a human-anchored tenant. |
552
552
 
553
553
  ### Dispatch & Chain of Custody (v2) Tools
package/index.js CHANGED
@@ -9310,7 +9310,8 @@ const TOOLS = [
9310
9310
  "admits outside text into the queue of a project whose stories an implementer will act " +
9311
9311
  "on). 422 when the repository is not `owner/name`, when an ACTIVE source already binds " +
9312
9312
  "that repository (revoke it first — the uniqueness is partial on not-yet-revoked), when " +
9313
- "the project is missing, archived or not a work project, or when `target_epic_id` names " +
9313
+ "the project is missing, archived or the wrong kind for the mode (a work project for " +
9314
+ "`pr`/`chg`, a KB scope for `ledger`), or when `target_epic_id` names " +
9314
9315
  "an epic outside that project. 429 when rate limited.\n\n" +
9315
9316
  "NAME `base_branch` AT ENROLMENT for a repository whose trunk is not `master`. It is the " +
9316
9317
  "branch every dispatch for this repository is cut FROM, it defaults to `master` when the " +
@@ -9327,7 +9328,16 @@ const TOOLS = [
9327
9328
  "here, and 422 at the server, without them — and a root that is not a parentless, " +
9328
9329
  "unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid`. The " +
9329
9330
  "change-events secret is write-only: no response and no tool result ever carries it. " +
9330
- "Any other mode, null included, is refused.",
9331
+ "Any other mode, null included, is refused.\n\n" +
9332
+ "SENDING IS NOT ROUTING (loopctl #1047). The two chg credentials authenticate the " +
9333
+ "ledger (POST /api/v1/chg_ledger/:source_id) and change-event endpoints in EVERY mode. " +
9334
+ "A `pr` source that holds them stays `pr`: its merge precondition still reads the PR, " +
9335
+ "and its change events are recorded without binding or moving any story. `ledger` " +
9336
+ "enrols a repository that has NO work project for the ledger alone: `project_id` must " +
9337
+ "then be an active KB scope (create_kb_scope), both credentials are required as for " +
9338
+ "`chg`, the source is never a dispatch binding (place_dispatch and candidate selection " +
9339
+ "skip it), and GitHub deliveries to it are refused. `ledger` on a work project, or " +
9340
+ "`pr`/`chg` on a kb scope, is 422 at the server.",
9331
9341
  inputSchema: {
9332
9342
  type: "object",
9333
9343
  properties: {
@@ -9340,8 +9350,9 @@ const TOOLS = [
9340
9350
  project_id: {
9341
9351
  type: "string",
9342
9352
  description:
9343
- "The ACTIVE WORK project (UUID) whose queue this repository's issues feed. A `kb` " +
9344
- "scope or an archived project is a 422.",
9353
+ "The ACTIVE WORK project (UUID) whose queue this repository's issues feed — or, " +
9354
+ "with `mode: ledger`, the active KB scope the ledger-only source belongs to. The " +
9355
+ "wrong kind for the mode, or an archived project, is a 422.",
9345
9356
  },
9346
9357
  target_epic_id: {
9347
9358
  type: "string",
@@ -9366,20 +9377,23 @@ const TOOLS = [
9366
9377
  },
9367
9378
  mode: {
9368
9379
  type: "string",
9369
- enum: ["pr", "chg"],
9380
+ enum: ["pr", "chg", "ledger"],
9370
9381
  description:
9371
9382
  "Optional. How this repository's changes reach its base branch: `pr` (the " +
9372
9383
  "default; the merge gate reads a pull request by number) or `chg` (the change " +
9373
9384
  "protocol lands them and the PR route is closed, 409 `change_protocol_enrolled`; " +
9374
- "needs the two fields below). Not nullable.",
9385
+ "needs the two fields below). `ledger` routes nothing: a KB scope's ledger-only " +
9386
+ "source, which also needs the two fields below. Not nullable.",
9375
9387
  },
9376
9388
  change_events_secret: {
9377
9389
  type: "string",
9378
9390
  description:
9379
- "WRITE-ONLY; required with `mode: chg`. The HMAC key chg-server signs its event " +
9380
- "webhook with (POST /api/v1/change_events/:source_id); chg-server must hold the " +
9381
- "same value. 32-256 bytes (422 otherwise). Encrypted at rest and NEVER returned by " +
9382
- "any response or tool result. A tool input lands in the transcript, so prefer " +
9391
+ "WRITE-ONLY; required with `mode: chg` or `mode: ledger`, and accepted on a `pr` " +
9392
+ "source, which then sends its ledger too. The HMAC key chg signs its ledger " +
9393
+ "batches and change events with (POST /api/v1/chg_ledger/:source_id and " +
9394
+ "/api/v1/change_events/:source_id); chg must hold the same value. 32-256 bytes " +
9395
+ "(422 otherwise). Encrypted at rest and NEVER returned by any response or tool " +
9396
+ "result. A tool input lands in the transcript, so prefer " +
9383
9397
  "`change_events_secret_file`. Not GitHub's webhook secret.",
9384
9398
  },
9385
9399
  change_events_secret_file: {
@@ -9392,7 +9406,8 @@ const TOOLS = [
9392
9406
  chg_root_dispatch_id: {
9393
9407
  type: "string",
9394
9408
  description:
9395
- "Required with `mode: chg`. The dispatch (UUID) chg-server's key was minted from: " +
9409
+ "Required with `mode: chg` or `mode: ledger`, and with the secret on a `pr` source " +
9410
+ "(a signed request is refused without both). The dispatch (UUID) chg's key was minted from: " +
9396
9411
  "a PARENTLESS, UNREVOKED, ORCHESTRATOR-role dispatch of this tenant, minted by the " +
9397
9412
  "operator key with `dispatch` and no parent. Anything else — a child, a revoked " +
9398
9413
  "or agent-role dispatch, another tenant's or an unknown id — is refused 422 " +
@@ -9440,7 +9455,7 @@ const TOOLS = [
9440
9455
  description:
9441
9456
  "LIST THE TENANT'S GITHUB INTAKE SOURCES (GET /api/v1/intake/sources): per source its " +
9442
9457
  "`id` (the webhook URL is /api/v1/intake/github/<id>), `project_id`, `repo_full_name`, " +
9443
- "`base_branch`, `mode` (`pr` or `chg`), `chg_root_dispatch_id`, `target_epic_id`, " +
9458
+ "`base_branch`, `mode` (`pr`, `chg` or `ledger`), `chg_root_dispatch_id`, `target_epic_id`, " +
9444
9459
  "`revoked_at` and " +
9445
9460
  "timestamps. Active sources only " +
9446
9461
  "unless `include_revoked` is true.\n\n" +
@@ -9468,8 +9483,14 @@ const TOOLS = [
9468
9483
  description:
9469
9484
  "SET WHERE A SOURCE'S WORK LANDS (PATCH /api/v1/intake/sources/:id): `target_epic_id`, " +
9470
9485
  "the epic triaged stories are created in, `base_branch`, the branch every dispatch " +
9471
- "for this repository is cut FROM and carries, `mode`, the merge route (`pr` or `chg`), " +
9472
- "and a `chg` source's `change_events_secret` and `chg_root_dispatch_id`.\n\n" +
9486
+ "for this repository is cut FROM and carries, `mode`, the merge route (`pr` or `chg`, " +
9487
+ "or `ledger` on a KB scope), and the `change_events_secret` and `chg_root_dispatch_id` " +
9488
+ "that authenticate a source's chg ledger and change events.\n\n" +
9489
+ "LEDGER FROM A `pr` SOURCE (loopctl #1047): naming both credentials on a `pr` source " +
9490
+ "lets chg send its ledger and change events for that repository while the source STAYS " +
9491
+ "`pr` — the merge precondition still reads the PR, and the events move no story. Do not " +
9492
+ "switch to `chg` for that. A mode change between a work project's modes (`pr`, `chg`) " +
9493
+ "and `ledger` is 422: a source never moves between a work project and a KB scope.\n\n" +
9473
9494
  "PRESENCE DECIDES, AND A FIELD YOU DO NOT NAME IS LEFT EXACTLY AS IT WAS. Naming " +
9474
9495
  "none of them is refused 422 `nothing_to_update` rather than being a silent no-op. DO NOT " +
9475
9496
  "SEND `target_epic_id: null` TO MEAN 'I AM NOT CHANGING THIS' — an explicit null is the " +
@@ -9491,10 +9512,13 @@ const TOOLS = [
9491
9512
  "— and whenever one is named (422 `chg_root_invalid` unless it is a parentless, " +
9492
9513
  "unrevoked, orchestrator-role dispatch of this tenant; a revoked root blocks every such " +
9493
9514
  "write until a live one is named, while switching to `pr` is never blocked). Switching " +
9494
- "to `pr` KEEPS both and ignores " +
9495
- "them; on a `pr` source an explicit null clears either, and on a `chg` source a null is " +
9496
- "a 422. Naming either credential, or setting `mode` to `chg` (which re-activates the " +
9497
- "kept ones), needs the tenant's operator key — a user-role key NO DISPATCH MINTED — " +
9515
+ "to `pr` KEEPS both and they stay LIVE: the sender's ledger and its new changes' events " +
9516
+ "are still accepted (recorded, routing nothing), while an event for a change the `chg` " +
9517
+ "route already acted on is 401 until the source is `chg` again. Send an explicit null " +
9518
+ "to refuse the sender. On a `pr` source a null clears either, and on a `chg` source a null is " +
9519
+ "a 422. Naming either credential, or setting `mode` to `chg` or `ledger` (which " +
9520
+ "re-activates the kept ones), needs the tenant's operator key — a user-role key NO " +
9521
+ "DISPATCH MINTED — " +
9498
9522
  "and anything else is 403 `chg_registration_forbidden`; a key minted by a dispatch " +
9499
9523
  "beneath yours is refused the same way. The secret is write-only and " +
9500
9524
  "never comes back.\n\n" +
@@ -9534,17 +9558,20 @@ const TOOLS = [
9534
9558
  },
9535
9559
  mode: {
9536
9560
  type: "string",
9537
- enum: ["pr", "chg"],
9561
+ enum: ["pr", "chg", "ledger"],
9538
9562
  description:
9539
9563
  "`pr` (the merge gate reads a pull request) or `chg` (the change protocol lands " +
9540
- "changes; the PR route is closed). Not nullable. Omit to leave the current value " +
9541
- "alone.",
9564
+ "changes; the PR route is closed) on a work project; `ledger` on a KB scope. A " +
9565
+ "switch across project kinds is 422. Not nullable. Omit to leave the current " +
9566
+ "value alone.",
9542
9567
  },
9543
9568
  change_events_secret: {
9544
9569
  type: ["string", "null"],
9545
9570
  description:
9546
- "WRITE-ONLY. The HMAC key chg-server signs its event webhook with, 32-256 bytes; " +
9547
- "never returned. Null clears it on a `pr` source (422 on a `chg` one). Prefer " +
9571
+ "WRITE-ONLY. The HMAC key chg signs its ledger batches and change events with, " +
9572
+ "32-256 bytes; never returned. On a `pr` source it (with `chg_root_dispatch_id`) " +
9573
+ "lets chg send the ledger while the source stays `pr`. Null clears it on a `pr` " +
9574
+ "source (422 on a `chg` or `ledger` one). Prefer " +
9548
9575
  "`change_events_secret_file`. Omit to leave it alone.",
9549
9576
  },
9550
9577
  change_events_secret_file: {
@@ -9559,8 +9586,8 @@ const TOOLS = [
9559
9586
  description:
9560
9587
  "The parentless, unrevoked, orchestrator-role dispatch of this tenant chg-server's " +
9561
9588
  "key was minted from; anything else is 422 `chg_root_invalid`, and the root a `chg` " +
9562
- "source keeps is re-checked on every write to it. Null clears it on a " +
9563
- "`pr` source (422 on a `chg` one). Omit to leave it alone.",
9589
+ "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.",
9564
9591
  },
9565
9592
  required_checks: {
9566
9593
  type: "array",
@@ -97,6 +97,16 @@
97
97
  * newline is stripped (what `openssl rand -hex 32 > file` writes); chg-server must hold the
98
98
  * value without it.
99
99
  *
100
+ * ## SENDING IS NOT ROUTING (issue #1047)
101
+ *
102
+ * The two credentials authenticate the ledger and change-event endpoints in EVERY mode, so a
103
+ * `pr` source that holds them sends its ledger rows and change events too: it stays `pr`, its
104
+ * 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.
109
+ *
100
110
  * ## `repo_full_name` IS NOT SHAPE-CHECKED HERE, AND THAT IS A DECISION
101
111
  *
102
112
  * The server's refusal is a 422 naming the field with `must be owner/name`, which is
@@ -162,18 +172,24 @@ function epicRefusal(value, { clearable }) {
162
172
  }
163
173
 
164
174
  /**
165
- * The merge routes a source may take: `pr`, the default, and `chg` (US-47.2), where the change
166
- * protocol lands the repository's changes and the PR route is closed. NOT nullable — the
167
- * server answers 422 — so a null is refused here where the reason can be stated.
175
+ * The modes a source may take: `pr`, the default, and `chg` (US-47.2), where the change
176
+ * 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
178
+ * nullable — the server answers 422 — so a null is refused here where the reason can be
179
+ * stated.
168
180
  */
169
- export const SOURCE_MODES = ["pr", "chg"];
181
+ export const SOURCE_MODES = ["pr", "chg", "ledger"];
182
+
183
+ /** The modes whose enrolment needs both chg credentials in the same call. */
184
+ export const CREDENTIALED_MODES = ["chg", "ledger"];
170
185
 
171
186
  export function modeRefusal(mode) {
172
187
  if (SOURCE_MODES.includes(mode)) return null;
173
188
 
174
189
  return refuse(
175
- "`mode` must be `pr` or `chg`, or must be left out entirely (enrolment then takes `pr`, " +
176
- "and an update keeps the current value). It cannot be null.",
190
+ "`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.",
177
193
  );
178
194
  }
179
195
 
@@ -272,12 +288,12 @@ async function readSecretFile(secretFile, { fs, homedir }) {
272
288
  }
273
289
 
274
290
  /**
275
- * `mode: "chg"` at ENROLMENT needs both credentials in the same call (there is no earlier
276
- * stint to keep them from), so their absence is refused here, before a secret file is
277
- * reserved, with the 422 the server would answer named.
291
+ * `mode: "chg"` or `mode: "ledger"` at ENROLMENT needs both credentials in the same call
292
+ * (there is no earlier stint to keep them from), so their absence is refused here, before a
293
+ * secret file is reserved, with the 422 the server would answer named.
278
294
  */
279
295
  function chgEnrolmentRefusal(mode, fields) {
280
- if (mode !== "chg") return null;
296
+ if (!CREDENTIALED_MODES.includes(mode)) return null;
281
297
 
282
298
  const missing = ["change_events_secret", "chg_root_dispatch_id"].filter(
283
299
  (field) => fields[field] === undefined,
@@ -286,7 +302,7 @@ function chgEnrolmentRefusal(mode, fields) {
286
302
  if (missing.length === 0) return null;
287
303
 
288
304
  return refuse(
289
- `\`mode: chg\` needs ${missing.map((f) => `\`${f}\``).join(" and ")} in the same call; ` +
305
+ `\`mode: ${mode}\` needs ${missing.map((f) => `\`${f}\``).join(" and ")} in the same call; ` +
290
306
  "the server answers 422 without them. `chg_root_dispatch_id` is the parentless " +
291
307
  "orchestrator-role dispatch chg-server's key was minted from (the operator mints it " +
292
308
  "with `dispatch`, no parent), and the secret is the HMAC key chg-server signs its " +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.14.1",
3
+ "version": "3.15.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",