loopctl-mcp-server 3.19.1 → 3.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -246,7 +246,7 @@ Epic 39 Repo Coordination Bus — a lightweight, tenant-isolated channel for age
246
246
 
247
247
  | Tool | Description |
248
248
  |---|---|
249
- | `list_stories` | List stories for a project, optionally filtered by agent_status, verified_status, or epic_id. Pass `include_token_totals=true` for per-story token data. |
249
+ | `list_stories` | List stories for a project, optionally filtered by agent_status, verified_status, epic_id, or `issue_number` (the stories an intake issue with that number produced; 400 unless an integer in 1..2147483647) and `repo` (owner/name: an issue number is unique only within one repository). Pass `include_token_totals=true` for per-story token data. |
250
250
  | `list_ready_stories` | List stories that are ready to be contracted and worked on (`pending`, dependencies met, delivery stage not held). |
251
251
  | `list_blocked_stories` | List stories with an unverified dependency (their own, or their epic's), whatever their own status, each with what blocks it (`GET /api/v1/stories/blocked`). The queued ones are what the dispatch driver skips and `place_dispatch` refuses `409 dependencies_not_met`. Optional `project_id` (422 if not a UUID), `page`, `page_size`. Agent key or higher. |
252
252
  | `get_story` | Get full details for a single story by ID. |
@@ -532,7 +532,7 @@ The order to wire it up, the stage machine these tools move a story through, and
532
532
  | `runner_enroll` | Enroll this machine as a runner (`POST /api/v1/runners`). Required: `name` (the machine name the runner declares when it joins) and `token_file` (absolute, or starting with `~/`). Optional: `max_sessions` (1..64, default 2) — the CEILING on how many dispatches loopctl will ever keep in flight on this machine at once, and the value it starts at. Since runner contract 1.13.0 every join re-applies the machine's own declared `max_sessions` bounded by this one, so a machine may take itself down below its grant and cannot raise itself above it: to carry FEWER sessions change `control.max_sessions` in the runner's own config and reconnect, to carry MORE `runner_revoke` it first and then enrol it again (nothing widens the ceiling in place, and enrolling the same name while its runner is active is a 422; the revoke invalidates the credential, so the new token file must reach the machine and the runner be restarted). The tenant's total across its runners is capped separately by the server. The credential is written to `token_file` with mode 0600 and is **never returned**: the result is only `{ runner: {id, name, inserted_at}, token_file }`, because a tool result lands in the transcript and the token lets its holder join as that machine. The file is created exclusively, so an existing path (or a symlink there) is refused before anything is enrolled; missing parent directories are created 0700. If the token cannot be written after enrollment, the runner is revoked before the error returns. Only a 4xx is treated as a refusal: any other failure (timeout, 5xx, a 2xx that did not parse) may have enrolled the runner, so its response body is never echoed, the runner is revoked when the response proves its id, and otherwise the error points at `runner_list` and `runner_revoke`. 422 (name malformed or taken) and 403 (`custody_tier_required`, `api_key_mint_forbidden`) pass through with their code. |
533
533
  | `runner_list` | List enrolled runners (`GET /api/v1/runners`). Optional: `include_revoked`. Enrollment only; connection state is `runner_pool`. |
534
534
  | `runner_revoke` | Revoke a runner (`DELETE /api/v1/runners/:id`): its credential stops authenticating and its live socket is disconnected. The undo for `runner_enroll`. Idempotent. Required: `id`. |
535
- | `runner_pool` | The tenant's connected runners from Presence (`GET /api/v1/runners/pool`): per machine name, `runner_id`, `joined_at`, `draining`, the latest `sample`, `live_sockets` (above 1 means more than one process holds the credential), and the `node` and `machine_id` (Fly Machine) holding the socket. `in_flight` and `max_sessions` are the capacity loopctl holds in Postgres — what dispatch reserves against — and are null only for a runner revoked while its socket drains; `reported_in_flight` and `reported_max_sessions` are the runner's own last report: `reported_in_flight` is a hint (the runner counts sessions, loopctl counts reservations), while `reported_max_sessions` is what `max_sessions` is copied from on every join (contract 1.13.0), capped at `enrolled_max_sessions` which is also returned. The two can differ in EITHER direction. `max_sessions` BELOW it happens when the machine is declaring above its enrolled ceiling (`enrolled_max_sessions` is what makes that one visible in the payload; the rest are not), when the declaration write has not LANDED — it can fail under lock contention on the runner row and is retried on that socket's 30-second recheck, downward only — or when the socket joined a node older than contract 1.13.0 and has not reconnected since. `max_sessions` ABOVE it happens when the machine declared `0`, held as `1` because the column is 1..64 while this field shows the raw `0`, and again when a declaration write has not landed and the row keeps an older, larger number. A `reported_max_sessions` of 0 means the machine is taking no work and `place_dispatch` refuses a new placement on it, like `draining`. `branch_prefixes` is what the machine declared it ACCEPTS as a branch-name prefix (runner contract 1.14.0): loopctl derives a branch starting with the FIRST entry, and `[]` means it declared no constraint. Read it when `place_dispatch` refuses 409 `no_conforming_branch`, and when a connected machine refuses every dispatch with `branch_not_allowed` — a runner that ENFORCES a prefix and declares none shows `[]` here, which is that misconfiguration made visible. Per-CONNECTION, like `kinds`. `specs` (runner contract 1.25.0) is the agent specs the machine declared it holds, as `{id, version}`, or null when it declared none, which loopctl reads as version 1 of the spec of each kind in `kinds`. A kind is sent only to a machine holding the spec loopctl runs it under, so a machine whose `kinds` names a kind it is never sent is explained here: it lists that spec at another version, or not at all. Per-CONNECTION, like `kinds`. `usage_exhausted_until` (runner contract 1.17.0) is until when the machine's SUBSCRIPTION is exhausted, or null: while it is in the future nothing is placed on it and `place_dispatch` refuses 409 `runner_exhausted`. It is the EFFECTIVE value, the latest of the machine's own and every machine's sharing its account, so a machine that never reported anything can show one; capacity returns at that instant on its own. Presence converges only within a cluster. |
535
+ | `runner_pool` | The tenant's connected runners from Presence (`GET /api/v1/runners/pool`): per machine name, `runner_id`, `joined_at`, `runner_version` (the version the runner joined with, runner contract 1.34.0; null for a runner that sent none), `draining`, the latest `sample`, `live_sockets` (above 1 means more than one process holds the credential), and the `node` and `machine_id` (Fly Machine) holding the socket. `in_flight` and `max_sessions` are the capacity loopctl holds in Postgres — what dispatch reserves against — and are null only for a runner revoked while its socket drains; `reported_in_flight` and `reported_max_sessions` are the runner's own last report: `reported_in_flight` is a hint (the runner counts sessions, loopctl counts reservations), while `reported_max_sessions` is what `max_sessions` is copied from on every join (contract 1.13.0), capped at `enrolled_max_sessions` which is also returned. The two can differ in EITHER direction. `max_sessions` BELOW it happens when the machine is declaring above its enrolled ceiling (`enrolled_max_sessions` is what makes that one visible in the payload; the rest are not), when the declaration write has not LANDED — it can fail under lock contention on the runner row and is retried on that socket's 30-second recheck, downward only — or when the socket joined a node older than contract 1.13.0 and has not reconnected since. `max_sessions` ABOVE it happens when the machine declared `0`, held as `1` because the column is 1..64 while this field shows the raw `0`, and again when a declaration write has not landed and the row keeps an older, larger number. A `reported_max_sessions` of 0 means the machine is taking no work and `place_dispatch` refuses a new placement on it, like `draining`. `branch_prefixes` is what the machine declared it ACCEPTS as a branch-name prefix (runner contract 1.14.0): loopctl derives a branch starting with the FIRST entry, and `[]` means it declared no constraint. Read it when `place_dispatch` refuses 409 `no_conforming_branch`, and when a connected machine refuses every dispatch with `branch_not_allowed` — a runner that ENFORCES a prefix and declares none shows `[]` here, which is that misconfiguration made visible. Per-CONNECTION, like `kinds`. `specs` (runner contract 1.25.0) is the agent specs the machine declared it holds, as `{id, version}`, or null when it declared none, which loopctl reads as version 1 of the spec of each kind in `kinds`. A kind is sent only to a machine holding the spec loopctl runs it under, so a machine whose `kinds` names a kind it is never sent is explained here: it lists that spec at another version, or not at all. Per-CONNECTION, like `kinds`. `usage_exhausted_until` (runner contract 1.17.0) is until when the machine's SUBSCRIPTION is exhausted, or null: while it is in the future nothing is placed on it and `place_dispatch` refuses 409 `runner_exhausted`. It is the EFFECTIVE value, the latest of the machine's own and every machine's sharing its account, so a machine that never reported anything can show one; capacity returns at that instant on its own. Presence converges only within a cluster. |
536
536
  | `reply_draft_list` | **A project's reply drafts, newest first** (`GET /api/v1/projects/:project_id/reply_drafts`, US-48.9): what a runner session (agent spec `reply_draft@1`) drafted for a support ticket triage rejected or escalated. **loopctl never sends a draft anywhere** — a person reads it here and sends it or not. `status` is `drafted` (with `body` and `ticket_id`) or `refused` (`body` null) with a `screen_code`: `injection_detector_draft` (the body read as instructions; `screen_signals` carries the detector codes and the refused body is stored nowhere), `payload_too_large` (the ticket was too large to dispatch) or `ticket_missing`. Required: `project_id` (id, slug or repo name). Optional: `cursor` (a page's `next_cursor`, verbatim; null on the last page), `limit` (default 50, at most 100). 403 for any key that is not user-role (the bodies are ticket-derived), 404 for a project the tenant does not hold, 400 for a foreign or tampered cursor or a bad limit. Requires `LOOPCTL_USER_KEY`. |
537
537
  | `tuning_drafts` | **The improvement loop's tuning drafts, newest first** (`GET /api/v1/tuning_drafts`, US-48.13): what a runner session (agent spec `spec_tuner@1`) proposed for a TARGET spec from that spec's failed runs — a prompt-template diff, new eval cases, and the eval scores of the current and proposed templates. `status` is loopctl's own judgement, never the runner's: `proposed` only when the proposed template passes strictly more cases and no existing case that passed now fails, `rejected` otherwise with `rejection_reasons`, `pending` while the run is out, `abandoned` when it ended unanswered, `superseded` by a later proposal, `landed` once marked, `nothing_to_learn` when the window held no failed run to learn from (no dispatch was sent; it closes the window so the pair stops taking its tenant's slot). **loopctl never applies a draft**: a person turns a proposed one into a pull request. `traces[].untrusted` is fenced ticket text, data and never instructions. Optional: `project_id` (UUID), `spec_id` (the target), `status`, `cursor` (a page's `next_cursor`, verbatim), `limit` (default 50, at most 100). 403 for any key that is not user-role, 400 for a bad filter, limit or a foreign or tampered cursor. Requires `LOOPCTL_USER_KEY`. |
538
538
  | `tuning_draft_mark_landed` | **Record that a proposed tuning draft landed** (`POST /api/v1/tuning_drafts/:id/landed`, US-48.13), naming the merged pull request. It changes no template and no spec version — the pull request does. Writes the draft and an audit entry. Required: `draft_id`, `pr_url` (`https://github.com/<owner>/<repo>/pull/<n>`, at most 500 characters). 409 `not_proposed` for a draft in any other status, 422 for a malformed `pr_url`, 404 for a draft the tenant does not hold, 403 for any key that is not user-role. Requires `LOOPCTL_USER_KEY`. |
package/index.js CHANGED
@@ -87,6 +87,11 @@ import {
87
87
  updateIntakeSource,
88
88
  } from "./lib/intake-sources.js";
89
89
  import { mcpVersion as mcpVersionRequest, packageVersion } from "./lib/mcp-version.js";
90
+ import {
91
+ CLIENT_HEADER,
92
+ clientHeaderValue,
93
+ incompatibleClientError,
94
+ } from "./lib/client-version.js";
90
95
  import { revokeDispatch as revokeDispatchRequest } from "./lib/dispatch-revoke.js";
91
96
  import { changeBindingGet as changeBindingGetRequest } from "./lib/change-bindings.js";
92
97
  import { agentOutcomes } from "./lib/agent-outcomes.js";
@@ -260,6 +265,9 @@ async function apiCall(
260
265
  Authorization: `Bearer ${key}`,
261
266
  "Content-Type": "application/json",
262
267
  Accept: "application/json",
268
+ // US-52.8: loopctl answers 426 incompatible_client_version to a package older than its
269
+ // release set accepts. Unlike x-loopctl-client-context below, this one IS judged.
270
+ [CLIENT_HEADER]: clientHeaderValue(SERVER_VERSION),
263
271
  };
264
272
 
265
273
  // #658: client-asserted context (session id, main-vs-child, repo, effort). None of it is
@@ -316,6 +324,10 @@ async function apiCall(
316
324
  }
317
325
  }
318
326
 
327
+ if (response.status === 426) {
328
+ return incompatibleClientError(responseBody, SERVER_VERSION);
329
+ }
330
+
319
331
  if (!response.ok) {
320
332
  let errorBody = responseBody;
321
333
  if (typeof errorBody === "string" && errorBody.length > 500) {
@@ -1115,11 +1127,13 @@ async function resolvePayload(inline, payloadPath) {
1115
1127
 
1116
1128
  // --- Story Tools ---
1117
1129
 
1118
- async function listStories({ project_id, agent_status, verified_status, epic_id, limit, offset, include_token_totals }) {
1130
+ async function listStories({ project_id, agent_status, verified_status, epic_id, issue_number, repo, limit, offset, include_token_totals }) {
1119
1131
  const params = new URLSearchParams({ project_id });
1120
1132
  if (agent_status) params.set("agent_status", agent_status);
1121
1133
  if (verified_status) params.set("verified_status", verified_status);
1122
1134
  if (epic_id) params.set("epic_id", epic_id);
1135
+ if (issue_number != null) params.set("issue_number", String(issue_number));
1136
+ if (repo) params.set("repo", repo);
1123
1137
  params.set(
1124
1138
  "limit",
1125
1139
  String(Math.min(limit ?? DEFAULT_STORY_PAGE_SIZE, SERVER_MAX_STORY_PAGE_SIZE)),
@@ -4760,7 +4774,10 @@ const TOOLS = [
4760
4774
  {
4761
4775
  name: "list_stories",
4762
4776
  description:
4763
- "List stories for a project, optionally filtered by agent_status, verified_status, or epic_id. " +
4777
+ "List stories for a project, optionally filtered by agent_status, verified_status, epic_id, " +
4778
+ "or issue_number (the stories an intake issue with that number produced; loopctl answers 400 " +
4779
+ "unless it is an integer in 1..2147483647). An issue number is unique only within one " +
4780
+ "repository, so pass repo (owner/name; 400 otherwise) to narrow it to that repository's issue. " +
4764
4781
  "Returns compact results (no acceptance_criteria/description) — use get_story for full details. " +
4765
4782
  "Defaults to 20 per page; pass `limit` up to 500 to page larger. Use offset to paginate " +
4766
4783
  "(response includes total_count). Filter by epic_id or agent_status to reduce result size.",
@@ -4784,6 +4801,16 @@ const TOOLS = [
4784
4801
  type: "string",
4785
4802
  description: "Filter by epic UUID.",
4786
4803
  },
4804
+ issue_number: {
4805
+ type: "integer",
4806
+ description:
4807
+ "Filter to the stories an intake issue with this number produced (stories.intake_record_id).",
4808
+ },
4809
+ repo: {
4810
+ type: "string",
4811
+ description:
4812
+ "Filter to the stories an intake source of this repository (owner/name, case-insensitive) produced.",
4813
+ },
4787
4814
  limit: {
4788
4815
  type: "integer",
4789
4816
  description: "Maximum number of stories to return (default 20, max 500).",
@@ -8689,7 +8716,9 @@ const TOOLS = [
8689
8716
  name: "runner_pool",
8690
8717
  description:
8691
8718
  "The tenant's CONNECTED runners, read from Presence (GET /api/v1/runners/pool): per machine " +
8692
- "name, runner_id, joined_at, draining, the latest health sample, live_sockets, and the node " +
8719
+ "name, runner_id, joined_at, runner_version (the version the runner joined with, runner " +
8720
+ "contract 1.34.0; null for a runner that sent none), draining, the latest health sample, " +
8721
+ "live_sockets, and the node " +
8693
8722
  "and machine_id (Fly Machine) holding the socket. in_flight and max_sessions are the " +
8694
8723
  "CAPACITY loopctl holds in Postgres — the slots dispatch reserves against — and are null " +
8695
8724
  "only for a runner revoked while its socket drains; reported_in_flight and " +
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The factory-client header (US-52.8).
3
+ *
4
+ * Every request `apiCall` makes names this package as `x-loopctl-client: mcp/<version>`.
5
+ * loopctl compares that version with the `mcp` component of the release set it was built from
6
+ * and answers `426 incompatible_client_version` (`component`, `sent`, `minimum`) to a package
7
+ * below that component's minimum, before it reads the key. A request without the header is
8
+ * never refused, so a package older than this module is not refused either.
9
+ *
10
+ * This is NOT `x-loopctl-client-context`: that header is analytics-only and never gates
11
+ * anything. This one is judged.
12
+ */
13
+
14
+ /** The request header a factory client names itself in. */
15
+ export const CLIENT_HEADER = "x-loopctl-client";
16
+
17
+ /** The header value for package version `version`. */
18
+ export function clientHeaderValue(version) {
19
+ return `mcp/${version}`;
20
+ }
21
+
22
+ /**
23
+ * The tool-facing error for a 426: the minimum the server accepts and the remedy. The remedy
24
+ * is a reconnect (`/mcp`) or a session restart, and it works only once that version is on
25
+ * npm: the deploy and the npm publish fire independently (see ./mcp-version.js).
26
+ */
27
+ export function incompatibleClientError(body, version) {
28
+ const error = (body && typeof body === "object" && body.error) || {};
29
+ const minimum = typeof error.minimum === "string" ? error.minimum : "a newer version";
30
+
31
+ return {
32
+ error: true,
33
+ status: 426,
34
+ body: {
35
+ code: "incompatible_client_version",
36
+ component: "mcp",
37
+ sent: version,
38
+ minimum,
39
+ message:
40
+ `loopctl refuses loopctl-mcp-server ${version}: it needs ${minimum} or later. ` +
41
+ "Reconnect the MCP server (/mcp) or restart the session once that version is " +
42
+ "published on npm; mcp_version reports whether it is.",
43
+ },
44
+ };
45
+ }
@@ -56,8 +56,12 @@
56
56
  * - `ahead` is normal on a development machine running the package from a checkout, and it
57
57
  * means the deployment is older than your client rather than anything being wrong.
58
58
  *
59
- * NEITHER SIDE IS A GATE. Nothing here refuses a call, and nothing should: this is a report so
60
- * that a session stops guessing, exactly as the join reply is for a runner.
59
+ * THIS REPORT IS NOT THE GATE. Nothing here refuses a call: it is a report so that a session
60
+ * stops guessing, as the join reply is for a runner. The gate is the server's (US-52.8): every
61
+ * request carries `x-loopctl-client: mcp/<version>` (./client-version.js), and loopctl answers
62
+ * 426 `incompatible_client_version` to a package below the `mcp` minimum of its release set.
63
+ * `behind` alone is never refused: a package between that minimum and the current version
64
+ * works, and this report says it is behind.
61
65
  */
62
66
 
63
67
  import { readFileSync } from "node:fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.19.1",
3
+ "version": "3.20.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",