loopctl-mcp-server 3.40.1 → 3.41.1

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.
@@ -19,9 +19,10 @@
19
19
  * 1. It mints the webhook secret and names the URL GitHub must POST to, so issues from one
20
20
  * repository reach one project's queue.
21
21
  * 2. It BINDS that project to a `repo_full_name` and a `base_branch`, which is where
22
- * `Loopctl.Delivery.DispatchPayload` reads the repository and trunk from. A project
23
- * bound to none is the `409 no_intake_source` refusal; bound to two, the `409
24
- * ambiguous_intake_source` one.
22
+ * `Loopctl.Delivery.DispatchPayload` reads the repository and trunk from, through the
23
+ * story's own source (US-54.3). A story with no live source is the `409
24
+ * no_intake_source` refusal; a caller naming another repository or base than the
25
+ * story's source, the `409 base_branch_mismatch` one.
25
26
  *
26
27
  * ## THE SECRET IS NEVER RETURNED BY THESE TOOLS
27
28
  *
@@ -52,21 +53,34 @@
52
53
  * What is not the same is the fallback when no id was proved. `enrollRunner` scrapes the
53
54
  * runner id out of an unparseable 2xx body, because a runner found by NAME alone might be an
54
55
  * earlier, legitimate enrollment. An intake source needs no such scraping:
55
- * `intake_sources_active_repo_uidx` is unique on `(tenant_id, lower(repo_full_name))` WHERE
56
- * `revoked_at IS NULL` — CASE-INSENSITIVELY, because GitHub names are — so at most one ACTIVE
57
- * source ever binds a repository however it was spelled, and `intake_source_list` identifies
58
- * it exactly. That branch therefore names the pair of tools rather than guessing at an id.
59
- *
60
- * MATCH THAT LISTING CASE-INSENSITIVELY. The uniqueness folds case; the STORED value does not
61
- * — the row keeps the spelling it was enrolled with — so a source enrolled as
62
- * `MKREYMAN/loopctl` refuses a re-enrolment of `mkreyman/loopctl` with a 422 while a reader
63
- * comparing the two exactly concludes there is nothing to revoke.
56
+ * `intake_sources_active_repo_base_uidx` is unique on
57
+ * `(tenant_id, lower(repo_full_name), base_branch)` WHERE `revoked_at IS NULL` (US-54.1) — the
58
+ * repository CASE-INSENSITIVELY, because GitHub names are, the branch exactly — so at most one
59
+ * ACTIVE source ever binds a repository and base branch however the repository was spelled,
60
+ * and `intake_source_list` identifies it exactly. That branch therefore names the pair of
61
+ * tools rather than guessing at an id.
62
+ *
63
+ * MATCH THAT LISTING CASE-INSENSITIVELY on the repository. The uniqueness folds case; the
64
+ * STORED value does not — the row keeps the spelling it was enrolled with — so a source
65
+ * enrolled as `MKREYMAN/loopctl` refuses a re-enrolment of `mkreyman/loopctl` on the same
66
+ * base branch with a 422 while a reader comparing the two exactly concludes there is nothing
67
+ * to revoke.
64
68
  *
65
69
  * A source whose secret nobody holds is also INERT rather than dangerous: no delivery can
66
70
  * ever be signed for it, so every POST to its URL is refused `401 invalid_signature`. What it
67
- * does cost is that unique slot — a second enrolment of the same repository is refused 422
68
- * until it is revoked — which is why a write failure after a successful create revokes it
69
- * here rather than leaving it.
71
+ * does cost is that unique slot — a second enrolment of the same repository and base branch
72
+ * is refused 422 until it is revoked — which is why a write failure after a successful create
73
+ * revokes it here rather than leaving it.
74
+ *
75
+ * ## `issue_label` AND THE PRIMARY SOURCE (US-54.1)
76
+ *
77
+ * A repository may have one live source per base branch, all on the repository's one project.
78
+ * `issue_label` says which issues belong to which: a project has ONE live `pr`/`chg` source
79
+ * with no label (its primary), so every other source of the project carries one. Three
80
+ * refusals, each a 422 naming the field: `repo_full_name` "already has a live intake source on
81
+ * base branch <b>", `issue_label` "is already the label of another live source on this
82
+ * repository" (labels compare case-insensitively, as GitHub's do), and `issue_label` "is
83
+ * required: this project already has a source with no issue label".
70
84
  *
71
85
  * ## KEY
72
86
  *
@@ -388,6 +402,72 @@ export function triageRequiresTicketRefusal(value) {
388
402
  );
389
403
  }
390
404
 
405
+ /** The longest `issue_label`, in characters: GitHub's own label limit (`Source.max_issue_label_chars/0`). */
406
+ export const MAX_ISSUE_LABEL_CHARS = 50;
407
+
408
+ /**
409
+ * The three identity refusals an enrolment or an update can meet (US-54.1), in the server's
410
+ * words, so every tool description names them from one place.
411
+ */
412
+ export const IDENTITY_REFUSALS =
413
+ "422 on `repo_full_name` `already has a live intake source on base branch <b>` when a live " +
414
+ "source of this repository already has that base branch; 422 on `issue_label` `is already " +
415
+ "the label of another live source on this repository` when a sibling has that label " +
416
+ "(case-insensitively); 422 on `issue_label` `is required: this project already has a " +
417
+ "source with no issue label` when the source would be a second primary of its project.";
418
+
419
+ /**
420
+ * `issue_label`: a string of 1..50 characters (counted as the server counts them, in code
421
+ * points). `null` is the cleared state and only an update may send it; on enrolment the
422
+ * primary source is the one that leaves the field out.
423
+ */
424
+ export function issueLabelRefusal(value, { clearable }) {
425
+ if (value === null && clearable) return null;
426
+
427
+ const length = typeof value === "string" ? [...value].length : 0;
428
+ if (length >= 1 && length <= MAX_ISSUE_LABEL_CHARS) return null;
429
+
430
+ return refuse(
431
+ `\`issue_label\` must be a GitHub label of 1 to ${MAX_ISSUE_LABEL_CHARS} characters` +
432
+ (clearable
433
+ ? ", or null to clear it (which makes the source its project's primary)."
434
+ : ". Leave it out to enrol the project's primary source, which carries no label."),
435
+ );
436
+ }
437
+
438
+ /** The longest `deploy_environment`, in characters (`Source.max_deploy_environment_chars/0`). */
439
+ export const MAX_DEPLOY_ENVIRONMENT_CHARS = 255;
440
+
441
+ // The same control-character class `Loopctl.Delivery.DeployEnvironment.valid?/1` refuses.
442
+ const CONTROL_CHAR = /[\x00-\x1f\x7f]/;
443
+
444
+ /**
445
+ * `deploy_environment` (US-54.7): the GitHub deployment environment post-deploy verification
446
+ * reads for this source's stories. A string of 1..255 characters with no control character,
447
+ * the rule the server's `DeployEnvironment.valid?/1` and the column's CHECK apply; spaces and
448
+ * punctuation are fine (`production (fly)`). `null` is the cleared state, the fleet-wide
449
+ * default, and only an update may send it; an enrolment that wants the default leaves it out.
450
+ */
451
+ export function deployEnvironmentRefusal(value, { clearable }) {
452
+ if (value === null && clearable) return null;
453
+
454
+ if (typeof value === "string") {
455
+ const length = [...value].length;
456
+ if (length >= 1 && length <= MAX_DEPLOY_ENVIRONMENT_CHARS && !CONTROL_CHAR.test(value)) {
457
+ return null;
458
+ }
459
+ }
460
+
461
+ return refuse(
462
+ "`deploy_environment` must be a GitHub deployment environment name of 1 to " +
463
+ `${MAX_DEPLOY_ENVIRONMENT_CHARS} characters with no control character` +
464
+ (clearable
465
+ ? ", or null to clear it (which returns the source to the fleet-wide " +
466
+ "DELIVERY_DEPLOY_ENVIRONMENT)."
467
+ : ". Leave it out to use the fleet-wide DELIVERY_DEPLOY_ENVIRONMENT."),
468
+ );
469
+ }
470
+
391
471
  export function sourcePath(sourceId) {
392
472
  return `${SOURCES_PATH}/${encodeURIComponent(sourceId)}`;
393
473
  }
@@ -416,6 +496,8 @@ export function publicSource(source) {
416
496
  project_id: source.project_id,
417
497
  repo_full_name: source.repo_full_name,
418
498
  base_branch: source.base_branch,
499
+ issue_label: source.issue_label,
500
+ deploy_environment: source.deploy_environment,
419
501
  mode: source.mode,
420
502
  required_checks: source.required_checks,
421
503
  triage_requires_ticket: source.triage_requires_ticket,
@@ -452,6 +534,8 @@ export async function enrollIntakeSource(
452
534
  project_id,
453
535
  target_epic_id,
454
536
  base_branch,
537
+ issue_label,
538
+ deploy_environment,
455
539
  mode,
456
540
  required_checks,
457
541
  triage_requires_ticket,
@@ -499,6 +583,19 @@ export async function enrollIntakeSource(
499
583
  }
500
584
  }
501
585
 
586
+ // OPTIONAL (US-54.1): omitted, the source is its project's primary. Judged here, before a
587
+ // secret file is reserved.
588
+ if (issue_label !== undefined) {
589
+ const badLabel = issueLabelRefusal(issue_label, { clearable: false });
590
+ if (badLabel) return badLabel;
591
+ }
592
+
593
+ // OPTIONAL (US-54.7): omitted, the source is verified against the fleet-wide default.
594
+ if (deploy_environment !== undefined) {
595
+ const badEnvironment = deployEnvironmentRefusal(deploy_environment, { clearable: false });
596
+ if (badEnvironment) return badEnvironment;
597
+ }
598
+
502
599
  // OPTIONAL, read by PRESENCE like the branch: omitted, the source takes `pr`. Named, it
503
600
  // must be a known mode; anything else (null included) is a 422 at the server and
504
601
  // is refused here, before a secret file is reserved.
@@ -578,6 +675,8 @@ export async function enrollIntakeSource(
578
675
  body.target_epic_id = target_epic_id;
579
676
  }
580
677
  if (base_branch !== undefined) body.base_branch = base_branch;
678
+ if (issue_label !== undefined) body.issue_label = issue_label;
679
+ if (deploy_environment !== undefined) body.deploy_environment = deploy_environment;
581
680
  if (mode !== undefined) body.mode = mode;
582
681
  if (required_checks !== undefined) body.required_checks = required_checks;
583
682
  if (triage_requires_ticket !== undefined) body.triage_requires_ticket = triage_requires_ticket;
@@ -617,7 +716,8 @@ export async function enrollIntakeSource(
617
716
 
618
717
  if (!sourceId || !usableSecret || path === undefined) {
619
718
  const removed = await discardReservation(fs, handle, secretPath, opened);
620
- return ambiguousEnrollment(result, apiCall, sourceId, repo_full_name, secretPath, removed);
719
+ const branch = base_branch === undefined ? "master" : base_branch;
720
+ return ambiguousEnrollment(result, apiCall, sourceId, repo_full_name, branch, secretPath, removed);
621
721
  }
622
722
 
623
723
  try {
@@ -660,10 +760,18 @@ export async function enrollIntakeSource(
660
760
  * the operator asked them to do by hand what this process could already prove and do itself.
661
761
  *
662
762
  * With NO id — an unparseable body, a timeout — the recovery names the tools instead, because
663
- * it can: an ACTIVE source is unique per repository (`intake_sources_active_repo_uidx`), so
664
- * the list identifies it exactly.
763
+ * it can: an ACTIVE source is unique per repository and base branch
764
+ * (`intake_sources_active_repo_base_uidx`), so the list identifies it exactly.
665
765
  */
666
- async function ambiguousEnrollment(result, apiCall, sourceId, repoFullName, secretPath, removed) {
766
+ async function ambiguousEnrollment(
767
+ result,
768
+ apiCall,
769
+ sourceId,
770
+ repoFullName,
771
+ baseBranch,
772
+ secretPath,
773
+ removed,
774
+ ) {
667
775
  const status = result && Number.isInteger(result.status) ? result.status : undefined;
668
776
 
669
777
  const what =
@@ -677,19 +785,22 @@ async function ambiguousEnrollment(result, apiCall, sourceId, repoFullName, secr
677
785
  const revoked = await revoke(apiCall, sourceId);
678
786
  next = revoked.ok
679
787
  ? `The response identified source ${sourceId}; it was revoked, since its secret cannot ` +
680
- "be recovered and an unusable source holds this repository's unique slot. Enrol again."
788
+ "be recovered and an unusable source holds this repository's slot for base branch " +
789
+ `'${baseBranch}'. Enrol again.`
681
790
  : `The response identified source ${sourceId}, but revoking it FAILED ` +
682
791
  `(${revoked.detail}); revoke it with intake_source_revoke source_id ${sourceId} — ` +
683
- "until you do, a second source for this repository is refused 422.";
792
+ `until you do, a second source for this repository on base branch '${baseBranch}' ` +
793
+ "is refused 422.";
684
794
  } else {
685
795
  next =
686
- `A source for '${repoFullName}' may exist with a secret nobody holds — it can never ` +
687
- "authenticate a delivery, and it holds that repository's unique slot, so a second " +
688
- "enrolment is refused 422 until it is gone. Run intake_source_list, and revoke any " +
689
- `active source whose repo_full_name equals '${repoFullName}' IGNORING CASE with ` +
690
- "intake_source_revoke before enrolling again — the uniqueness is case-insensitive " +
691
- "(`lower(repo_full_name)`) while the stored value keeps whatever spelling it was " +
692
- "enrolled with, so an exact match can miss the row that is blocking you.";
796
+ `A source for '${repoFullName}' on base branch '${baseBranch}' may exist with a secret ` +
797
+ "nobody holds — it can never authenticate a delivery, and it holds that repository's " +
798
+ "slot for that base branch, so a second enrolment is refused 422 until it is gone. Run " +
799
+ "intake_source_list, and revoke any active source whose repo_full_name equals " +
800
+ `'${repoFullName}' IGNORING CASE and whose base_branch is exactly '${baseBranch}' with ` +
801
+ "intake_source_revoke before enrolling again — the uniqueness is case-insensitive on " +
802
+ "the repository (`lower(repo_full_name)`) while the stored value keeps whatever " +
803
+ "spelling it was enrolled with, so an exact match can miss the row that is blocking you.";
693
804
  }
694
805
 
695
806
  return {
@@ -766,6 +877,22 @@ export async function updateIntakeSource(
766
877
  body.base_branch = args.base_branch;
767
878
  }
768
879
 
880
+ // US-54.1: null is FORWARDED, like the epic's, because it is the only way to clear a label,
881
+ // which makes the source its project's primary (a 422 while the project has another).
882
+ if (args.issue_label !== undefined) {
883
+ const badLabel = issueLabelRefusal(args.issue_label, { clearable: true });
884
+ if (badLabel) return badLabel;
885
+ body.issue_label = args.issue_label;
886
+ }
887
+
888
+ // US-54.7: null is FORWARDED too, because it is the only way to return the source to the
889
+ // fleet-wide DELIVERY_DEPLOY_ENVIRONMENT.
890
+ if (args.deploy_environment !== undefined) {
891
+ const badEnvironment = deployEnvironmentRefusal(args.deploy_environment, { clearable: true });
892
+ if (badEnvironment) return badEnvironment;
893
+ body.deploy_environment = args.deploy_environment;
894
+ }
895
+
769
896
  if (args.mode !== undefined) {
770
897
  const badMode = modeRefusal(args.mode);
771
898
  if (badMode) return badMode;
@@ -794,7 +921,9 @@ export async function updateIntakeSource(
794
921
  if (Object.keys(body).length === 0) {
795
922
  return refuse(
796
923
  "Nothing to update. Name at least one of `target_epic_id` (null clears it), " +
797
- "`base_branch`, `mode`, `required_checks`, `triage_requires_ticket`, " +
924
+ "`base_branch`, `issue_label` (null clears it), `deploy_environment` (null clears " +
925
+ "it), `mode`, `required_checks`, " +
926
+ "`triage_requires_ticket`, " +
798
927
  "`change_events_secret` (or " +
799
928
  "`change_events_secret_file`), `chg_root_dispatch_id` or `mint_chg_root`. A body " +
800
929
  "carrying none of them " +
@@ -6,7 +6,8 @@
6
6
  * KEY: the session's own key (`agentKey()` in index.js, the holder credential once the
7
7
  * startup register succeeded). The server compares that key's holder with the item's: the
8
8
  * holder that holds the item is refused 409 self_intervention_blocked, and a key with no
9
- * holder that is not a human's is 409 holder_required.
9
+ * holder that is not a human's is 409 holder_required. The one exception is `close` on the
10
+ * holder's own INTERACTIVE item (see `intervene`).
10
11
  *
11
12
  * Each call carries an `intervention_id`; one is generated when the caller gives none, so a
12
13
  * caller that retries after a lost response should pass the id it used the first time. The
@@ -45,10 +46,17 @@ function postIntervention(apiCall, verb, storyId, body) {
45
46
  }
46
47
  }
47
48
 
48
- /** `POST /api/v1/stories/:id/<verb>`. */
49
+ /**
50
+ * `POST /api/v1/stories/:id/<verb>`.
51
+ *
52
+ * `evidence` is sent on `close` only. The holder of an INTERACTIVE work item (one
53
+ * `work_item_open` opened) may close its OWN item, and the server then REQUIRES evidence: the
54
+ * item ends at `done` over `:self_closed`, never `verified`. The server decides whether a close
55
+ * is a self-close, so the tool forwards evidence whenever it is given and never demands it.
56
+ */
49
57
  export async function intervene(
50
58
  verb,
51
- { story_id, reason, intervention_id } = {},
59
+ { story_id, reason, intervention_id, evidence } = {},
52
60
  { apiCall, randomUUID = () => crypto.randomUUID() } = {},
53
61
  ) {
54
62
  if (!INTERVENTION_VERBS.includes(verb)) {
@@ -70,5 +78,14 @@ export async function intervene(
70
78
  if (badId) return badId;
71
79
  }
72
80
 
73
- return postIntervention(apiCall, verb, story_id, { reason, intervention_id: id });
81
+ const body = { reason, intervention_id: id };
82
+
83
+ if (verb === "close" && evidence !== undefined && evidence !== null) {
84
+ if (typeof evidence !== "string") {
85
+ return refuse("`evidence` must be text: what was done and where.");
86
+ }
87
+ body.evidence = evidence;
88
+ }
89
+
90
+ return postIntervention(apiCall, verb, story_id, body);
74
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.40.1",
3
+ "version": "3.41.1",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",