loopctl-mcp-server 3.57.0 → 3.58.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
@@ -496,7 +496,7 @@ Each row names the key it sends; an entity definition is a security root and nee
496
496
  | `bootstrap_audit_key` | **Generate the first audit signing keypair** for a tenant created before Chain of Custody v2 (#873, `POST /api/v1/tenants/:id/bootstrap-audit-key`). Takes `tenant_id`; returns the public key. Refuses `409 key_already_exists` (rotation is the WebAuthn ceremony) and `403` for a key that is not user role or not the tenant's. Requires **user** key. |
497
497
  | `clear_github_credential` | **Remove the tenant's GitHub token** (#936, `DELETE /api/v1/tenants/me/github-credential`). Calls then use the operator's token only for `operator_repositories` and are refused `credential_unavailable` everywhere else, so a pr-mode repository outside that list stops merging. Idempotent. Requires **user** key. |
498
498
  | `fly_metrics_credential` | **Is there a Fly metrics credential for this tenant?** (US-55.7, `GET /api/v1/tenants/me/fly-metrics-credential`) `has_token`, a masked last-4 `token_hint`, the Fly `org` and `updated_at`. Never returns the token. The post-deploy monitor reads the edge metrics of the Fly apps the tenant's intake sources name (`fly_app`, set with `intake_source_update`) with this credential and no other: there is no operator token, so a tenant without one is not monitored. Requires **user** key (403 `insufficient_role` otherwise). |
499
- | `set_fly_metrics_credential` | **Set or replace the tenant's own Fly metrics credential** (US-55.7, `PUT /api/v1/tenants/me/fly-metrics-credential`): the Fly org slug and a read-only token from `fly tokens create readonly <org>`, which the post-deploy monitor reads the org's managed Prometheus with. Stored encrypted, never returned, and not checked against Fly on the way in: a token that cannot read the org shows up as the monitor's read failure. Refused locally and 422 at the server on `details.org` unless the org is a Fly org slug (lowercase letters, digits and hyphens, at most 63, starting with a letter or digit), and on `details.token` unless the trimmed token starts `FlyV1 `, is at most 4096 characters and holds only `A-Z a-z 0-9 _ + / = , -` after the prefix; a `Bearer` personal token is refused, because it reaches every org its user can. `403 custody_tier_required` on an agent-rooted tenant. Required: `org`, `token`. Requires **user** key. |
499
+ | `set_fly_metrics_credential` | **Set or replace the tenant's own Fly metrics credential** (US-55.7, `PUT /api/v1/tenants/me/fly-metrics-credential`): the Fly org slug and a read-only token from `fly tokens create readonly <org>`, which the post-deploy monitor reads the org's managed Prometheus with. Stored encrypted, never returned, and not checked against Fly on the way in: a token that cannot read the org shows up as the monitor's read failure. Refused locally and 422 at the server on `details.org` unless the org is a Fly org slug (lowercase letters, digits and hyphens, at most 63, starting with a letter or digit), and on `details.token` unless the trimmed token starts `FlyV1 `, is at most 4096 characters and holds only `A-Z a-z 0-9 _ + / = , -` after the prefix; a `Bearer` personal token is refused, because it reaches every org its user can. `403 custody_tier_required` on an agent-rooted tenant. Required: `org`, and exactly one of `token` or `token_file` (an absolute or `~/` path the tool reads the token from, so it never passes through the transcript: a single line, or exactly one line starting `FlyV1 `). Requires **user** key. |
500
500
  | `clear_fly_metrics_credential` | **Remove the tenant's Fly metrics credential** (US-55.7, `DELETE /api/v1/tenants/me/fly-metrics-credential`). The post-deploy monitor then skips the tenant. Idempotent: `has_token: false` whether or not one was set. `403 custody_tier_required` on an agent-rooted tenant. Requires **user** key. |
501
501
  | `knowledge_llm_usage` | Per-tenant LLM token-usage summary, grouped by operation + model + source_type + day over an optional `from`/`to` range (defaults to a 90-day lookback; effective window echoed in `meta.from`/`meta.to`), with `limit`/`offset` pagination. Record-only (no budget enforcement). Requires orchestrator key. |
502
502
 
package/index.js CHANGED
@@ -9052,7 +9052,8 @@ const TOOLS = [
9052
9052
  description:
9053
9053
  "SET OR REPLACE this tenant's own Fly metrics credential (US-55.7, PUT " +
9054
9054
  "/api/v1/tenants/me/fly-metrics-credential): the Fly org slug and a read-only token " +
9055
- "for it, from `fly tokens create readonly <org>`. The post-deploy monitor reads your " +
9055
+ "for it, from `fly tokens create readonly <org>`, passed as `token` or read from " +
9056
+ "`token_file` (exactly one; the file keeps it out of the transcript). The post-deploy monitor reads your " +
9056
9057
  "apps' edge metrics from Fly's managed Prometheus for that org with it. Stored " +
9057
9058
  "encrypted, never returned. NOT checked against Fly here: a token that cannot read the " +
9058
9059
  "org shows up as the monitor's read failure. Refused locally and 422 at the server on " +
@@ -9068,10 +9069,19 @@ const TOOLS = [
9068
9069
  org: { type: "string", description: "The Fly org slug, e.g. `personal`." },
9069
9070
  token: {
9070
9071
  type: "string",
9071
- description: "The FlyV1 read-only token. Write-only; stored encrypted, never returned.",
9072
+ description:
9073
+ "The FlyV1 read-only token. Write-only; stored encrypted, never returned. Prefer " +
9074
+ "`token_file`, which keeps the token out of the transcript.",
9075
+ },
9076
+ token_file: {
9077
+ type: "string",
9078
+ description:
9079
+ "Alternative to `token`: an absolute (or `~/`) path the tool reads the token from, " +
9080
+ "e.g. a file written by `fly tokens create readonly <org> > <file>`. A single line, " +
9081
+ "or exactly one line starting `FlyV1 `. Not both.",
9072
9082
  },
9073
9083
  },
9074
- required: ["org", "token"],
9084
+ required: ["org"],
9075
9085
  },
9076
9086
  },
9077
9087
  {
@@ -11,6 +11,11 @@
11
11
  * returned — reads show `has_token`, a last-4 `token_hint` and the `org`.
12
12
  */
13
13
 
14
+ import os from "node:os";
15
+ import defaultFs from "node:fs/promises";
16
+
17
+ import { readSecretPath } from "./runners.js";
18
+
14
19
  export const FLY_METRICS_CREDENTIAL_PATH = "/api/v1/tenants/me/fly-metrics-credential";
15
20
 
16
21
  /** The longest token the server accepts (`TenantCredential.max_token_length/0`). */
@@ -27,11 +32,39 @@ export async function flyMetricsCredential(_args = {}, { apiCall } = {}) {
27
32
  return apiCall("GET", FLY_METRICS_CREDENTIAL_PATH, null);
28
33
  }
29
34
 
35
+ /**
36
+ * The token from `token_file`: an absolute (or `~/`) path holding the output of
37
+ * `fly tokens create readonly <org>`, so the token never passes through the transcript. A file
38
+ * of several lines is read for its one line starting `FlyV1 `. Resolves to `{ token }` or
39
+ * `{ refusal }`; no refusal carries the file's contents.
40
+ */
41
+ async function readTokenFile(tokenFile, { fs, homedir }) {
42
+ const read = await readSecretPath("token_file", tokenFile, { fs, homedir });
43
+ if (read.message) return { refusal: refuse(read.message) };
44
+ const { path, raw } = read;
45
+
46
+ const lines = raw.split(/\r?\n/).map((l) => l.trim()).filter((l) => l !== "");
47
+ const flyLines = lines.filter((l) => l.startsWith("FlyV1 "));
48
+ if (flyLines.length === 1) return { token: flyLines[0] };
49
+ if (lines.length === 1) return { token: lines[0] };
50
+
51
+ return {
52
+ refusal: refuse(
53
+ `token_file '${path}' must hold one token: a single line, or exactly one line starting ` +
54
+ "`FlyV1 `. Nothing was sent.",
55
+ ),
56
+ };
57
+ }
58
+
30
59
  /**
31
60
  * A malformed org or token is refused HERE, before any call, with the server's rule; the
32
- * refusal never repeats the token, because a tool result lands in the transcript.
61
+ * refusal never repeats the token, because a tool result lands in the transcript. The token
62
+ * comes from `token` or `token_file`, never both.
33
63
  */
34
- export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } = {}) {
64
+ export async function setFlyMetricsCredential(
65
+ { org, token, token_file: tokenFile } = {},
66
+ { apiCall, fs = defaultFs, homedir = os.homedir() } = {},
67
+ ) {
35
68
  if (typeof org !== "string" || !ORG_FORMAT.test(org)) {
36
69
  return refuse(
37
70
  "`org` is required: the Fly org slug (`fly orgs list`), e.g. `personal` — lowercase " +
@@ -39,6 +72,16 @@ export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } =
39
72
  );
40
73
  }
41
74
 
75
+ if (token !== undefined && tokenFile !== undefined) {
76
+ return refuse("Send `token` OR `token_file`, not both: they are two ways of naming the same value.");
77
+ }
78
+
79
+ if (tokenFile !== undefined) {
80
+ const read = await readTokenFile(tokenFile, { fs, homedir });
81
+ if (read.refusal) return read.refusal;
82
+ token = read.token;
83
+ }
84
+
42
85
  const trimmed = typeof token === "string" ? token.trim() : "";
43
86
 
44
87
  if (
@@ -47,7 +90,7 @@ export async function setFlyMetricsCredential({ org, token } = {}, { apiCall } =
47
90
  !TOKEN_FORMAT.test(trimmed)
48
91
  ) {
49
92
  return refuse(
50
- "`token` is required: the output of `fly tokens create readonly <org>`, which starts " +
93
+ "`token` (or `token_file`) is required: the output of `fly tokens create readonly <org>`, which starts " +
51
94
  `\`FlyV1 \` and holds only A-Z a-z 0-9 _ + / = , - after it, at most ` +
52
95
  `${MAX_FLY_TOKEN_CHARS} characters. A \`Bearer\` personal token is refused: it ` +
53
96
  "reaches every org its user can.",
@@ -142,7 +142,13 @@ import os from "node:os";
142
142
  import defaultFs from "node:fs/promises";
143
143
 
144
144
  import { uuid as uuidRefusal } from "./delivery-loop.js";
145
- import { expandHome, TOKEN_DIR_MODE, TOKEN_FILE_FLAGS, TOKEN_FILE_MODE } from "./runners.js";
145
+ import {
146
+ expandHome,
147
+ readSecretPath,
148
+ TOKEN_DIR_MODE,
149
+ TOKEN_FILE_FLAGS,
150
+ TOKEN_FILE_MODE,
151
+ } from "./runners.js";
146
152
 
147
153
  export const SOURCES_PATH = "/api/v1/intake/sources";
148
154
 
@@ -298,32 +304,9 @@ export async function chgCredentials(args, { clearable, fs = defaultFs, homedir
298
304
  }
299
305
 
300
306
  async function readSecretFile(secretFile, { fs, homedir }) {
301
- if (typeof secretFile !== "string" || secretFile.trim() === "") {
302
- return {
303
- refusal: refuse("`change_events_secret_file` must be a path to the file holding the secret."),
304
- };
305
- }
306
-
307
- const path = expandHome(secretFile, homedir);
308
- if (!nodePath.isAbsolute(path)) {
309
- return {
310
- refusal: refuse(
311
- `change_events_secret_file must be absolute or start with ~/ (got '${secretFile}').`,
312
- ),
313
- };
314
- }
315
-
316
- let raw;
317
- try {
318
- raw = await fs.readFile(path, "utf8");
319
- } catch (err) {
320
- return {
321
- refusal: refuse(
322
- `Could not read change_events_secret_file '${path}' (${err?.code || "error"}). ` +
323
- "Nothing was sent.",
324
- ),
325
- };
326
- }
307
+ const read = await readSecretPath("change_events_secret_file", secretFile, { fs, homedir });
308
+ if (read.message) return { refusal: refuse(read.message) };
309
+ const { path, raw } = read;
327
310
 
328
311
  const secret = raw.replace(/\r?\n$/, "");
329
312
  if (secret === "") {
package/lib/runners.js CHANGED
@@ -64,6 +64,52 @@ export function expandHome(p, homedir = os.homedir()) {
64
64
  return p;
65
65
  }
66
66
 
67
+ /** The largest file a `*_file` secret argument may name; every secret here is far smaller. */
68
+ export const MAX_SECRET_FILE_BYTES = 64 * 1024;
69
+
70
+ /**
71
+ * Read the file a `*_file` secret argument names (`field` is the argument's name, for the
72
+ * messages). Resolves to `{ path, raw }` or `{ message }`, a refusal that never carries the
73
+ * file's contents. The path must be absolute or `~/`, and must be a regular file of at most
74
+ * `maxBytes`: it is stat'ed BEFORE it is opened, because opening a FIFO blocks until a writer
75
+ * comes and a device such as /dev/zero never ends, either of which would hang the tool call.
76
+ */
77
+ export async function readSecretPath(
78
+ field,
79
+ value,
80
+ { fs, homedir = os.homedir(), maxBytes = MAX_SECRET_FILE_BYTES } = {},
81
+ ) {
82
+ if (typeof value !== "string" || value.trim() === "") {
83
+ return { message: `\`${field}\` must be a path to the file holding the secret.` };
84
+ }
85
+
86
+ const path = expandHome(value, homedir);
87
+ if (!nodePath.isAbsolute(path)) {
88
+ return { message: `${field} must be absolute or start with ~/ (got '${value}').` };
89
+ }
90
+
91
+ let stat;
92
+ try {
93
+ stat = await fs.stat(path);
94
+ } catch (err) {
95
+ return { message: `Could not read ${field} '${path}' (${err?.code || "error"}). Nothing was sent.` };
96
+ }
97
+
98
+ if (!stat.isFile()) {
99
+ return { message: `${field} '${path}' is not a regular file. Nothing was sent.` };
100
+ }
101
+
102
+ if (stat.size > maxBytes) {
103
+ return { message: `${field} '${path}' is larger than ${maxBytes} bytes. Nothing was sent.` };
104
+ }
105
+
106
+ try {
107
+ return { path, raw: await fs.readFile(path, "utf8") };
108
+ } catch (err) {
109
+ return { message: `Could not read ${field} '${path}' (${err?.code || "error"}). Nothing was sent.` };
110
+ }
111
+ }
112
+
67
113
  /**
68
114
  * `POST /api/v1/runners {name, max_sessions?}`, with the returned token written to
69
115
  * `token_file` and never returned. Resolves to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.57.0",
3
+ "version": "3.58.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",