loopctl-mcp-server 3.33.0 → 3.34.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 +4 -0
- package/index.js +183 -0
- package/lib/factory-policy.js +17 -0
- package/lib/review-rounds.js +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -581,6 +581,10 @@ Key distribution for the dispatch pattern (Epic 26): per-dispatch ephemeral keys
|
|
|
581
581
|
| `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. |
|
|
582
582
|
| `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 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. |
|
|
583
583
|
| `factory_overview` | **Read the factory overview** (`GET /api/v1/factory/overview`): per project and summed for the fleet, `in_flight` counts per stage (claimed through verified), `waiting` counts (detected, triaged, queued, and escalated per reason class) with the oldest item's age, `throughput` over the window (done count, median seconds opened to done) and `failure_classes` (moves into escalated or failed, by edge). Counts come from the stage machine; drill into an item with `work_item_timeline`. Optional `project_id` and `window_days` (default 7, 1..30). Read-only on any key. `400` for a bad window, `404` for another tenant's project, `503` when the read times out. |
|
|
584
|
+
| `factory_policy` | **Read the factory policy** (`GET /api/v1/factory/policy`, US-52.51): every delivery-loop rule value, compiled into loopctl from `factory/policy.toml` — review-round `normal` and `ceiling` per diff kind (`prose`, `code`), `open_prs_per_session`, `epics_open_per_repo`, `pr_body.required_sections`, `review.default_level` and `review.max_level`, `epic_merge.new_tip_seconds`, `protected_branches`. Returns `{schema, version, rules}`; `version` is the file's sha256 (the endpoint's ETag, so a client that kept a copy gets `304` on `If-None-Match`). The same for every tenant. Any tenant key; refuses nothing else (`401` only without a valid key). No arguments. |
|
|
585
|
+
| `review_round_open` | **Open a review round** (`POST /api/v1/review_rounds`, US-52.53): counts one round on the work item for `repo_url` and `branch` and answers from the factory policy's `review_rounds.<diff_kind>` limits — `201 {round_id, round, normal, ceiling, verdict, message, attested}`, `verdict` `allow` while round <= normal and `warn` up to the ceiling. A repeated `round_id` counts nothing and answers `200` with the first answer. `attested: true` with a `reason` counts a review the hook could not see. `kind: "security"` with a `head_sha` records a /security-review at that head instead (`201 {round_id, kind, head_sha, message, attested}`), never counted against the ceiling. `ancestor_shas` (the branch's commits outside the base, at most 500) refuses a round whose branch carries another unmerged item's ceiling-round head (claude-config#810). Holder credential (the round's actor is its holder). `409 review_ceiling_reached` (nothing counted; the session decides a redesign or a narrower merge), `409 inherited_ceiling_reached` (`parent_branch`, `head_sha`, `round_count`, `ceiling`), `422 attestation_reason_required`, `422 head_sha_required`, `404 work_item_not_found` (open one with `work_item_open`), `403 holder_credential_required`, `400 repo_and_branch_required`, `409 ambiguous_project`, `422 invalid_round_id`/`invalid_kind`/`invalid_diff_kind`/`invalid_head_sha`/`invalid_ancestor_shas`/`invalid_branch`, `503 busy`. |
|
|
586
|
+
| `review_round_void` | **Void a review round** that did not review (`POST /api/v1/review_rounds/:round_id/void`, US-52.53): it stops counting on its item. `201 {round_id, voided, round, count}`; a second void is `200`. Holder credential. `404 review_round_not_found`, `409 ambiguous_round_id`, `403 holder_credential_required`, `422 invalid_reason`, `503 busy`. |
|
|
587
|
+
| `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`. |
|
|
584
588
|
| `intake_pause` | **Pause a project's intake** (`POST /api/v1/projects/:id/intake/pause`, US-52.33): new issues stay `pending_triage` and get no triage. 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`, `409 ambiguous_intake_source`, `403` on an agent-rooted tenant. Session's own key. |
|
|
585
589
|
| `intake_resume` | **Resume a project's intake** (`POST /api/v1/projects/:id/intake/resume`, US-52.33): the minute promotion run picks up what arrived while paused. Same scope, refusals and idempotency as `intake_pause`. |
|
|
586
590
|
| `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. |
|
package/index.js
CHANGED
|
@@ -31,6 +31,12 @@ import { readCheckpoints, recordCheckpoint, resolveCheckpoint } from "./lib/chec
|
|
|
31
31
|
import { moveWorkItem } from "./lib/work-item-move.js";
|
|
32
32
|
import { pullWorkItem } from "./lib/work-item-pull.js";
|
|
33
33
|
import { pauseIntake, readFactoryOverview, resumeIntake } from "./lib/factory.js";
|
|
34
|
+
import { readFactoryPolicy } from "./lib/factory-policy.js";
|
|
35
|
+
import {
|
|
36
|
+
openReviewRound,
|
|
37
|
+
readReviewRoundStatus,
|
|
38
|
+
voidReviewRound,
|
|
39
|
+
} from "./lib/review-rounds.js";
|
|
34
40
|
import { intervene } from "./lib/interventions.js";
|
|
35
41
|
import { refuseChannelPost, sendMessage } from "./lib/messages.js";
|
|
36
42
|
import { readInbox } from "./lib/inbox.js";
|
|
@@ -3190,6 +3196,41 @@ async function factoryOverviewTool(args) {
|
|
|
3190
3196
|
);
|
|
3191
3197
|
}
|
|
3192
3198
|
|
|
3199
|
+
// US-52.51: the factory policy, read on the session's own key (any key reads it).
|
|
3200
|
+
async function factoryPolicyTool(args) {
|
|
3201
|
+
return toContent(
|
|
3202
|
+
await readFactoryPolicy(args, {
|
|
3203
|
+
apiCall: (method, path, body) => apiCall(method, path, body, agentKey()),
|
|
3204
|
+
}),
|
|
3205
|
+
);
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
// US-52.53: review rounds on the work item. The writes travel on the holder credential, whose
|
|
3209
|
+
// holder the server records as the round's actor; the read takes the same key.
|
|
3210
|
+
async function reviewRoundOpenTool(args) {
|
|
3211
|
+
return toContent(
|
|
3212
|
+
await openReviewRound(args, {
|
|
3213
|
+
apiCall: (method, path, body) => apiCall(method, path, body, agentKey()),
|
|
3214
|
+
}),
|
|
3215
|
+
);
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
async function reviewRoundVoidTool(args) {
|
|
3219
|
+
return toContent(
|
|
3220
|
+
await voidReviewRound(args, {
|
|
3221
|
+
apiCall: (method, path, body) => apiCall(method, path, body, agentKey()),
|
|
3222
|
+
}),
|
|
3223
|
+
);
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
async function reviewRoundStatusTool(args) {
|
|
3227
|
+
return toContent(
|
|
3228
|
+
await readReviewRoundStatus(args, {
|
|
3229
|
+
apiCall: (method, path, body) => apiCall(method, path, body, agentKey()),
|
|
3230
|
+
}),
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3193
3234
|
// US-52.33: pause and resume a project's intake, on the session's own key (role agent,
|
|
3194
3235
|
// human-anchored tenant).
|
|
3195
3236
|
async function intakePauseTool(args) {
|
|
@@ -8953,6 +8994,140 @@ const TOOLS = [
|
|
|
8953
8994
|
},
|
|
8954
8995
|
},
|
|
8955
8996
|
|
|
8997
|
+
{
|
|
8998
|
+
name: "factory_policy",
|
|
8999
|
+
description:
|
|
9000
|
+
"READ THE FACTORY POLICY (GET /api/v1/factory/policy): every delivery-loop rule value, " +
|
|
9001
|
+
"decided once on the server and compiled from loopctl's factory/policy.toml — " +
|
|
9002
|
+
"`rules.review_rounds.{prose,code}.{normal,ceiling}`, `rules.open_prs_per_session`, " +
|
|
9003
|
+
"`rules.epics_open_per_repo`, `rules.pr_body.required_sections`, " +
|
|
9004
|
+
"`rules.review.{default_level,max_level}`, `rules.epic_merge.new_tip_seconds` and " +
|
|
9005
|
+
"`rules.protected_branches`. Returns `{schema, version, rules}`: `version` is the " +
|
|
9006
|
+
"sha256 of the policy file, `schema` is bumped on any key rename or removal. The same " +
|
|
9007
|
+
"for every tenant. Needs any tenant key (agent role or higher); " +
|
|
9008
|
+
"refuses nothing else: 401 only without a valid key. No arguments.",
|
|
9009
|
+
inputSchema: { type: "object", properties: {} },
|
|
9010
|
+
},
|
|
9011
|
+
|
|
9012
|
+
{
|
|
9013
|
+
name: "review_round_open",
|
|
9014
|
+
description:
|
|
9015
|
+
"OPEN A REVIEW ROUND (POST /api/v1/review_rounds): counts one review round on the work " +
|
|
9016
|
+
"item whose stage row names `branch` in the project `repo_url` resolves to, and answers " +
|
|
9017
|
+
"from the factory policy's `review_rounds.<diff_kind>` limits: 201 `{round_id, round, " +
|
|
9018
|
+
"normal, ceiling, verdict, message, attested}`, `verdict` `allow` while round <= normal " +
|
|
9019
|
+
"and `warn` while normal < round <= ceiling. A `round_id` already on the item counts " +
|
|
9020
|
+
"nothing and answers 200 with the first answer, so a retry is safe. `attested: true` " +
|
|
9021
|
+
"with a `reason` records a review that ran where the hook could not count it. " +
|
|
9022
|
+
"`kind: \"security\"` with a `head_sha` records a /security-review at that head instead: " +
|
|
9023
|
+
"201 `{round_id, kind, head_sha, message, attested}`, never counted against the ceiling " +
|
|
9024
|
+
"and needing no `diff_kind`. `ancestor_shas` (the branch's commits outside the base, at " +
|
|
9025
|
+
"most 500) refuses a round whose branch carries the head of another unmerged item's " +
|
|
9026
|
+
"ceiling round. Needs the holder credential (the round's actor is its holder). REFUSES: " +
|
|
9027
|
+
"409 `review_ceiling_reached` (the round would pass the ceiling; nothing is counted, and " +
|
|
9028
|
+
"the session decides a redesign or a narrower merge), 409 `inherited_ceiling_reached` " +
|
|
9029
|
+
"(`parent_branch`, `head_sha`, `round_count`, `ceiling`: wait for the parent to merge or " +
|
|
9030
|
+
"recut from the base), 422 `attestation_reason_required`, 422 `head_sha_required` (a " +
|
|
9031
|
+
"security record with no head), 404 `work_item_not_found` (no item of this tenant on " +
|
|
9032
|
+
"that repo and branch: open one with `work_item_open`), 403 " +
|
|
9033
|
+
"`holder_credential_required`, 400 `repo_and_branch_required`, 409 `ambiguous_project`, " +
|
|
9034
|
+
"422 `invalid_round_id` / `invalid_kind` / `invalid_diff_kind` / `invalid_head_sha` / " +
|
|
9035
|
+
"`invalid_ancestor_shas` / `invalid_branch`, 503 `busy` (retry).",
|
|
9036
|
+
inputSchema: {
|
|
9037
|
+
type: "object",
|
|
9038
|
+
properties: {
|
|
9039
|
+
repo_url: { type: "string", description: "The repository, any form the project resolves." },
|
|
9040
|
+
branch: { type: "string", description: "The branch under review." },
|
|
9041
|
+
round_id: {
|
|
9042
|
+
type: "string",
|
|
9043
|
+
description: "The round's identity: 1..128 of letters, digits, . _ : -. Reuse it to retry.",
|
|
9044
|
+
},
|
|
9045
|
+
kind: {
|
|
9046
|
+
type: "string",
|
|
9047
|
+
enum: ["round", "security"],
|
|
9048
|
+
description: "Optional: `round` (default) or `security` (a /security-review, not a round).",
|
|
9049
|
+
},
|
|
9050
|
+
diff_kind: {
|
|
9051
|
+
type: "string",
|
|
9052
|
+
enum: ["prose", "code"],
|
|
9053
|
+
description: "Whose limits apply. Required for a round, ignored for a security record.",
|
|
9054
|
+
},
|
|
9055
|
+
head_sha: {
|
|
9056
|
+
type: "string",
|
|
9057
|
+
description: "The reviewed head, 40 or 64 hex. Optional for a round, required for security.",
|
|
9058
|
+
},
|
|
9059
|
+
ancestor_shas: {
|
|
9060
|
+
type: "array",
|
|
9061
|
+
items: { type: "string" },
|
|
9062
|
+
description: "Optional: the branch's commits outside the base, for the inherited ceiling.",
|
|
9063
|
+
},
|
|
9064
|
+
attested: { type: "boolean", description: "Optional: a review the hook could not count." },
|
|
9065
|
+
reason: { type: "string", description: "Required when attested: where it ran, what it read." },
|
|
9066
|
+
},
|
|
9067
|
+
required: ["repo_url", "branch", "round_id"],
|
|
9068
|
+
},
|
|
9069
|
+
},
|
|
9070
|
+
|
|
9071
|
+
{
|
|
9072
|
+
name: "review_round_void",
|
|
9073
|
+
description:
|
|
9074
|
+
"VOID A REVIEW ROUND (POST /api/v1/review_rounds/:round_id/void): that round did not " +
|
|
9075
|
+
"review, so it stops counting on its work item. 201 `{round_id, voided, round, count}` " +
|
|
9076
|
+
"(`count` after the void); a second void counts nothing and answers 200. Needs the " +
|
|
9077
|
+
"holder credential. REFUSES: 404 `review_round_not_found` (no item of this tenant " +
|
|
9078
|
+
"carries that round), 409 `ambiguous_round_id`, 403 `holder_credential_required`, 422 " +
|
|
9079
|
+
"`invalid_reason`, 503 `busy` (retry).",
|
|
9080
|
+
inputSchema: {
|
|
9081
|
+
type: "object",
|
|
9082
|
+
properties: {
|
|
9083
|
+
round_id: { type: "string", description: "The round to void." },
|
|
9084
|
+
reason: { type: "string", description: "Optional: what showed the round did not review." },
|
|
9085
|
+
},
|
|
9086
|
+
required: ["round_id"],
|
|
9087
|
+
},
|
|
9088
|
+
},
|
|
9089
|
+
|
|
9090
|
+
{
|
|
9091
|
+
name: "review_round_status",
|
|
9092
|
+
description:
|
|
9093
|
+
"READ A BRANCH'S REVIEW ROUNDS (GET /api/v1/review_rounds?repo_url=&branch=): the work " +
|
|
9094
|
+
"item's rounds oldest first, `{rounds: [{round_id, round, diff_kind, head_sha, attested, " +
|
|
9095
|
+
"voided, actor_holder_id, inserted_at}], count, diff_kind, normal, ceiling, security, " +
|
|
9096
|
+
"inherited, capped}`; `count` excludes voided rounds. `security` lists the item's " +
|
|
9097
|
+
"/security-review records `{round_id, head_sha, attested, voided, reason, " +
|
|
9098
|
+
"actor_holder_id, inserted_at}`, which are not rounds. With `ancestor_shas`, `inherited` " +
|
|
9099
|
+
"is the capped parent the branch descends from `{branch, head_sha, round_count, " +
|
|
9100
|
+
"ceiling, message}`, else null. `capped` lists the project's other items capped in the " +
|
|
9101
|
+
"last 7 days `{branch, capped_at, heads, ceiling_heads, released}` (at most 20), for the " +
|
|
9102
|
+
"carry-over check (claude-config#812). With `ancestor_shas` (at most 500) the read is " +
|
|
9103
|
+
"sent as POST /api/v1/review_rounds/status, the same read with the list in a JSON body, " +
|
|
9104
|
+
"because 500 shas do not fit the server's 10,000-byte request line; it writes nothing. " +
|
|
9105
|
+
"Any agent key of the tenant. REFUSES: 400 " +
|
|
9106
|
+
"`repo_and_branch_required`, 404 `work_item_not_found` (names repo and branch; open one " +
|
|
9107
|
+
"with `work_item_open`), 409 `ambiguous_project`, 422 `invalid_diff_kind` / " +
|
|
9108
|
+
"`invalid_ancestor_shas` (more than 500, or not 40- or 64-character hex).",
|
|
9109
|
+
inputSchema: {
|
|
9110
|
+
type: "object",
|
|
9111
|
+
properties: {
|
|
9112
|
+
repo_url: { type: "string", description: "The repository." },
|
|
9113
|
+
branch: { type: "string", description: "The branch." },
|
|
9114
|
+
diff_kind: {
|
|
9115
|
+
type: "string",
|
|
9116
|
+
enum: ["prose", "code"],
|
|
9117
|
+
description: "Optional: whose limits to answer with (default: the newest round's).",
|
|
9118
|
+
},
|
|
9119
|
+
ancestor_shas: {
|
|
9120
|
+
type: "array",
|
|
9121
|
+
items: { type: "string" },
|
|
9122
|
+
description:
|
|
9123
|
+
"Optional: the branch's commits outside the base (at most 500); answers `inherited`. " +
|
|
9124
|
+
"Sent in a POST body, never in the URL.",
|
|
9125
|
+
},
|
|
9126
|
+
},
|
|
9127
|
+
required: ["repo_url", "branch"],
|
|
9128
|
+
},
|
|
9129
|
+
},
|
|
9130
|
+
|
|
8956
9131
|
{
|
|
8957
9132
|
name: "intake_pause",
|
|
8958
9133
|
description:
|
|
@@ -11771,6 +11946,14 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
11771
11946
|
return await workItemTimelineTool(args);
|
|
11772
11947
|
case "factory_overview":
|
|
11773
11948
|
return await factoryOverviewTool(args);
|
|
11949
|
+
case "factory_policy":
|
|
11950
|
+
return await factoryPolicyTool(args);
|
|
11951
|
+
case "review_round_open":
|
|
11952
|
+
return await reviewRoundOpenTool(args);
|
|
11953
|
+
case "review_round_void":
|
|
11954
|
+
return await reviewRoundVoidTool(args);
|
|
11955
|
+
case "review_round_status":
|
|
11956
|
+
return await reviewRoundStatusTool(args);
|
|
11774
11957
|
case "intake_pause":
|
|
11775
11958
|
return await intakePauseTool(args);
|
|
11776
11959
|
case "intake_resume":
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `factory_policy` (loopctl US-52.51): `GET /api/v1/factory/policy`, every delivery-loop rule
|
|
3
|
+
* value (review-round ceilings, open PRs per session, epics per repo, PR-body sections, review
|
|
4
|
+
* levels, the epic-merge tip age, protected branches) as loopctl compiled it from
|
|
5
|
+
* `factory/policy.toml`. The same for every tenant; `version` is the sha256 of that file.
|
|
6
|
+
*
|
|
7
|
+
* Any authenticated key reads it, and it takes no arguments, so there is nothing to refuse
|
|
8
|
+
* locally.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function policyPath() {
|
|
12
|
+
return `/api/v1/factory/policy`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function readFactoryPolicy(_args = {}, { apiCall } = {}) {
|
|
16
|
+
return apiCall("GET", policyPath(), null);
|
|
17
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review rounds, counted on the work item (loopctl US-52.53).
|
|
3
|
+
*
|
|
4
|
+
* - `review_round_open`: `POST /api/v1/review_rounds` — count one round on the work item for
|
|
5
|
+
* `repo_url` and `branch`. 201 `{round, normal, ceiling, verdict, message}`; a repeated
|
|
6
|
+
* `round_id` is 200 with the first answer; a round past the ceiling is 409
|
|
7
|
+
* `review_ceiling_reached` and nothing is counted. `kind: "security"` records a
|
|
8
|
+
* /security-review at `head_sha` instead, never counted against the ceiling; `ancestor_shas`
|
|
9
|
+
* refuses a round whose branch carries another unmerged item's capped head (409
|
|
10
|
+
* `inherited_ceiling_reached`).
|
|
11
|
+
* - `review_round_void`: `POST /api/v1/review_rounds/:round_id/void` — that round did not
|
|
12
|
+
* review; it stops counting. 404 `review_round_not_found` for an unknown round.
|
|
13
|
+
* - `review_round_status`: `GET /api/v1/review_rounds?repo_url=&branch=` — the item's rounds
|
|
14
|
+
* and the counted total, its security records, `inherited` for `ancestor_shas`, and the
|
|
15
|
+
* project's capped items (`capped`) for the carry-over check. With `ancestor_shas` it is
|
|
16
|
+
* `POST /api/v1/review_rounds/status`, the same read with the list in a body.
|
|
17
|
+
*
|
|
18
|
+
* The writes need a holder credential (the round's actor is the key's holder, resolved
|
|
19
|
+
* server-side); the read takes any agent key. Nothing here is decided locally beyond the
|
|
20
|
+
* argument shape: the server owns the count and every refusal.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const OPEN_FIELDS = [
|
|
24
|
+
"repo_url",
|
|
25
|
+
"branch",
|
|
26
|
+
"round_id",
|
|
27
|
+
"kind",
|
|
28
|
+
"diff_kind",
|
|
29
|
+
"head_sha",
|
|
30
|
+
"ancestor_shas",
|
|
31
|
+
"attested",
|
|
32
|
+
"reason",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
// A local refusal has the shape every tool here answers one with (status 0, a sentence); the
|
|
36
|
+
// server owns every other bound and answers it with its own code.
|
|
37
|
+
function required(args, names) {
|
|
38
|
+
const missing = names.filter((n) => typeof args?.[n] !== "string" || args[n].trim() === "");
|
|
39
|
+
if (missing.length > 0) {
|
|
40
|
+
return { error: true, status: 0, body: `Required: ${missing.map((n) => `\`${n}\``).join(", ")}.` };
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function reviewRoundsPath() {
|
|
46
|
+
return "/api/v1/review_rounds";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function reviewRoundVoidPath(roundId) {
|
|
50
|
+
return `/api/v1/review_rounds/${encodeURIComponent(roundId)}/void`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The plain read: repo_url, branch and diff_kind only. ancestor_shas never goes in a URL. */
|
|
54
|
+
export function reviewRoundStatusPath({ repo_url, branch, diff_kind } = {}) {
|
|
55
|
+
const query = new URLSearchParams({ repo_url, branch });
|
|
56
|
+
if (typeof diff_kind === "string" && diff_kind !== "") query.set("diff_kind", diff_kind);
|
|
57
|
+
return `/api/v1/review_rounds?${query.toString()}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The same read with its arguments in a body, for ancestor_shas. */
|
|
61
|
+
export function reviewRoundStatusBodyPath() {
|
|
62
|
+
return "/api/v1/review_rounds/status";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The ancestors as a list: an array as given, a comma-separated string split. The server checks
|
|
66
|
+
// each sha and the bound of 500.
|
|
67
|
+
function ancestorList(value) {
|
|
68
|
+
if (Array.isArray(value)) return value;
|
|
69
|
+
if (typeof value === "string") return value.split(",").map((s) => s.trim()).filter((s) => s !== "");
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function openReviewRound(args = {}, { apiCall } = {}) {
|
|
74
|
+
// A security record needs no diff kind; the server refuses one with no head.
|
|
75
|
+
const names = ["repo_url", "branch", "round_id"];
|
|
76
|
+
if (args?.kind !== "security") names.push("diff_kind");
|
|
77
|
+
const refused = required(args, names);
|
|
78
|
+
if (refused) return refused;
|
|
79
|
+
|
|
80
|
+
const body = {};
|
|
81
|
+
for (const field of OPEN_FIELDS) {
|
|
82
|
+
if (args[field] !== undefined && args[field] !== null) body[field] = args[field];
|
|
83
|
+
}
|
|
84
|
+
return apiCall("POST", reviewRoundsPath(), body);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function voidReviewRound(args = {}, { apiCall } = {}) {
|
|
88
|
+
const refused = required(args, ["round_id"]);
|
|
89
|
+
if (refused) return refused;
|
|
90
|
+
|
|
91
|
+
const body = typeof args.reason === "string" && args.reason !== "" ? { reason: args.reason } : {};
|
|
92
|
+
return apiCall("POST", reviewRoundVoidPath(args.round_id), body);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function readReviewRoundStatus(args = {}, { apiCall } = {}) {
|
|
96
|
+
const refused = required(args, ["repo_url", "branch"]);
|
|
97
|
+
if (refused) return refused;
|
|
98
|
+
|
|
99
|
+
// 500 ancestor shas are ~33 KB, past the server's 10,000-byte request line: they travel in a
|
|
100
|
+
// POST body, to the same read. Without them the read stays a GET.
|
|
101
|
+
const ancestors = ancestorList(args.ancestor_shas);
|
|
102
|
+
if (ancestors.length === 0) return apiCall("GET", reviewRoundStatusPath(args), null);
|
|
103
|
+
|
|
104
|
+
const body = { repo_url: args.repo_url, branch: args.branch, ancestor_shas: ancestors };
|
|
105
|
+
if (typeof args.diff_kind === "string" && args.diff_kind !== "") body.diff_kind = args.diff_kind;
|
|
106
|
+
return apiCall("POST", reviewRoundStatusBodyPath(), body);
|
|
107
|
+
}
|