loopctl-mcp-server 3.36.0 → 3.39.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,62 @@
1
+ /**
2
+ * US-52.61: `holder_replay`, POST /api/v1/holders/:id/replay.
3
+ *
4
+ * A session that lost loopctl kept its notes and checkpoints in a local journal; this sends
5
+ * them, in the order it wrote them, on the session's own holder credential. loopctl answers
6
+ * one result per entry: applied, replayed (already applied), fenced (recorded after the claim
7
+ * ended, kept as history) or refused.
8
+ *
9
+ * The holder id is the session's own and is never taken from the caller: loopctl refuses
10
+ * 403 holder_mismatch for a key whose holder is not the path's, so a holder id passed in could
11
+ * only ever fail. The bound on a body is loopctl's (422 replay_too_large); this module checks
12
+ * only what it can say without that number: a non-empty list in strictly ascending seq.
13
+ * Everything an entry carries is judged per entry by loopctl, so one bad entry is refused
14
+ * there without holding back the others.
15
+ */
16
+
17
+ import { HOLDERS_PATH } from "./holder.js";
18
+
19
+ function refuse(body) {
20
+ return { error: true, status: 0, body };
21
+ }
22
+
23
+ /** @param {string} id */
24
+ export function replayPath(id) {
25
+ return `${HOLDERS_PATH}/${encodeURIComponent(id)}/replay`;
26
+ }
27
+
28
+ /**
29
+ * @param {{entries?: unknown}} args
30
+ * @param {{apiCall: Function, holderId: string | null | undefined}} deps
31
+ */
32
+ export async function replayHolder({ entries } = {}, { apiCall, holderId } = {}) {
33
+ if (typeof holderId !== "string" || holderId === "") {
34
+ return refuse(
35
+ "This session holds no live holder credential, so it has nothing to replay under. " +
36
+ "Call holder_register first; entries of an earlier holder of this session come back fenced.",
37
+ );
38
+ }
39
+
40
+ if (!Array.isArray(entries) || entries.length === 0) {
41
+ return refuse("`entries` is a non-empty list of journal entries.");
42
+ }
43
+
44
+ let previous = null;
45
+ for (const [i, entry] of entries.entries()) {
46
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) {
47
+ return refuse(`entries[${i}] is not an object.`);
48
+ }
49
+ if (!Number.isInteger(entry.seq)) {
50
+ return refuse(`entries[${i}].seq is not an integer.`);
51
+ }
52
+ if (previous !== null && entry.seq <= previous) {
53
+ return refuse(
54
+ `entries[${i}].seq (${entry.seq}) is not greater than the one before it (${previous}); ` +
55
+ "send the journal in the order it was written.",
56
+ );
57
+ }
58
+ previous = entry.seq;
59
+ }
60
+
61
+ return apiCall("POST", replayPath(holderId), { entries });
62
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * `snapshot_urls` (loopctl US-52.57): `POST /api/v1/projects/:id/snapshots/urls`, presigned URLs
3
+ * for named build snapshot objects in loopctl's object store, so no machine holds a bucket
4
+ * credential. `op: "get"` runs on the session's agent key; `op: "put"` needs an orchestrator
5
+ * key, and each PUT URL signs `if-none-match: *`, which the uploader must send.
6
+ *
7
+ * The shape is checked here so an obvious mistake costs no round trip; the server owns the
8
+ * name rules and the 1..64 bound and answers 422 invalid_snapshot_object naming the first bad
9
+ * name.
10
+ */
11
+
12
+ import { uuid } from "./delivery-loop.js";
13
+
14
+ export const SNAPSHOT_OPS = ["get", "put"];
15
+ export const MAX_SNAPSHOT_OBJECTS = 64;
16
+
17
+ export function snapshotUrlsPath(projectId) {
18
+ return `/api/v1/projects/${encodeURIComponent(projectId)}/snapshots/urls`;
19
+ }
20
+
21
+ function refuse(body) {
22
+ return { error: true, status: 0, body };
23
+ }
24
+
25
+ /**
26
+ * `apiCall(method, path, body, op)` gets the op as its fourth argument so the caller picks the
27
+ * key: `get` on the agent key, `put` on the orchestrator key.
28
+ */
29
+ export async function snapshotUrls({ project_id, op, objects } = {}, { apiCall } = {}) {
30
+ const bad = uuid(project_id, "project_id");
31
+ if (bad) return bad;
32
+
33
+ if (!SNAPSHOT_OPS.includes(op)) {
34
+ return refuse('`op` must be "get" (agent key) or "put" (orchestrator key).');
35
+ }
36
+
37
+ if (
38
+ !Array.isArray(objects) ||
39
+ objects.length < 1 ||
40
+ objects.length > MAX_SNAPSHOT_OBJECTS ||
41
+ !objects.every((name) => typeof name === "string" && name !== "")
42
+ ) {
43
+ return refuse(
44
+ `\`objects\` must be a list of 1 to ${MAX_SNAPSHOT_OBJECTS} object names, each ` +
45
+ "`index/<40 lowercase hex>.json` or `<64 lowercase hex>.tar.zst`.",
46
+ );
47
+ }
48
+
49
+ return apiCall("POST", snapshotUrlsPath(project_id), { op, objects }, op);
50
+ }
package/lib/work-items.js CHANGED
@@ -27,10 +27,18 @@ export function notesPath(storyId) {
27
27
  return `/api/v1/stories/${encodeURIComponent(storyId)}/notes`;
28
28
  }
29
29
 
30
- /** `POST /api/v1/stories/:id/notes`: append one note. */
30
+ /**
31
+ * `POST /api/v1/stories/:id/notes`: append one note.
32
+ *
33
+ * With `journal` (lib/holder-journal.js, US-52.62) the note carries a client UUIDv7
34
+ * `event_id` from its first attempt, and a note that gets no answer from loopctl is journaled
35
+ * and answered `{queued: true, event_id}`. Its journal entry needs the claim epoch it was
36
+ * written under: `claim_epoch` when given, else the one this session last saw for the story,
37
+ * else read from the story before the write (once per story; its answer is remembered).
38
+ */
31
39
  export async function writeWorkItemNote(
32
- { story_id, section, body, idempotency_key } = {},
33
- { apiCall } = {},
40
+ { story_id, section, body, idempotency_key, claim_epoch } = {},
41
+ { apiCall, journal = null } = {},
34
42
  ) {
35
43
  const bad = uuid(story_id, "story_id");
36
44
  if (bad) return bad;
@@ -47,12 +55,43 @@ export async function writeWorkItemNote(
47
55
  return refuse("`idempotency_key` must be a string.");
48
56
  }
49
57
 
58
+ if (claim_epoch !== undefined && claim_epoch !== null && !Number.isInteger(claim_epoch)) {
59
+ return refuse("`claim_epoch` must be an integer: the epoch the claim returned.");
60
+ }
61
+
50
62
  const payload = { section, body };
51
63
  if (typeof idempotency_key === "string" && idempotency_key !== "") {
52
64
  payload.idempotency_key = idempotency_key;
53
65
  }
54
66
 
55
- return apiCall("POST", notesPath(story_id), payload);
67
+ if (!journal) return apiCall("POST", notesPath(story_id), payload);
68
+
69
+ const event_id = journal.newEventId();
70
+ payload.event_id = event_id;
71
+ const send = () => apiCall("POST", notesPath(story_id), payload);
72
+
73
+ if (!journal.active()) return send();
74
+
75
+ let epoch = Number.isInteger(claim_epoch) ? claim_epoch : journal.epochOf(story_id);
76
+ if (!Number.isInteger(epoch)) {
77
+ // One read per story: its answer is what the journal remembers. A read that gets no
78
+ // answer leaves the epoch unknown, and the write says so if it must be journaled.
79
+ const read = await apiCall("GET", `/api/v1/stories/${encodeURIComponent(story_id)}`, null);
80
+ const seen = read && !read.error && read.story && read.story.claim_epoch;
81
+ if (Number.isInteger(seen)) {
82
+ journal.rememberEpoch(story_id, seen);
83
+ epoch = seen;
84
+ }
85
+ }
86
+
87
+ return journal.write({
88
+ kind: "note",
89
+ story_id,
90
+ claim_epoch: Number.isInteger(epoch) ? epoch : null,
91
+ event_id,
92
+ payload: { section, body },
93
+ send,
94
+ });
56
95
  }
57
96
 
58
97
  /** `GET /api/v1/stories/:id/notes`: one page, oldest first, `current` on the first page. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.36.0",
3
+ "version": "3.39.0",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",