loopctl-mcp-server 3.43.0 → 3.45.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.
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A story's evidence: `artifact_report` / `artifact_list` (`POST` / `GET
3
+ * /api/v1/stories/:id/artifacts`, `ArtifactReportController`) and `verification_list`
4
+ * (`GET /api/v1/stories/:story_id/verifications`, `StoryVerificationController.index`),
5
+ * loopctl #872.
6
+ *
7
+ * KEYS, from the controllers' plugs:
8
+ *
9
+ * - artifact create is `exact_role: [:agent, :orchestrator]` — NO hierarchy, so a user or
10
+ * superadmin key is 403 insufficient_role like any non-member — and human-anchored (403
11
+ * custody_tier_required on an agent-rooted tenant). It is custody surface
12
+ * (`LoopctlWeb.CustodySurface`), so a custody halt answers 503 tenant_halted. It travels on
13
+ * the session's own key (`agentKey()`), the key that did the work. The report's
14
+ * `reporter_agent_id` is the key's agent and `reported_by` is derived from the key's role,
15
+ * both server-side: neither is a parameter.
16
+ * - artifact list is `role: :agent` (any key), on the session's own key.
17
+ * - verification list is `role: :orchestrator` WITH the hierarchy, so an agent key is 403
18
+ * insufficient_role. It travels on LOOPCTL_ORCH_KEY, else LOOPCTL_USER_KEY, sent verbatim
19
+ * when set (index.js `orchestratorPinnedApiCall`).
20
+ *
21
+ * Each answers 404 for a story outside the caller's tenant. A non-UUID story id would reach
22
+ * the same 404 through `LoopctlWeb.CastErrorHandler`, so it is refused here instead. The
23
+ * artifact's `artifact_type` and `path` are required by the changeset (422 without them); they
24
+ * are required here too, so a call that cannot succeed sends nothing.
25
+ */
26
+
27
+ import { uuid } from "./delivery-loop.js";
28
+
29
+ function refuse(body) {
30
+ return { error: true, status: 0, body };
31
+ }
32
+
33
+ // ONE template literal per builder (see `test/tool-surface.js`).
34
+ export function artifactsPath(storyId, query = "") {
35
+ return `/api/v1/stories/${encodeURIComponent(storyId)}/artifacts${query}`;
36
+ }
37
+
38
+ export function verificationsPath(storyId, query = "") {
39
+ return `/api/v1/stories/${encodeURIComponent(storyId)}/verifications${query}`;
40
+ }
41
+
42
+ function pageQuery({ page, page_size }) {
43
+ const params = new URLSearchParams();
44
+ if (page != null) params.set("page", String(page));
45
+ if (page_size != null) params.set("page_size", String(page_size));
46
+ const qs = params.toString();
47
+ return qs === "" ? "" : `?${qs}`;
48
+ }
49
+
50
+ function badPage({ page, page_size }) {
51
+ if (page != null && !(Number.isInteger(page) && page >= 1)) {
52
+ return refuse("`page` must be a positive integer.");
53
+ }
54
+ if (page_size != null && !(Number.isInteger(page_size) && page_size >= 1 && page_size <= 100)) {
55
+ return refuse("`page_size` must be an integer from 1 to 100 (default 20).");
56
+ }
57
+ return null;
58
+ }
59
+
60
+ export async function submitArtifactReport(
61
+ { story_id, artifact_type, path, exists, details } = {},
62
+ { apiCall } = {},
63
+ ) {
64
+ const bad = uuid(story_id, "story_id");
65
+ if (bad) return bad;
66
+
67
+ if (typeof artifact_type !== "string" || artifact_type.trim() === "") {
68
+ return refuse("`artifact_type` is required: what kind of artifact (e.g. test_file, migration).");
69
+ }
70
+
71
+ if (typeof path !== "string" || path.trim() === "") {
72
+ return refuse("`path` is required: where the artifact is (a file path or URL).");
73
+ }
74
+
75
+ if (exists != null && typeof exists !== "boolean") {
76
+ return refuse("`exists` must be a boolean (default true).");
77
+ }
78
+
79
+ if (details != null && (typeof details !== "object" || Array.isArray(details))) {
80
+ return refuse("`details` must be an object.");
81
+ }
82
+
83
+ const body = { artifact_type, path };
84
+ if (exists != null) body.exists = exists;
85
+ if (details != null) body.details = details;
86
+
87
+ return apiCall("POST", artifactsPath(story_id), body);
88
+ }
89
+
90
+ export async function listArtifactReports({ story_id, page, page_size } = {}, { apiCall } = {}) {
91
+ const bad = uuid(story_id, "story_id") ?? badPage({ page, page_size });
92
+ if (bad) return bad;
93
+
94
+ return apiCall("GET", artifactsPath(story_id, pageQuery({ page, page_size })), null);
95
+ }
96
+
97
+ export async function listStoryVerifications({ story_id, page, page_size } = {}, { apiCall } = {}) {
98
+ const bad = uuid(story_id, "story_id") ?? badPage({ page, page_size });
99
+ if (bad) return bad;
100
+
101
+ return apiCall("GET", verificationsPath(story_id, pageQuery({ page, page_size })), null);
102
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The tenant's own settings and its authenticator labels: `update_tenant`
3
+ * (`PATCH /api/v1/tenants/me`, `TenantController.update`), `list_authenticators` and
4
+ * `rename_authenticator` (`GET /api/v1/tenants/:id/authenticators`,
5
+ * `PATCH /api/v1/tenants/:id/authenticators/:auth_id`, `TenantAuthenticatorController.index` /
6
+ * `.rename`), and `list_trusted_endpoints` (`GET /api/v1/egress/trusted-endpoints`,
7
+ * `EgressController.list_trusted`), loopctl #872.
8
+ *
9
+ * KEYS, from the controllers' plugs:
10
+ *
11
+ * - update_tenant is `role: :user` WITH the hierarchy (403 insufficient_role below it), not
12
+ * human-anchored and not custody surface: index.js `userKeyApiCall`, LOOPCTL_USER_KEY when
13
+ * set. It casts `name`, `email`, `settings`, `default_story_budget_millicents` and
14
+ * `token_data_retention_days`; `settings` is MERGED into the stored map key by key, never
15
+ * replaced. 422 for a malformed or taken email, a `settings` that is not an object or whose
16
+ * `knowledge_auto_extract` / `kb_curation_log` is not a boolean, a budget that is not above
17
+ * 0, and a retention that is not an integer of at least 30 (null turns retention off).
18
+ * - the authenticator list and rename are `role: :user` plus tenant ownership: 403 (insufficient_role
19
+ * below user, a bare `Forbidden` when `tenant_id` is not the key's own tenant). Neither
20
+ * verifies a WebAuthn assertion, unlike enroll and revoke, so a tool can complete both. The
21
+ * list carries ids, labels and `credential_fingerprint` (the identity to confirm before
22
+ * `revoke_authenticator`; a label is rewritable by any user key), never credential
23
+ * material. Rename refusals: 400 without a string `friendly_name`, 404 for an unknown
24
+ * authenticator, 422 friendly_name_blank / friendly_name_invalid / friendly_name_too_long
25
+ * (over 120 bytes after trimming), 429 past the per-tenant rename budget (300 an hour), 500
26
+ * when the rename or its audit entry could not be written.
27
+ * - the trusted-endpoint list has no role plug: any key of the tenant, the session's own.
28
+ * Every entry is an UNVERIFIED tenant attestation, not network locality.
29
+ *
30
+ * CHECKED HERE, because the server would answer them WRONGLY rather than refuse:
31
+ *
32
+ * - update_tenant's `slug`: the update never casts it (it keys the audit-key secret, rls-02),
33
+ * so a body carrying one answers 200 with the slug unchanged;
34
+ * - an update with no field at all, which answers 200 having changed nothing;
35
+ * - a `tenant_id` in upper case: ownership compares the id as a STRING against the key's
36
+ * lower-case tenant id, so the right tenant in the wrong case answers 403. It is sent lower
37
+ * case, which names the same tenant;
38
+ * - non-UUID ids and a label the server would refuse, so a call that cannot succeed sends
39
+ * nothing.
40
+ */
41
+
42
+ import { uuid } from "./delivery-loop.js";
43
+
44
+ export const TENANT_UPDATE_FIELDS = [
45
+ "name",
46
+ "email",
47
+ "settings",
48
+ "default_story_budget_millicents",
49
+ "token_data_retention_days",
50
+ ];
51
+
52
+ export const MAX_FRIENDLY_NAME_BYTES = 120;
53
+
54
+ function refuse(body) {
55
+ return { error: true, status: 0, body };
56
+ }
57
+
58
+ // ONE template literal per builder (see `test/tool-surface.js`).
59
+ export function tenantMePath() {
60
+ return `/api/v1/tenants/me`;
61
+ }
62
+
63
+ export function authenticatorsPath(tenantId) {
64
+ return `/api/v1/tenants/${encodeURIComponent(tenantId)}/authenticators`;
65
+ }
66
+
67
+ export function authenticatorPath(tenantId, authenticatorId) {
68
+ return `/api/v1/tenants/${encodeURIComponent(tenantId)}/authenticators/${encodeURIComponent(authenticatorId)}`;
69
+ }
70
+
71
+ export function trustedEndpointsPath() {
72
+ return `/api/v1/egress/trusted-endpoints`;
73
+ }
74
+
75
+ export async function updateTenant(args = {}, { apiCall } = {}) {
76
+ if (Object.hasOwn(args, "slug")) {
77
+ return refuse(
78
+ "`slug` is immutable: it keys the tenant's audit-key secret, and loopctl ignores it on " +
79
+ "update and answers 200 with the slug unchanged. Nothing was sent.",
80
+ );
81
+ }
82
+
83
+ const body = {};
84
+ for (const field of TENANT_UPDATE_FIELDS) {
85
+ if (args[field] !== undefined) body[field] = args[field];
86
+ }
87
+
88
+ if (Object.keys(body).length === 0) {
89
+ return refuse(`Pass at least one of: ${TENANT_UPDATE_FIELDS.join(", ")}.`);
90
+ }
91
+
92
+ if (
93
+ body.settings !== undefined &&
94
+ (body.settings === null || typeof body.settings !== "object" || Array.isArray(body.settings))
95
+ ) {
96
+ return refuse("`settings` must be an object; its keys are merged into the stored settings.");
97
+ }
98
+
99
+ return apiCall("PATCH", tenantMePath(), body);
100
+ }
101
+
102
+ function tenantIdOf(tenant_id) {
103
+ return uuid(tenant_id, "tenant_id") ?? { ok: tenant_id.toLowerCase() };
104
+ }
105
+
106
+ export async function listAuthenticators({ tenant_id } = {}, { apiCall } = {}) {
107
+ const tenant = tenantIdOf(tenant_id);
108
+ if (!tenant.ok) return tenant;
109
+
110
+ return apiCall("GET", authenticatorsPath(tenant.ok), null);
111
+ }
112
+
113
+ export async function renameAuthenticator(
114
+ { tenant_id, authenticator_id, friendly_name } = {},
115
+ { apiCall } = {},
116
+ ) {
117
+ const tenant = tenantIdOf(tenant_id);
118
+ if (!tenant.ok) return tenant;
119
+
120
+ const bad = uuid(authenticator_id, "authenticator_id");
121
+ if (bad) return bad;
122
+
123
+ if (typeof friendly_name !== "string" || friendly_name.trim() === "") {
124
+ return refuse("`friendly_name` is required: the new label, not blank.");
125
+ }
126
+
127
+ if (Buffer.byteLength(friendly_name.trim(), "utf8") > MAX_FRIENDLY_NAME_BYTES) {
128
+ return refuse(
129
+ `\`friendly_name\` is at most ${MAX_FRIENDLY_NAME_BYTES} bytes after trimming ` +
130
+ "(a multi-byte character counts each byte).",
131
+ );
132
+ }
133
+
134
+ return apiCall("PATCH", authenticatorPath(tenant.ok, authenticator_id), { friendly_name });
135
+ }
136
+
137
+ export async function listTrustedEndpoints(_args = {}, { apiCall } = {}) {
138
+ return apiCall("GET", trustedEndpointsPath(), null);
139
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `get_project` / `list_epic_stories` — `GET /api/v1/projects/:id` (`ProjectController.show`)
3
+ * and `GET /api/v1/epics/:epic_id/stories` (`StoryController.index`), loopctl #872.
4
+ *
5
+ * KEY: the session's own key (`agentKey()` in index.js). Both are `role: :agent` WITH the
6
+ * hierarchy, so any key of the tenant reads them, and neither is human-anchored.
7
+ *
8
+ * - get_project answers the project with its `epic_count` and `story_count`, 404 for a
9
+ * project outside the tenant. The path id is NOT rewritten by `ResolveProjectRef` (that plug
10
+ * reads only a `project_id` param), so a slug would answer 404 as if the project did not
11
+ * exist: a non-UUID is refused here and pointed at `resolve_project`.
12
+ * - list_epic_stories pages an epic's stories in `sort_key` order (`page`, `page_size`
13
+ * 1..100, default 20) and filters by `agent_status` / `verified_status`. 404 for an epic
14
+ * outside the tenant. `Stories.apply_filters/2` IGNORES a status it does not know rather
15
+ * than refusing it, so a misspelt filter would answer every story as if it matched; the two
16
+ * enums are checked here.
17
+ */
18
+
19
+ import { uuid } from "./delivery-loop.js";
20
+ import { projectPath } from "./project-update.js";
21
+
22
+ // `Loopctl.WorkBreakdown.Story`'s `@agent_statuses` and `@verified_statuses`.
23
+ export const AGENT_STATUSES = ["pending", "contracted", "assigned", "implementing", "reported_done"];
24
+ export const VERIFIED_STATUSES = ["unverified", "verified", "rejected"];
25
+
26
+ function refuse(body) {
27
+ return { error: true, status: 0, body };
28
+ }
29
+
30
+ // ONE template literal (see `test/tool-surface.js`).
31
+ export function epicStoriesPath(epicId, query = "") {
32
+ return `/api/v1/epics/${encodeURIComponent(epicId)}/stories${query}`;
33
+ }
34
+
35
+ function epicStoriesQuery({ agent_status, verified_status, page, page_size }) {
36
+ const params = new URLSearchParams();
37
+ if (agent_status != null) params.set("agent_status", agent_status);
38
+ if (verified_status != null) params.set("verified_status", verified_status);
39
+ if (page != null) params.set("page", String(page));
40
+ if (page_size != null) params.set("page_size", String(page_size));
41
+ const qs = params.toString();
42
+ return qs === "" ? "" : `?${qs}`;
43
+ }
44
+
45
+ export async function getProjectById({ project_id } = {}, { apiCall } = {}) {
46
+ const bad = uuid(project_id, "project_id");
47
+ if (bad) {
48
+ return {
49
+ ...bad,
50
+ body: `${bad.body} A slug or repo name answers 404 on this path: resolve it to an id with resolve_project first.`,
51
+ };
52
+ }
53
+
54
+ return apiCall("GET", projectPath(project_id), null);
55
+ }
56
+
57
+ export async function listEpicStories(
58
+ { epic_id, agent_status, verified_status, page, page_size } = {},
59
+ { apiCall } = {},
60
+ ) {
61
+ const bad = uuid(epic_id, "epic_id");
62
+ if (bad) return bad;
63
+
64
+ if (agent_status != null && !AGENT_STATUSES.includes(agent_status)) {
65
+ return refuse(`\`agent_status\` is one of: ${AGENT_STATUSES.join(", ")}.`);
66
+ }
67
+
68
+ if (verified_status != null && !VERIFIED_STATUSES.includes(verified_status)) {
69
+ return refuse(`\`verified_status\` is one of: ${VERIFIED_STATUSES.join(", ")}.`);
70
+ }
71
+
72
+ if (page != null && !(Number.isInteger(page) && page >= 1)) {
73
+ return refuse("`page` must be a positive integer.");
74
+ }
75
+
76
+ if (page_size != null && !(Number.isInteger(page_size) && page_size >= 1 && page_size <= 100)) {
77
+ return refuse("`page_size` must be an integer from 1 to 100 (default 20).");
78
+ }
79
+
80
+ const query = epicStoriesQuery({ agent_status, verified_status, page, page_size });
81
+ return apiCall("GET", epicStoriesPath(epic_id, query), null);
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.43.0",
3
+ "version": "3.45.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",