loopctl-mcp-server 3.46.1 → 3.47.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/lib/skills.js ADDED
@@ -0,0 +1,315 @@
1
+ /**
2
+ * `skill_create` / `skill_list` / `skill_get` / `skill_update` / `skill_delete` /
3
+ * `skill_import` / `skill_version_create` / `skill_versions` / `skill_version_get` /
4
+ * `skill_stats` / `skill_version_results` / `skill_cost_performance` — the `/api/v1/skills`
5
+ * routes (`SkillController`) — and `skill_result_report`, `POST /api/v1/skill_results`
6
+ * (`SkillResultController`), loopctl #872.
7
+ *
8
+ * KEYS, from the controllers' plugs:
9
+ *
10
+ * - create, update, delete, create_version, import and cost-performance are `role: :user`
11
+ * with the hierarchy (`skill_controller.ex:26-35`), so an agent or orchestrator key is 403
12
+ * insufficient_role. They travel on LOOPCTL_USER_KEY verbatim when set (index.js
13
+ * `userKeyApiCall`).
14
+ * - list, show, list_versions, get_version, stats and version_results are `role: :agent`
15
+ * with the hierarchy (`skill_controller.ex:37-39`): any key, sent as the session's own
16
+ * (index.js `ownKeyApiCall`).
17
+ * - create, update, delete, create_version and import are also behind `RequireHumanAnchor`
18
+ * (`skill_controller.ex:44-45`): 403 custody_tier_required on an agent-rooted tenant.
19
+ * Cost-performance is not.
20
+ * - the skill result is `exact_role: [:orchestrator, :superadmin]`
21
+ * (`skill_result_controller.ex:17`), NO hierarchy below superadmin: a user key is 403
22
+ * insufficient_role there like an agent key. It selects its key through
23
+ * `orchestratorKeyArgs` (lib/custody-key.js), as the other exact-orchestrator tools do. It
24
+ * is human-anchored as well (`skill_result_controller.ex:20`).
25
+ *
26
+ * CHECKED HERE, because the server would answer them WRONGLY rather than refuse:
27
+ *
28
+ * - a non-UUID skill id, which reaches `AdminRepo.get_by` uncast instead of answering the
29
+ * plain 404 a missing skill does;
30
+ * - a version that is not a positive integer: loopctl parses it with `Integer.parse`, so
31
+ * "2abc" reads as version 2;
32
+ * - list's `page` / `page_size`: a non-integer is dropped and `page_size` clamped to 1..100;
33
+ * - list's `status`: compared against the `active`/`archived` enum, so any other value is
34
+ * not a filter loopctl can run;
35
+ * - an update with no field, or a null one: loopctl drops every nil field and answers 200
36
+ * with the skill unchanged;
37
+ * - `metadata` / `metrics` that is not an object;
38
+ * - an import item that is not an object (loopctl reads each with `Map.get`);
39
+ * - a skill result's ids that are not UUIDs: they are set on the row uncast, so a malformed
40
+ * one fails at insert instead of answering a 422.
41
+ *
42
+ * A duplicate name, a project_id that resolves to no project and a foreign key naming no row
43
+ * are loopctl's to judge (422 with the field named), so they are sent.
44
+ */
45
+
46
+ import { uuid } from "./delivery-loop.js";
47
+
48
+ export const SKILL_STATUSES = ["active", "archived"];
49
+ export const SKILL_UPDATE_FIELDS = ["description", "status", "metadata"];
50
+ export const SKILL_MAX_PAGE_SIZE = 100;
51
+
52
+ function refuse(body) {
53
+ return { error: true, status: 0, body };
54
+ }
55
+
56
+ // ONE template literal per builder (see `test/tool-surface.js`).
57
+ export function skillsPath(query = "") {
58
+ return `/api/v1/skills${query}`;
59
+ }
60
+
61
+ export function skillPath(skillId) {
62
+ return `/api/v1/skills/${encodeURIComponent(skillId)}`;
63
+ }
64
+
65
+ export function skillImportPath() {
66
+ return `/api/v1/skills/import`;
67
+ }
68
+
69
+ export function skillVersionsPath(skillId) {
70
+ return `/api/v1/skills/${encodeURIComponent(skillId)}/versions`;
71
+ }
72
+
73
+ export function skillVersionPath(skillId, version) {
74
+ return `/api/v1/skills/${encodeURIComponent(skillId)}/versions/${encodeURIComponent(version)}`;
75
+ }
76
+
77
+ export function skillStatsPath(skillId) {
78
+ return `/api/v1/skills/${encodeURIComponent(skillId)}/stats`;
79
+ }
80
+
81
+ export function skillVersionResultsPath(skillId, version) {
82
+ return `/api/v1/skills/${encodeURIComponent(skillId)}/versions/${encodeURIComponent(version)}/results`;
83
+ }
84
+
85
+ export function skillCostPerformancePath(skillId) {
86
+ return `/api/v1/skills/${encodeURIComponent(skillId)}/cost-performance`;
87
+ }
88
+
89
+ export function skillResultsPath() {
90
+ return `/api/v1/skill_results`;
91
+ }
92
+
93
+ function notObject(value) {
94
+ return value === null || typeof value !== "object" || Array.isArray(value);
95
+ }
96
+
97
+ function badMetadata(metadata, field = "metadata") {
98
+ if (metadata !== undefined && notObject(metadata)) {
99
+ return refuse(`\`${field}\` must be an object.`);
100
+ }
101
+ return null;
102
+ }
103
+
104
+ function requiredText(value, field, why) {
105
+ if (typeof value !== "string" || value.trim() === "") {
106
+ return refuse(`\`${field}\` is required: ${why}`);
107
+ }
108
+ return null;
109
+ }
110
+
111
+ function optionalText(value, field) {
112
+ if (value !== undefined && typeof value !== "string") {
113
+ return refuse(`\`${field}\` must be a string.`);
114
+ }
115
+ return null;
116
+ }
117
+
118
+ function badVersion(version) {
119
+ if (!(Number.isInteger(version) && version >= 1)) {
120
+ return refuse(
121
+ "`version` must be a positive integer. loopctl parses the path segment leniently, so " +
122
+ "\"2abc\" would read as version 2.",
123
+ );
124
+ }
125
+ return null;
126
+ }
127
+
128
+ function badProjectId(project_id) {
129
+ if (project_id !== undefined && (typeof project_id !== "string" || project_id.trim() === "")) {
130
+ return refuse("`project_id` must be a project's UUID, slug or repo name.");
131
+ }
132
+ return null;
133
+ }
134
+
135
+ export async function skillCreate(
136
+ { name, prompt_text, description, project_id, metadata } = {},
137
+ { apiCall } = {},
138
+ ) {
139
+ const bad =
140
+ requiredText(name, "name", "the skill's name, unique per tenant and project.") ??
141
+ requiredText(prompt_text, "prompt_text", "the text of version 1.") ??
142
+ optionalText(description, "description") ??
143
+ badProjectId(project_id) ??
144
+ badMetadata(metadata);
145
+ if (bad) return bad;
146
+
147
+ const body = { name, prompt_text };
148
+ if (description !== undefined) body.description = description;
149
+ if (project_id !== undefined) body.project_id = project_id;
150
+ if (metadata !== undefined) body.metadata = metadata;
151
+
152
+ return apiCall("POST", skillsPath(), body);
153
+ }
154
+
155
+ export async function skillList({ page, page_size, project_id, status, name } = {}, { apiCall } = {}) {
156
+ if (page != null && !(Number.isInteger(page) && page >= 1)) {
157
+ return refuse("`page` must be a positive integer.");
158
+ }
159
+
160
+ if (
161
+ page_size != null &&
162
+ !(Number.isInteger(page_size) && page_size >= 1 && page_size <= SKILL_MAX_PAGE_SIZE)
163
+ ) {
164
+ return refuse(
165
+ `\`page_size\` must be an integer from 1 to ${SKILL_MAX_PAGE_SIZE} (default 20); loopctl ` +
166
+ "would clamp any other value without saying so.",
167
+ );
168
+ }
169
+
170
+ if (project_id != null) {
171
+ const bad = badProjectId(project_id);
172
+ if (bad) return bad;
173
+ }
174
+
175
+ if (status != null && !SKILL_STATUSES.includes(status)) {
176
+ return refuse(`\`status\` is one of: ${SKILL_STATUSES.join(", ")}.`);
177
+ }
178
+
179
+ if (name != null && (typeof name !== "string" || name.trim() === "")) {
180
+ return refuse("`name` must be a non-empty string (matched as a case-insensitive substring).");
181
+ }
182
+
183
+ const params = new URLSearchParams();
184
+ if (page != null) params.set("page", String(page));
185
+ if (page_size != null) params.set("page_size", String(page_size));
186
+ if (project_id != null) params.set("project_id", project_id);
187
+ if (status != null) params.set("status", status);
188
+ if (name != null) params.set("name", name);
189
+ const qs = params.toString();
190
+ const query = qs === "" ? "" : `?${qs}`;
191
+
192
+ return apiCall("GET", skillsPath(query), null);
193
+ }
194
+
195
+ export async function skillGet({ skill_id } = {}, { apiCall } = {}) {
196
+ return uuid(skill_id, "skill_id") ?? apiCall("GET", skillPath(skill_id), null);
197
+ }
198
+
199
+ export async function skillUpdate(args = {}, { apiCall } = {}) {
200
+ const { skill_id, description, status, metadata } = args;
201
+ const idBad = uuid(skill_id, "skill_id");
202
+ if (idBad) return idBad;
203
+
204
+ for (const field of SKILL_UPDATE_FIELDS) {
205
+ if (args[field] === null) {
206
+ return refuse(
207
+ `\`${field}\` cannot be null: loopctl drops a null field and would answer 200 with the ` +
208
+ "skill unchanged.",
209
+ );
210
+ }
211
+ }
212
+
213
+ const bad =
214
+ optionalText(description, "description") ??
215
+ (status !== undefined && !SKILL_STATUSES.includes(status)
216
+ ? refuse(`\`status\` is one of: ${SKILL_STATUSES.join(", ")}.`)
217
+ : null) ??
218
+ badMetadata(metadata);
219
+ if (bad) return bad;
220
+
221
+ const body = {};
222
+ for (const field of SKILL_UPDATE_FIELDS) {
223
+ if (args[field] !== undefined) body[field] = args[field];
224
+ }
225
+
226
+ if (Object.keys(body).length === 0) {
227
+ return refuse(
228
+ `Name at least one of ${SKILL_UPDATE_FIELDS.map((f) => `\`${f}\``).join(", ")}: loopctl ` +
229
+ "would answer 200 with the skill unchanged. A new prompt is skill_version_create.",
230
+ );
231
+ }
232
+
233
+ return apiCall("PATCH", skillPath(skill_id), body);
234
+ }
235
+
236
+ export async function skillDelete({ skill_id } = {}, { apiCall } = {}) {
237
+ return uuid(skill_id, "skill_id") ?? apiCall("DELETE", skillPath(skill_id), null);
238
+ }
239
+
240
+ export async function skillImport({ skills } = {}, { apiCall } = {}) {
241
+ if (!Array.isArray(skills) || skills.length === 0) {
242
+ return refuse(
243
+ "`skills` must be a non-empty list of objects, each `{name, prompt_text, description?, " +
244
+ "project_id?}`.",
245
+ );
246
+ }
247
+
248
+ const index = skills.findIndex(notObject);
249
+ if (index !== -1) {
250
+ return refuse(`\`skills[${index}]\` must be an object; loopctl reads each item as a map.`);
251
+ }
252
+
253
+ return apiCall("POST", skillImportPath(), { skills });
254
+ }
255
+
256
+ export async function skillVersionCreate(
257
+ { skill_id, prompt_text, changelog, created_by } = {},
258
+ { apiCall } = {},
259
+ ) {
260
+ const bad =
261
+ uuid(skill_id, "skill_id") ??
262
+ requiredText(prompt_text, "prompt_text", "the full text of the new version.") ??
263
+ optionalText(changelog, "changelog") ??
264
+ optionalText(created_by, "created_by");
265
+ if (bad) return bad;
266
+
267
+ const body = { prompt_text };
268
+ if (changelog !== undefined) body.changelog = changelog;
269
+ if (created_by !== undefined) body.created_by = created_by;
270
+
271
+ return apiCall("POST", skillVersionsPath(skill_id), body);
272
+ }
273
+
274
+ export async function skillVersions({ skill_id } = {}, { apiCall } = {}) {
275
+ return uuid(skill_id, "skill_id") ?? apiCall("GET", skillVersionsPath(skill_id), null);
276
+ }
277
+
278
+ export async function skillVersionGet({ skill_id, version } = {}, { apiCall } = {}) {
279
+ const bad = uuid(skill_id, "skill_id") ?? badVersion(version);
280
+ if (bad) return bad;
281
+
282
+ return apiCall("GET", skillVersionPath(skill_id, version), null);
283
+ }
284
+
285
+ export async function skillStats({ skill_id } = {}, { apiCall } = {}) {
286
+ return uuid(skill_id, "skill_id") ?? apiCall("GET", skillStatsPath(skill_id), null);
287
+ }
288
+
289
+ export async function skillVersionResults({ skill_id, version } = {}, { apiCall } = {}) {
290
+ const bad = uuid(skill_id, "skill_id") ?? badVersion(version);
291
+ if (bad) return bad;
292
+
293
+ return apiCall("GET", skillVersionResultsPath(skill_id, version), null);
294
+ }
295
+
296
+ export async function skillCostPerformance({ skill_id } = {}, { apiCall } = {}) {
297
+ return uuid(skill_id, "skill_id") ?? apiCall("GET", skillCostPerformancePath(skill_id), null);
298
+ }
299
+
300
+ export async function skillResultReport(
301
+ { skill_version_id, verification_result_id, story_id, metrics } = {},
302
+ { apiCall } = {},
303
+ ) {
304
+ const bad =
305
+ uuid(skill_version_id, "skill_version_id") ??
306
+ uuid(verification_result_id, "verification_result_id") ??
307
+ uuid(story_id, "story_id") ??
308
+ badMetadata(metrics, "metrics");
309
+ if (bad) return bad;
310
+
311
+ const body = { skill_version_id, verification_result_id, story_id };
312
+ if (metrics !== undefined) body.metrics = metrics;
313
+
314
+ return apiCall("POST", skillResultsPath(), body);
315
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * `ui_test_start` / `ui_test_list` / `ui_test_get` / `ui_test_add_finding` / `ui_test_complete` —
3
+ * `POST /api/v1/projects/:project_id/ui-tests`, `GET .../ui-tests`, `GET .../ui-tests/:id`,
4
+ * `POST .../ui-tests/:id/findings` and `POST .../ui-tests/:id/complete` (`UiTestController`),
5
+ * loopctl #872.
6
+ *
7
+ * KEY: every action is `role: :agent` with the hierarchy (ui_test_controller.ex:24-25), so the
8
+ * session's own key passes; not human-anchored. Start, add_finding and complete are behind
9
+ * `RequireWorkProject` (:30): a knowledge-only (kind: kb) project is 422 kb_project_no_work.
10
+ * The project segment takes a UUID, slug or repo name (`ResolveProjectRef` rewrites it); one
11
+ * that resolves to nothing is 422.
12
+ *
13
+ * The run actions (get, add_finding, complete) find the run by its id within the tenant and do
14
+ * not compare it with the project in the path; the project still decides the kb refusal.
15
+ *
16
+ * What the controller reads: start `guide_reference`; list `status`, `limit`, `offset`;
17
+ * add_finding `step`, `severity`, `type`, `description`, `screenshot_path`, `console_errors`;
18
+ * complete `status` (passed or failed) and `summary`. Both run writes are 422 once the run is
19
+ * no longer in progress.
20
+ *
21
+ * CHECKED HERE, because the server would answer them WRONGLY rather than refuse:
22
+ *
23
+ * - a non-UUID run id, which reaches the lookup uncast (not the plain 404 a missing run is);
24
+ * - a list `status` outside the four run statuses, or a negative `limit`/`offset`, which
25
+ * reach the query uncast;
26
+ * - a finding `severity` outside critical/high/medium/low, which loopctl stores and then
27
+ * counts as neither critical nor high, and a finding naming no field at all.
28
+ */
29
+
30
+ import { uuid } from "./delivery-loop.js";
31
+
32
+ export const UI_TEST_STATUSES = ["in_progress", "passed", "failed", "cancelled"];
33
+ export const UI_TEST_SEVERITIES = ["critical", "high", "medium", "low"];
34
+ export const UI_TEST_FINDING_FIELDS = [
35
+ "step",
36
+ "severity",
37
+ "type",
38
+ "description",
39
+ "screenshot_path",
40
+ "console_errors",
41
+ ];
42
+
43
+ function refuse(body) {
44
+ return { error: true, status: 0, body };
45
+ }
46
+
47
+ // ONE template literal per builder (see `test/tool-surface.js`).
48
+ export function uiTestsPath(projectId, query = "") {
49
+ return `/api/v1/projects/${encodeURIComponent(projectId)}/ui-tests${query}`;
50
+ }
51
+
52
+ export function uiTestPath(projectId, runId) {
53
+ return `/api/v1/projects/${encodeURIComponent(projectId)}/ui-tests/${encodeURIComponent(runId)}`;
54
+ }
55
+
56
+ export function uiTestFindingsPath(projectId, runId) {
57
+ return `/api/v1/projects/${encodeURIComponent(projectId)}/ui-tests/${encodeURIComponent(runId)}/findings`;
58
+ }
59
+
60
+ export function uiTestCompletePath(projectId, runId) {
61
+ return `/api/v1/projects/${encodeURIComponent(projectId)}/ui-tests/${encodeURIComponent(runId)}/complete`;
62
+ }
63
+
64
+ function badProject(project_id) {
65
+ if (typeof project_id !== "string" || project_id.trim() === "") {
66
+ return refuse("`project_id` is required: the project's UUID, slug or repo name.");
67
+ }
68
+ return null;
69
+ }
70
+
71
+ function badRun(project_id, run_id) {
72
+ return badProject(project_id) ?? uuid(run_id, "run_id");
73
+ }
74
+
75
+ export async function uiTestStart({ project_id, guide_reference } = {}, { apiCall } = {}) {
76
+ const bad = badProject(project_id);
77
+ if (bad) return bad;
78
+
79
+ if (typeof guide_reference !== "string" || guide_reference.trim() === "") {
80
+ return refuse(
81
+ "`guide_reference` is required: the test guide this run follows (1..1000 characters).",
82
+ );
83
+ }
84
+
85
+ return apiCall("POST", uiTestsPath(project_id), { guide_reference });
86
+ }
87
+
88
+ export async function uiTestList({ project_id, status, limit, offset } = {}, { apiCall } = {}) {
89
+ const bad = badProject(project_id);
90
+ if (bad) return bad;
91
+
92
+ if (status !== undefined && !UI_TEST_STATUSES.includes(status)) {
93
+ return refuse(`\`status\` must be one of ${UI_TEST_STATUSES.join(", ")}.`);
94
+ }
95
+
96
+ if (limit !== undefined && !(Number.isInteger(limit) && limit >= 1)) {
97
+ return refuse("`limit` must be a positive integer (default 20).");
98
+ }
99
+
100
+ if (offset !== undefined && !(Number.isInteger(offset) && offset >= 0)) {
101
+ return refuse("`offset` must be a non-negative integer (default 0).");
102
+ }
103
+
104
+ const params = new URLSearchParams();
105
+ if (status !== undefined) params.set("status", status);
106
+ if (limit !== undefined) params.set("limit", String(limit));
107
+ if (offset !== undefined) params.set("offset", String(offset));
108
+ const qs = params.toString();
109
+
110
+ return apiCall("GET", uiTestsPath(project_id, qs === "" ? "" : `?${qs}`), null);
111
+ }
112
+
113
+ export async function uiTestGet({ project_id, run_id } = {}, { apiCall } = {}) {
114
+ return badRun(project_id, run_id) ?? apiCall("GET", uiTestPath(project_id, run_id), null);
115
+ }
116
+
117
+ export async function uiTestAddFinding(args = {}, { apiCall } = {}) {
118
+ const { project_id, run_id, severity } = args;
119
+ const bad = badRun(project_id, run_id);
120
+ if (bad) return bad;
121
+
122
+ if (severity !== undefined && !UI_TEST_SEVERITIES.includes(severity)) {
123
+ return refuse(
124
+ `\`severity\` must be one of ${UI_TEST_SEVERITIES.join(", ")}: loopctl would store any ` +
125
+ "other value and count it as neither critical nor high.",
126
+ );
127
+ }
128
+
129
+ const body = {};
130
+ for (const field of UI_TEST_FINDING_FIELDS) {
131
+ if (args[field] !== undefined) body[field] = args[field];
132
+ }
133
+
134
+ if (Object.keys(body).length === 0) {
135
+ return refuse(
136
+ `Name at least one of ${UI_TEST_FINDING_FIELDS.map((f) => `\`${f}\``).join(", ")}: ` +
137
+ "loopctl would record an empty finding.",
138
+ );
139
+ }
140
+
141
+ return apiCall("POST", uiTestFindingsPath(project_id, run_id), body);
142
+ }
143
+
144
+ export async function uiTestComplete({ project_id, run_id, status, summary } = {}, { apiCall } = {}) {
145
+ const bad = badRun(project_id, run_id);
146
+ if (bad) return bad;
147
+
148
+ const body = {};
149
+ if (status !== undefined) body.status = status;
150
+ if (summary !== undefined) body.summary = summary;
151
+
152
+ return apiCall("POST", uiTestCompletePath(project_id, run_id), body);
153
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.46.1",
3
+ "version": "3.47.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",