loopctl-mcp-server 3.41.0 → 3.41.2
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 +6 -6
- package/index.js +79 -30
- package/lib/branch-item.js +38 -3
- package/lib/holder.js +143 -20
- package/lib/interventions.js +21 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -556,8 +556,8 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
|
|
|
556
556
|
|---|---|
|
|
557
557
|
| `signup` | **US-26.7.1.** Create a NEW **agent-rooted (KB-tier)** tenant and mint its one-time root API key — entirely through this call, no human operator, no hardware authenticator, no existing API key required. The tenant gets the FULL knowledge-wiki surface but **cannot** perform work-breakdown / chain-of-custody operations (those require a separate human-anchored tenant via the WebAuthn ceremony at `https://loopctl.com/signup`). Rate-limited per client IP (<= 5/hour). The `raw_key` is shown ONCE — save it immediately (e.g. as `LOOPCTL_USER_KEY`). Required: `name`, `slug`, `email`. |
|
|
558
558
|
| `dispatch` | Mint an ephemeral, scoped api_key for a sub-agent dispatch, carrying its lineage path. The `raw_key` is returned ONCE — pass it to the sub-agent's launch args, never store it in env vars; it expires after `expires_in_seconds` (default 3600, max 14400). Required: `role` (`agent`/`orchestrator`), `agent_id`, and `parent_dispatch_id` for every caller a dispatch minted — a dispatch may only be minted INSIDE the caller's own lineage. Omitting `parent_dispatch_id` requests a ROOT dispatch (a new independent lineage tree), which only the tenant's `user`-role operator key may create; anyone else gets `403 root_dispatch_forbidden` with their own dispatch id in `remediation.your_dispatch_id`. A parent outside the caller's lineage is `403 parent_outside_caller_lineage`. Optional: `story_id`. **LCP-1 §9.2 signed profile:** optionally enroll an agent key via `agent_pubkey` (hex) + `alg` + an `attestation` (from `custody_sign_attestation`) + `attestation_conditions`. |
|
|
559
|
-
| `holder_register` | **Register this session as a holder** (`POST /api/v1/holders`, US-52.13). The server does this at startup and heartbeats on a timer; call it to re-register after `holder_end`. Sends `LOOPCTL_AGENT_KEY` exactly, with `kind: interactive`, the session id (`CLAUDE_CODE_SESSION_ID`, else `CLAUDE_SESSION_ID`, else a per-process uuid), the host and the git top level. A live holder of the same session answers with the SAME holder and a new credential, which this process keeps in memory and sends on every agent-key request; the raw key is never returned to the caller. Each register and every rotation also writes it to the holder credential file `$HOME/.claude/loopctl-holders/<session_id>.key` (mode 0600, directory 0700, written atomically by temp file and rename), named by the same session id, so a hook of the same session (claude-config's SessionStart inbox read and its tool-round hook) can read the inbox as this holder. A register rotates the live holder's credential and revokes every earlier key, another MCP process of the same session's included (an `/mcp` reconnect), so you do not need it after a 401: a request sent on the holder credential that gets 401 takes up the newer key another process of the session wrote to the file, or else registers, and is retried once on its own (a pinned request on the holder credential, such as `holder_replay` and the journal's replay, recovers too; the holder's own register, heartbeat and end, a request on `LOOPCTL_AGENT_KEY` or any other key, and a second 401 are returned as they are; concurrent 401s share one recovery). The id must match `[A-Za-z0-9._-]`; a process with no session marker, or a runner session (`LOOP_MODE`), writes no file. `403 custody_tier_required` on an agent-rooted tenant, `403 holder_mint_forbidden` for a dispatch-minted key, `422 agent_required` for a key naming no agent; on any refusal the session keeps using `LOOPCTL_AGENT_KEY`. |
|
|
560
|
-
| `holder_heartbeat` | **Renew this session holder's lease now** (`POST /api/v1/holders/:id/heartbeat`), by the holder's own credential. Runs on its own every `heartbeat_seconds`. Also moves every uncapped claim this holder holds to the new lease (US-52.19). A 401, 404 or 409 (credential revoked or expired, holder ended) first takes up a newer key another process of this session wrote to the holder credential file and beats once with it; only without one, or when that beat is refused too, does it register again (which would revoke the other process's key); a `409 holder_lease_expired` means the lease ran out first, so loopctl ended the holder and released its claims: the session registers as a NEW holder (logged to stderr) and must re-claim. |
|
|
559
|
+
| `holder_register` | **Register this session as a holder** (`POST /api/v1/holders`, US-52.13). The server does this at startup and heartbeats on a timer; call it to re-register after `holder_end`. Sends `LOOPCTL_AGENT_KEY` exactly, with `kind: interactive`, the session id (`CLAUDE_CODE_SESSION_ID`, else `CLAUDE_SESSION_ID`, else a per-process uuid), the host and the git top level. A live holder of the same session answers with the SAME holder and a new credential, which this process keeps in memory and sends on every agent-key request; the raw key is never returned to the caller. Each register and every rotation also writes it to the holder credential file `$HOME/.claude/loopctl-holders/<session_id>.key` (mode 0600, directory 0700, written atomically by temp file and rename), named by the same session id, so a hook of the same session (claude-config's SessionStart inbox read and its tool-round hook) can read the inbox as this holder. A register rotates the live holder's credential and revokes every earlier key, another MCP process of the same session's included (an `/mcp` reconnect), so you do not need it after a 401: a request sent on the holder credential that gets 401 takes up the newer key another process of the session wrote to the file, or else registers, and is retried once on its own (a pinned request on the holder credential, such as `holder_replay` and the journal's replay, recovers too; the holder's own register, heartbeat and end, a request on `LOOPCTL_AGENT_KEY` or any other key, and a second 401 are returned as they are; concurrent 401s share one recovery). Such a recovery registers at most once per heartbeat interval per process: a second refusal inside it, with no newer key in the file, falls back to `LOOPCTL_AGENT_KEY` (logged to stderr) instead of revoking the other process's key, and the next heartbeat takes up that key from the file; a register's new key is written over the file only when the file has not changed since the register was sent, so a concurrent register's key is never replaced by a revoked one. This tool and the startup register are never held back. The id must match `[A-Za-z0-9._-]`; a process with no session marker, or a runner session (`LOOP_MODE`), writes no file. `403 custody_tier_required` on an agent-rooted tenant, `403 holder_mint_forbidden` for a dispatch-minted key, `422 agent_required` for a key naming no agent; on any refusal the session keeps using `LOOPCTL_AGENT_KEY`. |
|
|
560
|
+
| `holder_heartbeat` | **Renew this session holder's lease now** (`POST /api/v1/holders/:id/heartbeat`), by the holder's own credential. Runs on its own every `heartbeat_seconds`. Also moves every uncapped claim this holder holds to the new lease (US-52.19). A 401, 404 or 409 (credential revoked or expired, holder ended) first takes up a newer key another process of this session wrote to the holder credential file and beats once with it; only without one, or when that beat is refused too, does it register again (which would revoke the other process's key), and at most once per heartbeat interval: inside it the session stays on `LOOPCTL_AGENT_KEY` and the next beat takes up the file's key when one appears; a `409 holder_lease_expired` means the lease ran out first, so loopctl ended the holder and released its claims: the session registers as a NEW holder (logged to stderr) and must re-claim. |
|
|
561
561
|
| `holder_end` | **End this session holder** (`POST /api/v1/holders/:id/end`): sets `ended_at`, revokes its credential and releases every uncapped claim it holds (a `released` item event, reason "holder ended"), then falls back to `LOOPCTL_AGENT_KEY`. Deletes the holder credential file before the request is sent; a heartbeat refused as gone deletes it too, until a new register writes the new key. Runs on its own when stdin closes, on SIGTERM or on SIGINT, and any other exit still deletes the file. A repeated end writes nothing. When another MCP process of this session holds the credential (the file holds another key, or this process took its key from the file) it sends no end and answers `ended: false`: ending would revoke that live process's key and release its claims; it drops only its own state, and the holder lapses on its lease if that process is gone too. |
|
|
562
562
|
| `holder_replay` | **Replay what this session recorded while loopctl was unreachable** (`POST /api/v1/holders/:id/replay`, US-52.61), on this session's holder credential and to its own holder id. `entries` in strictly ascending `seq`, each `{event_id, seq, kind, story_id, claim_epoch, recorded_at, payload}`; only `note` (`{section, body}`) and `checkpoint` (`{branch, head_sha, diff` base64 `or wip_branch, done, next}`) replay, never a claim, stage move, report, review or verify. One result per entry in seq order: `applied` (held at that `claim_epoch`, through the verb's own checks), `replayed` (the `event_id` already applied with this payload: the first result, nothing written), `fenced` (the session held the story at that epoch and no longer does: a note becomes a `fenced_replay` event, a checkpoint is stored fenced for the current holder; the story does not move) or `refused` with `error.code` (`invalid_entry`, `not_found`, `event_id_conflict`, `not_holder`, `stale_claim_epoch`, `busy`, `fenced_note_limit` when the item already keeps 50 fenced notes from this holder or 200 from all late holders and nothing is written, a checkpoint refusal such as `fenced_checkpoint_limit`); one refusal never stops the rest. A holder that lapsed during the outage is replayed by the session's next holder, fenced. Refused whole: `403 holder_mismatch`, `409 holder_ended`, `422 replay_not_ordered`, `422 replay_too_large` (over 200 entries). Refused locally, sending nothing, with no live holder credential or a body out of seq order. |
|
|
563
563
|
| `work_item_note` | **Write a note on a work item** (`POST /api/v1/stories/:id/notes`, US-52.17): `section` (plan, progress, decision, question) and `body`, appended and never edited, plus a `note_written` event on the story log in the same transaction. Sends this session's own key (its holder credential). Only the story's current holder writes one: `409 held_by_other_holder` when another session holds it, `409 not_holder` when nobody does, `404` for another tenant's story, `422` for an unknown section, an empty body, a body over 16384 bytes or a credential-shaped body. A writer repeating its own `idempotency_key` gets its first note back; a key another writer's note already carries is `409 idempotency_key_reused`. Every note carries a client UUIDv7 `event_id` (US-52.62); when loopctl does not answer (network error, timeout, 502/503/504) the note is journaled (`LOOPCTL_JOURNAL_DIR`) and answered `{queued: true, event_id}`, then replayed in order through `holder_replay`; while the journal holds entries a new note queues behind them. The journal entry needs the `claim_epoch` (optional argument; else the one the session last saw, else read from the story once). |
|
|
@@ -565,13 +565,13 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
|
|
|
565
565
|
| `work_item_checkpoint` | **Checkpoint a work item** (`POST /api/v1/stories/:id/checkpoints`, US-52.41): computes from `worktree` the branch, the commit its work applies to (the pushed head, else the merge-base with origin's default branch) and `git diff --binary` on top of it with untracked files, without writing to the worktree, and records them with one progress note from `done` and `next` and a `checkpointed` event. Sends this session's own key (its holder credential): only the current holder at the story's `claim_epoch` (read from the story when omitted) with a live lease. `409 not_holder` (names the holder), `409 stale_claim_epoch`, `409 claim_lease_expired`, `409 checkpoint_id_conflict`, `403 holder_credential_required`, `404` for another tenant's story; `413 diff_over_bound` over 4 MiB (push a `wip/...` branch and pass `wip_branch` instead); `422 secret_in_diff` (names the files), `422 diff_and_wip_branch`, `422 invalid_wip_branch`. A repeated `checkpoint_id` with the same content returns the stored checkpoint (`replayed: true`). A checkpoint from a claim that has ended (the epoch you held, after the item moved on) is stored fenced and answered `202` (`fenced: true`, `current_holder_id`), with no note and no change to the item, for the current holder to resolve (US-52.42). Past 5 unresolved fenced checkpoints from you on one item, or 10 on the item from all late holders, a late checkpoint is `409 fenced_checkpoint_limit` (`limit_scope`, `max_unresolved_fenced`) and nothing is stored: push a `wip/...` branch instead. The checkpoint id is a client UUIDv7 unless given (US-52.62); one that gets no answer from loopctl is journaled under the epoch the session last saw and answered `{queued: true, event_id}`, unless it is too large for one replay body (about 1.5 MB encoded): then push a `wip/...` branch. |
|
|
566
566
|
| `work_item_checkpoints` | **Read a work item's checkpoints**: the newest 20, newest first, without diffs (`GET /api/v1/stories/:id/checkpoints`), with `fenced: "unresolved"` the fenced ones nobody resolved yet, oldest first, or with `checkpoint_id` one checkpoint with its diff base64 (`GET .../checkpoints/:checkpoint_id`), which `git apply` takes on a checkout of its `head_sha`. Any key of the tenant. `404` for another tenant's story or checkpoint. |
|
|
567
567
|
| `work_item_checkpoint_resolve` | **Apply or ignore a fenced checkpoint** (`POST /api/v1/stories/:id/checkpoints/:checkpoint_id/resolve`, US-52.42): `resolution` (`applied` or `ignored`) and a `reason`, on this session's own key; only the story's current holder with a live lease. The same resolution again is `200` and writes nothing. `409 not_holder` (names `holder_id`), `409 already_resolved`, `422 not_fenced`, `403 holder_credential_required`, `404` for a checkpoint not on this tenant's story. |
|
|
568
|
-
| `work_item_move` | **Move a work item** to a host, a holder, the cloud or the loop (`POST /api/v1/stories/:id/move`, US-52.43), on this session's own key; the server picks the path from who calls. The holder (live lease) names its own `checkpoint_id` at the current epoch and the claim is released at once over the uncounted `:moved` edge: `200 released`. Anyone else REQUESTS it: the holder is told on the item's thread and has `MOVE_RELEASE_SECONDS` to answer with the same `move_id`, after which the deadline worker releases it: `202 requested`. An unheld item is released at once: `200`. While reserved only the target claims it (`409 reserved_for_move`); a move to a host, holder or the cloud unpulled after `MOVE_PULL_SECONDS` expires to the loop, and a move to the loop never expires: implement@1 places it with the move's checkpoint as `resume`, on a runner of contract 1.40.0 or later (US-52.46). An item an interactive session released is reserved for any interactive session until
|
|
568
|
+
| `work_item_move` | **Move a work item** to a host, a holder, the cloud or the loop (`POST /api/v1/stories/:id/move`, US-52.43), on this session's own key; the server picks the path from who calls. The holder (live lease) names its own `checkpoint_id` at the current epoch and the claim is released at once over the uncounted `:moved` edge: `200 released`. Anyone else REQUESTS it: the holder is told on the item's thread and has `MOVE_RELEASE_SECONDS` to answer with the same `move_id`, after which the deadline worker releases it: `202 requested`. An unheld item is released at once: `200`. While reserved only the target claims it (`409 reserved_for_move`); a move to a host, holder or the cloud unpulled after `MOVE_PULL_SECONDS` expires to the loop, and a move to the loop never expires: implement@1 places it with the move's checkpoint as `resume`, on a runner of contract 1.40.0 or later (US-52.46). An item an interactive session released is reserved for any interactive session until someone moves it on. A move to a host whose runner joined on contract 1.40.0 or later is placed there and resumes from the move's checkpoint (US-52.44); a runner session holding the item is asked over its runner's socket. The same `move_id` and target answers the first result. `400 move_id_required`/`reason_required`/`invalid_reason`, `404` (incl. `unknown_story_stage`), `409 holder_ended`/`item_closed`/`item_escalated`/`move_pending`/`item_changed`, `422 invalid_target`/`unknown_host`/`unknown_holder`/`holder_cannot_pull` (a runner_session holder claims nothing after its own placement: move to its host)/`target_unavailable`/`already_held_by_target`/`checkpoint_not_current`, `403 boundary_move_needs_mark` only when ANOTHER session holds the item on a live lease, the move crosses the interactive boundary (that holder or the target holder is an interactive session), and the caller is not Mark's own user key (fleet_dash; US-52.45): a holder moves its own item anywhere, the loop included, and an item nobody is working is anyone's to move on; a key with no holder omits `checkpoint_id`; and `403` without the human anchor. |
|
|
569
569
|
| `work_item_pull` | **Pull a work item into a git worktree here**, then claim it (US-52.46). Reads the item's newest unfenced checkpoint and its unresolved fenced ones, fetches the checkpoint's branch and `head_sha` from origin, adds a worktree on that branch at `head_sha` (default `.claude/worktrees/<branch with / replaced by ->` under the repository's top level), checks then applies the diff with `git apply --binary`, and only then claims the item (`POST /api/v1/stories/:id/claim`) on this session's own key. git runs through `execFile`. Returns `path`, `branch`, `head_sha`, `checkpoint_id`, `applied_files`, `fenced_checkpoint_ids` and the claim. Refuses `path_not_empty` before any git write, `no_checkpoint`, `head_not_found`, `local_branch_differs` (a local branch of that name is never moved), `diff_does_not_apply` naming the rejected files (worktree removed, nothing claimed), `diff_apply_failed` when the check passed but writing the diff failed (worktree and any branch it created removed, nothing claimed), `worktree_add_failed`, and returns the claim's own refusal (`409 reserved_for_move`, `held_by_other_holder`) with the worktree removed. |
|
|
570
570
|
| `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. |
|
|
571
571
|
| `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`. |
|
|
572
572
|
| `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). 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. |
|
|
573
573
|
| `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. |
|
|
574
|
-
| `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` (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`. |
|
|
574
|
+
| `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`. |
|
|
575
575
|
| `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`. |
|
|
576
576
|
| `review_round_status` | **Read a branch's review rounds** (`GET /api/v1/review_rounds?repo_url=&branch=`, US-52.53): `{rounds: [{round_id, round, diff_kind, head_sha, attested, voided, actor_holder_id, inserted_at}], count, diff_kind, normal, ceiling, security, inherited, capped}`, `count` excluding voided rounds; `security` lists the item's /security-review records (not rounds); with `ancestor_shas`, `inherited` names the capped parent the branch descends from, else null; `capped` lists the project's other items capped in the last 7 days (`{branch, capped_at, heads, ceiling_heads, released}`, at most 20) for the carry-over check (claude-config#812); optional `diff_kind` picks the limits. With `ancestor_shas` (at most 500) the tool sends `POST /api/v1/review_rounds/status`, the same read with the list in a JSON body, since 500 shas pass the server's 10,000-byte request line; it writes nothing. Any agent key. `400 repo_and_branch_required`, `404 work_item_not_found`, `409 ambiguous_project`, `422 invalid_diff_kind`/`invalid_ancestor_shas`. |
|
|
577
577
|
| `intake_pause` | **Pause one intake source of a project** (`POST /api/v1/projects/:id/intake/pause`, US-52.33, US-54.4): that source's new issues stay `pending_triage` and get no triage. Optional `source_id` names the source; without it the pause acts on the project's primary (unlabelled) source, so a sibling source (e2e) keeps running. Stops promotion and triage ONLY: never in-flight work and never the webhook, which keeps recording. `reason` required; `intervention_id` generated when absent (a repeat writes nothing). `404 no_intake_source` (a `source_id` that is not a live source of this project, or no primary source), `403` on an agent-rooted tenant. Session's own key. |
|
|
@@ -580,8 +580,8 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
|
|
|
580
580
|
| `work_item_requeue` | **Requeue a work item** (`POST /api/v1/stories/:id/requeue`, US-52.32): an escalated item goes back to `queued` over this holder's resolution edge (`409 self_resolve_blocked` / `review_missing_unreviewed` as for `resolve_escalation`); an in-flight item is released, uncounted, its dispatch revoked, and re-contracted. Any other stage is `409 not_requeueable`. The linked issue is not touched. |
|
|
581
581
|
| `work_item_retriage` | **Re-triage a work item** (`POST /api/v1/stories/:id/retriage`, US-52.32): an item no implementer touched, at `escalated` or `queued`, goes back to `detected`; its triage is discarded and its triage dispatches superseded. `409 not_retriageable` names what a touched item holds, or the stage. The linked issue is not touched. |
|
|
582
582
|
| `work_item_cancel` | **Cancel a work item** (`POST /api/v1/stories/:id/cancel`, US-52.32): to `failed` over `:cancelled` from detected, triaged, queued, escalated or in flight. The linked issue is left open. `409 already_landed` (merged, deployed, verified), `409 already_finished` (done, failed). |
|
|
583
|
-
| `work_item_close` | **Close a work item
|
|
584
|
-
| `work_item_open` | **Open the work item for a branch** (`POST /api/v1/work_items`, US-52.18): `repo_url` and `branch`, optional `title` (default: the branch), `base_branch` (US-54.2: the branch the work merges into; selects the project's live intake source with exactly that base branch and records it as the item's source; omitted, the item belongs to the project's primary, unlabelled source) and `epic_id` (default: that source's target epic). Creates one story already implementing and held by this session, with a stage row naming the branch; the MCP server also does it on each heartbeat for the worktree's non-default branch, once per branch per holder. That heartbeat open sends `base_branch` only from the environment variable `LOOPCTL_BASE_BRANCH` when not blank (US-54.9), and otherwise omits it; nothing is guessed from the checkout, and a worktree on that base branch opens nothing. Reopening your own item, or an unheld one, returns it (200). Needs this session's holder credential: `403 holder_credential_required` otherwise. `409 branch_held` (another session's open item has the branch), `409 holder_ended`, `409 holder_lease_expired`, `409 story_held`, `409 base_branch_mismatch` (the branch's open item merges into another base branch), `404 project_not_found`, `404 epic_not_found`, `422 no_source_for_base` (no live source of the project merges into `base_branch`), `422 no_target_epic` (pass `epic_id`), `422 invalid_branch` / `invalid_base_branch`. |
|
|
583
|
+
| `work_item_close` | **Close a work item** (`POST /api/v1/stories/:id/close`, US-52.32): on another holder's item, as `work_item_cancel` over `:closed`; the only verb that closes the linked issue, as not actionable. On your OWN interactive item (one `work_item_open` opened), a self-close: `done` over `:self_closed` with required `evidence` (`400 evidence_required`), recorded on the stage event and audit log; `verified_status` is untouched. Refused `409 open_pull_request` (`pr_number`; the merge ends the item), `503 pull_request_state_unavailable` (GitHub unreadable, retry; a retry with the same `intervention_id` answers without asking GitHub again), `409 change_bound` (a chg change is bound to the item: it lands through chg, and its landing ends it), `409 not_self_closable` (at `queued`, `escalated`, `detected` or `triaged`), `409 already_finished` (`done` or `failed`), `409 already_landed` (`merged`, `deployed` or `verified`). Each of the four verbs sends this session's own key: `409 self_intervention_blocked` when its holder holds the item (except that self-close), `409 holder_required` for a non-human key with no holder, `409 stage_moved` when the item moved while the verb ran (nothing changed), `409 already_landed` for an escalated item whose change already landed (every verb but a reviewed `review_missing` requeue), `409 independent_verification` for a held chg landing on an independent path, `403` on an agent-rooted tenant, `400 reason_required` without a reason. A repeated `intervention_id` (generated when absent) writes nothing and returns the current stage row. |
|
|
584
|
+
| `work_item_open` | **Open the work item for a branch** (`POST /api/v1/work_items`, US-52.18): `repo_url` and `branch`, optional `title` (default: the branch), `base_branch` (US-54.2: the branch the work merges into; selects the project's live intake source with exactly that base branch and records it as the item's source; omitted, the item belongs to the project's primary, unlabelled source) and `epic_id` (default: that source's target epic). Creates one story already implementing and held by this session, with a stage row naming the branch; the MCP server also does it on each heartbeat for the worktree's non-default branch, once per branch per holder. That heartbeat open sends `base_branch` only from the environment variable `LOOPCTL_BASE_BRANCH` when not blank (US-54.9), and otherwise omits it; nothing is guessed from the checkout, and a worktree on that base branch opens nothing. Reopening your own item, or an unheld one, returns it (200). A branch with no open item whose most recent item ended at `done` while held by your holder answers that item (`200`, outcome `finished`) and creates nothing (another holder's finished item gets you a new item of your own), and the heartbeat stops opening that branch for the life of the process; `new_item: true` opens the next item for new work on that branch name. Needs this session's holder credential: `403 holder_credential_required` otherwise. `409 branch_held` (another session's open item has the branch), `409 holder_ended`, `409 holder_lease_expired`, `409 story_held`, `409 base_branch_mismatch` (the branch's open item merges into another base branch), `404 project_not_found`, `404 epic_not_found`, `422 no_source_for_base` (no live source of the project merges into `base_branch`), `422 no_target_epic` (pass `epic_id`), `422 invalid_branch` / `invalid_base_branch`. The item ends with no second session and no human: a MERGE of the branch's pull request ends it at `done` as the system actor (`:pr_merged`, naming the PR and merge sha); with no pull request, its holder ends it with `work_item_close` and `evidence` (`done` over `:self_closed`). Neither verifies it. |
|
|
585
585
|
| `inbox` | **Read this session's inbox** (`GET /api/v1/inbox`, US-52.24): `dms`, `threads` (each held story with unread messages; a story taken over arrives from its first message) and, with `project_id`, `channel`, each above the session's stored cursor, with `last_seq` per section and `has_more`. `limit` defaults to 50, at most 200, DMs first. The cursor moves only on ack, so an unacked message is returned again: `ack` (a list of `{kind, id, seq}`, kind `dm`/`story`/`channel`, seq a `last_seq` a read returned) is posted first (`POST /api/v1/inbox/ack`), then the inbox is read, and the answer carries `acked`. A refused batch moves no cursor: `422 ack_beyond_end`, `422 not_in_inbox`, `422 invalid_ack`. Needs this session's holder credential: `403 holder_credential_required` otherwise. The answer carries `journal` (US-52.62, read locally, present even when loopctl does not answer): `{pending, oldest_recorded_at, last_fenced}`, what this session still owes loopctl from an outage and the entries of its last replay that came back fenced. |
|
|
586
586
|
| `revoke_dispatch` | **Revoke a dispatch AND ITS WHOLE SUBTREE** (`POST /api/v1/dispatches/:id/revoke`), plus the ephemeral api_key each one minted — the revoke matches the dispatch OR any row carrying it in `lineage_path`, so name a LEAF unless you mean the subtree. Reach for it when a dead session's key is blocking new work: an un-revoked key OCCUPIES its agent's slot in the partial unique index `api_keys_one_role_per_agent_idx` (`(tenant_id, agent_id, role)` WHERE `revoked_at IS NULL`), which cannot also test `expires_at` — a partial-index predicate must be IMMUTABLE and `now()` is STABLE — so even an EXPIRED key holds it and the next mint answers `422 agent already has an active key with this role`. Waiting works too, slowly: the expired-dispatch sweep runs every minute and the expired-api-key sweep every five, so the slot clears at the TTL (four hours for a placement session dispatch). For a PARKED STORY prefer `force_unclaim_story`, which revokes that story's own session dispatch and frees the stage as well. It does NOT clear `implementer_dispatch_id`: that is custody provenance, and a revoked dispatch still resolves, so verify/report/review-complete compare the same lineage afterwards. `role: :orchestrator` WITH the hierarchy (orchestrator, user or superadmin all pass; an agent key is `403 insufficient_role`), so no env var is pinned — `LOOPCTL_USER_KEY` is merely PREFERRED, for the ceiling reason next. `403 dispatch_outside_caller_lineage` when the target is not in your lineage — a dispatch may only be revoked by a caller it descends from, because the revoke cascades; the body carries `remediation.your_dispatch_id`, and the tenant's `user`-role operator key may revoke anywhere in its tenant. `403 unlineaged_revoke_forbidden` when your key was minted by no dispatch and is below `user` role — a legacy `LOOPCTL_ORCH_KEY` is exactly that, and with no lineage there is no subtree that would bound a cascading revoke, so it could otherwise revoke the tenant's root; use the operator key, or `force_unclaim_story` for a parked story, or mint a dispatch under an active parent and revoke from inside that lineage. `403 custody_tier_required` on an agent-rooted tenant, `503 tenant_halted` under a custody halt, 404 for an unknown dispatch or another tenant's. Idempotent: an already-revoked dispatch answers 200 with `revoked_count: 0` and its ORIGINAL `revoked_at`. Required: `dispatch_id` (refused locally if it is not a UUID). |
|
|
587
587
|
| `register_custody_owner_key` | **LCP-1 §9.2.** Register/rotate the tenant custody OWNER key — the root of trust the attestation chain hangs from. Private half stays with you; requires `LOOPCTL_USER_KEY` and a human-anchored tenant. Required: `owner_pubkey` (hex). ROTATION additionally requires `rotation_proof` (from `custody_sign_owner_rotation`); first registration needs none. |
|
package/index.js
CHANGED
|
@@ -3202,13 +3202,14 @@ async function interventionTool(verb, args) {
|
|
|
3202
3202
|
}
|
|
3203
3203
|
|
|
3204
3204
|
// US-52.18: open (or reopen) the work item for a branch, on the session's own key: the
|
|
3205
|
-
// route accepts only a holder credential (lib/branch-item.js).
|
|
3205
|
+
// route accepts only a holder credential (lib/branch-item.js). Its answer tells the heartbeat's
|
|
3206
|
+
// opener whether the branch is finished (lib/branch-item.js, "A finished branch").
|
|
3206
3207
|
async function workItemOpenTool(args) {
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
);
|
|
3208
|
+
const result = await openWorkItem(args, {
|
|
3209
|
+
apiCall: (method, path, body) => apiCall(method, path, body, agentKey()),
|
|
3210
|
+
});
|
|
3211
|
+
branchItemOpener.noteOpen(args && args.branch, result);
|
|
3212
|
+
return toContent(result);
|
|
3212
3213
|
}
|
|
3213
3214
|
|
|
3214
3215
|
async function workItemNotesTool(args) {
|
|
@@ -8685,7 +8686,11 @@ const TOOLS = [
|
|
|
8685
8686
|
"holder's credential and revokes every earlier key, including another MCP process of " +
|
|
8686
8687
|
"this session's (an /mcp reconnect). You do not need it after a 401: a request on the " +
|
|
8687
8688
|
"holder credential that gets 401 takes up the newer key that process wrote, or " +
|
|
8688
|
-
"registers, and is retried once by itself.
|
|
8689
|
+
"registers, and is retried once by itself. Such a recovery registers at most once per " +
|
|
8690
|
+
"heartbeat interval: a second refusal inside it, with no newer key in the file, falls " +
|
|
8691
|
+
"back to LOOPCTL_AGENT_KEY (logged to stderr) instead of revoking the other process's " +
|
|
8692
|
+
"key, and the next heartbeat takes up that key from the file. This tool is never held " +
|
|
8693
|
+
"back. REFUSES: 403 " +
|
|
8689
8694
|
"custody_tier_required on an agent-rooted tenant, 403 holder_mint_forbidden for a " +
|
|
8690
8695
|
"dispatch-minted key, 422 agent_required for a key naming no agent. On any refusal the " +
|
|
8691
8696
|
"session keeps using LOOPCTL_AGENT_KEY.",
|
|
@@ -8700,7 +8705,9 @@ const TOOLS = [
|
|
|
8700
8705
|
"It also moves every uncapped claim the holder holds to the new lease. A 401, 404 or " +
|
|
8701
8706
|
"409 (credential revoked or expired, holder ended) first takes up a newer credential " +
|
|
8702
8707
|
"another MCP process of this session wrote to the holder key file and beats once with " +
|
|
8703
|
-
"it; only without one, or when that beat is refused too, does it register again
|
|
8708
|
+
"it; only without one, or when that beat is refused too, does it register again, and " +
|
|
8709
|
+
"at most once per heartbeat interval (inside it the session stays on LOOPCTL_AGENT_KEY " +
|
|
8710
|
+
"and the next beat takes up the file's key when one appears). 409 " +
|
|
8704
8711
|
"holder_lease_expired means the lease ran out first, so loopctl ended the holder and " +
|
|
8705
8712
|
"released its claims: the session registers as a NEW holder and must re-claim.",
|
|
8706
8713
|
inputSchema: { type: "object", properties: {} },
|
|
@@ -8831,7 +8838,12 @@ const TOOLS = [
|
|
|
8831
8838
|
"belongs to the project's primary (unlabelled) source. The epic is `epic_id`, else " +
|
|
8832
8839
|
"that source's target epic. Reopening your own item returns it (200, outcome " +
|
|
8833
8840
|
"existing), an unheld item on the branch is claimed back for you (200, claimed), and " +
|
|
8834
|
-
"your one held item with no branch takes this one (200, branch_recorded).
|
|
8841
|
+
"your one held item with no branch takes this one (200, branch_recorded). A branch with " +
|
|
8842
|
+
"no open item whose most recent item ended at done (its pull request merged, or you " +
|
|
8843
|
+
"closed it) while YOUR holder held it answers that item (200, finished) and creates " +
|
|
8844
|
+
"nothing (another holder's finished item gets you a new item of your own); the heartbeat then " +
|
|
8845
|
+
"stops opening that branch. For NEW work on a finished branch name pass `new_item: " +
|
|
8846
|
+
"true`, which creates the next item. Needs this " +
|
|
8835
8847
|
"session's holder credential: 403 holder_credential_required for any other key. 409 " +
|
|
8836
8848
|
"branch_held (another session's open item has the branch; names story_id and " +
|
|
8837
8849
|
"holder_id), 409 holder_ended, 409 story_held (the item is escalated), 409 " +
|
|
@@ -8839,9 +8851,13 @@ const TOOLS = [
|
|
|
8839
8851
|
"never relinked). 404 project_not_found (no project of your tenant has the repo), 404 " +
|
|
8840
8852
|
"epic_not_found. 422 no_source_for_base (no live intake source of the repo's project " +
|
|
8841
8853
|
"merges into base_branch), 422 no_target_epic (pass epic_id), 422 invalid_branch / " +
|
|
8842
|
-
"invalid_base_branch (empty, whitespace, HEAD, over 255 bytes).
|
|
8843
|
-
"
|
|
8844
|
-
"
|
|
8854
|
+
"invalid_base_branch (empty, whitespace, HEAD, over 255 bytes). HOW THE ITEM ENDS, " +
|
|
8855
|
+
"with no second session and no human: when the branch's pull request MERGES, loopctl " +
|
|
8856
|
+
"ends the item at done as the system actor (from GitHub's merge, naming the PR and " +
|
|
8857
|
+
"merge sha); with no pull request, you end it yourself with work_item_close and " +
|
|
8858
|
+
"`evidence` (done over :self_closed). Neither verifies it: the item reaches verified " +
|
|
8859
|
+
"only through report, review and verify like any story, and you cannot report it " +
|
|
8860
|
+
"yourself.",
|
|
8845
8861
|
inputSchema: {
|
|
8846
8862
|
type: "object",
|
|
8847
8863
|
properties: {
|
|
@@ -8849,6 +8865,13 @@ const TOOLS = [
|
|
|
8849
8865
|
branch: { type: "string", description: "The branch the work is on." },
|
|
8850
8866
|
title: { type: "string", description: "Optional: the item's title (default: the branch)." },
|
|
8851
8867
|
epic_id: { type: "string", description: "Optional: the UUID of the epic to file it under." },
|
|
8868
|
+
new_item: {
|
|
8869
|
+
type: "boolean",
|
|
8870
|
+
description:
|
|
8871
|
+
"Optional, default false: open a NEW item even when the branch's most recent " +
|
|
8872
|
+
"item ended at done (new work on a branch name whose earlier work merged or was " +
|
|
8873
|
+
"closed). Without it such a branch answers its finished item.",
|
|
8874
|
+
},
|
|
8852
8875
|
base_branch: {
|
|
8853
8876
|
type: "string",
|
|
8854
8877
|
description:
|
|
@@ -8894,12 +8917,33 @@ const TOOLS = [
|
|
|
8894
8917
|
{
|
|
8895
8918
|
name: "work_item_close",
|
|
8896
8919
|
description:
|
|
8897
|
-
"CLOSE A WORK ITEM
|
|
8898
|
-
"failed over :closed, from the same stages as
|
|
8899
|
-
"verb that closes the linked issue, as not
|
|
8900
|
-
"
|
|
8920
|
+
"CLOSE A WORK ITEM (POST /api/v1/stories/:id/close). On ANOTHER holder's item: end " +
|
|
8921
|
+
"it at failed over :closed as not actionable, from the same stages as " +
|
|
8922
|
+
"work_item_cancel; this is the only verb that closes the linked issue, as not " +
|
|
8923
|
+
"actionable. On YOUR OWN INTERACTIVE item (one work_item_open opened, held by this " +
|
|
8924
|
+
"session): a SELF-CLOSE, allowed, ending it at done over :self_closed with the " +
|
|
8925
|
+
"`evidence` you give (REQUIRED: 400 evidence_required) recorded on the stage event " +
|
|
8926
|
+
"and the audit log. Use it for work with no pull request (an investigation, an ops " +
|
|
8927
|
+
"task). It never verifies anything: verified_status is untouched, and the item " +
|
|
8928
|
+
"reads as self-closed, not verified. Refused 409 open_pull_request (names " +
|
|
8929
|
+
"pr_number) while the branch has an open pull request, because merging it ends the " +
|
|
8930
|
+
"item on its own; 503 pull_request_state_unavailable when GitHub could not be read " +
|
|
8931
|
+
"(retry), and a retry with the same intervention_id answers without asking it again; 409 " +
|
|
8932
|
+
"change_bound while a chg change is bound to the item (it lands through chg, and its " +
|
|
8933
|
+
"landing ends the item); 409 " +
|
|
8934
|
+
"not_self_closable at queued, escalated or a pre-queue stage (detected, triaged). " +
|
|
8935
|
+
"409 already_landed for merged, deployed or verified; 409 already_finished for done " +
|
|
8936
|
+
"or failed.",
|
|
8937
|
+
extraProperties: {
|
|
8938
|
+
evidence: {
|
|
8939
|
+
type: "string",
|
|
8940
|
+
description:
|
|
8941
|
+
"What was done and where, 1 to 4000 characters. REQUIRED to close your own " +
|
|
8942
|
+
"interactive item; optional otherwise.",
|
|
8943
|
+
},
|
|
8944
|
+
},
|
|
8901
8945
|
},
|
|
8902
|
-
].map(({ name, description }) => ({
|
|
8946
|
+
].map(({ name, description, extraProperties = {} }) => ({
|
|
8903
8947
|
name,
|
|
8904
8948
|
description:
|
|
8905
8949
|
description +
|
|
@@ -8908,7 +8952,8 @@ const TOOLS = [
|
|
|
8908
8952
|
"and a held chg landing on an independent path is 409 independent_verification until " +
|
|
8909
8953
|
"a host-separated verify closes its hold; only a human resolves either. " +
|
|
8910
8954
|
"Uses this session's own key: 409 self_intervention_blocked when this session's " +
|
|
8911
|
-
"holder holds the item (escalate or unclaim instead
|
|
8955
|
+
"holder holds the item (escalate or unclaim instead; the one exception is " +
|
|
8956
|
+
"work_item_close on your own interactive item), 409 holder_required for a " +
|
|
8912
8957
|
"non-human key with no holder, 409 stage_moved when the item moved while the verb ran " +
|
|
8913
8958
|
"(nothing changed), 403 on an agent-rooted tenant. A reason is required " +
|
|
8914
8959
|
"(400 reason_required). Pass the same intervention_id to retry after a lost " +
|
|
@@ -8923,6 +8968,7 @@ const TOOLS = [
|
|
|
8923
8968
|
type: "string",
|
|
8924
8969
|
description: "Optional UUID naming this intervention, so a retry applies it once.",
|
|
8925
8970
|
},
|
|
8971
|
+
...extraProperties,
|
|
8926
8972
|
},
|
|
8927
8973
|
required: ["story_id", "reason"],
|
|
8928
8974
|
},
|
|
@@ -9074,18 +9120,19 @@ const TOOLS = [
|
|
|
9074
9120
|
"MOVE_PULL_SECONDS (default 1800) expires to the loop, and a move to the loop never " +
|
|
9075
9121
|
"expires: implement@1 places it with the move's checkpoint as resume, on a runner of " +
|
|
9076
9122
|
"contract 1.40.0 or later. An item an interactive session released is reserved for " +
|
|
9077
|
-
"any interactive session until
|
|
9123
|
+
"any interactive session until someone moves it on; pull it with work_item_pull. A move to a HOST whose runner joined on contract 1.40.0 or later is placed " +
|
|
9078
9124
|
"there, and its session resumes from the move's checkpoint; a runner session holding " +
|
|
9079
9125
|
"the item is asked over its runner's socket and hands it over itself. Pass the same " +
|
|
9080
9126
|
"move_id to retry: the same move_id and target answers the " +
|
|
9081
|
-
"first result and writes nothing.
|
|
9082
|
-
"
|
|
9083
|
-
"
|
|
9084
|
-
"
|
|
9085
|
-
"
|
|
9086
|
-
"
|
|
9087
|
-
"
|
|
9088
|
-
"holder has no checkpoint of its own: omit checkpoint_id.
|
|
9127
|
+
"first result and writes nothing. YOUR OWN ITEM IS YOURS TO MOVE: the holder of an " +
|
|
9128
|
+
"item (live lease) moves it anywhere, the loop included, with its own checkpoint_id, " +
|
|
9129
|
+
"interactive session or not, and an item NOBODY is working (unheld, reserved, or its " +
|
|
9130
|
+
"lease ran out) is anyone's to move on. The one refusal: an item ANOTHER session is " +
|
|
9131
|
+
"working on a live lease, moved across the interactive boundary (that holder or the " +
|
|
9132
|
+
"target holder is an interactive session), is 403 boundary_move_needs_mark to every " +
|
|
9133
|
+
"key but Mark's own user key (fleet_dash), before anything is written. A key with no " +
|
|
9134
|
+
"holder has no checkpoint of its own: omit checkpoint_id. " +
|
|
9135
|
+
"Refusals: 400 " +
|
|
9089
9136
|
"move_id_required / reason_required / invalid_reason; 403 boundary_move_needs_mark; " +
|
|
9090
9137
|
"404 (not this tenant's story, or unknown_story_stage); 409 " +
|
|
9091
9138
|
"holder_ended, item_closed (done or failed), item_escalated (use work_item_requeue), " +
|
|
@@ -9147,8 +9194,9 @@ const TOOLS = [
|
|
|
9147
9194
|
"worktree_add_failed, and the claim's own refusal " +
|
|
9148
9195
|
"with the worktree removed: 409 reserved_for_move (a move reserved the item for another " +
|
|
9149
9196
|
"target; an item an interactive session released is reserved for any interactive " +
|
|
9150
|
-
"session), held_by_other_holder.
|
|
9151
|
-
"(work_item_move answers boundary_move_needs_mark); pull an item
|
|
9197
|
+
"session), held_by_other_holder. Moving another session's item across the interactive " +
|
|
9198
|
+
"boundary is Mark's (work_item_move answers boundary_move_needs_mark); pull an item " +
|
|
9199
|
+
"moved here.",
|
|
9152
9200
|
inputSchema: {
|
|
9153
9201
|
type: "object",
|
|
9154
9202
|
properties: {
|
|
@@ -9275,7 +9323,8 @@ const TOOLS = [
|
|
|
9275
9323
|
"(`parent_branch`, `head_sha`, `round_count`, `ceiling`: wait for the parent to merge or " +
|
|
9276
9324
|
"recut from the base), 422 `attestation_reason_required`, 422 `head_sha_required` (a " +
|
|
9277
9325
|
"security record with no head), 404 `work_item_not_found` (no item of this tenant on " +
|
|
9278
|
-
"that repo and branch: open one with
|
|
9326
|
+
"that repo and branch, or only ended items your holder never held: open one with " +
|
|
9327
|
+
"`work_item_open`), 403 " +
|
|
9279
9328
|
"`holder_credential_required`, 400 `repo_and_branch_required`, 409 `ambiguous_project`, " +
|
|
9280
9329
|
"422 `invalid_round_id` / `invalid_kind` / `invalid_diff_kind` / `invalid_head_sha` / " +
|
|
9281
9330
|
"`invalid_ancestor_shas` / `invalid_branch`, 503 `busy` (retry).",
|
package/lib/branch-item.js
CHANGED
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
* error, a 429 or a 5xx is retried on the next heartbeat. Nothing is created locally, and the
|
|
17
17
|
* open is idempotent on the server, so a lost response costs one repeated call.
|
|
18
18
|
*
|
|
19
|
+
* ## A finished branch
|
|
20
|
+
*
|
|
21
|
+
* loopctl answers `outcome: "finished"` when the branch's most recent item ended at done (its
|
|
22
|
+
* pull request merged, or its holder closed it), and creates nothing. Such a branch is
|
|
23
|
+
* remembered for the life of the PROCESS, not the holder: a re-register must not ask again, and
|
|
24
|
+
* a new process asks once and is told the same. The automatic open never sends `new_item`; new
|
|
25
|
+
* work on a finished branch name is opened deliberately with work_item_open and `new_item: true`,
|
|
26
|
+
* which also makes this process open that branch again on its heartbeat.
|
|
27
|
+
*
|
|
19
28
|
* ## The base branch (US-54.9)
|
|
20
29
|
*
|
|
21
30
|
* The open carries `base_branch` only when the session was TOLD it: the environment variable
|
|
@@ -39,7 +48,7 @@ function present(value) {
|
|
|
39
48
|
|
|
40
49
|
/** `POST /api/v1/work_items`: open (or reopen) the item for a branch. */
|
|
41
50
|
export async function openWorkItem(
|
|
42
|
-
{ repo_url, branch, title, epic_id, base_branch } = {},
|
|
51
|
+
{ repo_url, branch, title, epic_id, base_branch, new_item } = {},
|
|
43
52
|
{ apiCall } = {},
|
|
44
53
|
) {
|
|
45
54
|
if (!present(repo_url)) return refuse("`repo_url` is required: the repo's remote URL.");
|
|
@@ -56,7 +65,13 @@ export async function openWorkItem(
|
|
|
56
65
|
return refuse("`base_branch` must be a branch name string.");
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
if (new_item !== undefined && new_item !== null && typeof new_item !== "boolean") {
|
|
69
|
+
return refuse("`new_item` must be a boolean.");
|
|
70
|
+
}
|
|
71
|
+
|
|
59
72
|
const payload = { repo_url, branch };
|
|
73
|
+
// Only a deliberate new item is asked for; the server's default is to answer a finished one.
|
|
74
|
+
if (new_item === true) payload.new_item = true;
|
|
60
75
|
if (present(title)) payload.title = title;
|
|
61
76
|
if (present(epic_id)) payload.epic_id = epic_id;
|
|
62
77
|
if (present(base_branch)) payload.base_branch = base_branch;
|
|
@@ -89,6 +104,8 @@ export function createBranchItemOpener(deps) {
|
|
|
89
104
|
} = deps;
|
|
90
105
|
let holderId = null;
|
|
91
106
|
let done = new Set();
|
|
107
|
+
// Branches whose work loopctl answered as finished: per process, never reset by a new holder.
|
|
108
|
+
const finished = new Set();
|
|
92
109
|
|
|
93
110
|
async function defaultBranch(wt) {
|
|
94
111
|
const ref = await git(["-C", wt, "symbolic-ref", "refs/remotes/origin/HEAD"]);
|
|
@@ -114,7 +131,9 @@ export function createBranchItemOpener(deps) {
|
|
|
114
131
|
|
|
115
132
|
const wt = worktree();
|
|
116
133
|
const branch = ((await git(["-C", wt, "rev-parse", "--abbrev-ref", "HEAD"])) || "").trim();
|
|
117
|
-
if (branch === "" || branch === "HEAD" || done.has(branch))
|
|
134
|
+
if (branch === "" || branch === "HEAD" || done.has(branch) || finished.has(branch)) {
|
|
135
|
+
return "skipped";
|
|
136
|
+
}
|
|
118
137
|
|
|
119
138
|
const fallbackDefaults = ["main", "master"];
|
|
120
139
|
const known = await defaultBranch(wt);
|
|
@@ -141,8 +160,24 @@ export function createBranchItemOpener(deps) {
|
|
|
141
160
|
log(`loopctl: work item for branch ${branch} not opened (${code}); not retrying it`);
|
|
142
161
|
return "refused";
|
|
143
162
|
}
|
|
163
|
+
if (result && result.outcome === "finished") {
|
|
164
|
+
finished.add(branch);
|
|
165
|
+
log(`loopctl: branch ${branch}'s work item has ended at done; not opening it again`);
|
|
166
|
+
return "finished";
|
|
167
|
+
}
|
|
144
168
|
return "opened";
|
|
145
169
|
}
|
|
146
170
|
|
|
147
|
-
|
|
171
|
+
/**
|
|
172
|
+
* A deliberate work_item_open answered for `branch`: a new item (`new_item: true`, or any
|
|
173
|
+
* open that did not answer finished) means the branch has open work again, so the heartbeat
|
|
174
|
+
* may open it after a re-register. A finished answer is remembered like the heartbeat's own.
|
|
175
|
+
*/
|
|
176
|
+
function noteOpen(branch, result) {
|
|
177
|
+
if (!present(branch) || !result || result.error) return;
|
|
178
|
+
if (result.outcome === "finished") finished.add(branch);
|
|
179
|
+
else finished.delete(branch);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { tick, noteOpen };
|
|
148
183
|
}
|
package/lib/holder.js
CHANGED
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
* one place: the holder credential file (US-52.28, lib/holder-key-file.js),
|
|
42
42
|
* $HOME/.claude/loopctl-holders/<session_id>.key, mode 0600, which a hook of the same session
|
|
43
43
|
* reads to call the inbox as this holder. The file belongs to the process that wrote it last:
|
|
44
|
-
* - a register (startup, every rotation) writes it, over whatever it held
|
|
44
|
+
* - a register (startup, every rotation) writes it, over whatever it held when the register was
|
|
45
|
+
* sent; a key another process wrote while it was in flight (a concurrent register) is left;
|
|
45
46
|
* - a successful heartbeat writes it only when it is missing, never over another key;
|
|
46
47
|
* - a key adopted from the file is never written while the file is there. When the file is
|
|
47
48
|
* gone (the process that wrote it crashed and its exit handler deleted it), the next
|
|
@@ -83,6 +84,22 @@
|
|
|
83
84
|
* process's own state and sends nothing. Ending it would revoke the live process's
|
|
84
85
|
* credential and release its claims.
|
|
85
86
|
*
|
|
87
|
+
* - **A recovery registers at most once per `reregisterIntervalMs` per process** (one heartbeat
|
|
88
|
+
* interval by default), counted from the last RECOVERY register this process sent (the one a
|
|
89
|
+
* refusal triggered), so a lone process's first recovery is never delayed.
|
|
90
|
+
* Inside that window a recovery that finds no newer key in the file does not register: the
|
|
91
|
+
* process YIELDS. It drops the refused credential (and the file, when the file still holds that
|
|
92
|
+
* dead key), falls back to LOOPCTL_AGENT_KEY, keeps the holder id, and logs it; the refused
|
|
93
|
+
* request is re-sent once on LOOPCTL_AGENT_KEY unless it was pinned (`withHolderRecovery`).
|
|
94
|
+
* Each heartbeat tick after that takes up the file's key when it is one loopctl has not
|
|
95
|
+
* refused this process,
|
|
96
|
+
* and registers only once the window has passed. Two processes that both read the file before
|
|
97
|
+
* either wrote it register once each; the loser's next refusal yields instead of revoking the
|
|
98
|
+
* winner, and the yield clears the loser's dead key from the file so the winner's next heartbeat
|
|
99
|
+
* writes its live one there. Without the bound, that race repeated is the ping-pong
|
|
100
|
+
* (2026-11-24, x1: a new key every 16-44 s, none used). The startup register and an explicit
|
|
101
|
+
* holder_register are never held back.
|
|
102
|
+
*
|
|
86
103
|
* Ownership follows the file (the list under "The session id"). An adopted key's file is the
|
|
87
104
|
* writer's: this process never deletes it, and writes it only when it is missing, which makes
|
|
88
105
|
* this process the owner, so its end() ends the holder rather than leaving the claims held
|
|
@@ -179,6 +196,11 @@ export function createHolderSession(deps) {
|
|
|
179
196
|
keyFileDir = holderKeyDir(env),
|
|
180
197
|
// The key file itself, for a test; built from keyFileDir and the session marker otherwise.
|
|
181
198
|
keyFile: injectedKeyFile = null,
|
|
199
|
+
// The clock the re-register bound reads, in milliseconds.
|
|
200
|
+
now = () => Date.now(),
|
|
201
|
+
// The shortest gap between a register this process sent and a RECOVERY register
|
|
202
|
+
// ("Two processes of one session"): one server heartbeat interval by default.
|
|
203
|
+
reregisterIntervalMs = DEFAULT_HEARTBEAT_SECONDS * 1000,
|
|
182
204
|
} = deps;
|
|
183
205
|
|
|
184
206
|
async function beat(result) {
|
|
@@ -211,6 +233,15 @@ export function createHolderSession(deps) {
|
|
|
211
233
|
let adopted = false;
|
|
212
234
|
// The one recovery in flight, shared by every 401 that arrives while it runs.
|
|
213
235
|
let recovering = null;
|
|
236
|
+
// When this process last SENT a RECOVERY register (after a refusal), for the bound. The startup
|
|
237
|
+
// register and an explicit holder_register are not counted: they are never held back.
|
|
238
|
+
let lastRegisterAt = null;
|
|
239
|
+
// The last holder credential loopctl refused this process: never taken up from the file again.
|
|
240
|
+
let refusedKey = null;
|
|
241
|
+
|
|
242
|
+
function reregisterAllowed() {
|
|
243
|
+
return lastRegisterAt === null || now() - lastRegisterAt >= reregisterIntervalMs;
|
|
244
|
+
}
|
|
214
245
|
|
|
215
246
|
/**
|
|
216
247
|
* Makes the file match the credential held: written when one is, gone when none is. It reads
|
|
@@ -218,15 +249,20 @@ export function createHolderSession(deps) {
|
|
|
218
249
|
* this one's file in a race (lib/holder-key-file.js remove), and the next sync rewrites it.
|
|
219
250
|
*
|
|
220
251
|
* `minted` (a register just returned the credential, revoking every other key) overwrites
|
|
221
|
-
*
|
|
222
|
-
* sibling
|
|
223
|
-
*
|
|
252
|
+
* what the file held when that register was SENT (`fileAtSend`). A key that appeared while it
|
|
253
|
+
* was in flight is a sibling's concurrent register: which of the two loopctl answered last is
|
|
254
|
+
* unknowable here, so the file is left, and whichever process loopctl refuses next takes up
|
|
255
|
+
* the other's key from it. Overwriting it could leave a revoked key in the file, which the
|
|
256
|
+
* live process never replaces (below) and the hooks would keep sending. Otherwise a file
|
|
257
|
+
* holding ANOTHER key is left alone: that key is a sibling process's newer rotation, and
|
|
258
|
+
* overwriting it with this process's soon-dead key is what made two processes ping-pong.
|
|
224
259
|
*/
|
|
225
|
-
function syncKeyFile({ minted = false } = {}) {
|
|
260
|
+
function syncKeyFile({ minted = false, fileAtSend = null } = {}) {
|
|
226
261
|
if (credential) {
|
|
227
|
-
|
|
262
|
+
const current = keyFile.holds(credential) ? credential : keyFile.read();
|
|
263
|
+
if (current === credential) {
|
|
228
264
|
if (!adopted) writtenKey = credential;
|
|
229
|
-
} else if (
|
|
265
|
+
} else if (current === null || (minted && current === fileAtSend)) {
|
|
230
266
|
if (keyFile.write(credential)) {
|
|
231
267
|
writtenKey = credential;
|
|
232
268
|
// This process wrote the file, so it owns the holder now: the process it adopted the
|
|
@@ -286,8 +322,12 @@ export function createHolderSession(deps) {
|
|
|
286
322
|
return beat(await registerOnly());
|
|
287
323
|
}
|
|
288
324
|
|
|
289
|
-
/**
|
|
290
|
-
|
|
325
|
+
/**
|
|
326
|
+
* register() without the after-beat hook: the recovery holds every waiting 401 until it ends.
|
|
327
|
+
* `recovery` marks a register sent because loopctl refused this process's credential, the
|
|
328
|
+
* kind the re-register bound counts.
|
|
329
|
+
*/
|
|
330
|
+
async function registerOnly({ recovery = false } = {}) {
|
|
291
331
|
// A runner session (loopctl-runner sets LOOP_MODE) is already a holder, placed with its
|
|
292
332
|
// dispatch (US-52.15). Registering it as interactive made its branch a new work item on
|
|
293
333
|
// every heartbeat's open, which the factory then placed again (2026-11-21).
|
|
@@ -299,6 +339,10 @@ export function createHolderSession(deps) {
|
|
|
299
339
|
if (!key) return { error: true, status: 0, body: "LOOPCTL_AGENT_KEY is not set" };
|
|
300
340
|
|
|
301
341
|
const gen = generation;
|
|
342
|
+
// Stamped when SENT: loopctl revokes the other keys as it answers, so a register that is
|
|
343
|
+
// slow or never answered counts toward the bound like one that came back.
|
|
344
|
+
if (recovery) lastRegisterAt = now();
|
|
345
|
+
const fileAtSend = keyFile.read();
|
|
302
346
|
const result = await apiCall(
|
|
303
347
|
"POST",
|
|
304
348
|
HOLDERS_PATH,
|
|
@@ -317,7 +361,7 @@ export function createHolderSession(deps) {
|
|
|
317
361
|
credential = result.credential.raw_key;
|
|
318
362
|
adopted = false;
|
|
319
363
|
}
|
|
320
|
-
syncKeyFile({ minted });
|
|
364
|
+
syncKeyFile({ minted, fileAtSend });
|
|
321
365
|
ended = false;
|
|
322
366
|
arm(result.heartbeat_seconds);
|
|
323
367
|
} else if (transient(result)) {
|
|
@@ -333,16 +377,21 @@ export function createHolderSession(deps) {
|
|
|
333
377
|
|
|
334
378
|
/**
|
|
335
379
|
* Replaces `staleKey`, a credential loopctl just refused, once per refusal however many
|
|
336
|
-
* requests saw it ("Two processes of one session"). Resolves to
|
|
337
|
-
* `key` is the credential to retry with
|
|
338
|
-
*
|
|
380
|
+
* requests saw it ("Two processes of one session"). Resolves to
|
|
381
|
+
* `{ key, adoptedKey, fallbackKey, result }`: `key` is the holder credential to retry with
|
|
382
|
+
* (null when there is none), `adoptedKey` is true when it came from the key file,
|
|
383
|
+
* `fallbackKey` is LOOPCTL_AGENT_KEY when the recovery left this process WITHOUT a holder
|
|
384
|
+
* credential (it yielded inside the re-register bound, or its register failed), and `result`
|
|
385
|
+
* is the register's answer when one was sent.
|
|
339
386
|
*
|
|
340
387
|
* @param {string} staleKey
|
|
341
388
|
*/
|
|
342
389
|
function recoverCredential(staleKey) {
|
|
343
390
|
if (!staleKey) return Promise.resolve({ key: null });
|
|
344
391
|
// Already replaced (a recovery finished, or a heartbeat adopted) or already dropped.
|
|
345
|
-
if (credential !== staleKey)
|
|
392
|
+
if (credential !== staleKey) {
|
|
393
|
+
return Promise.resolve(credential ? { key: credential } : { key: null, ...fallback() });
|
|
394
|
+
}
|
|
346
395
|
if (!recovering) {
|
|
347
396
|
recovering = renew(staleKey).finally(() => {
|
|
348
397
|
recovering = null;
|
|
@@ -352,36 +401,94 @@ export function createHolderSession(deps) {
|
|
|
352
401
|
}
|
|
353
402
|
|
|
354
403
|
async function renew(staleKey) {
|
|
404
|
+
refusedKey = staleKey;
|
|
355
405
|
const sibling = siblingKey();
|
|
356
406
|
if (sibling) {
|
|
357
407
|
adopt(sibling);
|
|
358
408
|
return { key: sibling, adoptedKey: true };
|
|
359
409
|
}
|
|
360
410
|
|
|
411
|
+
// Registered too recently: another process of this session is most likely registering too,
|
|
412
|
+
// and a register now would revoke its live key and start the ping-pong.
|
|
413
|
+
if (!reregisterAllowed()) {
|
|
414
|
+
yieldCredential();
|
|
415
|
+
return { key: null, throttled: true, ...fallback() };
|
|
416
|
+
}
|
|
417
|
+
|
|
361
418
|
const gen = generation;
|
|
362
|
-
const result = await registerOnly();
|
|
419
|
+
const result = await registerOnly({ recovery: true });
|
|
363
420
|
if (gen !== generation) return { key: null, result };
|
|
364
421
|
|
|
365
422
|
if (credential !== staleKey) return { key: credential || null, result };
|
|
366
423
|
|
|
367
424
|
if (!result || result.error) {
|
|
368
425
|
// Not registered: the refused credential is dead, so the session falls back to
|
|
369
|
-
// LOOPCTL_AGENT_KEY
|
|
426
|
+
// LOOPCTL_AGENT_KEY. A transient failure keeps the holder id, so the next tick can take
|
|
427
|
+
// up a key a sibling wrote meanwhile before it registers over it (`resume`); a refusal is
|
|
428
|
+
// final and forgets the holder.
|
|
370
429
|
credential = null;
|
|
371
|
-
holder = null;
|
|
430
|
+
if (!transient(result)) holder = null;
|
|
372
431
|
adopted = false;
|
|
373
432
|
syncKeyFile();
|
|
433
|
+
return { key: null, result, ...fallback() };
|
|
374
434
|
}
|
|
375
435
|
return { key: null, result };
|
|
376
436
|
}
|
|
377
437
|
|
|
438
|
+
// The key this process fell back to when it holds no holder credential: its own
|
|
439
|
+
// LOOPCTL_AGENT_KEY, which every unpinned request now goes out on (`agentKey()`).
|
|
440
|
+
function fallback() {
|
|
441
|
+
const key = plainKey();
|
|
442
|
+
return key ? { fallbackKey: key } : {};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Gives up the refused credential without registering: the session falls back to
|
|
447
|
+
* LOOPCTL_AGENT_KEY and keeps the holder id for `resume`. The file is deleted only when it
|
|
448
|
+
* still holds this process's dead key (syncKeyFile removes `writtenKey` only while the file
|
|
449
|
+
* holds it), so the live sibling's next heartbeat writes its own key there.
|
|
450
|
+
*/
|
|
451
|
+
function yieldCredential() {
|
|
452
|
+
credential = null;
|
|
453
|
+
adopted = false;
|
|
454
|
+
syncKeyFile();
|
|
455
|
+
const seconds = Math.ceil(reregisterIntervalMs / 1000);
|
|
456
|
+
log(
|
|
457
|
+
"loopctl: the holder credential was refused again within " +
|
|
458
|
+
`${seconds}s of this process's last register; another MCP process of this session is ` +
|
|
459
|
+
"likely registering too. Using LOOPCTL_AGENT_KEY and taking up that process's key from " +
|
|
460
|
+
"the holder key file when it appears, instead of registering over it.",
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* A heartbeat tick with no credential. A holder this process knows and a key in the file that
|
|
466
|
+
* loopctl has not refused this process: take it up and beat with it. Otherwise register,
|
|
467
|
+
* unless a yield is still inside the re-register bound.
|
|
468
|
+
*/
|
|
469
|
+
async function resume() {
|
|
470
|
+
// An ended process registers afresh, as before: end() was this process letting go.
|
|
471
|
+
if (ended) return register();
|
|
472
|
+
const fileKey = keyFile.read();
|
|
473
|
+
if (holder && fileKey && fileKey !== refusedKey) {
|
|
474
|
+
adopt(fileKey);
|
|
475
|
+
return heartbeat({ retried: true });
|
|
476
|
+
}
|
|
477
|
+
// Without a holder there is nothing to recover: the first register, or one after a refusal.
|
|
478
|
+
if (!holder) return register();
|
|
479
|
+
if (!reregisterAllowed()) {
|
|
480
|
+
return { error: true, status: 0, body: "holder re-register held back; using LOOPCTL_AGENT_KEY" };
|
|
481
|
+
}
|
|
482
|
+
return beat(await registerOnly({ recovery: true }));
|
|
483
|
+
}
|
|
484
|
+
|
|
378
485
|
/** True when `key` is the holder credential this process sends right now. */
|
|
379
486
|
function holdsCredential(key) {
|
|
380
487
|
return Boolean(key) && key === credential;
|
|
381
488
|
}
|
|
382
489
|
|
|
383
490
|
async function heartbeat({ retried = false } = {}) {
|
|
384
|
-
if (!holder || !credential) return
|
|
491
|
+
if (!holder || !credential) return resume();
|
|
385
492
|
|
|
386
493
|
const gen = generation;
|
|
387
494
|
const key = credential;
|
|
@@ -506,6 +613,20 @@ export function createHolderSession(deps) {
|
|
|
506
613
|
* 401 means loopctl applied nothing, so the retry cannot do anything twice; a second 401 is
|
|
507
614
|
* returned as it is.
|
|
508
615
|
*
|
|
616
|
+
* When the recovery leaves the process with no holder credential (it yielded inside the
|
|
617
|
+
* re-register bound, or its register failed), an UNPINNED request is retried once on
|
|
618
|
+
* LOOPCTL_AGENT_KEY instead (`fallbackKey`). That is not a change of principal the earlier
|
|
619
|
+
* design guarded against: an unpinned request goes out on `agentKey()`, the process's own
|
|
620
|
+
* default key, and the holder credential and LOOPCTL_AGENT_KEY are both THIS process's keys for
|
|
621
|
+
* the SAME agent (the holder file is the session's own credential, the env var the process's
|
|
622
|
+
* own). Had the yield come a moment earlier, the request would have been sent on
|
|
623
|
+
* LOOPCTL_AGENT_KEY in the first place; returning its 401 only turned a recovered refusal into
|
|
624
|
+
* a failed tool call. A PINNED request (`exactKey`: the journal's replay, holder_replay, the
|
|
625
|
+
* branch open) is never re-sent on the fallback: its caller chose the holder identity because
|
|
626
|
+
* what it does depends on it (a checkpoint the current holder alone may write, an open only a
|
|
627
|
+
* holder credential may make), so on another key it would be refused, or recorded as
|
|
628
|
+
* someone else.
|
|
629
|
+
*
|
|
509
630
|
* The key a request went out on is `keyOverride` itself under `exactKey` (sent verbatim), and
|
|
510
631
|
* `resolveKey(keyOverride)` otherwise, so a pinned request on the holder credential (the
|
|
511
632
|
* journal's replay, holder_replay) recovers like any other.
|
|
@@ -533,12 +654,14 @@ export function withHolderRecovery({ send, resolveKey, session }) {
|
|
|
533
654
|
const result = await send(method, apiPath, body, keyOverride, opts);
|
|
534
655
|
if (!viaHolder || !result || !result.error || result.status !== 401) return result;
|
|
535
656
|
|
|
536
|
-
let
|
|
657
|
+
let recovered;
|
|
537
658
|
try {
|
|
538
|
-
|
|
659
|
+
recovered = (await session.recoverCredential(sent)) || {};
|
|
539
660
|
} catch {
|
|
540
661
|
return result;
|
|
541
662
|
}
|
|
663
|
+
const pinned = Boolean(opts && opts.exactKey);
|
|
664
|
+
const fresh = recovered.key || (pinned ? null : recovered.fallbackKey || null);
|
|
542
665
|
if (!fresh || fresh === sent) return result;
|
|
543
666
|
|
|
544
667
|
return send(method, apiPath, body, fresh, opts);
|
package/lib/interventions.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* KEY: the session's own key (`agentKey()` in index.js, the holder credential once the
|
|
7
7
|
* startup register succeeded). The server compares that key's holder with the item's: the
|
|
8
8
|
* holder that holds the item is refused 409 self_intervention_blocked, and a key with no
|
|
9
|
-
* holder that is not a human's is 409 holder_required.
|
|
9
|
+
* holder that is not a human's is 409 holder_required. The one exception is `close` on the
|
|
10
|
+
* holder's own INTERACTIVE item (see `intervene`).
|
|
10
11
|
*
|
|
11
12
|
* Each call carries an `intervention_id`; one is generated when the caller gives none, so a
|
|
12
13
|
* caller that retries after a lost response should pass the id it used the first time. The
|
|
@@ -45,10 +46,17 @@ function postIntervention(apiCall, verb, storyId, body) {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* `POST /api/v1/stories/:id/<verb>`.
|
|
51
|
+
*
|
|
52
|
+
* `evidence` is sent on `close` only. The holder of an INTERACTIVE work item (one
|
|
53
|
+
* `work_item_open` opened) may close its OWN item, and the server then REQUIRES evidence: the
|
|
54
|
+
* item ends at `done` over `:self_closed`, never `verified`. The server decides whether a close
|
|
55
|
+
* is a self-close, so the tool forwards evidence whenever it is given and never demands it.
|
|
56
|
+
*/
|
|
49
57
|
export async function intervene(
|
|
50
58
|
verb,
|
|
51
|
-
{ story_id, reason, intervention_id } = {},
|
|
59
|
+
{ story_id, reason, intervention_id, evidence } = {},
|
|
52
60
|
{ apiCall, randomUUID = () => crypto.randomUUID() } = {},
|
|
53
61
|
) {
|
|
54
62
|
if (!INTERVENTION_VERBS.includes(verb)) {
|
|
@@ -70,5 +78,14 @@ export async function intervene(
|
|
|
70
78
|
if (badId) return badId;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
|
|
81
|
+
const body = { reason, intervention_id: id };
|
|
82
|
+
|
|
83
|
+
if (verb === "close" && evidence !== undefined && evidence !== null) {
|
|
84
|
+
if (typeof evidence !== "string") {
|
|
85
|
+
return refuse("`evidence` must be text: what was done and where.");
|
|
86
|
+
}
|
|
87
|
+
body.evidence = evidence;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return postIntervention(apiCall, verb, story_id, body);
|
|
74
91
|
}
|