loopctl-mcp-server 3.0.0 → 3.1.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 +4 -4
- package/index.js +97 -18
- package/lib/delivery-loop.js +1 -1
- package/lib/intake-sources.js +174 -11
- package/lib/story-update.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -529,10 +529,10 @@ The order to wire it up, the stage machine these tools move a story through, and
|
|
|
529
529
|
| `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`. |
|
|
530
530
|
| `resolve_escalation` | **Move an escalated story off `escalated`, as a human** (`POST /api/v1/stories/:id/stage/resolve`): `to` is `queued` (work it again), `done` or `failed`. 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`. |
|
|
531
531
|
| `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). |
|
|
532
|
-
| `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, 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`. |
|
|
533
|
-
| `intake_source_enroll` | **Bind a GitHub repository to a work project and mint its webhook secret** (`POST /api/v1/intake/sources`) — the step that gives the delivery loop an input, and the row `place_dispatch` reads `repo` and `base_branch` from (its 409 `no_intake_source` means this has not been done; 409 `ambiguous_intake_source` means it has been done twice). **The secret is returned ONCE and can never be read again** — the column is encrypted at rest and redacted on the schema, so no other tool carries it and losing it costs a revoke, a re-enrolment and a reconfigured GitHub webhook. **This tool does not return it either:** a tool result lands in the transcript and the audit log, so it is written to the required `secret_file` with mode 0600 (the handling `runner_enroll` gives a runner credential) and the result carries the source row, the `webhook_url` and that path. The path is reserved before the request, so an existing file or an unwritable directory is refused with nothing enrolled, and any outcome that is not a clean creation withholds the response body — an unparsed 2xx body IS the secret. A 2xx carrying the source and the secret but no webhook path is RECOVERED rather than discarded (the path is derived from the source id, flagged `webhook_url_derived`), and an outcome that proves a source id but no usable secret REVOKES that source rather than leaving it holding the repository's unique slot. Then configure GitHub: Payload URL = the returned `webhook_url`, content type `application/json`, Secret = the contents of the file, and the **Issues** event only — `gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f config[content_type]=json -f config[secret]="$(cat <secret_file>)" -f 'events[]=issues'`. Every later delivery failure is the SAME 401 `invalid_signature` — unknown or revoked source, suspended tenant, missing or wrong signature, or a payload whose `repository.full_name` does not match — so the webhook's Recent Deliveries tab cannot tell you which. `base_branch` is set HERE: it defaults to `master` when the body does not name it, so name `main` for a repository created on GitHub since 2020 or every dispatch is cut from a trunk that does not exist. It is not nullable (a dispatch must name a branch), so null or blank is refused rather than falling back to the default, and `intake_source_update` changes it afterwards. Refusals: 403 `api_key_mint_forbidden` if your key was minted by a dispatch (this mints a credential belonging to no lineage, so only an unlineaged operator key may), 403 `custody_tier_required` on an agent-rooted tenant, 422 for a repository that is not `owner/name`, an ACTIVE source already binding it, a project that is missing / archived / not a work project, or a `target_epic_id` outside that project. `mode` is the merge route: `pr` (the default when omitted)
|
|
534
|
-
| `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`), `target_epic_id`, `revoked_at`, timestamps. **The webhook secret is not here and is not anywhere
|
|
535
|
-
| `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
|
|
532
|
+
| `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`. |
|
|
533
|
+
| `intake_source_enroll` | **Bind a GitHub repository to a work project and mint its webhook secret** (`POST /api/v1/intake/sources`) — the step that gives the delivery loop an input, and the row `place_dispatch` reads `repo` and `base_branch` from (its 409 `no_intake_source` means this has not been done; 409 `ambiguous_intake_source` means it has been done twice). **The secret is returned ONCE and can never be read again** — the column is encrypted at rest and redacted on the schema, so no other tool carries it and losing it costs a revoke, a re-enrolment and a reconfigured GitHub webhook. **This tool does not return it either:** a tool result lands in the transcript and the audit log, so it is written to the required `secret_file` with mode 0600 (the handling `runner_enroll` gives a runner credential) and the result carries the source row, the `webhook_url` and that path. The path is reserved before the request, so an existing file or an unwritable directory is refused with nothing enrolled, and any outcome that is not a clean creation withholds the response body — an unparsed 2xx body IS the secret. A 2xx carrying the source and the secret but no webhook path is RECOVERED rather than discarded (the path is derived from the source id, flagged `webhook_url_derived`), and an outcome that proves a source id but no usable secret REVOKES that source rather than leaving it holding the repository's unique slot. Then configure GitHub: Payload URL = the returned `webhook_url`, content type `application/json`, Secret = the contents of the file, and the **Issues** event only — `gh api repos/OWNER/REPO/hooks -f name=web -f config[url]=<webhook_url> -f config[content_type]=json -f config[secret]="$(cat <secret_file>)" -f 'events[]=issues'`. Every later delivery failure is the SAME 401 `invalid_signature` — unknown or revoked source, suspended tenant, missing or wrong signature, or a payload whose `repository.full_name` does not match — so the webhook's Recent Deliveries tab cannot tell you which. `base_branch` is set HERE: it defaults to `master` when the body does not name it, so name `main` for a repository created on GitHub since 2020 or every dispatch is cut from a trunk that does not exist. It is not nullable (a dispatch must name a branch), so null or blank is refused rather than falling back to the default, and `intake_source_update` changes it afterwards. Refusals: 403 `api_key_mint_forbidden` if your key was minted by a dispatch (this mints a credential belonging to no lineage, so only an unlineaged operator key may), 403 `custody_tier_required` on an agent-rooted tenant, 422 for a repository that is not `owner/name`, an ACTIVE source already binding it, a project that is missing / archived / not a work project, or a `target_epic_id` outside that project. `mode` is the merge route: `pr` (the default when omitted; the merge gate reads a pull request) or `chg` (Epic 47: the change protocol lands the repository's changes with `chg submit`, and `merge_precondition` refuses every story on the source with 409 `change_protocol_enrolled`); any other value, null included, is refused. A `chg` enrolment needs `change_events_secret` (or, preferred, `change_events_secret_file`, a path the tool reads so the value never enters the transcript) AND `chg_root_dispatch_id` in the same call — refused locally and 422 at the server without them — and a root that is not a parentless, unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid` (a child, a revoked or agent-role dispatch, another tenant's and an unknown id all alike). The change-events secret is write-only: no response and no tool result ever carries it. `required_checks` are the CI checks story verification judges a story's commit by, GitHub Actions job names, bounded in number and length by the server; `local-gate` is refused because whoever pushed posts it. Story verification judges a story's commit against the same `required_checks` in EITHER mode, satisfied only by a job of a push run of the story's branch; it first needs a GitHub credential for this tenant, its own token (`set_github_credential`) or an entry in the operator's `VERIFICATION_OPERATOR_TOKEN_TENANTS` (`credential_unavailable` otherwise, whatever the list holds); then a `pr` source that names none records `no_required_checks` and reads nothing, so naming them is how a pr source opts in, and a source that names some has its (tenant, repository) credential resolved before any GitHub read (`credential_unavailable` if there is none). Required: `repo_full_name`, `project_id`, `secret_file`. Optional: `base_branch`, `mode`, `required_checks`, `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`. |
|
|
534
|
+
| `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`), `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. |
|
|
535
|
+
| `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). 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. |
|
|
536
536
|
| `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. |
|
|
537
537
|
|
|
538
538
|
### Dispatch & Chain of Custody (v2) Tools
|
package/index.js
CHANGED
|
@@ -8661,7 +8661,10 @@ const TOOLS = [
|
|
|
8661
8661
|
"REFUSALS. Needs an ORCHESTRATOR- or USER-role key: the action is `exact_role: " +
|
|
8662
8662
|
"[:orchestrator, :user]`, so an agent key is 403'd. LOOPCTL_ORCH_KEY is sent when set, " +
|
|
8663
8663
|
"else LOOPCTL_API_KEY. 403 `custody_tier_required` on a tenant without a human anchor, " +
|
|
8664
|
-
"404 for an unknown story,
|
|
8664
|
+
"404 for an unknown story, 409 `change_protocol_enrolled` when the story's intake source " +
|
|
8665
|
+
"is in mode `chg` (the PR route is closed for that repository — land the change with " +
|
|
8666
|
+
"`chg submit`; decided before the stage check and any GitHub read, and nothing is " +
|
|
8667
|
+
"escalated), 422 when `claim_epoch` is missing or the story is not at `ci` " +
|
|
8665
8668
|
"or has no stage row. A `story_id` that is not a UUID or a bad `claim_epoch` is refused " +
|
|
8666
8669
|
"here, before any call.",
|
|
8667
8670
|
inputSchema: {
|
|
@@ -8792,8 +8795,15 @@ const TOOLS = [
|
|
|
8792
8795
|
"does not exist, and the failure arrives after the claim. There is no cleared state for " +
|
|
8793
8796
|
"it (a dispatch must name one), so null or blank is refused rather than falling back to " +
|
|
8794
8797
|
"the default; intake_source_update changes it afterwards.\n\n" +
|
|
8795
|
-
"`mode` is the merge route
|
|
8796
|
-
"
|
|
8798
|
+
"`mode` is the merge route. `pr` (the default): the merge gate reads a pull request by " +
|
|
8799
|
+
"number. `chg` (Epic 47): the change protocol lands the repository's changes with " +
|
|
8800
|
+
"`chg submit`, and merge_precondition refuses every story on the source with 409 " +
|
|
8801
|
+
"`change_protocol_enrolled`. A `chg` enrolment needs `change_events_secret` (or " +
|
|
8802
|
+
"`change_events_secret_file`) AND `chg_root_dispatch_id` in the same call — refused " +
|
|
8803
|
+
"here, and 422 at the server, without them — and a root that is not a parentless, " +
|
|
8804
|
+
"unrevoked, orchestrator-role dispatch of this tenant is 422 `chg_root_invalid`. The " +
|
|
8805
|
+
"change-events secret is write-only: no response and no tool result ever carries it. " +
|
|
8806
|
+
"Any other mode, null included, is refused.",
|
|
8797
8807
|
inputSchema: {
|
|
8798
8808
|
type: "object",
|
|
8799
8809
|
properties: {
|
|
@@ -8832,10 +8842,37 @@ const TOOLS = [
|
|
|
8832
8842
|
},
|
|
8833
8843
|
mode: {
|
|
8834
8844
|
type: "string",
|
|
8835
|
-
enum: ["pr"],
|
|
8845
|
+
enum: ["pr", "chg"],
|
|
8836
8846
|
description:
|
|
8837
|
-
"Optional. How this repository's changes reach its base branch: `pr
|
|
8838
|
-
"
|
|
8847
|
+
"Optional. How this repository's changes reach its base branch: `pr` (the " +
|
|
8848
|
+
"default; the merge gate reads a pull request by number) or `chg` (the change " +
|
|
8849
|
+
"protocol lands them and the PR route is closed, 409 `change_protocol_enrolled`; " +
|
|
8850
|
+
"needs the two fields below). Not nullable.",
|
|
8851
|
+
},
|
|
8852
|
+
change_events_secret: {
|
|
8853
|
+
type: "string",
|
|
8854
|
+
description:
|
|
8855
|
+
"WRITE-ONLY; required with `mode: chg`. The HMAC key chg-server signs its event " +
|
|
8856
|
+
"webhook with (POST /api/v1/change_events/:source_id); chg-server must hold the " +
|
|
8857
|
+
"same value. 32-256 bytes (422 otherwise). Encrypted at rest and NEVER returned by " +
|
|
8858
|
+
"any response or tool result. A tool input lands in the transcript, so prefer " +
|
|
8859
|
+
"`change_events_secret_file`. Not GitHub's webhook secret.",
|
|
8860
|
+
},
|
|
8861
|
+
change_events_secret_file: {
|
|
8862
|
+
type: "string",
|
|
8863
|
+
description:
|
|
8864
|
+
"Alternative to `change_events_secret`, and the preferred one: an absolute (or " +
|
|
8865
|
+
"`~/`) path the tool READS the secret from, so the value never passes through the " +
|
|
8866
|
+
"transcript. One trailing newline is stripped. Not both.",
|
|
8867
|
+
},
|
|
8868
|
+
chg_root_dispatch_id: {
|
|
8869
|
+
type: "string",
|
|
8870
|
+
description:
|
|
8871
|
+
"Required with `mode: chg`. The dispatch (UUID) chg-server's key was minted from: " +
|
|
8872
|
+
"a PARENTLESS, UNREVOKED, ORCHESTRATOR-role dispatch of this tenant, minted by the " +
|
|
8873
|
+
"operator key with `dispatch` and no parent. Anything else — a child, a revoked " +
|
|
8874
|
+
"or agent-role dispatch, another tenant's or an unknown id — is refused 422 " +
|
|
8875
|
+
"`chg_root_invalid`, all alike.",
|
|
8839
8876
|
},
|
|
8840
8877
|
required_checks: {
|
|
8841
8878
|
type: "array",
|
|
@@ -8868,10 +8905,12 @@ const TOOLS = [
|
|
|
8868
8905
|
description:
|
|
8869
8906
|
"LIST THE TENANT'S GITHUB INTAKE SOURCES (GET /api/v1/intake/sources): per source its " +
|
|
8870
8907
|
"`id` (the webhook URL is /api/v1/intake/github/<id>), `project_id`, `repo_full_name`, " +
|
|
8871
|
-
"`base_branch`, `mode` (`pr`), `
|
|
8908
|
+
"`base_branch`, `mode` (`pr` or `chg`), `chg_root_dispatch_id`, `target_epic_id`, " +
|
|
8909
|
+
"`revoked_at` and " +
|
|
8872
8910
|
"timestamps. Active sources only " +
|
|
8873
8911
|
"unless `include_revoked` is true.\n\n" +
|
|
8874
|
-
"THE WEBHOOK SECRET IS NOT HERE AND IS NOT ANYWHERE
|
|
8912
|
+
"THE WEBHOOK SECRET IS NOT HERE AND IS NOT ANYWHERE, and neither is a `chg` source's " +
|
|
8913
|
+
"change-events secret, which is never returned at all. The webhook secret is returned once by " +
|
|
8875
8914
|
"intake_source_enroll and the column is redacted on the schema, so this is not the way " +
|
|
8876
8915
|
"to recover one — revoking and enrolling again is. Use this to find the source behind a " +
|
|
8877
8916
|
"409 `no_intake_source` (the project is bound to none) or a 409 " +
|
|
@@ -8894,19 +8933,36 @@ const TOOLS = [
|
|
|
8894
8933
|
description:
|
|
8895
8934
|
"SET WHERE A SOURCE'S WORK LANDS (PATCH /api/v1/intake/sources/:id): `target_epic_id`, " +
|
|
8896
8935
|
"the epic triaged stories are created in, `base_branch`, the branch every dispatch " +
|
|
8897
|
-
"for this repository is cut FROM and carries,
|
|
8898
|
-
"
|
|
8936
|
+
"for this repository is cut FROM and carries, `mode`, the merge route (`pr` or `chg`), " +
|
|
8937
|
+
"and a `chg` source's `change_events_secret` and `chg_root_dispatch_id`.\n\n" +
|
|
8899
8938
|
"PRESENCE DECIDES, AND A FIELD YOU DO NOT NAME IS LEFT EXACTLY AS IT WAS. Naming " +
|
|
8900
8939
|
"none of them is refused 422 `nothing_to_update` rather than being a silent no-op. DO NOT " +
|
|
8901
8940
|
"SEND `target_epic_id: null` TO MEAN 'I AM NOT CHANGING THIS' — an explicit null is the " +
|
|
8902
8941
|
"only way to CLEAR the epic, and clearing it returns the source to escalating every " +
|
|
8903
8942
|
"report to a human instead of filing a story. Leave the field out instead. " +
|
|
8904
8943
|
"`base_branch` and `mode` have no cleared state at all, so a null there is refused. " +
|
|
8905
|
-
"
|
|
8906
|
-
"
|
|
8907
|
-
"
|
|
8908
|
-
"
|
|
8909
|
-
"
|
|
8944
|
+
"`base_branch` is BOUND to each implement dispatch when it is placed: a story already " +
|
|
8945
|
+
"placed is merge-gated against the base branch its dispatch was sent with. `mode` is " +
|
|
8946
|
+
"NOT bound that way: the merge gate reads the source's current mode.\n\n" +
|
|
8947
|
+
"SWITCHING TO `chg` closes the PR route for EVERY story on the source at once: " +
|
|
8948
|
+
"merge_precondition reads the source's current mode and answers 409 " +
|
|
8949
|
+
"`change_protocol_enrolled` (land with `chg submit`). The switch is itself refused 409 " +
|
|
8950
|
+
"`pr_route_in_flight`, with the `story_ids`, while any story of the project sits at " +
|
|
8951
|
+
"`ci` holding a merge allow it has not merged on: merge those (or let the gate escalate " +
|
|
8952
|
+
"them) and retry. The resulting source must carry " +
|
|
8953
|
+
"BOTH `change_events_secret` and `chg_root_dispatch_id`, named here or kept from an " +
|
|
8954
|
+
"earlier `chg` stint (422 naming the missing one), and the root is re-checked on EVERY " +
|
|
8955
|
+
"write that leaves the source `chg` — a secret rotation or a base-branch edit included " +
|
|
8956
|
+
"— and whenever one is named (422 `chg_root_invalid` unless it is a parentless, " +
|
|
8957
|
+
"unrevoked, orchestrator-role dispatch of this tenant; a revoked root blocks every such " +
|
|
8958
|
+
"write until a live one is named, while switching to `pr` is never blocked). Switching " +
|
|
8959
|
+
"to `pr` KEEPS both and ignores " +
|
|
8960
|
+
"them; on a `pr` source an explicit null clears either, and on a `chg` source a null is " +
|
|
8961
|
+
"a 422. Naming either credential, or setting `mode` to `chg` (which re-activates the " +
|
|
8962
|
+
"kept ones), needs the tenant's operator key — a user-role key NO DISPATCH MINTED — " +
|
|
8963
|
+
"and anything else is 403 `chg_registration_forbidden`; a key minted by a dispatch " +
|
|
8964
|
+
"beneath yours is refused the same way. The secret is write-only and " +
|
|
8965
|
+
"never comes back.\n\n" +
|
|
8910
8966
|
"THIS IS THE FIX FOR A SOURCE ALREADY POINTED AT THE WRONG TRUNK. intake_source_enroll " +
|
|
8911
8967
|
"now takes `base_branch` itself, so a `main` repository is enrolled correctly in one " +
|
|
8912
8968
|
"call; this is what corrects one that was not — a source enrolled before the parameter " +
|
|
@@ -8943,10 +8999,33 @@ const TOOLS = [
|
|
|
8943
8999
|
},
|
|
8944
9000
|
mode: {
|
|
8945
9001
|
type: "string",
|
|
8946
|
-
enum: ["pr"],
|
|
9002
|
+
enum: ["pr", "chg"],
|
|
9003
|
+
description:
|
|
9004
|
+
"`pr` (the merge gate reads a pull request) or `chg` (the change protocol lands " +
|
|
9005
|
+
"changes; the PR route is closed). Not nullable. Omit to leave the current value " +
|
|
9006
|
+
"alone.",
|
|
9007
|
+
},
|
|
9008
|
+
change_events_secret: {
|
|
9009
|
+
type: ["string", "null"],
|
|
9010
|
+
description:
|
|
9011
|
+
"WRITE-ONLY. The HMAC key chg-server signs its event webhook with, 32-256 bytes; " +
|
|
9012
|
+
"never returned. Null clears it on a `pr` source (422 on a `chg` one). Prefer " +
|
|
9013
|
+
"`change_events_secret_file`. Omit to leave it alone.",
|
|
9014
|
+
},
|
|
9015
|
+
change_events_secret_file: {
|
|
9016
|
+
type: "string",
|
|
9017
|
+
description:
|
|
9018
|
+
"Alternative to `change_events_secret`: an absolute (or `~/`) path the tool reads " +
|
|
9019
|
+
"the secret from, so it never passes through the transcript. One trailing newline " +
|
|
9020
|
+
"is stripped. Not both.",
|
|
9021
|
+
},
|
|
9022
|
+
chg_root_dispatch_id: {
|
|
9023
|
+
type: ["string", "null"],
|
|
8947
9024
|
description:
|
|
8948
|
-
"
|
|
8949
|
-
"
|
|
9025
|
+
"The parentless, unrevoked, orchestrator-role dispatch of this tenant chg-server's " +
|
|
9026
|
+
"key was minted from; anything else is 422 `chg_root_invalid`, and the root a `chg` " +
|
|
9027
|
+
"source keeps is re-checked on every write to it. Null clears it on a " +
|
|
9028
|
+
"`pr` source (422 on a `chg` one). Omit to leave it alone.",
|
|
8950
9029
|
},
|
|
8951
9030
|
required_checks: {
|
|
8952
9031
|
type: "array",
|
package/lib/delivery-loop.js
CHANGED
|
@@ -84,7 +84,7 @@ function refuse(body) {
|
|
|
84
84
|
* That 404 is the problem, not a 500. It is BYTE-IDENTICAL to the 404 for a perfectly
|
|
85
85
|
* well-formed id that names no story — `FallbackController` answers `{:error, :not_found}` with
|
|
86
86
|
* the same `%{error: %{status: 404, message: "Not found"}}`
|
|
87
|
-
* (`lib/loopctl_web/fallback_controller.ex:
|
|
87
|
+
* (`lib/loopctl_web/fallback_controller.ex:84-88`) — so it cannot tell an operator which
|
|
88
88
|
* of the two happened, and the two have opposite remedies: re-read the argument you passed, or
|
|
89
89
|
* go find the right story. The check here can tell them apart, and does it without a round trip.
|
|
90
90
|
*
|
package/lib/intake-sources.js
CHANGED
|
@@ -74,10 +74,28 @@
|
|
|
74
74
|
* is. The controller mounts `RequireRole, role: :user` — the HIERARCHY form, so a
|
|
75
75
|
* `:superadmin` key would pass too and this package holds no such variable — plus
|
|
76
76
|
* `RequireHumanAnchor` on create/update/delete and `RequireUnlineagedCaller` on create
|
|
77
|
-
* (`lib/loopctl_web/controllers/intake_source_controller.ex:
|
|
77
|
+
* (`lib/loopctl_web/controllers/intake_source_controller.ex:34-36`). That last one is why a
|
|
78
78
|
* global `LOOPCTL_API_KEY` must not stand in: creating a source MINTS A CREDENTIAL that
|
|
79
79
|
* belongs to no dispatch lineage, so a caller whose own key a dispatch minted is refused
|
|
80
|
-
* `403 api_key_mint_forbidden`, exactly as it is on `POST /api/v1/api_keys`.
|
|
80
|
+
* `403 api_key_mint_forbidden`, exactly as it is on `POST /api/v1/api_keys`. An update that
|
|
81
|
+
* names a `chg` credential or sets `mode` to `chg` is held to the same ceiling under its own
|
|
82
|
+
* code, `403 chg_registration_forbidden`, whose remedy is the operator key itself.
|
|
83
|
+
*
|
|
84
|
+
* ## MODE `chg` AND ITS TWO CREDENTIALS (US-47.2, AC-47.7.2)
|
|
85
|
+
*
|
|
86
|
+
* A source in `mode: "chg"` has its changes landed by the change protocol (`chg submit`), and
|
|
87
|
+
* loopctl's merge precondition refuses every story on it with `409 change_protocol_enrolled`.
|
|
88
|
+
* It needs BOTH `change_events_secret` — the HMAC key chg-server signs its event webhook with,
|
|
89
|
+
* which the OPERATOR supplies because chg-server must hold the same value — and
|
|
90
|
+
* `chg_root_dispatch_id`, the parentless orchestrator-role dispatch chg-server's key was minted
|
|
91
|
+
* from (`422 chg_root_invalid` for anything else, another tenant's included).
|
|
92
|
+
*
|
|
93
|
+
* The secret is WRITE-ONLY on both sides: the server never serialises it, and `publicSource`
|
|
94
|
+
* below never names it, so no tool result carries it. A tool INPUT is recorded in the
|
|
95
|
+
* transcript too, so `change_events_secret_file` is offered beside it: the tool reads the
|
|
96
|
+
* value from that file and it never passes through a transcript at all. Exactly one trailing
|
|
97
|
+
* newline is stripped (what `openssl rand -hex 32 > file` writes); chg-server must hold the
|
|
98
|
+
* value without it.
|
|
81
99
|
*
|
|
82
100
|
* ## `repo_full_name` IS NOT SHAPE-CHECKED HERE, AND THAT IS A DECISION
|
|
83
101
|
*
|
|
@@ -144,18 +162,135 @@ function epicRefusal(value, { clearable }) {
|
|
|
144
162
|
}
|
|
145
163
|
|
|
146
164
|
/**
|
|
147
|
-
* The merge routes a source may take: `pr`, the default and
|
|
148
|
-
*
|
|
149
|
-
* reason can be stated.
|
|
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.
|
|
150
168
|
*/
|
|
151
|
-
export const SOURCE_MODES = ["pr"];
|
|
169
|
+
export const SOURCE_MODES = ["pr", "chg"];
|
|
152
170
|
|
|
153
171
|
export function modeRefusal(mode) {
|
|
154
172
|
if (SOURCE_MODES.includes(mode)) return null;
|
|
155
173
|
|
|
156
174
|
return refuse(
|
|
157
|
-
"`mode` must be `pr`, or must be left out entirely (enrolment then takes `pr`,
|
|
158
|
-
"update keeps the current value). It cannot be null.",
|
|
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.",
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The `chg` credentials a call NAMED, resolved into the request body fields, or a refusal.
|
|
182
|
+
*
|
|
183
|
+
* Resolves to `{ fields }` or `{ refusal }`. `clearable` is the update path, where an explicit
|
|
184
|
+
* null clears a credential on a `pr` source (the server refuses it on a `chg` one). No branch
|
|
185
|
+
* of this function puts the secret's value in a message.
|
|
186
|
+
*/
|
|
187
|
+
export async function chgCredentials(args, { clearable, fs = defaultFs, homedir = os.homedir() }) {
|
|
188
|
+
const fields = {};
|
|
189
|
+
const { change_events_secret: secret, change_events_secret_file: secretFile } = args;
|
|
190
|
+
|
|
191
|
+
if (secret !== undefined && secretFile !== undefined) {
|
|
192
|
+
return {
|
|
193
|
+
refusal: refuse(
|
|
194
|
+
"Send `change_events_secret` OR `change_events_secret_file`, not both: they are two " +
|
|
195
|
+
"ways of naming the same value.",
|
|
196
|
+
),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (secret !== undefined) {
|
|
201
|
+
if (secret === null && clearable) {
|
|
202
|
+
fields.change_events_secret = null;
|
|
203
|
+
} else if (typeof secret !== "string" || secret === "") {
|
|
204
|
+
return {
|
|
205
|
+
refusal: refuse(
|
|
206
|
+
"`change_events_secret` must be a non-empty string (the server holds it to " +
|
|
207
|
+
"32-256 bytes)" +
|
|
208
|
+
(clearable ? ", or null to clear it on a `pr` source." : ".") +
|
|
209
|
+
" Prefer `change_events_secret_file`, which keeps the value out of the transcript.",
|
|
210
|
+
),
|
|
211
|
+
};
|
|
212
|
+
} else {
|
|
213
|
+
fields.change_events_secret = secret;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (secretFile !== undefined) {
|
|
218
|
+
const read = await readSecretFile(secretFile, { fs, homedir });
|
|
219
|
+
if (read.refusal) return read;
|
|
220
|
+
fields.change_events_secret = read.secret;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const root = args.chg_root_dispatch_id;
|
|
224
|
+
|
|
225
|
+
if (root !== undefined) {
|
|
226
|
+
if (root === null && clearable) {
|
|
227
|
+
fields.chg_root_dispatch_id = null;
|
|
228
|
+
} else {
|
|
229
|
+
const badRoot = uuidRefusal(root, "chg_root_dispatch_id");
|
|
230
|
+
if (badRoot) return { refusal: badRoot };
|
|
231
|
+
fields.chg_root_dispatch_id = root;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return { fields };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function readSecretFile(secretFile, { fs, homedir }) {
|
|
239
|
+
if (typeof secretFile !== "string" || secretFile.trim() === "") {
|
|
240
|
+
return {
|
|
241
|
+
refusal: refuse("`change_events_secret_file` must be a path to the file holding the secret."),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const path = expandHome(secretFile, homedir);
|
|
246
|
+
if (!nodePath.isAbsolute(path)) {
|
|
247
|
+
return {
|
|
248
|
+
refusal: refuse(
|
|
249
|
+
`change_events_secret_file must be absolute or start with ~/ (got '${secretFile}').`,
|
|
250
|
+
),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let raw;
|
|
255
|
+
try {
|
|
256
|
+
raw = await fs.readFile(path, "utf8");
|
|
257
|
+
} catch (err) {
|
|
258
|
+
return {
|
|
259
|
+
refusal: refuse(
|
|
260
|
+
`Could not read change_events_secret_file '${path}' (${err?.code || "error"}). ` +
|
|
261
|
+
"Nothing was sent.",
|
|
262
|
+
),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const secret = raw.replace(/\r?\n$/, "");
|
|
267
|
+
if (secret === "") {
|
|
268
|
+
return { refusal: refuse(`change_events_secret_file '${path}' is empty. Nothing was sent.`) };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return { secret };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
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.
|
|
278
|
+
*/
|
|
279
|
+
function chgEnrolmentRefusal(mode, fields) {
|
|
280
|
+
if (mode !== "chg") return null;
|
|
281
|
+
|
|
282
|
+
const missing = ["change_events_secret", "chg_root_dispatch_id"].filter(
|
|
283
|
+
(field) => fields[field] === undefined,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
if (missing.length === 0) return null;
|
|
287
|
+
|
|
288
|
+
return refuse(
|
|
289
|
+
`\`mode: chg\` needs ${missing.map((f) => `\`${f}\``).join(" and ")} in the same call; ` +
|
|
290
|
+
"the server answers 422 without them. `chg_root_dispatch_id` is the parentless " +
|
|
291
|
+
"orchestrator-role dispatch chg-server's key was minted from (the operator mints it " +
|
|
292
|
+
"with `dispatch`, no parent), and the secret is the HMAC key chg-server signs its " +
|
|
293
|
+
"events with (`change_events_secret_file` keeps it out of the transcript).",
|
|
159
294
|
);
|
|
160
295
|
}
|
|
161
296
|
|
|
@@ -221,6 +356,8 @@ export function publicSource(source) {
|
|
|
221
356
|
base_branch: source.base_branch,
|
|
222
357
|
mode: source.mode,
|
|
223
358
|
required_checks: source.required_checks,
|
|
359
|
+
// `change_events_secret` is NEVER named here: write-only (US-47.2).
|
|
360
|
+
chg_root_dispatch_id: source.chg_root_dispatch_id,
|
|
224
361
|
target_epic_id: source.target_epic_id,
|
|
225
362
|
revoked_at: source.revoked_at,
|
|
226
363
|
inserted_at: source.inserted_at,
|
|
@@ -255,6 +392,9 @@ export async function enrollIntakeSource(
|
|
|
255
392
|
mode,
|
|
256
393
|
required_checks,
|
|
257
394
|
secret_file,
|
|
395
|
+
change_events_secret,
|
|
396
|
+
change_events_secret_file,
|
|
397
|
+
chg_root_dispatch_id,
|
|
258
398
|
} = {},
|
|
259
399
|
{ userKey, apiCall, baseUrl, fs = defaultFs, homedir = os.homedir() } = {},
|
|
260
400
|
) {
|
|
@@ -309,6 +449,16 @@ export async function enrollIntakeSource(
|
|
|
309
449
|
if (badChecks) return badChecks;
|
|
310
450
|
}
|
|
311
451
|
|
|
452
|
+
// The `chg` credentials (US-47.2), resolved and judged before a secret file is reserved.
|
|
453
|
+
const chg = await chgCredentials(
|
|
454
|
+
{ change_events_secret, change_events_secret_file, chg_root_dispatch_id },
|
|
455
|
+
{ clearable: false, fs, homedir },
|
|
456
|
+
);
|
|
457
|
+
if (chg.refusal) return chg.refusal;
|
|
458
|
+
|
|
459
|
+
const badChg = chgEnrolmentRefusal(mode, chg.fields);
|
|
460
|
+
if (badChg) return badChg;
|
|
461
|
+
|
|
312
462
|
if (typeof secret_file !== "string" || secret_file.trim() === "") {
|
|
313
463
|
return refuse(
|
|
314
464
|
"`secret_file` is required: the path the webhook secret is written to (mode 0600). " +
|
|
@@ -360,6 +510,7 @@ export async function enrollIntakeSource(
|
|
|
360
510
|
if (base_branch !== undefined) body.base_branch = base_branch;
|
|
361
511
|
if (mode !== undefined) body.mode = mode;
|
|
362
512
|
if (required_checks !== undefined) body.required_checks = required_checks;
|
|
513
|
+
Object.assign(body, chg.fields);
|
|
363
514
|
|
|
364
515
|
let result;
|
|
365
516
|
try {
|
|
@@ -514,7 +665,10 @@ export async function listIntakeSources({ include_revoked } = {}, { userKey, api
|
|
|
514
665
|
* uses `empty_values: []` precisely so that a caller who SENT a value gets an answer about
|
|
515
666
|
* the value it sent, which is a 422.
|
|
516
667
|
*/
|
|
517
|
-
export async function updateIntakeSource(
|
|
668
|
+
export async function updateIntakeSource(
|
|
669
|
+
args = {},
|
|
670
|
+
{ userKey, apiCall, fs = defaultFs, homedir = os.homedir() } = {},
|
|
671
|
+
) {
|
|
518
672
|
if (!userKey) return refuse(MISSING_USER_KEY);
|
|
519
673
|
|
|
520
674
|
const bad = uuidRefusal(args.source_id, "source_id");
|
|
@@ -553,11 +707,20 @@ export async function updateIntakeSource(args = {}, { userKey, apiCall } = {}) {
|
|
|
553
707
|
body.required_checks = args.required_checks;
|
|
554
708
|
}
|
|
555
709
|
|
|
710
|
+
// Switching to `chg` may rely on credentials an earlier `chg` stint left on the row, so their
|
|
711
|
+
// absence here is the SERVER's to judge (422 naming the missing one); only their shape is
|
|
712
|
+
// judged here.
|
|
713
|
+
const chg = await chgCredentials(args, { clearable: true, fs, homedir });
|
|
714
|
+
if (chg.refusal) return chg.refusal;
|
|
715
|
+
Object.assign(body, chg.fields);
|
|
716
|
+
|
|
556
717
|
if (Object.keys(body).length === 0) {
|
|
557
718
|
return refuse(
|
|
558
719
|
"Nothing to update. Name at least one of `target_epic_id` (null clears it), " +
|
|
559
|
-
"`base_branch`, `mode
|
|
560
|
-
"`
|
|
720
|
+
"`base_branch`, `mode`, `required_checks`, `change_events_secret` (or " +
|
|
721
|
+
"`change_events_secret_file`) or `chg_root_dispatch_id`. A body carrying none of them " +
|
|
722
|
+
"is refused 422 `nothing_to_update`, because a field you do not send is left exactly " +
|
|
723
|
+
"as it was.",
|
|
561
724
|
);
|
|
562
725
|
}
|
|
563
726
|
|
package/lib/story-update.js
CHANGED
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
* (`lib/loopctl_web/plugs/cast_error_handler.ex:32-35`), and the body is
|
|
73
73
|
* `LoopctlWeb.ErrorJSON`'s generic `{"error": {"status": 404, "message": "Not found"}}` — byte
|
|
74
74
|
* for byte what `FallbackController` answers for a well-formed id naming no story
|
|
75
|
-
* (`lib/loopctl_web/fallback_controller.ex:
|
|
75
|
+
* (`lib/loopctl_web/fallback_controller.ex:84-88`). Two opposite remedies, one answer.
|
|
76
76
|
*
|
|
77
77
|
* The check is `uuid()`, IMPORTED from `lib/delivery-loop.js` rather than reimplemented, so the
|
|
78
78
|
* refusal a caller reads for a bad `story_id` does not depend on which tool they reached for.
|