loopctl-mcp-server 3.41.2 → 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 +1 -0
- package/index.js +45 -0
- package/lib/api-keys.js +168 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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.
|
|
@@ -9532,6 +9539,42 @@ const TOOLS = [
|
|
|
9532
9539
|
},
|
|
9533
9540
|
},
|
|
9534
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
|
+
|
|
9535
9578
|
{
|
|
9536
9579
|
name: "inbox",
|
|
9537
9580
|
description:
|
|
@@ -12412,6 +12455,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
12412
12455
|
|
|
12413
12456
|
case "snapshot_urls":
|
|
12414
12457
|
return await snapshotUrlsTool(args);
|
|
12458
|
+
case "api_key_create":
|
|
12459
|
+
return await apiKeyCreateTool(args);
|
|
12415
12460
|
|
|
12416
12461
|
case "inbox":
|
|
12417
12462
|
return await inboxTool(args);
|
package/lib/api-keys.js
ADDED
|
@@ -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
|
+
}
|