loopctl-mcp-server 3.21.0 → 3.21.2
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 +6 -9
- package/index.js +13 -22
- package/lib/custody-key.js +2 -2
- package/lib/default-key.js +17 -0
- package/lib/escalation-playbook.js +1 -1
- package/lib/holder.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,15 +95,12 @@ first and answers with `code: "insufficient_role"` and `required_roles: ["orches
|
|
|
95
95
|
which names the problem correctly.
|
|
96
96
|
|
|
97
97
|
`report_story` and `review_complete` are NOT in this table: their gates take a role RANGE
|
|
98
|
-
(`exact_role: [:agent, :orchestrator]` and `[:orchestrator, :user]`), so
|
|
99
|
-
|
|
100
|
-
`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
gate. Most agent-facing tools do name `LOOPCTL_AGENT_KEY` as their own key and so do work
|
|
105
|
-
under it alone; these two are the exception, and `story_stage` reads it explicitly for the
|
|
106
|
-
same reason. The conditional pin in the first row is that same reasoning applied to the
|
|
98
|
+
(`exact_role: [:agent, :orchestrator]` and `[:orchestrator, :user]`), so they are not pinned
|
|
99
|
+
and take the default order (`lib/default-key.js`): `LOOPCTL_API_KEY`, then their own key
|
|
100
|
+
(`LOOPCTL_ORCH_KEY`), then the session's agent key (its holder credential once registered,
|
|
101
|
+
else `LOOPCTL_AGENT_KEY`). With only `LOOPCTL_AGENT_KEY` set they therefore send the agent key
|
|
102
|
+
and loopctl's gate decides: `report_story` accepts an agent key, `review_complete` refuses it
|
|
103
|
+
403. The conditional pin in the first row is that same reasoning applied to the
|
|
107
104
|
single-role gates.
|
|
108
105
|
|
|
109
106
|
## First-time setup — provision your BYO LLM keys
|
package/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { clientContextHeader } from "./lib/client-context.js";
|
|
|
24
24
|
import { resolveClaimSessionId } from "./lib/claim-session.js";
|
|
25
25
|
import { createBranchItemOpener, openWorkItem } from "./lib/branch-item.js";
|
|
26
26
|
import { createHolderSession } from "./lib/holder.js";
|
|
27
|
+
import { resolveDefaultKey } from "./lib/default-key.js";
|
|
27
28
|
import { listWorkItemNotes, writeWorkItemNote } from "./lib/work-items.js";
|
|
28
29
|
import { execFile, execFileSync } from "node:child_process";
|
|
29
30
|
import { degradedSearchNotice } from "./lib/search-notices.js";
|
|
@@ -185,19 +186,11 @@ function getBaseUrl() {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
/**
|
|
188
|
-
* Resolve which API key to use for a request
|
|
189
|
-
*
|
|
190
|
-
* Priority:
|
|
191
|
-
* 1. LOOPCTL_API_KEY (global override — if set, always used)
|
|
192
|
-
* 2. keyOverride passed by the tool function (role-specific key)
|
|
193
|
-
* 3. LOOPCTL_ORCH_KEY (safe default for reads)
|
|
189
|
+
* Resolve which API key to use for a request: the order is `resolveDefaultKey`'s
|
|
190
|
+
* (`lib/default-key.js`), ending with this session's agent key.
|
|
194
191
|
*/
|
|
195
192
|
function resolveKey(keyOverride) {
|
|
196
|
-
return (
|
|
197
|
-
process.env.LOOPCTL_API_KEY ||
|
|
198
|
-
keyOverride ||
|
|
199
|
-
process.env.LOOPCTL_ORCH_KEY
|
|
200
|
-
);
|
|
193
|
+
return resolveDefaultKey({ env: process.env, keyOverride, agentKey });
|
|
201
194
|
}
|
|
202
195
|
|
|
203
196
|
// US-52.13: this process's session holder. Every request that used to send
|
|
@@ -283,8 +276,8 @@ async function apiCall(
|
|
|
283
276
|
) {
|
|
284
277
|
const url = `${getBaseUrl()}${path}`;
|
|
285
278
|
// `exactKey` sends `keyOverride` VERBATIM instead of consulting `resolveKey`
|
|
286
|
-
// (defined above
|
|
287
|
-
//
|
|
279
|
+
// (defined above, order in `lib/default-key.js`), where LOOPCTL_API_KEY comes
|
|
280
|
+
// before the override — so without it a global LOOPCTL_API_KEY displaces the key a
|
|
288
281
|
// tool names. Two families pass it, for two different reasons:
|
|
289
282
|
//
|
|
290
283
|
// - USER-ROLE-PINNED tools pass LOOPCTL_USER_KEY with `exactKey: true`
|
|
@@ -3600,10 +3593,10 @@ async function placeDispatch(args) {
|
|
|
3600
3593
|
}
|
|
3601
3594
|
|
|
3602
3595
|
async function storyStage(args) {
|
|
3603
|
-
// THE AGENT KEY IS EXPLICIT, like every other agent-facing tool here:
|
|
3604
|
-
//
|
|
3605
|
-
//
|
|
3606
|
-
//
|
|
3596
|
+
// THE AGENT KEY IS EXPLICIT, like every other agent-facing tool here: as the override it
|
|
3597
|
+
// comes before LOOPCTL_ORCH_KEY in `resolveKey`'s order (`lib/default-key.js`). A session
|
|
3598
|
+
// refused `stale_stage` is running on an agent key, and this read is what tells it where the
|
|
3599
|
+
// row actually is.
|
|
3607
3600
|
const key = agentKey();
|
|
3608
3601
|
|
|
3609
3602
|
return toContent(
|
|
@@ -3614,11 +3607,9 @@ async function storyStage(args) {
|
|
|
3614
3607
|
}
|
|
3615
3608
|
|
|
3616
3609
|
// US-47.7: a READ, `role: :agent` with the hierarchy, so any role's key clears the gate and
|
|
3617
|
-
// nothing is pinned.
|
|
3618
|
-
//
|
|
3619
|
-
//
|
|
3620
|
-
// OVERRIDE, not `exactKey`, so `resolveKey`'s order holds: LOOPCTL_API_KEY when set, else
|
|
3621
|
-
// LOOPCTL_AGENT_KEY, else LOOPCTL_ORCH_KEY.
|
|
3610
|
+
// nothing is pinned. The agent key is passed as this tool's own key for the reason storyStage
|
|
3611
|
+
// gives above. It is an OVERRIDE, not `exactKey`, so `resolveKey`'s order holds
|
|
3612
|
+
// (`lib/default-key.js`): LOOPCTL_API_KEY when set, else the agent key.
|
|
3622
3613
|
async function changeBindingGet(args) {
|
|
3623
3614
|
const key = agentKey();
|
|
3624
3615
|
|
package/lib/custody-key.js
CHANGED
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
* excused an assertion at the far end of the very block that disproves the claim.
|
|
28
28
|
*
|
|
29
29
|
* What the pinning IS for is an operator's expressed configuration. `resolveKey` in
|
|
30
|
-
* `index.js` reads
|
|
31
|
-
* override wins over the key the tool names. So an operator who set `LOOPCTL_ORCH_KEY`
|
|
30
|
+
* `index.js` reads LOOPCTL_API_KEY before the tool's override (`lib/default-key.js`) — the
|
|
31
|
+
* global override wins over the key the tool names. So an operator who set `LOOPCTL_ORCH_KEY`
|
|
32
32
|
* specifically for these verbs AND a `LOOPCTL_API_KEY` of some other role for everything else
|
|
33
33
|
* had the orchestrator key silently discarded on precisely the calls they set it for, and paid a
|
|
34
34
|
* round trip to learn it. Honouring it costs nothing and is what they asked for.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key a request sends when its tool pins none (`apiCall` without `exactKey`).
|
|
3
|
+
*
|
|
4
|
+
* Order: LOOPCTL_API_KEY, then the caller's override (a tool that names the agent or user
|
|
5
|
+
* key), then LOOPCTL_ORCH_KEY, then this session's agent key (its holder credential once
|
|
6
|
+
* registered, else LOOPCTL_AGENT_KEY).
|
|
7
|
+
*
|
|
8
|
+
* The last step is what lets a session that holds ONLY an agent key read at all. Without
|
|
9
|
+
* it, list_stories and every other default-key read answered "No API key configured" in a
|
|
10
|
+
* holder session, the shape the custody rule asks for (one key per process, never the
|
|
11
|
+
* implementer's and the reviewer's together). Falling back to a key the process already
|
|
12
|
+
* holds grants nothing: loopctl decides what that key's role may do, and a write it may not
|
|
13
|
+
* make is still refused there.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveDefaultKey({ env, keyOverride, agentKey }) {
|
|
16
|
+
return env.LOOPCTL_API_KEY || keyOverride || env.LOOPCTL_ORCH_KEY || agentKey() || undefined;
|
|
17
|
+
}
|
|
@@ -33,7 +33,7 @@ export const TAKE_OVER_STEPS = Object.freeze([
|
|
|
33
33
|
"If the row's run.work_left_behind is \"true\", the runner left unpushed commits on run.branch. runner_list gives the runner's host; the commits are in <repo>/.claude/worktrees/loop-story-<story_id> there. Push that branch or cherry-pick from it rather than starting over.",
|
|
34
34
|
"Do the work through the normal delivery loop in the story's repo: branch from the repo's base branch (the intake source's base_branch in intake_source_list, the trunk the runner used), tests, the review round, a PR whose body says \"Fixes #<issue>\" so GitHub closes the issue, merge on green.",
|
|
35
35
|
"Close the story: resolve_escalation {story_id, to: \"done\", reason: \"fixed by <owner/repo>#<PR>\"}. That needs LOOPCTL_USER_KEY, an operator key no dispatch minted; an interactive fleet session holds one, so the session that took the story over resolves it itself, never Mark. If the work turns out not to be wanted, use to: \"failed\" instead.",
|
|
36
|
-
"Finish the escalation handoff loopctl posted for the story on its repo channel (handoff:<repo>:escalation-<story_id>-g<N>): claim it before you start (step 1 of its body)
|
|
36
|
+
"Finish the escalation handoff loopctl posted for the story on its repo channel (handoff:<repo>:escalation-<story_id>-g<N>): claim it before you start (step 1 of its body). The resolve marks that claim done itself, so do not channel_done it afterwards (that answers 404); channel_done it only if you stop without resolving, and loopctl then posts a new generation while the story is still escalated.",
|
|
37
37
|
]);
|
|
38
38
|
|
|
39
39
|
const ALREADY_MERGED =
|
package/lib/holder.js
CHANGED
|
@@ -36,10 +36,20 @@
|
|
|
36
36
|
* prevent. A uuid minted once per process stands in when neither is set.
|
|
37
37
|
*
|
|
38
38
|
* The raw credential lives only in this process's memory and is never returned by a tool.
|
|
39
|
+
*
|
|
40
|
+
* ## A runner session registers nothing
|
|
41
|
+
*
|
|
42
|
+
* loopctl-runner launches its sessions with LOOP_MODE set, and placement already made such a
|
|
43
|
+
* session a holder (US-52.15). With LOOP_MODE present, `register()` sends nothing and the
|
|
44
|
+
* session stays on LOOPCTL_AGENT_KEY, so the branch open (lib/branch-item.js) never runs.
|
|
39
45
|
*/
|
|
40
46
|
|
|
41
47
|
import { envClaimSessionId } from "./claim-session.js";
|
|
42
48
|
|
|
49
|
+
function present(value) {
|
|
50
|
+
return typeof value === "string" && value.trim() !== "";
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
export const HOLDERS_PATH = "/api/v1/holders";
|
|
44
54
|
|
|
45
55
|
/** @param {string} id */
|
|
@@ -150,6 +160,13 @@ export function createHolderSession(deps) {
|
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
async function register() {
|
|
163
|
+
// A runner session (loopctl-runner sets LOOP_MODE) is already a holder, placed with its
|
|
164
|
+
// dispatch (US-52.15). Registering it as interactive made its branch a new work item on
|
|
165
|
+
// every heartbeat's open, which the factory then placed again (2026-11-21).
|
|
166
|
+
if (present(env.LOOP_MODE)) {
|
|
167
|
+
return { error: true, status: 0, body: "a runner session (LOOP_MODE) registers no interactive holder" };
|
|
168
|
+
}
|
|
169
|
+
|
|
153
170
|
const key = plainKey();
|
|
154
171
|
if (!key) return { error: true, status: 0, body: "LOOPCTL_AGENT_KEY is not set" };
|
|
155
172
|
|