loopctl-mcp-server 3.50.0 → 3.57.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.
@@ -44,3 +44,58 @@ export async function agentOutcomes({ spec_id, window_days } = {}, { apiCall } =
44
44
  const qs = Number.isInteger(window_days) ? `?window_days=${window_days}` : "";
45
45
  return apiCall("GET", `${agentOutcomesPath(spec_id)}${qs}`, null);
46
46
  }
47
+
48
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
49
+
50
+ export function agentOutcomesComparePath(specId) {
51
+ return `${agentOutcomesPath(specId)}/compare`;
52
+ }
53
+
54
+ /**
55
+ * `agent_outcomes_compare` (loopctl US-55.2): `GET
56
+ * /api/v1/agent_specs/:spec_id/outcomes/compare?at=&window_days=&project_id=` — the spec's runs
57
+ * in the window before `at` (a landed prompt change) against its runs since, and whether each
58
+ * side holds the server's minimum. Keyed like `agent_outcomes`.
59
+ *
60
+ * `at` is required and must be readable by `Date.parse`, or nothing is sent. The server is
61
+ * stricter (ISO-8601 with an offset, not in the future) and answers 400 for the rest.
62
+ */
63
+ export async function agentOutcomesCompare(
64
+ { spec_id, at, window_days, project_id } = {},
65
+ { apiCall } = {},
66
+ ) {
67
+ if (typeof spec_id !== "string" || !SPEC_ID.test(spec_id)) {
68
+ return refuse(
69
+ "`spec_id` is required: an agent spec id, lower-case (e.g. `triage`, `verify`).",
70
+ );
71
+ }
72
+
73
+ if (typeof at !== "string" || at === "" || Number.isNaN(Date.parse(at))) {
74
+ return refuse(
75
+ "`at` is required: an ISO-8601 date-time with an offset, e.g. `2026-11-01T00:00:00Z` " +
76
+ "(a tuning draft's `landed_at`, or a deploy time).",
77
+ );
78
+ }
79
+
80
+ if (
81
+ window_days !== undefined &&
82
+ window_days !== null &&
83
+ !(Number.isInteger(window_days) && window_days >= 1 && window_days <= MAX_WINDOW_DAYS)
84
+ ) {
85
+ return refuse(`\`window_days\` must be an integer from 1 to ${MAX_WINDOW_DAYS}.`);
86
+ }
87
+
88
+ if (
89
+ project_id !== undefined &&
90
+ project_id !== null &&
91
+ !(typeof project_id === "string" && UUID.test(project_id))
92
+ ) {
93
+ return refuse("`project_id` must be a project UUID.");
94
+ }
95
+
96
+ const params = [`at=${encodeURIComponent(at)}`];
97
+ if (Number.isInteger(window_days)) params.push(`window_days=${window_days}`);
98
+ if (typeof project_id === "string") params.push(`project_id=${encodeURIComponent(project_id)}`);
99
+
100
+ return apiCall("GET", `${agentOutcomesComparePath(spec_id)}?${params.join("&")}`, null);
101
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * `agent_replay_set` (loopctl US-55.5, US-55.13): an agent spec's past runs rebuilt as replay
3
+ * cases — `GET /api/v1/agent_specs/:spec_id/replay_set?limit=N`, for `triage` or `verify`.
4
+ *
5
+ * triage: the newest triage runs (ended `triage_verdict` or `triage_incomplete`), each as the
6
+ * dispatch the live triage pass would send for its story TODAY. verify: the newest verify@1
7
+ * verdicts, each as the live verify dispatch at the head the runner measured. Each case says where
8
+ * its expected answer comes from (`human`, `downstream`, verify's `downstream_tree`, or `agent`,
9
+ * which is never scored). Save the response to a file and run
10
+ * `mix loopctl_runner.eval <spec>@<version> --replay-from FILE`.
11
+ *
12
+ * `role: :user`: every case carries customer text, as tuning drafts do, so this takes the EXACT
13
+ * user key (`runnerDeps()`), and a global LOOPCTL_API_KEY must not stand in. It writes nothing.
14
+ */
15
+
16
+ export const MISSING_USER_KEY =
17
+ "No user-role API key configured. Set LOOPCTL_USER_KEY to a user-role key to export a " +
18
+ "replay set: every case carries the reporter's ticket text, so the endpoint refuses agent " +
19
+ "and orchestrator keys.";
20
+
21
+ export const MAX_LIMIT = 100;
22
+
23
+ const SPEC_ID = /^[a-z][a-z0-9_]{0,63}$/;
24
+
25
+ function refuse(body) {
26
+ return { error: true, status: 0, body };
27
+ }
28
+
29
+ export function replaySetPath(specId) {
30
+ return `/api/v1/agent_specs/${encodeURIComponent(specId)}/replay_set`;
31
+ }
32
+
33
+ /** `GET /api/v1/agent_specs/:spec_id/replay_set`, optionally `?limit=N` (1..100). */
34
+ export async function agentReplaySet({ spec_id, limit } = {}, { userKey, apiCall } = {}) {
35
+ if (!userKey) return refuse(MISSING_USER_KEY);
36
+
37
+ if (typeof spec_id !== "string" || !SPEC_ID.test(spec_id)) {
38
+ return refuse("`spec_id` is required: an agent spec id, lower-case (today `triage` or `verify`).");
39
+ }
40
+
41
+ if (
42
+ limit !== undefined &&
43
+ limit !== null &&
44
+ !(Number.isInteger(limit) && limit >= 1 && limit <= MAX_LIMIT)
45
+ ) {
46
+ return refuse(`\`limit\` must be an integer from 1 to ${MAX_LIMIT}.`);
47
+ }
48
+
49
+ const qs = Number.isInteger(limit) ? `?limit=${limit}` : "";
50
+ return apiCall("GET", `${replaySetPath(spec_id)}${qs}`, null);
51
+ }
@@ -6,8 +6,9 @@
6
6
  * gated like clear: a user key, used exactly.
7
7
  *
8
8
  * A finding is a problem the nightly sweep derived from the chg ledger (a selection miss, a
9
- * flaky test, a merge with no review, a stuck change, a silent ledger sender), filed as a
10
- * GitHub issue that the delivery loop then fixes.
9
+ * flaky test, a merge with no review, a stuck change, a silent ledger sender) or one the
10
+ * post-deploy monitor recorded (a deploy regression, loopctl US-55.14), filed as a GitHub
11
+ * issue that the delivery loop then fixes.
11
12
  *
12
13
  * The list is a READ, `role: :agent` with the hierarchy, so the handler passes
13
14
  * LOOPCTL_AGENT_KEY as an override and `resolveKey`'s order holds. Clearing an ESCALATED
@@ -22,6 +23,7 @@ export const KINDS = [
22
23
  "missing_review",
23
24
  "stuck_change",
24
25
  "source_silent",
26
+ "deploy_regression",
25
27
  ];
26
28
  export const LIST_CAP = 200;
27
29
 
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `fly_metrics_credential`, `set_fly_metrics_credential`, `clear_fly_metrics_credential` — the
3
+ * tenant's own Fly metrics credential (loopctl US-55.7),
4
+ * `GET|PUT|DELETE /api/v1/tenants/me/fly-metrics-credential`.
5
+ *
6
+ * The post-deploy monitor reads the edge metrics of the Fly apps a tenant's intake sources name
7
+ * (`fly_app`) from Fly's managed Prometheus for the tenant's org, with this credential and no
8
+ * other: there is no operator token, so a tenant with none is simply not monitored.
9
+ *
10
+ * All three need the `:user` key: the endpoint manages a stored credential. The token is never
11
+ * returned — reads show `has_token`, a last-4 `token_hint` and the `org`.
12
+ */
13
+
14
+ export const FLY_METRICS_CREDENTIAL_PATH = "/api/v1/tenants/me/fly-metrics-credential";
15
+
16
+ /** The longest token the server accepts (`TenantCredential.max_token_length/0`). */
17
+ export const MAX_FLY_TOKEN_CHARS = 4096;
18
+
19
+ const ORG_FORMAT = /^[a-z0-9][a-z0-9-]{0,62}$/;
20
+ const TOKEN_FORMAT = /^FlyV1 [A-Za-z0-9_+/=,-]+$/;
21
+
22
+ function refuse(body) {
23
+ return { error: true, status: 0, body };
24
+ }
25
+
26
+ export async function flyMetricsCredential(_args = {}, { apiCall } = {}) {
27
+ return apiCall("GET", FLY_METRICS_CREDENTIAL_PATH, null);
28
+ }
29
+
30
+ /**
31
+ * A malformed org or token is refused HERE, before any call, with the server's rule; the
32
+ * refusal never repeats the token, because a tool result lands in the transcript.
33
+ */
34
+ export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } = {}) {
35
+ if (typeof org !== "string" || !ORG_FORMAT.test(org)) {
36
+ return refuse(
37
+ "`org` is required: the Fly org slug (`fly orgs list`), e.g. `personal` — lowercase " +
38
+ "letters, digits and hyphens, at most 63 characters, starting with a letter or digit.",
39
+ );
40
+ }
41
+
42
+ const trimmed = typeof token === "string" ? token.trim() : "";
43
+
44
+ if (
45
+ trimmed === "" ||
46
+ [...trimmed].length > MAX_FLY_TOKEN_CHARS ||
47
+ !TOKEN_FORMAT.test(trimmed)
48
+ ) {
49
+ return refuse(
50
+ "`token` is required: the output of `fly tokens create readonly <org>`, which starts " +
51
+ `\`FlyV1 \` and holds only A-Z a-z 0-9 _ + / = , - after it, at most ` +
52
+ `${MAX_FLY_TOKEN_CHARS} characters. A \`Bearer\` personal token is refused: it ` +
53
+ "reaches every org its user can.",
54
+ );
55
+ }
56
+
57
+ return apiCall("PUT", FLY_METRICS_CREDENTIAL_PATH, { org, token: trimmed });
58
+ }
59
+
60
+ export async function clearFlyMetricsCredential(_args = {}, { apiCall } = {}) {
61
+ return apiCall("DELETE", FLY_METRICS_CREDENTIAL_PATH, null);
62
+ }
@@ -468,6 +468,25 @@ export function deployEnvironmentRefusal(value, { clearable }) {
468
468
  );
469
469
  }
470
470
 
471
+ // The rule `Loopctl.Intake.Source.fly_app_pattern/0` states and `intake_sources_fly_app_shape`
472
+ // holds.
473
+ const FLY_APP_FORMAT = /^[a-z0-9][a-z0-9-]{0,62}$/;
474
+
475
+ /**
476
+ * `fly_app` (loopctl US-55.7): the Fly app the post-deploy monitor reads this source's edge
477
+ * metrics for. A Fly app name, or `null`, which clears it; only an update may send it.
478
+ */
479
+ export function flyAppRefusal(value) {
480
+ if (value === null) return null;
481
+ if (typeof value === "string" && FLY_APP_FORMAT.test(value)) return null;
482
+
483
+ return refuse(
484
+ "`fly_app` must be a Fly app name — lowercase letters, digits and hyphens, at most 63 " +
485
+ "characters, starting with a letter or digit — or null to clear it (which stops the " +
486
+ "post-deploy monitor reading the source).",
487
+ );
488
+ }
489
+
471
490
  export function sourcePath(sourceId) {
472
491
  return `${SOURCES_PATH}/${encodeURIComponent(sourceId)}`;
473
492
  }
@@ -498,6 +517,7 @@ export function publicSource(source) {
498
517
  base_branch: source.base_branch,
499
518
  issue_label: source.issue_label,
500
519
  deploy_environment: source.deploy_environment,
520
+ fly_app: source.fly_app,
501
521
  mode: source.mode,
502
522
  required_checks: source.required_checks,
503
523
  triage_requires_ticket: source.triage_requires_ticket,
@@ -893,6 +913,13 @@ export async function updateIntakeSource(
893
913
  body.deploy_environment = args.deploy_environment;
894
914
  }
895
915
 
916
+ // US-55.7: null is FORWARDED, the only way to stop the post-deploy monitor reading the source.
917
+ if (args.fly_app !== undefined) {
918
+ const badApp = flyAppRefusal(args.fly_app);
919
+ if (badApp) return badApp;
920
+ body.fly_app = args.fly_app;
921
+ }
922
+
896
923
  if (args.mode !== undefined) {
897
924
  const badMode = modeRefusal(args.mode);
898
925
  if (badMode) return badMode;
@@ -922,7 +949,7 @@ export async function updateIntakeSource(
922
949
  return refuse(
923
950
  "Nothing to update. Name at least one of `target_epic_id` (null clears it), " +
924
951
  "`base_branch`, `issue_label` (null clears it), `deploy_environment` (null clears " +
925
- "it), `mode`, `required_checks`, " +
952
+ "it), `fly_app` (null clears it), `mode`, `required_checks`, " +
926
953
  "`triage_requires_ticket`, " +
927
954
  "`change_events_secret` (or " +
928
955
  "`change_events_secret_file`), `chg_root_dispatch_id` or `mint_chg_root`. A body " +
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The three body reads that record a knowledge access event, and the story each one names
3
+ * (loopctl US-55.17): `knowledge_get` (`GET /api/v1/articles/:id`), `knowledge_context`
4
+ * (`GET /api/v1/knowledge/context`) and `knowledge_progressive_drill`
5
+ * (`GET /api/v1/knowledge/progressive/:id`).
6
+ *
7
+ * `story_id` is attribution only. When the caller passes one it is sent as given. When it
8
+ * passes none, `LOOPCTL_STORY_ID` is sent, read from the environment at CALL time: the loopctl
9
+ * runner sets it in a dispatched implement session to the story that session works, and this
10
+ * server inherits the session's environment. loopctl records either as `story_attribution:
11
+ * caller` (its word is the caller's, never the server's). An env value that is not a UUID is
12
+ * ignored rather than sent, since the context and drill reads refuse a malformed one with a
13
+ * 422 and a stray variable must not break every read. With neither, nothing is sent, and a
14
+ * holder key's reads are attributed server-side to its one open item.
15
+ *
16
+ * The article id arrives already checked (`articleId` in index.js, which its wiring test
17
+ * pins), as `id`.
18
+ */
19
+ import { uuid } from "./delivery-loop.js";
20
+
21
+ export const STORY_ID_ENV = "LOOPCTL_STORY_ID";
22
+
23
+ /** The story id a read sends: the caller's, else a UUID-shaped `LOOPCTL_STORY_ID`, else none. */
24
+ export function readStoryId(story_id, env = process.env) {
25
+ if (story_id) return story_id;
26
+ const fromEnv = typeof env[STORY_ID_ENV] === "string" ? env[STORY_ID_ENV].trim() : "";
27
+ return fromEnv && uuid(fromEnv, STORY_ID_ENV) === null ? fromEnv : undefined;
28
+ }
29
+
30
+ function setWindow(params, body_max_bytes, body_offset) {
31
+ // 0 is meaningful on both (whole body / start at the beginning), so test for
32
+ // null/undefined rather than truthiness.
33
+ if (body_max_bytes !== undefined && body_max_bytes !== null)
34
+ params.set("body_max_bytes", String(body_max_bytes));
35
+ if (body_offset !== undefined && body_offset !== null)
36
+ params.set("body_offset", String(body_offset));
37
+ }
38
+
39
+ function withQuery(base, params) {
40
+ const qs = params.toString();
41
+ return qs ? `${base}?${qs}` : base;
42
+ }
43
+
44
+ /** `knowledge_get`: `GET /api/v1/articles/:id`. */
45
+ export async function knowledgeGetRead(
46
+ { id, project_id, story_id, links, body_max_bytes, body_offset } = {},
47
+ { apiCall, env = process.env } = {},
48
+ ) {
49
+ const params = new URLSearchParams();
50
+ if (project_id) params.set("project_id", project_id);
51
+ const story = readStoryId(story_id, env);
52
+ if (story) params.set("story_id", story);
53
+ if (links) params.set("links", links);
54
+ setWindow(params, body_max_bytes, body_offset);
55
+ return apiCall("GET", withQuery(`/api/v1/articles/${id}`, params), null);
56
+ }
57
+
58
+ /** `knowledge_context`: `GET /api/v1/knowledge/context`. */
59
+ export async function knowledgeContextRead(
60
+ { query, project_id, story_id, limit, recency_weight, memory_types, agents, conversation_id } = {},
61
+ { apiCall, env = process.env } = {},
62
+ ) {
63
+ const params = new URLSearchParams({ query });
64
+ if (project_id) params.set("project_id", project_id);
65
+ const story = readStoryId(story_id, env);
66
+ if (story) params.set("story_id", story);
67
+ if (limit != null) params.set("limit", String(limit));
68
+ if (recency_weight != null) params.set("recency_weight", String(recency_weight));
69
+ // Agent-memory scoping (comma-separated lists are OR'd; conversation_id is exact).
70
+ if (memory_types)
71
+ params.set("memory_types", Array.isArray(memory_types) ? memory_types.join(",") : memory_types);
72
+ if (agents) params.set("agents", Array.isArray(agents) ? agents.join(",") : agents);
73
+ if (conversation_id) params.set("conversation_id", conversation_id);
74
+ return apiCall("GET", `/api/v1/knowledge/context?${params}`, null);
75
+ }
76
+
77
+ /** `knowledge_progressive_drill`: `GET /api/v1/knowledge/progressive/:id`. */
78
+ export async function knowledgeDrillRead(
79
+ { id, story_id, body_max_bytes, body_offset } = {},
80
+ { apiCall, env = process.env } = {},
81
+ ) {
82
+ const params = new URLSearchParams();
83
+ const story = readStoryId(story_id, env);
84
+ if (story) params.set("story_id", story);
85
+ setWindow(params, body_max_bytes, body_offset);
86
+ return apiCall("GET", withQuery(`/api/v1/knowledge/progressive/${id}`, params), null);
87
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * `story_retrieval` (loopctl US-55.3): which knowledge articles were opened while work was
3
+ * done, beside how the work came out.
4
+ *
5
+ * - with `story_id`: `GET /api/v1/knowledge/analytics/stories/:id/retrieval` — the story's
6
+ * body reads per article (title, reads, first read, reads per route) and its outcome
7
+ * (`first_time_pass` for a loop story; `review_rounds` and `merged` for an interactive
8
+ * item).
9
+ * - with `project_id`: `GET /api/v1/knowledge/analytics/projects/:id/retrieval-outcomes`,
10
+ * optionally `?window_days=N` (1..90, default 30) — the project's decided loop stories and
11
+ * ended interactive items in the window, grouped by whether any article was opened.
12
+ *
13
+ * Both are `role: :orchestrator` with the hierarchy (knowledge_analytics_controller.ex), so
14
+ * the handler sends the orchestrator key pinned as `knowledge_project_usage` does. Exactly
15
+ * one of `story_id` and `project_id` is required; both, neither, a malformed id or a window
16
+ * out of range is refused here, before any request.
17
+ */
18
+
19
+ import { uuid } from "./delivery-loop.js";
20
+
21
+ export const MAX_WINDOW_DAYS = 90;
22
+
23
+ function refuse(body) {
24
+ return { error: true, status: 0, body };
25
+ }
26
+
27
+ // ONE template literal per builder (see `test/tool-surface.js`).
28
+ export function storyRetrievalPath(storyId) {
29
+ return `/api/v1/knowledge/analytics/stories/${encodeURIComponent(storyId)}/retrieval`;
30
+ }
31
+
32
+ export function projectRetrievalOutcomesPath(projectId, query = "") {
33
+ return `/api/v1/knowledge/analytics/projects/${encodeURIComponent(projectId)}/retrieval-outcomes${query}`;
34
+ }
35
+
36
+ function given(value) {
37
+ return value !== undefined && value !== null && value !== "";
38
+ }
39
+
40
+ export async function storyRetrieval({ story_id, project_id, window_days } = {}, { apiCall } = {}) {
41
+ const hasStory = given(story_id);
42
+ const hasProject = given(project_id);
43
+
44
+ if (hasStory === hasProject) {
45
+ return refuse(
46
+ "Pass exactly one of `story_id` (one work item's opened articles and outcome) or " +
47
+ "`project_id` (the project's outcomes grouped by whether an article was opened).",
48
+ );
49
+ }
50
+
51
+ if (hasStory) {
52
+ if (given(window_days)) {
53
+ return refuse("`window_days` applies to `project_id` only.");
54
+ }
55
+
56
+ const bad = uuid(story_id, "story_id");
57
+ if (bad) return bad;
58
+
59
+ return apiCall("GET", storyRetrievalPath(story_id), null);
60
+ }
61
+
62
+ const bad = uuid(project_id, "project_id");
63
+ if (bad) return bad;
64
+
65
+ if (
66
+ given(window_days) &&
67
+ !(Number.isInteger(window_days) && window_days >= 1 && window_days <= MAX_WINDOW_DAYS)
68
+ ) {
69
+ return refuse(
70
+ `\`window_days\` must be an integer from 1 to ${MAX_WINDOW_DAYS} (default 30); ` +
71
+ "loopctl answers 400 for any other value.",
72
+ );
73
+ }
74
+
75
+ const qs = given(window_days) ? `?window_days=${window_days}` : "";
76
+ return apiCall("GET", projectRetrievalOutcomesPath(project_id, qs), null);
77
+ }
@@ -81,8 +81,19 @@ export async function tuningDrafts(
81
81
  return apiCall("GET", `/api/v1/tuning_drafts${qs ? `?${qs}` : ""}`, null);
82
82
  }
83
83
 
84
- /** `POST /api/v1/tuning_drafts/:id/landed` with `{pr_url}`. */
85
- export async function tuningDraftMarkLanded({ draft_id, pr_url } = {}, { userKey, apiCall } = {}) {
84
+ /** The most characters `replay_evidence` may carry (loopctl US-55.5). */
85
+ export const MAX_REPLAY_EVIDENCE_CHARS = 4000;
86
+
87
+ /**
88
+ * `POST /api/v1/tuning_drafts/:id/landed` with `{pr_url}`, and `replay_evidence` when given
89
+ * (loopctl US-55.5: required by the server for a draft of a replayable target, today `triage`).
90
+ * The local cap counts code points; the server counts graphemes, which are never more, so
91
+ * nothing this sends is over the server's cap.
92
+ */
93
+ export async function tuningDraftMarkLanded(
94
+ { draft_id, pr_url, replay_evidence } = {},
95
+ { userKey, apiCall } = {},
96
+ ) {
86
97
  if (!userKey) return refuse(MISSING_USER_KEY);
87
98
 
88
99
  if (typeof draft_id !== "string" || !UUID.test(draft_id)) {
@@ -93,5 +104,22 @@ export async function tuningDraftMarkLanded({ draft_id, pr_url } = {}, { userKey
93
104
  return refuse("`pr_url` is required: https://github.com/<owner>/<repo>/pull/<n>.");
94
105
  }
95
106
 
96
- return apiCall("POST", landedPath(draft_id), { pr_url });
107
+ const hasEvidence = replay_evidence !== undefined && replay_evidence !== null;
108
+
109
+ if (
110
+ hasEvidence &&
111
+ !(
112
+ typeof replay_evidence === "string" &&
113
+ replay_evidence.trim() !== "" &&
114
+ [...replay_evidence].length <= MAX_REPLAY_EVIDENCE_CHARS
115
+ )
116
+ ) {
117
+ return refuse(
118
+ `\`replay_evidence\` must be text of 1 to ${MAX_REPLAY_EVIDENCE_CHARS} characters: the ` +
119
+ "table `mix loopctl_runner.eval --replay-from` printed.",
120
+ );
121
+ }
122
+
123
+ const body = hasEvidence ? { pr_url, replay_evidence } : { pr_url };
124
+ return apiCall("POST", landedPath(draft_id), body);
97
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.50.0",
3
+ "version": "3.57.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",