loopctl-mcp-server 3.15.0 → 3.16.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
@@ -538,7 +538,9 @@ The order to wire it up, the stage machine these tools move a story through, and
538
538
  | `place_dispatch` | **Place a queued story on a runner** (`POST /api/v1/runners/:runner_id/dispatches`): claims it under a freshly minted custody dispatch and pushes the work. The control-side trigger of the delivery loop. 409 `runner_declines_work` when the machine declares `draining` or `max_sessions` 0 — refused before the mint, so nothing was claimed; a retry carrying a `dispatch_id` loopctl already holds is re-sent anyway, because its claim is already standing. 409 `runner_exhausted` when the machine's subscription (its own, or one it shares an account with) is exhausted — also refused before the mint, and the body carries `usage_exhausted_until`, when it clears on its own. Required: `story_id`, `runner_id` (from `runner_pool`). Optional: `kind` (`implement`, the only kind this tool sends — `triage` is dispatchable on the contract but placement CLAIMS the story, which triage must not do; the server refuses any kind whose agent spec is not a `:build` with 422 `not_placeable_kind`, before anything is minted or claimed), `dispatch_id` (the idempotency key — generated when absent; pass the SAME one to retry rather than start a second session), `base_branch`, `wall_clock_seconds`, `max_turns`, and `branch` — **which you should not send**. Since runner contract 1.14.0 loopctl DERIVES the branch from the story number and an id fragment, behind a prefix the target runner declared it accepts (`branch_prefixes`, visible on `runner_pool`), which is a per-machine fact only the server can read. A branch you name is never rewritten, only judged, and it must satisfy three things: it must be a valid git ref name (422 `invalid_branch_name`, which also refuses a non-string such as `null`), it must start with one of that machine's declared prefixes (422 `branch_not_allowed`), and it must END WITH THIS STORY'S OWN SUFFIX (422 `branch_not_unique`) so that two stories on one repository can never be given one branch — you may choose the prefix, you may not drop the suffix. Nothing is claimed on any of them, and the fix is to drop the field. `base_branch` is judged as a git ref name too (422 `invalid_branch_name`): it reaches git on the runner just as `branch` does. It is NOT story-unique — every dispatch cutting from `master` is the normal case. A retry naming a different `branch` from the one this dispatch was already sent on is 422 `branch_conflict`: the branch is recorded at the first push and re-sent verbatim, because a session may be running on it right now, and a retry naming a different `base_branch` from the recorded one is 422 `base_branch_conflict`, because the merge gate judges against the recorded base. 409 `no_conforming_branch` is the machine's problem rather than the request's: it declares prefixes and none of them can produce a valid branch name carrying the story number and id fragment that keeps two stories off one branch, so nothing was claimed and an operator has to fix `branch_prefixes` on that box — the body echoes the declared prefixes. A retry carrying a `dispatch_id` loopctl already holds is never refused for either prefix reason: its claim is already standing, so the declaration only steers the name. The story object is NOT a parameter: loopctl builds it from its own rows and refuses a caller-supplied one. The story must be `pending` or `contracted` (a pending one is contracted by the placement), its dependencies met, with its stage at `queued`. A retry also moves the claim's deadline to now + its `wall_clock_seconds` + `DISPATCH_LEASE_GRACE_SECONDS` (never earlier than the one already sent), and 409 `dispatch_claim_ended` means the claim that `dispatch_id` was placed under has ended — nothing was pushed or written; place again with a new `dispatch_id`. Requires `LOOPCTL_USER_KEY`. |
539
539
  | `story_stage` | **Where a story is in the delivery machine** (`GET /api/v1/stories/:id/stage`): stage, `claim_epoch`, `lock_version`, `attempts`, the runner holding it, and the escalation reason when parked. `stage: null` means the loop has never touched it. This is how you watch a run, and the only way to see why a stage report was refused `stale_stage`. `escalation_reason` is untrusted session text. Required: `story_id`. |
540
540
  | `agent_outcomes` | **An agent spec's track record, per version** (`GET /api/v1/agent_specs/:spec_id/outcomes`, loopctl US-48.12): every runner dispatch ends in one outcome row keyed by its spec `{id, version}`, and this summarises one spec's rows recorded in the last `window_days` (default 30, at most 365), newest version first — `runs`, `ended`, `successes` (a build whose work merged, a triage verdict no human overrode, a verify verdict loopctl recorded, a reply draft stored `drafted`, a spec_tuner run whose draft loopctl judged `proposed`), `human_overrides`, `budget_exhausted` (sessions ended `wall_clock_exceeded` / `max_turns_exceeded`), each also as a rate, and `median_elapsed_s` / `median_turns` (null when no run carries one; turns come from the runner's session-end report, runner contract 1.27.0, so a run on an older runner has none). Every figure is from an event loopctl recorded, never session text. Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for a malformed `spec_id` or a `window_days` outside 1..365 (both also refused locally), 401 without a valid key; no role is refused. Required: `spec_id` (`triage`, `implement`, `reply_draft`, `verify`, `spec_tuner`). |
541
- | `chg_ledger_summary` | **The chg audit questions, answered** (`GET /api/v1/chg_ledger/summary`, loopctl US-50.6): what the `/chg` dashboard shows, computed by the same functions, from the ledger rows the fleet's chg outboxes sent — `gate_outcomes` (per day and kind, counts per verdict), `fallbacks` (checks that ran mode `all`, the rate, the top reasons), `selection` (stats and misses: a chg check that passed on a commit whose gate failed), `phase_times` (hydrate, static, affected, tests, lock_wait), `flaky`, `runner_samples`, `review_outcomes` (merged PRs' findings by severity and disposition, and how many merged without a counted round, totalled over EVERY merged PR in range) and `attention` (changes flagged gap or stale and still flagged: current state, so `since` and `until` do not apply). Lists cap at 50 rows; a panel shed under load is the string `unavailable`. Optional: `repo`, `host` (review outcomes and flagged changes ignore it), `since` (ISO 8601, default 7 days before `until`), `until` (default now). 422 for a malformed timestamp, a `since` not before `until`, or a period over 90 days (all also refused locally); 401 without a valid key; no role is refused. Any tenant key: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. |
541
+ | `chg_ledger_summary` | **The chg audit questions, answered** (`GET /api/v1/chg_ledger/summary`, loopctl US-50.6): what the `/chg` dashboard shows, computed by the same functions, from the ledger rows the fleet's chg outboxes sent — `gate_outcomes` (per day and kind, counts per verdict), `fallbacks` (checks that ran mode `all`, the rate, the top reasons), `selection` (stats and misses: a chg check that passed on a commit whose gate failed), `phase_times` (hydrate, static, affected, tests, lock_wait), `flaky`, `runner_samples`, `review_outcomes` (merged PRs' findings by severity and disposition, and how many merged without a counted round, totalled over EVERY merged PR in range), `attention` (changes flagged gap or stale and still flagged: current state, so `since` and `until` do not apply) and `findings` (the feedback loop's findings: `by_state` and `by_kind` counts and the escalated ones; current state, only `repo` applies). Lists cap at 50 rows; a panel shed under load is the string `unavailable`. Optional: `repo`, `host` (review outcomes and flagged changes ignore it), `since` (ISO 8601, default 7 days before `until`), `until` (default now). 422 for a malformed timestamp, a `since` not before `until`, or a period over 90 days (all also refused locally); 401 without a valid key; no role is refused. Any tenant key: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. |
542
+ | `chg_findings` | **What the chg feedback loop is working on** (`GET /api/v1/chg_findings`, loopctl US-51.6): the problems the nightly sweep derived from the chg ledger and filed as GitHub issues for the delivery loop to fix (`selection_miss`, `flaky_test`, `missing_review`, `stuck_change`, `source_silent`), newest sighting first, each with its `state` (queued, filed, fixed, closed, escalated), `occurrences`, `fix_attempts`, `loop_depth`, `cycle`, `issue_url` and `escalated_reason`. Optional: `state`, `kind`, `repo`, `limit` (default 50, at most 200). 422 for an unknown `state` or `kind` or a `limit` out of range (also refused locally); 401 without a valid key; no role is refused. Any tenant key: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. |
543
+ | `chg_finding_clear` | **Send an escalated finding round the loop again** (`POST /api/v1/chg_findings/:id/clear`, loopctl US-51.6): back to `queued`, fix attempts reset, issue number dropped, so the next sweep files a fresh issue; the escalated issue stays open for you to close. Audited (`chg_finding_cleared`). Required: `finding_id`. 409 `not_escalated` for any other state; 404 for a finding the tenant does not hold; 403 for a non-user key or a tenant with no human anchor. Requires `LOOPCTL_USER_KEY`, used exactly. |
542
544
  | `change_binding_get` | **The chg changes bound to a story** (`GET /api/v1/stories/:id/changes`, loopctl US-47.7): every change a chg `submitted` event bound to the story, OLDEST FIRST so the current one is last, each with `repo`, `change_id`, `current`, `superseded_at`, `submitter_not_claimant`, `inserted_at`, and its APPLIED events in `event_seq` order (`event_seq`, `kind`, `revision`, `sha`, `occurred_at`, `applied_at`; never the event `data` payload). Bounded by the server, bounds in `meta` (`max_bindings`, `max_events_per_change`): the newest of each are kept, so the current binding is always listed, and `binding_count` / `applied_event_count` / `events_truncated` say when more exist. Any tenant key reads it (`role: :agent` with the hierarchy), so nothing is pinned: `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 404 when the story is not your tenant's — another tenant's id answers exactly like an unknown one; 401 without a valid key; 400 for a superadmin key without `X-Impersonate-Tenant`; no role is refused. Required: `story_id` (refused locally if not a UUID). |
543
545
  | `resolve_escalation` | **Move an escalated story off `escalated`, as a human** (`POST /api/v1/stories/:id/stage/resolve`): `to` is `detected` (triage it again), `queued` (work it again), `done` or `failed`. `detected` is for a story triage escalated, such as `triage_verdict:verdict_invalid`. It is refused 409 `not_retriageable`, with what the story holds in `held`, for a story an implementer was assigned or worked. `queued` on a triage escalation skips triage. The other half of `escalate_story` — without it a parked story stays parked for ever. Requires `LOOPCTL_USER_KEY` on a key no dispatch minted: a session cannot resolve the escalation it raised. Optional: `reason`. |
544
546
  | `escalation_list` | **The escalation inbox** (`GET /api/v1/escalations`, loopctl US-48.11): every story of your tenant parked at `escalated`, newest escalation first, so a timed-out or failed implementation can be found and worked again. **Reads only** — `resolve_escalation` with `to: "queued"` is what works a row again. Each row: `story_id`, `project_id`, `escalated_at`, `edge`, `reason_class`, `spec` (`{id, version}` of the dispatch that parked it, or null), `dispatch_id`, and `escalation_reason`, which is untrusted session text: read `escalation_reason_fenced`. `reason_class` comes from the stage-machine edge, never from text: `budget_exhausted`, `session_failed`, `triage_escalated`, `gate_refused`, `operator_released`, `other`. A `budget_exhausted` row carries `run`: `elapsed_seconds`, `wall_clock_seconds`, `turns_used` against `max_turns` (the budget it was placed under), `branch`, `session_ended_reason`, `work_left_behind` (from the ledger and the runner's session-end report: `"true"` or `"false"` as the runner reported unpushed commits at exit, `"unknown"` when it did not say — a runner older than contract 1.27.0, or one that could not tell; `turns_used` is then null too). Optional: `reason_class`, `project_id` (UUID), `since` (ISO8601), `cursor` (a page's `next_cursor`, verbatim), `limit` (default 50, at most 100). Any tenant key reads it (`role: :agent` with the hierarchy): `LOOPCTL_API_KEY` when set, else `LOOPCTL_AGENT_KEY`, else `LOOPCTL_ORCH_KEY`. 400 for an unknown `reason_class`, a bad `since` or `limit`, or a foreign or tampered cursor; 422 for a malformed `project_id`; no role is refused. The MCP server adds `remedies` to the page, holding each present `reason_class`'s text once (`meaning`, `options`: which `resolve_escalation` target fits, in order, and `take_over`), and a `remedy` to every row: `see` (its `remedies` key), a `warning` when the change already merged, and `salvage` when the runner left unpushed commits. |
package/index.js CHANGED
@@ -91,6 +91,7 @@ import { revokeDispatch as revokeDispatchRequest } from "./lib/dispatch-revoke.j
91
91
  import { changeBindingGet as changeBindingGetRequest } from "./lib/change-bindings.js";
92
92
  import { agentOutcomes } from "./lib/agent-outcomes.js";
93
93
  import { chgLedgerSummary } from "./lib/chg-ledger-summary.js";
94
+ import { chgFindings, chgFindingClear } from "./lib/chg-findings.js";
94
95
  import {
95
96
  clearGithubCredential as clearGithubCredentialRequest,
96
97
  githubCredential as githubCredentialRequest,
@@ -3517,6 +3518,22 @@ async function chgLedgerSummaryRead(args) {
3517
3518
  );
3518
3519
  }
3519
3520
 
3521
+ // US-51.6: the findings list is a READ keyed as chgLedgerSummaryRead is; clearing one is a
3522
+ // person's act and takes the EXACT user key through runnerDeps().
3523
+ async function chgFindingsRead(args) {
3524
+ const key = process.env.LOOPCTL_AGENT_KEY;
3525
+
3526
+ return toContent(
3527
+ await chgFindings(args, {
3528
+ apiCall: (method, path, body) => apiCall(method, path, body, key),
3529
+ }),
3530
+ );
3531
+ }
3532
+
3533
+ async function chgFindingClearCall(args) {
3534
+ return toContent(await chgFindingClear(args, runnerDeps()));
3535
+ }
3536
+
3520
3537
  async function resolveEscalation(args) {
3521
3538
  return toContent(await resolveEscalationRequest(args, deliveryDeps()));
3522
3539
  }
@@ -9004,6 +9021,61 @@ const TOOLS = [
9004
9021
  },
9005
9022
  },
9006
9023
  },
9024
+ {
9025
+ name: "chg_findings",
9026
+ description:
9027
+ "THE CHG FEEDBACK LOOP'S FINDINGS (GET /api/v1/chg_findings, loopctl US-51.6): the " +
9028
+ "problems the nightly sweep derived from the chg ledger and files as GitHub issues for " +
9029
+ "the delivery loop to fix — `selection_miss`, `flaky_test`, `missing_review`, " +
9030
+ "`stuck_change`, `source_silent` — newest sighting first. Each row: `id`, `kind`, " +
9031
+ "`fingerprint`, `repo`, `state` (queued, filed, fixed, closed, escalated), " +
9032
+ "`occurrences`, `fix_attempts`, `loop_depth`, `cycle`, `issue_number`, `issue_url`, " +
9033
+ "`escalated_reason` and the timestamps.\n\n" +
9034
+ "Filters, all optional: `state`, `kind`, `repo` (owner/name, any case), `limit` " +
9035
+ "(default 50, at most 200). Any key of the tenant may read it (`role: :agent` with the " +
9036
+ "hierarchy): LOOPCTL_API_KEY when set, else LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY. " +
9037
+ "REFUSES: 422 for an unknown `state` or `kind` or a `limit` outside 1..200 (also " +
9038
+ "refused locally, status 0, nothing sent); 401 for no key or one that does not " +
9039
+ "authenticate. No 403: every key role clears the gate.",
9040
+ inputSchema: {
9041
+ type: "object",
9042
+ properties: {
9043
+ state: {
9044
+ type: "string",
9045
+ enum: ["queued", "filed", "fixed", "closed", "escalated"],
9046
+ description: "Only findings in this state.",
9047
+ },
9048
+ kind: {
9049
+ type: "string",
9050
+ enum: ["selection_miss", "flaky_test", "missing_review", "stuck_change", "source_silent"],
9051
+ description: "Only findings of this kind.",
9052
+ },
9053
+ repo: { type: "string", description: "Only findings filed on this repository." },
9054
+ limit: { type: "integer", description: "Default 50, at most 200." },
9055
+ },
9056
+ },
9057
+ },
9058
+ {
9059
+ name: "chg_finding_clear",
9060
+ description:
9061
+ "SEND AN ESCALATED CHG FINDING ROUND THE LOOP AGAIN (POST " +
9062
+ "/api/v1/chg_findings/:id/clear, loopctl US-51.6). The finding goes back to `queued` " +
9063
+ "with its fix attempts reset and its issue number dropped, so the next nightly sweep " +
9064
+ "files a fresh issue. The escalated issue is left open for you to close. Audited as " +
9065
+ "`chg_finding_cleared`. Use it after a person has looked at why the loop escalated " +
9066
+ "(depth 2, or two fixes that did not hold) and decided the loop should try again. " +
9067
+ "REFUSES: 409 not_escalated for a finding in any other state; 404 for a finding the " +
9068
+ "tenant does not hold; 403 for any key that is not user-role; 403 " +
9069
+ "custody_tier_required on a tenant with no human anchor. Requires LOOPCTL_USER_KEY " +
9070
+ "(user role), used exactly; refused locally when it is not set.",
9071
+ inputSchema: {
9072
+ type: "object",
9073
+ properties: {
9074
+ finding_id: { type: "string", description: "The finding's id, from chg_findings." },
9075
+ },
9076
+ required: ["finding_id"],
9077
+ },
9078
+ },
9007
9079
  {
9008
9080
  name: "change_binding_get",
9009
9081
  description:
@@ -10752,6 +10824,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
10752
10824
  return await agentOutcomesRead(args);
10753
10825
  case "chg_ledger_summary":
10754
10826
  return await chgLedgerSummaryRead(args);
10827
+ case "chg_findings":
10828
+ return await chgFindingsRead(args);
10829
+ case "chg_finding_clear":
10830
+ return await chgFindingClearCall(args);
10755
10831
 
10756
10832
  case "resolve_escalation":
10757
10833
  return await resolveEscalation(args);
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `chg_findings` and `chg_finding_clear` (loopctl US-51.6): the chg feedback loop's findings —
3
+ * `GET /api/v1/chg_findings` and `POST /api/v1/chg_findings/:id/clear`.
4
+ *
5
+ * A finding is a problem the nightly sweep derived from the chg ledger (a selection miss, a
6
+ * flaky test, a merge with no review, a stuck change, a silent ledger sender), filed as a
7
+ * GitHub issue that the delivery loop then fixes.
8
+ *
9
+ * The list is a READ, `role: :agent` with the hierarchy, so the handler passes
10
+ * LOOPCTL_AGENT_KEY as an override and `resolveKey`'s order holds. Clearing an ESCALATED
11
+ * finding sends it round the loop again, so it is `role: :user` on a human-anchored tenant and
12
+ * takes the EXACT user key, like the runner tools.
13
+ */
14
+
15
+ export const STATES = ["queued", "filed", "fixed", "closed", "escalated"];
16
+ export const KINDS = [
17
+ "selection_miss",
18
+ "flaky_test",
19
+ "missing_review",
20
+ "stuck_change",
21
+ "source_silent",
22
+ ];
23
+ export const LIST_CAP = 200;
24
+
25
+ export const MISSING_USER_KEY =
26
+ "No user-role API key configured. Set LOOPCTL_USER_KEY to a user-role key to clear a chg " +
27
+ "finding: clearing sends an escalated problem back to the loop, so it is a person's act and " +
28
+ "the endpoint refuses agent and orchestrator keys.";
29
+
30
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
31
+
32
+ function refuse(body) {
33
+ return { error: true, status: 0, body };
34
+ }
35
+
36
+ /** `GET /api/v1/chg_findings`, with the optional `state`, `kind`, `repo`, `limit`. */
37
+ export async function chgFindings(args = {}, { apiCall } = {}) {
38
+ const { state, kind, repo, limit } = args;
39
+
40
+ if (state !== undefined && state !== null && !STATES.includes(state)) {
41
+ return refuse(`\`state\` must be one of ${STATES.join(", ")}.`);
42
+ }
43
+ if (kind !== undefined && kind !== null && !KINDS.includes(kind)) {
44
+ return refuse(`\`kind\` must be one of ${KINDS.join(", ")}.`);
45
+ }
46
+ if (repo !== undefined && repo !== null && typeof repo !== "string") {
47
+ return refuse("`repo` must be a string.");
48
+ }
49
+ if (
50
+ limit !== undefined &&
51
+ limit !== null &&
52
+ !(Number.isInteger(limit) && limit >= 1 && limit <= LIST_CAP)
53
+ ) {
54
+ return refuse(`\`limit\` must be an integer from 1 to ${LIST_CAP}.`);
55
+ }
56
+
57
+ const qs = new URLSearchParams();
58
+ if (typeof state === "string") qs.set("state", state);
59
+ if (typeof kind === "string") qs.set("kind", kind);
60
+ if (typeof repo === "string" && repo !== "") qs.set("repo", repo);
61
+ if (Number.isInteger(limit)) qs.set("limit", String(limit));
62
+
63
+ const query = qs.toString();
64
+ return apiCall("GET", `/api/v1/chg_findings${query ? `?${query}` : ""}`, null);
65
+ }
66
+
67
+ /** `POST /api/v1/chg_findings/:id/clear` with the exact user key. */
68
+ export async function chgFindingClear({ finding_id } = {}, { userKey, apiCall } = {}) {
69
+ if (!userKey) return refuse(MISSING_USER_KEY);
70
+
71
+ if (typeof finding_id !== "string" || !UUID.test(finding_id)) {
72
+ return refuse("`finding_id` is required: the finding's UUID, from chg_findings.");
73
+ }
74
+
75
+ return apiCall("POST", `/api/v1/chg_findings/${encodeURIComponent(finding_id)}/clear`, {});
76
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",