loopctl-mcp-server 3.57.0 → 3.59.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 +3 -3
- package/index.js +34 -5
- package/lib/fly-metrics-credential.js +46 -3
- package/lib/intake-sources.js +32 -28
- package/lib/runners.js +46 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -496,7 +496,7 @@ Each row names the key it sends; an entity definition is a security root and nee
|
|
|
496
496
|
| `bootstrap_audit_key` | **Generate the first audit signing keypair** for a tenant created before Chain of Custody v2 (#873, `POST /api/v1/tenants/:id/bootstrap-audit-key`). Takes `tenant_id`; returns the public key. Refuses `409 key_already_exists` (rotation is the WebAuthn ceremony) and `403` for a key that is not user role or not the tenant's. Requires **user** key. |
|
|
497
497
|
| `clear_github_credential` | **Remove the tenant's GitHub token** (#936, `DELETE /api/v1/tenants/me/github-credential`). Calls then use the operator's token only for `operator_repositories` and are refused `credential_unavailable` everywhere else, so a pr-mode repository outside that list stops merging. Idempotent. Requires **user** key. |
|
|
498
498
|
| `fly_metrics_credential` | **Is there a Fly metrics credential for this tenant?** (US-55.7, `GET /api/v1/tenants/me/fly-metrics-credential`) `has_token`, a masked last-4 `token_hint`, the Fly `org` and `updated_at`. Never returns the token. The post-deploy monitor reads the edge metrics of the Fly apps the tenant's intake sources name (`fly_app`, set with `intake_source_update`) with this credential and no other: there is no operator token, so a tenant without one is not monitored. Requires **user** key (403 `insufficient_role` otherwise). |
|
|
499
|
-
| `set_fly_metrics_credential` | **Set or replace the tenant's own Fly metrics credential** (US-55.7, `PUT /api/v1/tenants/me/fly-metrics-credential`): the Fly org slug and a read-only token from `fly tokens create readonly <org>`, which the post-deploy monitor reads the org's managed Prometheus with. Stored encrypted, never returned, and not checked against Fly on the way in: a token that cannot read the org shows up as the monitor's read failure. Refused locally and 422 at the server on `details.org` unless the org is a Fly org slug (lowercase letters, digits and hyphens, at most 63, starting with a letter or digit), and on `details.token` unless the trimmed token starts `FlyV1 `, is at most 4096 characters and holds only `A-Z a-z 0-9 _ + / = , -` after the prefix; a `Bearer` personal token is refused, because it reaches every org its user can. `403 custody_tier_required` on an agent-rooted tenant. Required: `org`, `token
|
|
499
|
+
| `set_fly_metrics_credential` | **Set or replace the tenant's own Fly metrics credential** (US-55.7, `PUT /api/v1/tenants/me/fly-metrics-credential`): the Fly org slug and a read-only token from `fly tokens create readonly <org>`, which the post-deploy monitor reads the org's managed Prometheus with. Stored encrypted, never returned, and not checked against Fly on the way in: a token that cannot read the org shows up as the monitor's read failure. Refused locally and 422 at the server on `details.org` unless the org is a Fly org slug (lowercase letters, digits and hyphens, at most 63, starting with a letter or digit), and on `details.token` unless the trimmed token starts `FlyV1 `, is at most 4096 characters and holds only `A-Z a-z 0-9 _ + / = , -` after the prefix; a `Bearer` personal token is refused, because it reaches every org its user can. `403 custody_tier_required` on an agent-rooted tenant. Required: `org`, and exactly one of `token` or `token_file` (an absolute or `~/` path the tool reads the token from, so it never passes through the transcript: a single line, or exactly one line starting `FlyV1 `). Requires **user** key. |
|
|
500
500
|
| `clear_fly_metrics_credential` | **Remove the tenant's Fly metrics credential** (US-55.7, `DELETE /api/v1/tenants/me/fly-metrics-credential`). The post-deploy monitor then skips the tenant. Idempotent: `has_token: false` whether or not one was set. `403 custody_tier_required` on an agent-rooted tenant. Requires **user** key. |
|
|
501
501
|
| `knowledge_llm_usage` | Per-tenant LLM token-usage summary, grouped by operation + model + source_type + day over an optional `from`/`to` range (defaults to a 90-day lookback; effective window echoed in `meta.from`/`meta.to`), with `limit`/`offset` pagination. Record-only (no budget enforcement). Requires orchestrator key. |
|
|
502
502
|
|
|
@@ -649,7 +649,7 @@ The order to wire it up, the stage machine these tools move a story through, and
|
|
|
649
649
|
| `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`). **The pull request must target exactly the base branch of the story's own intake source** (`base_branch` on the answer, compared case-sensitively): a pull request into any other branch, open or already merged, is a `refuse` with reason `pr_base_mismatch` (never `already_merged`), and one whose base cannot be read is a `refuse` with `pr_base_unreadable`; the story is escalated like any refusal, and the remedy is to retarget the pull request (`gh pr edit --base <base_branch>`). 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`. |
|
|
650
650
|
| `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 (each story reads its OWN source; its 409 `no_intake_source` means the story has none). **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`, a project that is missing / archived / the wrong kind for the mode, or a `target_epic_id` outside that project. **One source per repository AND base branch (US-54.1):** a repository may have a second live source (a release, staging or e2e branch) on the same project, and `issue_label` (1-50 characters, compared case-insensitively) says which issues are whose. A project has ONE live `pr`/`chg` source with no label — its primary — so every other source of it carries one. Three refusals, each a 422 naming the field: `repo_full_name` `already has a live intake source on base branch <b>`, `issue_label` `is already the label of another live source on this repository`, and `issue_label` `is required: this project already has a source with no issue label`. `issue_label` is optional here (leave it out for the primary) and a null or blank one is refused locally. `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. `deploy_environment` (US-54.7) is the GitHub deployment environment post-deploy verification reads this source's stories against; leave it out for the default, the operator's fleet-wide `DELIVERY_DEPLOY_ENVIRONMENT` (`production` when unset), and name it (e.g. `e2e-sandbox`) for a branch whose deploy workflow writes another environment: 1-255 characters with no control character (null, blank or a control character is refused locally, 422 on `deploy_environment` at the server); a wrong name is not a silent pass, the story escalates at the sweep's bound. Optional: `base_branch`, `issue_label`, `deploy_environment`, `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`. |
|
|
651
651
|
| `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`, `issue_label` (null on the project's primary source), `deploy_environment` (the deployment environment its stories are verified against; null means the fleet-wide `DELIVERY_DEPLOY_ENVIRONMENT`, `production` when unset), `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 `base_branch_mismatch`, to check a repository's `base_branch` before placing work, to see a repository's sources side by side (`base_branch`, `issue_label`) before enrolling another, 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. |
|
|
652
|
-
| `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, `issue_label`, the GitHub label that marks this source's issues (an explicit null clears it, which makes the source its project's primary; a `base_branch` or `issue_label` change meets the same three 422 refusals as `intake_source_enroll`: `already has a live intake source on base branch <b>`, `is already the label of another live source on this repository`, `is required: this project already has a source with no issue label`), `deploy_environment`, the GitHub deployment environment post-deploy verification reads this source's stories against (US-54.7; an explicit null clears it, returning the source to the fleet-wide `DELIVERY_DEPLOY_ENVIRONMENT`, `production` when unset; read on every sweep, so it reaches stories already waiting; an empty string, a control character or more than 255 characters is refused locally and 422 at the server), `fly_app`, the Fly app the post-deploy monitor reads this source's edge metrics for with the tenant's own Fly metrics credential (US-55.7, `set_fly_metrics_credential`; an explicit null clears it, which stops the monitor reading the source; anything but a Fly app name, lowercase letters, digits and hyphens of at most 63 characters starting with a letter or digit, is refused locally and 422 on `fly_app` at the server), `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. |
|
|
652
|
+
| `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, `issue_label`, the GitHub label that marks this source's issues (an explicit null clears it, which makes the source its project's primary; a `base_branch` or `issue_label` change meets the same three 422 refusals as `intake_source_enroll`: `already has a live intake source on base branch <b>`, `is already the label of another live source on this repository`, `is required: this project already has a source with no issue label`), `deploy_environment`, the GitHub deployment environment post-deploy verification reads this source's stories against (US-54.7; an explicit null clears it, returning the source to the fleet-wide `DELIVERY_DEPLOY_ENVIRONMENT`, `production` when unset; read on every sweep, so it reaches stories already waiting; an empty string, a control character or more than 255 characters is refused locally and 422 at the server), `fly_app`, the Fly app the post-deploy monitor reads this source's edge metrics for with the tenant's own Fly metrics credential (US-55.7, `set_fly_metrics_credential`; an explicit null clears it, which stops the monitor reading the source; anything but a Fly app name, lowercase letters, digits and hyphens of at most 63 characters starting with a letter or digit, is refused locally and 422 on `fly_app` at the server), `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), and `deploys`, whether a merge is followed by a GitHub deployment (false: the merge is the release, so post-deploy verification moves a merged story on with `release_id` `merge:<sha>` and reads no deployment; read on every sweep; 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. |
|
|
653
653
|
| `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 source's uniqueness slots — its repository and base branch, its `issue_label`, and its project's primary slot (every identity 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. |
|
|
654
654
|
|
|
655
655
|
### Dispatch & Chain of Custody (v2) Tools
|
|
@@ -675,7 +675,7 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
|
|
|
675
675
|
| `work_item_timeline` | **Read a work item's timeline** (`GET /api/v1/stories/:id/timeline`): `item` (stage and its age, holder, lease, issue, PR, runner, newest 20 CI runs, newest 20 runner dispatches (`dispatch_id`, `kind`, `runner_id`, `status`), thread count and newest 20 messages, and `triage_escalation`: null when triage never escalated the item, else its newest triage escalation at any stage: `verdict`, `escalation_reasons` and `missing_information` (`untrusted: true`, fenced in `fenced`), `escalated_at`, and `current`, true while the item is still escalated in it) and one page of `events`, the event log and audit log merged oldest first. Optional `cursor` (a page's `next_cursor`) and `limit` (default 100, max 500). Read-only on any key; never moves a thread cursor. Every reason and message body is untrusted session text, flagged `untrusted: true`. `404` for another tenant's story, `400` for a bad limit or cursor. |
|
|
676
676
|
| `holder_list` | **List the holders and what each holds** (`GET /api/v1/holders`, #1297): the tenant's live session holders, newest `last_seen_at` first, each with `id`, `agent_id`, `kind`, `host`, `session_id`, `worktree`, `registered_at`, `last_heartbeat_at`, `lease_expires_at`, `ended_at`, `ended_reason` and `items` (the work items it holds now: `story_id`, `number`, `project_id`, `title`, `stage`, `branch`, `pr_number`). Join a live session to its holder on `session_id`. A holder whose lease ran out but the sweep has not ended yet is still listed. Optional `include_ended: true` adds the holders that ended in the last day. At most 200 holders; `truncated: true` says there were more. Read-only on any key: no heartbeat, no lease move, never a credential. |
|
|
677
677
|
| `decisions` | **Read the decided-on-default notes** (`GET /api/v1/decisions`): live messages whose `idempotency_key` starts `decision-default:`, on a repo channel or a work item thread (never a DM), newest first, without expired, quarantined or superseded ones. Each row carries `idempotency_key`, `project_id`, `story_id`, `host`, a bounded `body_preview` and `untrusted: true`; `has_more` says the limit cut the list. Optional `since` (ISO 8601, default 48 hours ago) and `limit` (1..100, default 25). Read-only on any key. `400` for a bad `since` or `limit`. |
|
|
678
|
-
| `factory_overview` | **Read the factory overview** (`GET /api/v1/factory/overview`): per project and summed for the fleet, `in_flight` counts per stage (claimed through verified), `waiting` counts (detected, triaged, queued, and escalated per reason class) with the oldest item's age, `throughput` over the window (done count, median seconds opened to done) and `failure_classes` (moves into escalated or failed, by edge), `reserved` (queue items a released move reserves for one host, holder or the cloud, with the oldest age and `by_kind`, not counted again under `waiting`; a released move to the loop stays under `waiting`) and `interactive` (`in_flight` items an interactive holder holds, a subset of `in_flight`, and `waiting` items reserved for an interactive session after a lapsed claim, with the oldest age). Counts come from the stage machine; drill into an item with `work_item_timeline`. Optional `project_id` and `window_days` (default 7, 1..30). Read-only on any key. `400` for a bad window, `404` for another tenant's project, `503` when the read times out. |
|
|
678
|
+
| `factory_overview` | **Read the factory overview** (`GET /api/v1/factory/overview`): per project and summed for the fleet, `in_flight` counts per stage (claimed through verified), `waiting` counts (detected, triaged, queued, and escalated per reason class) with the oldest item's age, `throughput` over the window (done count, median seconds opened to done) and `failure_classes` (moves into escalated or failed, by edge), `reserved` (queue items a released move reserves for one host, holder or the cloud, with the oldest age and `by_kind`, not counted again under `waiting`; a released move to the loop stays under `waiting`) and `interactive` (`in_flight` items an interactive holder holds, a subset of `in_flight`, and `waiting` items reserved for an interactive session after a lapsed claim, with the oldest age), and `detected_blocked` (the `waiting.detected` items split by why each is still there, under the first reason that holds: `no_intake_record`, `issue_closed`, `no_triage_source`, `intake_paused`, `ticket_required`, `triaging` (a triage dispatch is in flight), `no_runner_for_repo` (no live connected runner takes triage for the repository without a config refusal), `runners_busy`, `triage_due`; each a count and oldest age, summing to `waiting.detected.count`). Counts come from the stage machine; drill into an item with `work_item_timeline`. Optional `project_id` and `window_days` (default 7, 1..30). Read-only on any key. `400` for a bad window, `404` for another tenant's project, `503` when the read times out. |
|
|
679
679
|
| `factory_policy` | **Read the factory policy** (`GET /api/v1/factory/policy`, US-52.51): every delivery-loop rule value, compiled into loopctl from `factory/policy.toml` — review-round `normal` and `ceiling` per diff kind (`prose`, `code`), `open_prs_per_session`, `epics_open_per_repo`, `pr_body.required_sections`, `review.default_level` and `review.max_level`, `epic_merge.new_tip_seconds`, `protected_branches`. Returns `{schema, version, rules}`; `version` is the file's sha256 (the endpoint's ETag, so a client that kept a copy gets `304` on `If-None-Match`). The same for every tenant. Any tenant key; refuses nothing else (`401` only without a valid key). No arguments. |
|
|
680
680
|
| `review_round_open` | **Open a review round** (`POST /api/v1/review_rounds`, US-52.53): counts one round on the work item for `repo_url` and `branch` and answers from the factory policy's `review_rounds.<diff_kind>` limits — `201 {round_id, round, normal, ceiling, verdict, message, attested}`, `verdict` `allow` while round <= normal and `warn` up to the ceiling. A repeated `round_id` counts nothing and answers `200` with the first answer. `attested: true` with a `reason` counts a review the hook could not see. `kind: "security"` with a `head_sha` records a /security-review at that head instead (`201 {round_id, kind, head_sha, message, attested}`), never counted against the ceiling. `ancestor_shas` (the branch's commits outside the base, at most 500) refuses a round whose branch carries another unmerged item's ceiling-round head (claude-config#810). Holder credential (the round's actor is its holder). `409 review_ceiling_reached` (nothing counted; the session decides a redesign or a narrower merge), `409 inherited_ceiling_reached` (`parent_branch`, `head_sha`, `round_count`, `ceiling`), `422 attestation_reason_required`, `422 head_sha_required`, `404 work_item_not_found` (no item, or only ended items your holder never held: open one with `work_item_open`), `403 holder_credential_required`, `400 repo_and_branch_required`, `409 ambiguous_project`, `422 invalid_round_id`/`invalid_kind`/`invalid_diff_kind`/`invalid_head_sha`/`invalid_ancestor_shas`/`invalid_branch`, `503 busy`. |
|
|
681
681
|
| `review_round_void` | **Void a review round** that did not review (`POST /api/v1/review_rounds/:round_id/void`, US-52.53): it stops counting on its item. `201 {round_id, voided, round, count}`; a second void is `200`. Holder credential. `404 review_round_not_found`, `409 ambiguous_round_id`, `403 holder_credential_required`, `422 invalid_reason`, `503 busy`. |
|
package/index.js
CHANGED
|
@@ -9052,7 +9052,8 @@ const TOOLS = [
|
|
|
9052
9052
|
description:
|
|
9053
9053
|
"SET OR REPLACE this tenant's own Fly metrics credential (US-55.7, PUT " +
|
|
9054
9054
|
"/api/v1/tenants/me/fly-metrics-credential): the Fly org slug and a read-only token " +
|
|
9055
|
-
"for it, from `fly tokens create readonly <org
|
|
9055
|
+
"for it, from `fly tokens create readonly <org>`, passed as `token` or read from " +
|
|
9056
|
+
"`token_file` (exactly one; the file keeps it out of the transcript). The post-deploy monitor reads your " +
|
|
9056
9057
|
"apps' edge metrics from Fly's managed Prometheus for that org with it. Stored " +
|
|
9057
9058
|
"encrypted, never returned. NOT checked against Fly here: a token that cannot read the " +
|
|
9058
9059
|
"org shows up as the monitor's read failure. Refused locally and 422 at the server on " +
|
|
@@ -9068,10 +9069,19 @@ const TOOLS = [
|
|
|
9068
9069
|
org: { type: "string", description: "The Fly org slug, e.g. `personal`." },
|
|
9069
9070
|
token: {
|
|
9070
9071
|
type: "string",
|
|
9071
|
-
description:
|
|
9072
|
+
description:
|
|
9073
|
+
"The FlyV1 read-only token. Write-only; stored encrypted, never returned. Prefer " +
|
|
9074
|
+
"`token_file`, which keeps the token out of the transcript.",
|
|
9075
|
+
},
|
|
9076
|
+
token_file: {
|
|
9077
|
+
type: "string",
|
|
9078
|
+
description:
|
|
9079
|
+
"Alternative to `token`: an absolute (or `~/`) path the tool reads the token from, " +
|
|
9080
|
+
"e.g. a file written by `fly tokens create readonly <org> > <file>`. A single line, " +
|
|
9081
|
+
"or exactly one line starting `FlyV1 `. Not both.",
|
|
9072
9082
|
},
|
|
9073
9083
|
},
|
|
9074
|
-
required: ["org"
|
|
9084
|
+
required: ["org"],
|
|
9075
9085
|
},
|
|
9076
9086
|
},
|
|
9077
9087
|
{
|
|
@@ -11881,7 +11891,12 @@ const TOOLS = [
|
|
|
11881
11891
|
"is loop work and stays under `waiting`); `interactive` (`in_flight`: items an " +
|
|
11882
11892
|
"interactive holder holds at an in-flight stage, a subset of `in_flight`; " +
|
|
11883
11893
|
"`waiting`: items reserved for an interactive session after its claim lapsed, with the " +
|
|
11884
|
-
"oldest age).
|
|
11894
|
+
"oldest age); `detected_blocked` (the `waiting.detected` items split by why each is " +
|
|
11895
|
+
"still there, under the first reason that holds: `no_intake_record`, `issue_closed` " +
|
|
11896
|
+
"(taken again if the issue reopens), `no_triage_source`, `intake_paused`, " +
|
|
11897
|
+
"`ticket_required`, `triaging` (a triage dispatch is in flight), `no_runner_for_repo` " +
|
|
11898
|
+
"(no live connected runner takes triage for its repository without a config refusal), `runners_busy`, `triage_due`; each a count and oldest age, summing to " +
|
|
11899
|
+
"`waiting.detected.count`). Every count is read " +
|
|
11885
11900
|
"from loopctl's stage machine at request time; drill into one item with " +
|
|
11886
11901
|
"work_item_timeline. Optional `project_id` narrows it to one project; `window_days` " +
|
|
11887
11902
|
"defaults to 7, 1..30. READ-ONLY on any key. 400 for a window outside 1..30; 404 for a " +
|
|
@@ -13912,7 +13927,9 @@ const TOOLS = [
|
|
|
13912
13927
|
"422 on `deploy_environment` at the server), `fly_app`, the Fly app the post-deploy " +
|
|
13913
13928
|
"monitor reads this source's edge metrics for with the tenant's own Fly metrics " +
|
|
13914
13929
|
"credential (US-55.7; null clears it; anything but a Fly app name is refused here and " +
|
|
13915
|
-
"422 on `fly_app` at the server), `
|
|
13930
|
+
"422 on `fly_app` at the server), `deploys` (false: the merge is the release, and " +
|
|
13931
|
+
"post-deploy verification waits for no deployment; null is refused here and 422 at the " +
|
|
13932
|
+
"server), `mode`, the merge route (`pr` or `chg`, " +
|
|
13916
13933
|
"or `ledger` on a KB scope or a work project), and the `change_events_secret` and " +
|
|
13917
13934
|
"`chg_root_dispatch_id` " +
|
|
13918
13935
|
"that authenticate a source's chg ledger and change events.\n\n" +
|
|
@@ -14089,6 +14106,18 @@ const TOOLS = [
|
|
|
14089
14106
|
"on every pass, so it reaches the stories and records already waiting. Null is " +
|
|
14090
14107
|
"refused; omit the field to leave it alone.",
|
|
14091
14108
|
},
|
|
14109
|
+
deploys: {
|
|
14110
|
+
type: "boolean",
|
|
14111
|
+
description:
|
|
14112
|
+
"WHETHER A MERGE IS FOLLOWED BY A DEPLOYMENT. True (the default): post-deploy " +
|
|
14113
|
+
"verification moves a merged story to `deployed` and `verified` once a GitHub " +
|
|
14114
|
+
"deployment carrying its merge succeeded, and escalates it when none does within " +
|
|
14115
|
+
"its bound. False: the merge is the release (a library, a config repository, a " +
|
|
14116
|
+
"service released by hand), so the sweep moves a merged story on with " +
|
|
14117
|
+
"`release_id` `merge:<sha>` and reads no deployment. Read on every sweep, so it " +
|
|
14118
|
+
"reaches stories already waiting at `merged`. Null is refused; omit the field to " +
|
|
14119
|
+
"leave it alone.",
|
|
14120
|
+
},
|
|
14092
14121
|
},
|
|
14093
14122
|
required: ["source_id"],
|
|
14094
14123
|
},
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
* returned — reads show `has_token`, a last-4 `token_hint` and the `org`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import os from "node:os";
|
|
15
|
+
import defaultFs from "node:fs/promises";
|
|
16
|
+
|
|
17
|
+
import { readSecretPath } from "./runners.js";
|
|
18
|
+
|
|
14
19
|
export const FLY_METRICS_CREDENTIAL_PATH = "/api/v1/tenants/me/fly-metrics-credential";
|
|
15
20
|
|
|
16
21
|
/** The longest token the server accepts (`TenantCredential.max_token_length/0`). */
|
|
@@ -27,11 +32,39 @@ export async function flyMetricsCredential(_args = {}, { apiCall } = {}) {
|
|
|
27
32
|
return apiCall("GET", FLY_METRICS_CREDENTIAL_PATH, null);
|
|
28
33
|
}
|
|
29
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The token from `token_file`: an absolute (or `~/`) path holding the output of
|
|
37
|
+
* `fly tokens create readonly <org>`, so the token never passes through the transcript. A file
|
|
38
|
+
* of several lines is read for its one line starting `FlyV1 `. Resolves to `{ token }` or
|
|
39
|
+
* `{ refusal }`; no refusal carries the file's contents.
|
|
40
|
+
*/
|
|
41
|
+
async function readTokenFile(tokenFile, { fs, homedir }) {
|
|
42
|
+
const read = await readSecretPath("token_file", tokenFile, { fs, homedir });
|
|
43
|
+
if (read.message) return { refusal: refuse(read.message) };
|
|
44
|
+
const { path, raw } = read;
|
|
45
|
+
|
|
46
|
+
const lines = raw.split(/\r?\n/).map((l) => l.trim()).filter((l) => l !== "");
|
|
47
|
+
const flyLines = lines.filter((l) => l.startsWith("FlyV1 "));
|
|
48
|
+
if (flyLines.length === 1) return { token: flyLines[0] };
|
|
49
|
+
if (lines.length === 1) return { token: lines[0] };
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
refusal: refuse(
|
|
53
|
+
`token_file '${path}' must hold one token: a single line, or exactly one line starting ` +
|
|
54
|
+
"`FlyV1 `. Nothing was sent.",
|
|
55
|
+
),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
30
59
|
/**
|
|
31
60
|
* A malformed org or token is refused HERE, before any call, with the server's rule; the
|
|
32
|
-
* refusal never repeats the token, because a tool result lands in the transcript.
|
|
61
|
+
* refusal never repeats the token, because a tool result lands in the transcript. The token
|
|
62
|
+
* comes from `token` or `token_file`, never both.
|
|
33
63
|
*/
|
|
34
|
-
export async function setFlyMetricsCredential(
|
|
64
|
+
export async function setFlyMetricsCredential(
|
|
65
|
+
{ org, token, token_file: tokenFile } = {},
|
|
66
|
+
{ apiCall, fs = defaultFs, homedir = os.homedir() } = {},
|
|
67
|
+
) {
|
|
35
68
|
if (typeof org !== "string" || !ORG_FORMAT.test(org)) {
|
|
36
69
|
return refuse(
|
|
37
70
|
"`org` is required: the Fly org slug (`fly orgs list`), e.g. `personal` — lowercase " +
|
|
@@ -39,6 +72,16 @@ export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } =
|
|
|
39
72
|
);
|
|
40
73
|
}
|
|
41
74
|
|
|
75
|
+
if (token !== undefined && tokenFile !== undefined) {
|
|
76
|
+
return refuse("Send `token` OR `token_file`, not both: they are two ways of naming the same value.");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (tokenFile !== undefined) {
|
|
80
|
+
const read = await readTokenFile(tokenFile, { fs, homedir });
|
|
81
|
+
if (read.refusal) return read.refusal;
|
|
82
|
+
token = read.token;
|
|
83
|
+
}
|
|
84
|
+
|
|
42
85
|
const trimmed = typeof token === "string" ? token.trim() : "";
|
|
43
86
|
|
|
44
87
|
if (
|
|
@@ -47,7 +90,7 @@ export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } =
|
|
|
47
90
|
!TOKEN_FORMAT.test(trimmed)
|
|
48
91
|
) {
|
|
49
92
|
return refuse(
|
|
50
|
-
"`token` is required: the output of `fly tokens create readonly <org>`, which starts " +
|
|
93
|
+
"`token` (or `token_file`) is required: the output of `fly tokens create readonly <org>`, which starts " +
|
|
51
94
|
`\`FlyV1 \` and holds only A-Z a-z 0-9 _ + / = , - after it, at most ` +
|
|
52
95
|
`${MAX_FLY_TOKEN_CHARS} characters. A \`Bearer\` personal token is refused: it ` +
|
|
53
96
|
"reaches every org its user can.",
|
package/lib/intake-sources.js
CHANGED
|
@@ -142,7 +142,13 @@ import os from "node:os";
|
|
|
142
142
|
import defaultFs from "node:fs/promises";
|
|
143
143
|
|
|
144
144
|
import { uuid as uuidRefusal } from "./delivery-loop.js";
|
|
145
|
-
import {
|
|
145
|
+
import {
|
|
146
|
+
expandHome,
|
|
147
|
+
readSecretPath,
|
|
148
|
+
TOKEN_DIR_MODE,
|
|
149
|
+
TOKEN_FILE_FLAGS,
|
|
150
|
+
TOKEN_FILE_MODE,
|
|
151
|
+
} from "./runners.js";
|
|
146
152
|
|
|
147
153
|
export const SOURCES_PATH = "/api/v1/intake/sources";
|
|
148
154
|
|
|
@@ -298,32 +304,9 @@ export async function chgCredentials(args, { clearable, fs = defaultFs, homedir
|
|
|
298
304
|
}
|
|
299
305
|
|
|
300
306
|
async function readSecretFile(secretFile, { fs, homedir }) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const path = expandHome(secretFile, homedir);
|
|
308
|
-
if (!nodePath.isAbsolute(path)) {
|
|
309
|
-
return {
|
|
310
|
-
refusal: refuse(
|
|
311
|
-
`change_events_secret_file must be absolute or start with ~/ (got '${secretFile}').`,
|
|
312
|
-
),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
let raw;
|
|
317
|
-
try {
|
|
318
|
-
raw = await fs.readFile(path, "utf8");
|
|
319
|
-
} catch (err) {
|
|
320
|
-
return {
|
|
321
|
-
refusal: refuse(
|
|
322
|
-
`Could not read change_events_secret_file '${path}' (${err?.code || "error"}). ` +
|
|
323
|
-
"Nothing was sent.",
|
|
324
|
-
),
|
|
325
|
-
};
|
|
326
|
-
}
|
|
307
|
+
const read = await readSecretPath("change_events_secret_file", secretFile, { fs, homedir });
|
|
308
|
+
if (read.message) return { refusal: refuse(read.message) };
|
|
309
|
+
const { path, raw } = read;
|
|
327
310
|
|
|
328
311
|
const secret = raw.replace(/\r?\n$/, "");
|
|
329
312
|
if (secret === "") {
|
|
@@ -402,6 +385,20 @@ export function triageRequiresTicketRefusal(value) {
|
|
|
402
385
|
);
|
|
403
386
|
}
|
|
404
387
|
|
|
388
|
+
/**
|
|
389
|
+
* `deploys`: a boolean, never null (`Source.put_deploys/2` answers 422 for null). False says the
|
|
390
|
+
* merge is the release, so post-deploy verification waits for no deployment record.
|
|
391
|
+
*/
|
|
392
|
+
export function deploysRefusal(value) {
|
|
393
|
+
if (typeof value === "boolean") return null;
|
|
394
|
+
|
|
395
|
+
return refuse(
|
|
396
|
+
"`deploys` must be true (a merge is followed by a GitHub deployment, which post-deploy " +
|
|
397
|
+
"verification waits for) or false (the merge is the release). It cannot be null; leave " +
|
|
398
|
+
"it out to keep the current value.",
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
405
402
|
/** The longest `issue_label`, in characters: GitHub's own label limit (`Source.max_issue_label_chars/0`). */
|
|
406
403
|
export const MAX_ISSUE_LABEL_CHARS = 50;
|
|
407
404
|
|
|
@@ -521,6 +518,7 @@ export function publicSource(source) {
|
|
|
521
518
|
mode: source.mode,
|
|
522
519
|
required_checks: source.required_checks,
|
|
523
520
|
triage_requires_ticket: source.triage_requires_ticket,
|
|
521
|
+
deploys: source.deploys,
|
|
524
522
|
// `change_events_secret` is NEVER named here: write-only (US-47.2).
|
|
525
523
|
chg_root_dispatch_id: source.chg_root_dispatch_id,
|
|
526
524
|
target_epic_id: source.target_epic_id,
|
|
@@ -938,6 +936,12 @@ export async function updateIntakeSource(
|
|
|
938
936
|
body.triage_requires_ticket = args.triage_requires_ticket;
|
|
939
937
|
}
|
|
940
938
|
|
|
939
|
+
if (args.deploys !== undefined) {
|
|
940
|
+
const badDeploys = deploysRefusal(args.deploys);
|
|
941
|
+
if (badDeploys) return badDeploys;
|
|
942
|
+
body.deploys = args.deploys;
|
|
943
|
+
}
|
|
944
|
+
|
|
941
945
|
// Switching to `chg` may rely on credentials an earlier `chg` stint left on the row, so their
|
|
942
946
|
// absence here is the SERVER's to judge (422 naming the missing one); only their shape is
|
|
943
947
|
// judged here.
|
|
@@ -950,7 +954,7 @@ export async function updateIntakeSource(
|
|
|
950
954
|
"Nothing to update. Name at least one of `target_epic_id` (null clears it), " +
|
|
951
955
|
"`base_branch`, `issue_label` (null clears it), `deploy_environment` (null clears " +
|
|
952
956
|
"it), `fly_app` (null clears it), `mode`, `required_checks`, " +
|
|
953
|
-
"`triage_requires_ticket`, " +
|
|
957
|
+
"`triage_requires_ticket`, `deploys`, " +
|
|
954
958
|
"`change_events_secret` (or " +
|
|
955
959
|
"`change_events_secret_file`), `chg_root_dispatch_id` or `mint_chg_root`. A body " +
|
|
956
960
|
"carrying none of them " +
|
package/lib/runners.js
CHANGED
|
@@ -64,6 +64,52 @@ export function expandHome(p, homedir = os.homedir()) {
|
|
|
64
64
|
return p;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** The largest file a `*_file` secret argument may name; every secret here is far smaller. */
|
|
68
|
+
export const MAX_SECRET_FILE_BYTES = 64 * 1024;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Read the file a `*_file` secret argument names (`field` is the argument's name, for the
|
|
72
|
+
* messages). Resolves to `{ path, raw }` or `{ message }`, a refusal that never carries the
|
|
73
|
+
* file's contents. The path must be absolute or `~/`, and must be a regular file of at most
|
|
74
|
+
* `maxBytes`: it is stat'ed BEFORE it is opened, because opening a FIFO blocks until a writer
|
|
75
|
+
* comes and a device such as /dev/zero never ends, either of which would hang the tool call.
|
|
76
|
+
*/
|
|
77
|
+
export async function readSecretPath(
|
|
78
|
+
field,
|
|
79
|
+
value,
|
|
80
|
+
{ fs, homedir = os.homedir(), maxBytes = MAX_SECRET_FILE_BYTES } = {},
|
|
81
|
+
) {
|
|
82
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
83
|
+
return { message: `\`${field}\` must be a path to the file holding the secret.` };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const path = expandHome(value, homedir);
|
|
87
|
+
if (!nodePath.isAbsolute(path)) {
|
|
88
|
+
return { message: `${field} must be absolute or start with ~/ (got '${value}').` };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let stat;
|
|
92
|
+
try {
|
|
93
|
+
stat = await fs.stat(path);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
return { message: `Could not read ${field} '${path}' (${err?.code || "error"}). Nothing was sent.` };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!stat.isFile()) {
|
|
99
|
+
return { message: `${field} '${path}' is not a regular file. Nothing was sent.` };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (stat.size > maxBytes) {
|
|
103
|
+
return { message: `${field} '${path}' is larger than ${maxBytes} bytes. Nothing was sent.` };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
return { path, raw: await fs.readFile(path, "utf8") };
|
|
108
|
+
} catch (err) {
|
|
109
|
+
return { message: `Could not read ${field} '${path}' (${err?.code || "error"}). Nothing was sent.` };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
67
113
|
/**
|
|
68
114
|
* `POST /api/v1/runners {name, max_sessions?}`, with the returned token written to
|
|
69
115
|
* `token_file` and never returned. Resolves to
|