loopctl-mcp-server 3.41.1 → 3.42.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
@@ -565,7 +565,7 @@ 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 Mark moves it. 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` when the item's holder (or, unheld, its last mover or claimer) or the target holder is an interactive session and the caller is not Mark's own user key (fleet_dash; US-52.45), except the holder answering a move Mark requested with his `move_id`, his target and its own `checkpoint_id`; a key with no holder omits `checkpoint_id`; and `403` without the human anchor. |
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`. |
@@ -576,6 +576,7 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
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. |
578
578
  | `intake_resume` | **Resume one intake source of a project** (`POST /api/v1/projects/:id/intake/resume`, US-52.33, US-54.4): the minute promotion run picks up what arrived while paused. Same `source_id` default (the primary source), scope, refusals and idempotency as `intake_pause`. |
579
+ | `api_key_create` | **Mint an API key** (`POST /api/v1/api_keys`, US-54.14) on `LOOPCTL_USER_KEY`. The raw key is written to `key_file` (absolute, must not exist, mode 0600) and is never in the result, which carries id, prefix, role, name and `snapshot_project_id`. `snapshot_project_id` mints a snapshot-scoped orchestrator key that authenticates only `POST /api/v1/projects/<id>/snapshots/urls` (401 everywhere else, sockets included); `422 invalid_snapshot_scope` for another role, an `agent_id` or another tenant's project. `403 insufficient_role` below user, `403 api_key_mint_forbidden` for a dispatch-minted caller. |
579
580
  | `snapshot_urls` | **Presigned URLs for build snapshot objects** (`POST /api/v1/projects/:id/snapshots/urls`, US-52.57): one URL per name, valid 900 s, for `<tenant_id>/<project_id>/<name>` in loopctl's snapshot bucket; a name is `index/<40 lowercase hex>.json` or `<64 lowercase hex>.tar.zst`, 1 to 64 per call. `op: "get"` on the session's agent key; `op: "put"` on `LOOPCTL_ORCH_KEY` (an agent key is `403 insufficient_role`), each PUT URL signing `if-none-match: *` so a published object is never overwritten, and audited. `422 invalid_snapshot_object` / `invalid_snapshot_op`, `404` for another tenant's project, `403 custody_tier_required` on an agent-rooted tenant, `503 snapshot_store_unconfigured`. |
580
581
  | `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
582
  | `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. |
package/index.js CHANGED
@@ -46,6 +46,7 @@ import {
46
46
  } from "./lib/factory.js";
47
47
  import { readFactoryPolicy } from "./lib/factory-policy.js";
48
48
  import { snapshotUrls } from "./lib/snapshots.js";
49
+ import { apiKeyCreate } from "./lib/api-keys.js";
49
50
  import {
50
51
  openReviewRound,
51
52
  readReviewRoundStatus,
@@ -3368,6 +3369,12 @@ async function snapshotUrlsTool(args) {
3368
3369
  );
3369
3370
  }
3370
3371
 
3372
+ // US-54.14: mint an API key on LOOPCTL_USER_KEY (`userKeyApiCall`); the route is `role: :user`
3373
+ // and refuses a dispatch-minted caller. The raw key goes to `key_file`, never into the result.
3374
+ async function apiKeyCreateTool(args) {
3375
+ return toContent(await apiKeyCreate(args, { apiCall: userKeyApiCall }));
3376
+ }
3377
+
3371
3378
  // US-52.24: this session's inbox, acks first, on the session's own key: both routes answer
3372
3379
  // only a holder credential (lib/inbox.js). US-52.62: the answer carries `journal`, what this
3373
3380
  // session still owes loopctl from an outage, even when the read itself got no answer.
@@ -9120,18 +9127,19 @@ const TOOLS = [
9120
9127
  "MOVE_PULL_SECONDS (default 1800) expires to the loop, and a move to the loop never " +
9121
9128
  "expires: implement@1 places it with the move's checkpoint as resume, on a runner of " +
9122
9129
  "contract 1.40.0 or later. An item an interactive session released is reserved for " +
9123
- "any interactive session until Mark moves it; pull it with work_item_pull. A move to a HOST whose runner joined on contract 1.40.0 or later is placed " +
9130
+ "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 " +
9124
9131
  "there, and its session resumes from the move's checkpoint; a runner session holding " +
9125
9132
  "the item is asked over its runner's socket and hands it over itself. Pass the same " +
9126
9133
  "move_id to retry: the same move_id and target answers the " +
9127
- "first result and writes nothing. ONLY MARK MOVES WORK ACROSS THE INTERACTIVE " +
9128
- "BOUNDARY: when the item's holder (or, unheld, its last mover or claimer) or the " +
9129
- "target holder is an interactive session, every key but Mark's own user key (no " +
9130
- "holder, no dispatch lineage: fleet_dash) is refused 403 boundary_move_needs_mark " +
9131
- "before anything is written; do not retry it, ask Mark. The one exception is ANSWERING " +
9132
- "a move Mark requested of you: the item's holder passing his move_id, his target and " +
9133
- "its own checkpoint_id is acting on his move and is released (200). A key with no " +
9134
- "holder has no checkpoint of its own: omit checkpoint_id. Refusals: 400 " +
9134
+ "first result and writes nothing. YOUR OWN ITEM IS YOURS TO MOVE: the holder of an " +
9135
+ "item (live lease) moves it anywhere, the loop included, with its own checkpoint_id, " +
9136
+ "interactive session or not, and an item NOBODY is working (unheld, reserved, or its " +
9137
+ "lease ran out) is anyone's to move on. The one refusal: an item ANOTHER session is " +
9138
+ "working on a live lease, moved across the interactive boundary (that holder or the " +
9139
+ "target holder is an interactive session), is 403 boundary_move_needs_mark to every " +
9140
+ "key but Mark's own user key (fleet_dash), before anything is written. A key with no " +
9141
+ "holder has no checkpoint of its own: omit checkpoint_id. " +
9142
+ "Refusals: 400 " +
9135
9143
  "move_id_required / reason_required / invalid_reason; 403 boundary_move_needs_mark; " +
9136
9144
  "404 (not this tenant's story, or unknown_story_stage); 409 " +
9137
9145
  "holder_ended, item_closed (done or failed), item_escalated (use work_item_requeue), " +
@@ -9193,8 +9201,9 @@ const TOOLS = [
9193
9201
  "worktree_add_failed, and the claim's own refusal " +
9194
9202
  "with the worktree removed: 409 reserved_for_move (a move reserved the item for another " +
9195
9203
  "target; an item an interactive session released is reserved for any interactive " +
9196
- "session), held_by_other_holder. A move across the interactive boundary is Mark's " +
9197
- "(work_item_move answers boundary_move_needs_mark); pull an item he moved here.",
9204
+ "session), held_by_other_holder. Moving another session's item across the interactive " +
9205
+ "boundary is Mark's (work_item_move answers boundary_move_needs_mark); pull an item " +
9206
+ "moved here.",
9198
9207
  inputSchema: {
9199
9208
  type: "object",
9200
9209
  properties: {
@@ -9530,6 +9539,42 @@ const TOOLS = [
9530
9539
  },
9531
9540
  },
9532
9541
 
9542
+ {
9543
+ name: "api_key_create",
9544
+ description:
9545
+ "MINT AN API KEY (POST /api/v1/api_keys, US-54.14), sent with LOOPCTL_USER_KEY. The raw " +
9546
+ "key is NEVER in the result: it is written to key_file (an absolute path that must not " +
9547
+ "exist yet, created mode 0600), and the result carries id, key_prefix, role, name and " +
9548
+ "snapshot_project_id. Move the file's contents where they belong and delete it. " +
9549
+ "snapshot_project_id mints a SNAPSHOT-SCOPED key: it authenticates only " +
9550
+ "POST /api/v1/projects/<that id>/snapshots/urls and is 401 on every other route and on " +
9551
+ "the sockets; it needs role orchestrator, no agent_id, and a project of this tenant " +
9552
+ "(422 invalid_snapshot_scope otherwise). Refusals: 403 insufficient_role below user " +
9553
+ "role, 403 api_key_mint_forbidden for a dispatch-minted caller, 403 for role " +
9554
+ "superadmin, 422 for a validation error or the tenant's key limit.",
9555
+ inputSchema: {
9556
+ type: "object",
9557
+ properties: {
9558
+ name: { type: "string", description: "A name for the key." },
9559
+ role: {
9560
+ type: "string",
9561
+ enum: ["user", "orchestrator", "agent"],
9562
+ description: "The key's role; a snapshot-scoped key is orchestrator.",
9563
+ },
9564
+ snapshot_project_id: {
9565
+ type: "string",
9566
+ description: "Optional: the project UUID a snapshot-scoped key may publish for.",
9567
+ },
9568
+ expires_at: { type: "string", description: "Optional ISO 8601 expiry." },
9569
+ key_file: {
9570
+ type: "string",
9571
+ description: "Absolute path, not existing yet, that receives the raw key (mode 0600).",
9572
+ },
9573
+ },
9574
+ required: ["name", "role", "key_file"],
9575
+ },
9576
+ },
9577
+
9533
9578
  {
9534
9579
  name: "inbox",
9535
9580
  description:
@@ -12410,6 +12455,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
12410
12455
 
12411
12456
  case "snapshot_urls":
12412
12457
  return await snapshotUrlsTool(args);
12458
+ case "api_key_create":
12459
+ return await apiKeyCreateTool(args);
12413
12460
 
12414
12461
  case "inbox":
12415
12462
  return await inboxTool(args);
@@ -0,0 +1,168 @@
1
+ /**
2
+ * `api_key_create` (loopctl US-54.14): `POST /api/v1/api_keys`, sent with LOOPCTL_USER_KEY.
3
+ *
4
+ * The raw key is a secret and a tool result lands in the session transcript, so the raw key
5
+ * NEVER appears in the result: it is written to `key_file` (an absolute path that must not
6
+ * exist yet, created with mode 0600) and the result carries the key's id, prefix, role, name
7
+ * and scope only. A caller then moves the file's contents where they belong (a CI secret) and
8
+ * deletes the file.
9
+ *
10
+ * The file is CREATED before the key is minted, so a key_file that exists or whose directory
11
+ * is missing is refused with nothing minted. Only a failure after the create (the write
12
+ * itself) can leave a minted key without its secret, and the result then names it to revoke.
13
+ */
14
+
15
+ import { isAbsolute } from "node:path";
16
+ import { closeSync, openSync, unlinkSync, writeSync } from "node:fs";
17
+
18
+ import { uuid } from "./delivery-loop.js";
19
+
20
+ export const API_KEY_ROLES = ["user", "orchestrator", "agent"];
21
+
22
+ function refuse(body) {
23
+ return { error: true, status: 0, body };
24
+ }
25
+
26
+ /**
27
+ * `deps.apiCall(method, path, body)` is the user-key caller; `deps.openKey(path)` creates the
28
+ * file and returns `{ writeRawKey(raw), discardKeyFile() }` (injected so a test owns the disk it touches).
29
+ */
30
+ export async function apiKeyCreate(
31
+ { name, role, snapshot_project_id, expires_at, key_file } = {},
32
+ { apiCall, openKey = defaultOpenKey } = {},
33
+ ) {
34
+ if (typeof name !== "string" || name.trim() === "") {
35
+ return refuse("`name` is required.");
36
+ }
37
+
38
+ if (!API_KEY_ROLES.includes(role)) {
39
+ return refuse(`\`role\` must be one of ${API_KEY_ROLES.join(", ")}.`);
40
+ }
41
+
42
+ if (typeof key_file !== "string" || !isAbsolute(key_file)) {
43
+ return refuse(
44
+ "`key_file` must be an absolute path that does not exist yet. The raw key is written " +
45
+ "there (mode 0600) and never returned, because a tool result lands in the transcript.",
46
+ );
47
+ }
48
+
49
+ if (snapshot_project_id !== undefined) {
50
+ const bad = uuid(snapshot_project_id, "snapshot_project_id");
51
+ if (bad) return bad;
52
+ }
53
+
54
+ let sink;
55
+ try {
56
+ sink = openKey(key_file);
57
+ } catch (error) {
58
+ return refuse(
59
+ `${key_file} could not be created (${error.code || error.message}); nothing was ` +
60
+ "minted. Pass a path that does not exist yet, in a directory that does.",
61
+ );
62
+ }
63
+
64
+ const body = { name, role };
65
+ if (snapshot_project_id !== undefined) body.snapshot_project_id = snapshot_project_id;
66
+ if (expires_at !== undefined) body.expires_at = expires_at;
67
+
68
+ let result;
69
+ try {
70
+ result = await apiCall("POST", "/api/v1/api_keys", body);
71
+ } catch (error) {
72
+ sink.discardKeyFile();
73
+ throw error;
74
+ }
75
+
76
+ const created = result && result.api_key;
77
+
78
+ if (!created || typeof created.raw_key !== "string") {
79
+ sink.discardKeyFile();
80
+ return transportUnknown(result) ? mayHaveMinted(result, name) : stripRaw(result);
81
+ }
82
+
83
+ const { raw_key, ...rest } = created;
84
+
85
+ // A server without US-54.14 (an older release, a rollback) ignores the unknown field and
86
+ // mints a TENANT-WIDE key. Never hand that over as the scoped key it was asked for.
87
+ if (snapshot_project_id !== undefined && rest.snapshot_project_id !== snapshot_project_id) {
88
+ sink.discardKeyFile();
89
+ const revoked = await apiCall("DELETE", `/api/v1/api_keys/${rest.id}`);
90
+ const revokeNote =
91
+ revoked && revoked.error
92
+ ? `Revoking it FAILED (${JSON.stringify(revoked.body)}); revoke ${rest.id} by hand.`
93
+ : "It was revoked.";
94
+ return refuse(
95
+ `The server minted ${rest.id} WITHOUT the requested snapshot_project_id (it returned ` +
96
+ `${JSON.stringify(rest.snapshot_project_id ?? null)}), so it is not scoped. ` +
97
+ `${revokeNote} The server does not support snapshot-scoped keys.`,
98
+ );
99
+ }
100
+
101
+ try {
102
+ sink.writeRawKey(raw_key);
103
+ } catch (error) {
104
+ sink.discardKeyFile();
105
+ return {
106
+ error: true,
107
+ status: 0,
108
+ body:
109
+ `The key ${rest.id} was minted but ${key_file} could not be written ` +
110
+ `(${error.code || error.message}); the raw key is lost. Revoke it ` +
111
+ `(DELETE /api/v1/api_keys/${rest.id}) and create another with a new key_file.`,
112
+ };
113
+ }
114
+
115
+ return { api_key: rest, key_file };
116
+ }
117
+
118
+ function defaultOpenKey(path) {
119
+ const fd = openSync(path, "wx", 0o600);
120
+ let open = true;
121
+
122
+ const closeKeyFd = () => {
123
+ if (open) {
124
+ open = false;
125
+ closeSync(fd);
126
+ }
127
+ };
128
+
129
+ return {
130
+ writeRawKey: (raw) => {
131
+ writeSync(fd, raw + "\n");
132
+ closeKeyFd();
133
+ },
134
+ discardKeyFile: () => {
135
+ closeKeyFd();
136
+ try {
137
+ unlinkSync(path);
138
+ } catch {
139
+ // already gone
140
+ }
141
+ },
142
+ };
143
+ }
144
+
145
+ // status 0 is apiCall's transport failure (a timeout, a dropped connection): the server may
146
+ // have committed the mint before the answer was lost.
147
+ function transportUnknown(result) {
148
+ return Boolean(result && result.error && result.status === 0);
149
+ }
150
+
151
+ function mayHaveMinted(result, name) {
152
+ return {
153
+ ...result,
154
+ body:
155
+ `${typeof result.body === "string" ? result.body : JSON.stringify(result.body)}. ` +
156
+ `The request may have minted a key named "${name}" whose raw value is lost: list the ` +
157
+ "tenant's keys (GET /api/v1/api_keys) and revoke any by that name before retrying.",
158
+ };
159
+ }
160
+
161
+ // A refusal body never carries a raw key, but nothing from this route is passed on unread.
162
+ function stripRaw(result) {
163
+ if (result && result.api_key && "raw_key" in result.api_key) {
164
+ const { raw_key: _raw, ...rest } = result.api_key;
165
+ return { ...result, api_key: rest };
166
+ }
167
+ return result;
168
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.41.1",
3
+ "version": "3.42.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",