loopctl-mcp-server 3.32.1 → 3.33.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 +11 -12
- package/index.js +344 -474
- package/lib/checkpoints.js +138 -0
- package/lib/escalation-playbook.js +0 -1
- package/lib/holder-key-file.js +1 -1
- package/lib/holder.js +4 -4
- package/lib/{claim-session.js → lock-session.js} +28 -32
- package/lib/messages.js +12 -12
- package/lib/work-item-move.js +61 -0
- package/lib/work-item-pull.js +286 -0
- package/lib/worktree-diff.js +120 -0
- package/package.json +1 -1
- package/lib/handoff.js +0 -427
package/lib/handoff.js
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One-call handoff composition (loopctl issue #528, follow-up to #517).
|
|
3
|
-
*
|
|
4
|
-
* WHY THIS EXISTS. #518 fixed the AUTHORIZATION crux behind #517 — an agent-role key
|
|
5
|
-
* can now post to a `kind: kb` channel in its own tenant, so the coordination bus is
|
|
6
|
-
* reachable for a repo with no work project. It did not fix the AFFORDANCE: creating a
|
|
7
|
-
* handoff for a brand-new repo was still `resolve_project` -> (404) -> `create_kb_scope`
|
|
8
|
-
* -> `channel_post`, with the `handoff:<anchor>` key convention documented only at the
|
|
9
|
-
* tail of `channel_post`'s description. #517 is the evidence that a path documented
|
|
10
|
-
* across six tools is not a discoverable path. `createHandoff` collapses the SENDER
|
|
11
|
-
* flow into one call.
|
|
12
|
-
*
|
|
13
|
-
* The receiver flow is deliberately NOT wrapped: `channel_handoffs` -> `channel_claim`
|
|
14
|
-
* -> `channel_done` is already one obvious call per step, and each is a distinct
|
|
15
|
-
* decision the agent must make explicitly (claiming is the anti-double-work gate).
|
|
16
|
-
*
|
|
17
|
-
* SINGLE SOURCE OF TRUTH. All composition/derivation logic lives here so the unit
|
|
18
|
-
* suite exercises the code the server ships (the repo convention — see
|
|
19
|
-
* lib/http-helpers.js). The three HTTP calls are INJECTED (`deps`), so every branch
|
|
20
|
-
* below is testable with fakes and no network.
|
|
21
|
-
*
|
|
22
|
-
* NEVER attempts `create_project`. A work project is human-anchor-gated by design, so on an
|
|
23
|
-
* agent-rooted tenant it cannot succeed and the attempt is a wasted round trip — that is the
|
|
24
|
-
* dead end #517 hit. NOT because the 403 is unhelpful: an earlier draft of this comment said
|
|
25
|
-
* it "reads as a wall rather than a redirect", and #505 is precisely what stopped that being
|
|
26
|
-
* true. `ProjectController` mounts `RequireHumanAnchor` on `:create` with an `alternative:`
|
|
27
|
-
* naming `create_kb_scope` (`lib/loopctl_web/controllers/project_controller.ex:46-58`), which
|
|
28
|
-
* the plug renders as `remediation.agent_native_alternative`
|
|
29
|
-
* (`lib/loopctl_web/plugs/require_human_anchor.ex:166-169`), and it mounts that tier gate
|
|
30
|
-
* BEFORE `RequireRole` (`:62`) so an agent-role key reads THAT 403 rather than
|
|
31
|
-
* `insufficient_role`. The 403 points at the kb scope. This code goes straight there because
|
|
32
|
-
* the round trip buys nothing, not because the answer would confuse anyone.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
export const HANDOFF_KEY_PREFIX = "handoff:";
|
|
36
|
-
|
|
37
|
-
// Mirrors Loopctl.Coordination.ChannelPost's @key_max_length
|
|
38
|
-
// (lib/loopctl/coordination/channel_post.ex:98). Validated HERE so an over-long anchor
|
|
39
|
-
// gets a specific, actionable client error instead of a server 422 the agent has to
|
|
40
|
-
// reverse-engineer.
|
|
41
|
-
export const KEY_MAX_BYTES = 200;
|
|
42
|
-
|
|
43
|
-
// Mirrors Loopctl.Projects.Project's slug rules (lib/loopctl/projects/project.ex:31,137):
|
|
44
|
-
// /^[a-z0-9][a-z0-9_-]*[a-z0-9]$/, 2..63 chars. A derived slug that cannot satisfy these
|
|
45
|
-
// is reported as underivable rather than sent on to fail server-side.
|
|
46
|
-
export const SLUG_MIN_LENGTH = 2;
|
|
47
|
-
export const SLUG_MAX_LENGTH = 63;
|
|
48
|
-
|
|
49
|
-
function byteLength(value) {
|
|
50
|
-
return Buffer.byteLength(value, "utf8");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Codepoint check rather than a regex literal: NUL and C0/DEL control characters are
|
|
54
|
-
// rejected server-side, and writing the range as an escape-laden regex is exactly the
|
|
55
|
-
// kind of literal that gets mangled in transit. 0x00-0x1f plus 0x7f.
|
|
56
|
-
function hasControlChars(value) {
|
|
57
|
-
for (const char of value) {
|
|
58
|
-
const code = char.codePointAt(0);
|
|
59
|
-
if (code < 0x20 || code === 0x7f) return true;
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Shape a failure the way `apiCall` does (`{ error: true, status, body }`) so
|
|
66
|
-
* `toContent` flags it as an MCP error, plus a `stage` naming WHICH step failed
|
|
67
|
-
* (validate | resolve | create_channel | post). The stage is the whole point: "422 on
|
|
68
|
-
* post" and "422 on create" send an agent to completely different places, and #517's
|
|
69
|
-
* core complaint was an error that pointed nowhere.
|
|
70
|
-
*/
|
|
71
|
-
function failure(stage, status, body, extra = {}) {
|
|
72
|
-
return { error: true, stage, status, body, ...extra };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Build the channel key for a handoff anchor.
|
|
77
|
-
*
|
|
78
|
-
* Idempotent on the prefix: an agent that passes "handoff:repo#812" gets that key back
|
|
79
|
-
* unchanged rather than "handoff:handoff:repo#812". Returns `{ key, anchor }` or
|
|
80
|
-
* `{ error }`.
|
|
81
|
-
*
|
|
82
|
-
* SCOPE OF THE KEY'S DEDUP: the keyed slot is unique on
|
|
83
|
-
* `(tenant_id, project_id, agent_id, session_id, key)`
|
|
84
|
-
* (`channel_posts_session_key_uidx`, priv/repo/migrations/20260718000000_*.exs:22), so a
|
|
85
|
-
* repeat post refreshes the slot IN PLACE only within the SAME session. A different
|
|
86
|
-
* session posting the same anchor appends its OWN handoff post — by design (two sessions
|
|
87
|
-
* genuinely have two working states), but it means the anchor is not a global singleton.
|
|
88
|
-
* Say "same-session retry" and never plain "idempotent" when documenting this.
|
|
89
|
-
*/
|
|
90
|
-
export function handoffKey(anchor) {
|
|
91
|
-
if (typeof anchor !== "string" || !anchor.trim()) {
|
|
92
|
-
return {
|
|
93
|
-
error:
|
|
94
|
-
"anchor is required: a stable, durable id for this handoff (e.g. " +
|
|
95
|
-
"'home_care_billing#812' or 'claude-harness-kit:review-vs-goal'). It becomes the " +
|
|
96
|
-
"channel key 'handoff:<anchor>', which is what makes the handoff discoverable to " +
|
|
97
|
-
"channel_handoffs, claimable via channel_claim, and idempotent on retry.",
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const trimmed = anchor.trim();
|
|
102
|
-
|
|
103
|
-
// NUL and control characters are rejected server-side; catch them here so the message
|
|
104
|
-
// names the offending field.
|
|
105
|
-
if (hasControlChars(trimmed)) {
|
|
106
|
-
return { error: "anchor must not contain control characters or NUL bytes." };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const key = trimmed.startsWith(HANDOFF_KEY_PREFIX)
|
|
110
|
-
? trimmed
|
|
111
|
-
: `${HANDOFF_KEY_PREFIX}${trimmed}`;
|
|
112
|
-
|
|
113
|
-
if (byteLength(key) > KEY_MAX_BYTES) {
|
|
114
|
-
return {
|
|
115
|
-
error:
|
|
116
|
-
`anchor is too long: the channel key '${HANDOFF_KEY_PREFIX}<anchor>' must be at ` +
|
|
117
|
-
`most ${KEY_MAX_BYTES} bytes (this one is ${byteLength(key)}). Use a short stable ` +
|
|
118
|
-
"id (repo#issue) and put the detail in the durable home.",
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return { key, anchor: key.slice(HANDOFF_KEY_PREFIX.length) };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* The repo basename from a git remote URL or a bare owner/repo, with original casing
|
|
127
|
-
* preserved; `deriveSlug` lowercases it.
|
|
128
|
-
*
|
|
129
|
-
* Handles: git@github.com:owner/repo.git, https://github.com/owner/repo(/),
|
|
130
|
-
* ssh://git@host/owner/repo.git, bare owner/repo, and trailing query/fragment.
|
|
131
|
-
*/
|
|
132
|
-
export function repoBasename(repoUrl) {
|
|
133
|
-
if (typeof repoUrl !== "string") return null;
|
|
134
|
-
|
|
135
|
-
let value = repoUrl.trim();
|
|
136
|
-
if (!value) return null;
|
|
137
|
-
|
|
138
|
-
value = value.split(/[?#]/)[0]; // drop any query/fragment
|
|
139
|
-
value = value.replace(/\/+$/, ""); // drop trailing slashes
|
|
140
|
-
value = value.replace(/\.git$/i, ""); // drop the .git suffix
|
|
141
|
-
|
|
142
|
-
// Split on both / and : so the scp-style git@host:owner/repo form yields "repo".
|
|
143
|
-
const segments = value.split(/[/:]/).filter(Boolean);
|
|
144
|
-
const basename = segments.pop();
|
|
145
|
-
return basename || null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Derive a server-valid project slug from a repo URL.
|
|
150
|
-
*
|
|
151
|
-
* DETERMINISM IS THE POINT (#528 AC4): the created scope must be re-resolvable by the
|
|
152
|
-
* same derivation on a retry, or a repeated handoff would create a second scope and burn
|
|
153
|
-
* the tenant's max_projects budget. The slug is the repo basename lowercased with `_` KEPT
|
|
154
|
-
* (#1038: repo home_care_billing -> slug home_care_billing); only other non-alphanumeric
|
|
155
|
-
* runs become `-`. The server resolves a slug on its folded form too, so a channel still
|
|
156
|
-
* stored under the old hyphenated slug is found rather than duplicated.
|
|
157
|
-
*
|
|
158
|
-
* Returns null when nothing valid can be derived — the caller then asks for an explicit
|
|
159
|
-
* slug instead of sending a doomed create.
|
|
160
|
-
*/
|
|
161
|
-
export function deriveSlug(repoUrl) {
|
|
162
|
-
const basename = repoBasename(repoUrl);
|
|
163
|
-
if (!basename) return null;
|
|
164
|
-
|
|
165
|
-
const slug = basename
|
|
166
|
-
.toLowerCase()
|
|
167
|
-
.replace(/[^a-z0-9_]+/g, "-")
|
|
168
|
-
.replace(/-+/g, "-")
|
|
169
|
-
.replace(/^[-_]+|[-_]+$/g, "")
|
|
170
|
-
.slice(0, SLUG_MAX_LENGTH)
|
|
171
|
-
// A mid-string separator can land last after truncation; the server's format regex
|
|
172
|
-
// requires an alphanumeric final character.
|
|
173
|
-
.replace(/[-_]+$/, "");
|
|
174
|
-
|
|
175
|
-
return slug.length >= SLUG_MIN_LENGTH ? slug : null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Extract the project object from a resolve/create response (`{ project: {...} }`). */
|
|
179
|
-
function projectOf(result) {
|
|
180
|
-
return result?.project ?? null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function channelSummary(project, { created, raced = false, source }) {
|
|
184
|
-
return {
|
|
185
|
-
project_id: project?.id ?? null,
|
|
186
|
-
kind: project?.kind ?? null,
|
|
187
|
-
slug: project?.slug ?? null,
|
|
188
|
-
name: project?.name ?? null,
|
|
189
|
-
created,
|
|
190
|
-
...(raced && { raced: true }),
|
|
191
|
-
source,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Remediation for a failed POST. A 422 here is the one #517 called out as
|
|
197
|
-
* non-actionable: the server deliberately returns a single
|
|
198
|
-
* "project_id does not exist or does not belong to your tenant" for
|
|
199
|
-
* not-a-member / not-eligible / truly-absent so it leaks no existence oracle. That is
|
|
200
|
-
* correct server behavior AND a dead end for the caller, so name the possibilities
|
|
201
|
-
* client-side, where we already know which channel we resolved.
|
|
202
|
-
*/
|
|
203
|
-
function postRemediation(status, channel) {
|
|
204
|
-
if (status !== 422) return null;
|
|
205
|
-
|
|
206
|
-
const workProject =
|
|
207
|
-
channel?.kind === "work"
|
|
208
|
-
? "The channel is a WORK project, so the most likely cause is that you are not a " +
|
|
209
|
-
"member of it: channel writes on a work project require an agent assigned to a " +
|
|
210
|
-
"story there. The server's 'does not exist or does not belong to your tenant' " +
|
|
211
|
-
"wording is deliberately non-specific (it must not leak an existence oracle), so " +
|
|
212
|
-
"do NOT read it as the project being missing. Fix it with a membership story in " +
|
|
213
|
-
"THIS project, never a second channel: create_story, then contract_story, " +
|
|
214
|
-
"claim_story, start_story and request_review, and leave it there (verify, unclaim " +
|
|
215
|
-
"or release clears the assignee). Then call handoff again. "
|
|
216
|
-
: "";
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
workProject +
|
|
220
|
-
"Otherwise check the payload limits: body is capped at 16 KB, refs at ~50 items, and a " +
|
|
221
|
-
"secret-shaped string in the body or any ref field is rejected outright."
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Remediation text for a failed kb-scope create. The two realistic causes need
|
|
227
|
-
* different next moves, and neither is guessable from the raw status.
|
|
228
|
-
*/
|
|
229
|
-
function createRemediation(status) {
|
|
230
|
-
if (status === 403) {
|
|
231
|
-
return (
|
|
232
|
-
"The kb-scope create was refused. This is the agent-native path (#331/#505), so a " +
|
|
233
|
-
"403 here is NOT the create_project tier wall — check that the key is an agent-role " +
|
|
234
|
-
"key for this tenant (get_tenant reports capabilities.kb_project_scopes)."
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
if (status === 422) {
|
|
238
|
-
return (
|
|
239
|
-
"The kb-scope create was rejected. Most likely the tenant is at its max_projects cap " +
|
|
240
|
-
"(free a slot with archive_kb_scope) or the derived slug is invalid — pass an explicit " +
|
|
241
|
-
"slug. Re-resolution already ran, so this is not a duplicate-slug race."
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Resolve the repo's channel, creating a kb scope when none exists.
|
|
249
|
-
*
|
|
250
|
-
* Returns a channel summary, or an `apiCall`-shaped failure.
|
|
251
|
-
*/
|
|
252
|
-
async function ensureChannel(
|
|
253
|
-
{ project_id, repo_url, slug, description, tech_stack, create_channel },
|
|
254
|
-
{ resolveProject, createKbScope },
|
|
255
|
-
) {
|
|
256
|
-
// An explicit project_id is taken at face value — the caller already resolved it, and
|
|
257
|
-
// channel_post is the authority on whether it is writable.
|
|
258
|
-
if (project_id) {
|
|
259
|
-
return channelSummary({ id: project_id }, { created: false, source: "explicit" });
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (!repo_url && !slug) {
|
|
263
|
-
return failure(
|
|
264
|
-
"validate",
|
|
265
|
-
0,
|
|
266
|
-
"Supply one of: repo_url (the repo's git remote — the usual case, run " +
|
|
267
|
-
"'git remote get-url origin'), slug, or an already-known project_id.",
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const resolved = await resolveProject({ slug, repo_url });
|
|
272
|
-
if (resolved?.error !== true) {
|
|
273
|
-
const project = projectOf(resolved);
|
|
274
|
-
if (project?.id) {
|
|
275
|
-
return channelSummary(project, { created: false, source: "resolved" });
|
|
276
|
-
}
|
|
277
|
-
// 2xx with no project is not something any current server version returns; treat it
|
|
278
|
-
// as a resolve failure rather than silently creating a duplicate scope.
|
|
279
|
-
return failure(
|
|
280
|
-
"resolve",
|
|
281
|
-
0,
|
|
282
|
-
"resolve_project returned success but no project — refusing to create a channel on " +
|
|
283
|
-
"an ambiguous resolve. Pass project_id explicitly.",
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Only a genuine "no project for this repo" is recoverable by creating one. A 401/403/
|
|
288
|
-
// 5xx means the resolve itself failed; creating a scope would paper over it.
|
|
289
|
-
if (resolved.status !== 404) {
|
|
290
|
-
return failure("resolve", resolved.status, resolved.body);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (create_channel === false) {
|
|
294
|
-
return failure(
|
|
295
|
-
"resolve",
|
|
296
|
-
404,
|
|
297
|
-
`No loopctl project exists for this repo and create_channel is false, so no channel ` +
|
|
298
|
-
`was created. Re-run with create_channel omitted (it defaults to true) to create a ` +
|
|
299
|
-
`kb scope for it, or create one explicitly with create_kb_scope.`,
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const createSlug = slug || deriveSlug(repo_url);
|
|
304
|
-
if (!createSlug) {
|
|
305
|
-
return failure(
|
|
306
|
-
"validate",
|
|
307
|
-
0,
|
|
308
|
-
`Could not derive a valid project slug from repo_url ${JSON.stringify(repo_url)} ` +
|
|
309
|
-
`(needs ${SLUG_MIN_LENGTH}-${SLUG_MAX_LENGTH} chars of lowercase alphanumerics and ` +
|
|
310
|
-
`hyphens or underscores). Pass an explicit slug.`,
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const created = await createKbScope({
|
|
315
|
-
// A channel's name IS its slug (#1038): the server refuses a kb scope whose name
|
|
316
|
-
// differs, so the tool takes no `name` at all.
|
|
317
|
-
name: createSlug,
|
|
318
|
-
slug: createSlug,
|
|
319
|
-
repo_url,
|
|
320
|
-
description,
|
|
321
|
-
tech_stack,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
if (created?.error === true) {
|
|
325
|
-
// A concurrent session may have created the same scope between our resolve and our
|
|
326
|
-
// create (the slug is deterministic, so both sessions target the same row). Re-resolve
|
|
327
|
-
// before reporting failure so a race converges on ONE scope instead of erroring.
|
|
328
|
-
const reresolved = await resolveProject({ slug: createSlug, repo_url });
|
|
329
|
-
const raceWinner = reresolved?.error !== true ? projectOf(reresolved) : null;
|
|
330
|
-
if (raceWinner?.id) {
|
|
331
|
-
return channelSummary(raceWinner, { created: false, raced: true, source: "resolved" });
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const remediation = createRemediation(created.status);
|
|
335
|
-
return failure("create_channel", created.status, created.body, {
|
|
336
|
-
attempted_slug: createSlug,
|
|
337
|
-
...(remediation && { remediation }),
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const project = projectOf(created);
|
|
342
|
-
if (!project?.id) {
|
|
343
|
-
return failure(
|
|
344
|
-
"create_channel",
|
|
345
|
-
0,
|
|
346
|
-
"create_kb_scope returned success but no project id; cannot post the handoff.",
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return channelSummary(project, { created: true, source: "created" });
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Compose the whole sender-side handoff: resolve-or-create the channel, then post the
|
|
355
|
-
* correctly-keyed pointer.
|
|
356
|
-
*
|
|
357
|
-
* `deps` injects the three raw HTTP calls (`resolveProject`, `createKbScope`,
|
|
358
|
-
* `channelPost`), each returning an `apiCall`-shaped result.
|
|
359
|
-
*/
|
|
360
|
-
export async function createHandoff(args = {}, deps = {}) {
|
|
361
|
-
const {
|
|
362
|
-
anchor,
|
|
363
|
-
body,
|
|
364
|
-
project_id,
|
|
365
|
-
repo_url,
|
|
366
|
-
slug,
|
|
367
|
-
description,
|
|
368
|
-
tech_stack,
|
|
369
|
-
to_host,
|
|
370
|
-
to_capability,
|
|
371
|
-
refs,
|
|
372
|
-
create_channel = true,
|
|
373
|
-
} = args;
|
|
374
|
-
|
|
375
|
-
const keyed = handoffKey(anchor);
|
|
376
|
-
if (keyed.error) return failure("validate", 0, keyed.error);
|
|
377
|
-
|
|
378
|
-
if (typeof body !== "string" || !body.trim()) {
|
|
379
|
-
return failure(
|
|
380
|
-
"validate",
|
|
381
|
-
0,
|
|
382
|
-
"body is required, and it is a POINTER not a payload: a one-line TL;DR plus where the " +
|
|
383
|
-
"full context lives (a GitHub issue/PR comment, a docs/ file, or a knowledge " +
|
|
384
|
-
"article). The receiver sees only a bounded preview of it.",
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const channel = await ensureChannel(
|
|
389
|
-
{ project_id, repo_url, slug, description, tech_stack, create_channel },
|
|
390
|
-
deps,
|
|
391
|
-
);
|
|
392
|
-
if (channel?.error === true) return channel;
|
|
393
|
-
|
|
394
|
-
const posted = await deps.channelPost({
|
|
395
|
-
project_id: channel.project_id,
|
|
396
|
-
key: keyed.key,
|
|
397
|
-
body,
|
|
398
|
-
refs,
|
|
399
|
-
to_host,
|
|
400
|
-
to_capability,
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
if (posted?.error === true) {
|
|
404
|
-
// Report the channel we resolved/created alongside the post failure — otherwise a
|
|
405
|
-
// freshly created scope looks like it never happened and the retry creates another.
|
|
406
|
-
const remediation = postRemediation(posted.status, channel);
|
|
407
|
-
return failure("post", posted.status, posted.body, {
|
|
408
|
-
channel,
|
|
409
|
-
...(remediation && { remediation }),
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
handoff: {
|
|
415
|
-
key: keyed.key,
|
|
416
|
-
anchor: keyed.anchor,
|
|
417
|
-
channel,
|
|
418
|
-
post: posted?.post ?? posted,
|
|
419
|
-
meta: posted?.meta,
|
|
420
|
-
receiver_next: [
|
|
421
|
-
`channel_handoffs({ project_id: "${channel.project_id}", host: "<their hostname>" })`,
|
|
422
|
-
`channel_claim({ project_id: "${channel.project_id}", ref: "${keyed.key}" })`,
|
|
423
|
-
`channel_done({ project_id: "${channel.project_id}", ref: "${keyed.key}" })`,
|
|
424
|
-
],
|
|
425
|
-
},
|
|
426
|
-
};
|
|
427
|
-
}
|