@indigoai-us/hq-cli 5.168.0 → 5.169.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/CHANGELOG.md +9 -0
- package/dist/commands/lanes.js +144 -31
- package/dist/lib/lanes/mesh-events.d.ts +4 -0
- package/dist/lib/lanes/mesh-events.js +72 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.169.0] — 2026-09-24
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- `hq lanes create` and `hq lanes story <add|start|block|done>` keep story work
|
|
10
|
+
local when an existing Work Mesh Board rejects a missing story. The
|
|
11
|
+
`story_warning` identifies the project and story and suggests:
|
|
12
|
+
`hq mesh project ensure <projectId> --company <slug> --stories-file prd.json`.
|
|
13
|
+
|
|
5
14
|
## [5.168.0] — 2026-09-24
|
|
6
15
|
|
|
7
16
|
### Fixed
|
package/dist/commands/lanes.js
CHANGED
|
@@ -1340,13 +1340,23 @@ async function emitLaneTerminalStateSoft(ctx, lane) {
|
|
|
1340
1340
|
}
|
|
1341
1341
|
}
|
|
1342
1342
|
async function emitLaneStartedForStories(ctx, company, lane, threadId) {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1343
|
+
let ready = lane;
|
|
1344
|
+
if (ctx.mesh.ensureLaneThread) {
|
|
1345
|
+
try {
|
|
1346
|
+
ready = await ensureLaneThreadRecord(ctx, lane, lane.project_id, lane.story_id, "running");
|
|
1347
|
+
}
|
|
1348
|
+
catch (err) {
|
|
1349
|
+
const warning = storyNotOnBoardWarning(err);
|
|
1350
|
+
if (warning !== undefined)
|
|
1351
|
+
return [warning];
|
|
1352
|
+
throw err;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1346
1355
|
const stableThreadId = ready.thread_id ?? threadId;
|
|
1347
1356
|
if (!stableThreadId)
|
|
1348
|
-
return;
|
|
1357
|
+
return [];
|
|
1349
1358
|
const failures = [];
|
|
1359
|
+
const warnings = [];
|
|
1350
1360
|
for (const story of laneStories(ready)) {
|
|
1351
1361
|
try {
|
|
1352
1362
|
await emitLaneMeshEvent(ctx, company, stableThreadId, "lane_started", {
|
|
@@ -1355,14 +1365,59 @@ async function emitLaneStartedForStories(ctx, company, lane, threadId) {
|
|
|
1355
1365
|
project_id: story.project_id,
|
|
1356
1366
|
story_id: story.story_id,
|
|
1357
1367
|
});
|
|
1358
|
-
await ctx.mesh.patchStoryStatus(company, story.project_id, story.story_id, "in_progress");
|
|
1359
1368
|
}
|
|
1360
1369
|
catch (err) {
|
|
1370
|
+
const warning = storyNotOnBoardWarning(err);
|
|
1371
|
+
if (warning !== undefined) {
|
|
1372
|
+
warnings.push(warning);
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1361
1375
|
failures.push(err);
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
try {
|
|
1379
|
+
await ctx.mesh.patchStoryStatus(company, story.project_id, story.story_id, "in_progress");
|
|
1380
|
+
}
|
|
1381
|
+
catch (err) {
|
|
1382
|
+
const warning = storyNotOnBoardWarning(err);
|
|
1383
|
+
if (warning !== undefined)
|
|
1384
|
+
warnings.push(warning);
|
|
1385
|
+
else
|
|
1386
|
+
failures.push(err);
|
|
1362
1387
|
}
|
|
1363
1388
|
}
|
|
1364
1389
|
if (failures.length > 0)
|
|
1365
1390
|
throw failures[0];
|
|
1391
|
+
return warnings;
|
|
1392
|
+
}
|
|
1393
|
+
async function assertStoriesOnBoard(ctx, company, projectId, storyIds) {
|
|
1394
|
+
const check = ctx.mesh.assertProjectStoriesOnBoard;
|
|
1395
|
+
if (!check) {
|
|
1396
|
+
throw new LanesError("story_board_check_unavailable", "Cannot confirm stories are on the Work Mesh Board; refusing to write lane state", { project_id: projectId, story_id: storyIds[0] ?? null });
|
|
1397
|
+
}
|
|
1398
|
+
await check.call(ctx.mesh, company, projectId, storyIds);
|
|
1399
|
+
}
|
|
1400
|
+
function storyNotOnBoardWarning(err) {
|
|
1401
|
+
return isLanesError(err) && err.error === "story_not_on_board"
|
|
1402
|
+
? err.message
|
|
1403
|
+
: undefined;
|
|
1404
|
+
}
|
|
1405
|
+
function combinedStoryWarning(lane, additional = []) {
|
|
1406
|
+
const warnings = [storyWarning(lane), ...additional]
|
|
1407
|
+
.filter((warning) => warning !== undefined && warning.trim().length > 0);
|
|
1408
|
+
return [...new Set(warnings)].join(" ") || null;
|
|
1409
|
+
}
|
|
1410
|
+
async function storyBoardWarning(ctx, company, projectId, storyIds) {
|
|
1411
|
+
try {
|
|
1412
|
+
await assertStoriesOnBoard(ctx, company, projectId, storyIds);
|
|
1413
|
+
return undefined;
|
|
1414
|
+
}
|
|
1415
|
+
catch (err) {
|
|
1416
|
+
const warning = storyNotOnBoardWarning(err);
|
|
1417
|
+
if (warning !== undefined)
|
|
1418
|
+
return warning;
|
|
1419
|
+
throw err;
|
|
1420
|
+
}
|
|
1366
1421
|
}
|
|
1367
1422
|
export const PICKUP_TERMINAL_REASONS = [
|
|
1368
1423
|
"account_not_logged_in",
|
|
@@ -1631,6 +1686,12 @@ async function runCreate(ctx, opts) {
|
|
|
1631
1686
|
}
|
|
1632
1687
|
const seniorCompany = companyOfSenior(hqRoot, senior, ctx);
|
|
1633
1688
|
assertSameTenant(company, senior, seniorCompany);
|
|
1689
|
+
const createStoryWarnings = [];
|
|
1690
|
+
if (meshCompany) {
|
|
1691
|
+
const warning = await storyBoardWarning(ctx, meshCompany, project, storyIds);
|
|
1692
|
+
if (warning !== undefined)
|
|
1693
|
+
createStoryWarnings.push(warning);
|
|
1694
|
+
}
|
|
1634
1695
|
let resolvedWorker;
|
|
1635
1696
|
if (opts.worker) {
|
|
1636
1697
|
resolvedWorker = resolveLaneWorker(hqRoot, opts.worker, company?.slug);
|
|
@@ -2079,19 +2140,25 @@ async function runCreate(ctx, opts) {
|
|
|
2079
2140
|
try {
|
|
2080
2141
|
lane = await ensureLaneThreadRecord(ctx, lane);
|
|
2081
2142
|
}
|
|
2082
|
-
catch {
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
state: "failed",
|
|
2087
|
-
queued_reason: undefined,
|
|
2088
|
-
terminal_reason: "mesh_thread_registration_failed",
|
|
2089
|
-
}));
|
|
2143
|
+
catch (err) {
|
|
2144
|
+
const warning = storyNotOnBoardWarning(err);
|
|
2145
|
+
if (warning !== undefined) {
|
|
2146
|
+
createStoryWarnings.push(warning);
|
|
2090
2147
|
}
|
|
2091
|
-
|
|
2092
|
-
|
|
2148
|
+
else {
|
|
2149
|
+
try {
|
|
2150
|
+
lane = casUpdateLane(ctx.hqRoot(), lane.lane_id, (current) => ({
|
|
2151
|
+
...current,
|
|
2152
|
+
state: "failed",
|
|
2153
|
+
queued_reason: undefined,
|
|
2154
|
+
terminal_reason: "mesh_thread_registration_failed",
|
|
2155
|
+
}));
|
|
2156
|
+
}
|
|
2157
|
+
catch {
|
|
2158
|
+
throw new LanesError("mesh_thread_registration_failed", `Work Mesh lane registration failed for ${lane.lane_id}, and its local record could not be marked terminal.`, { lane_id: lane.lane_id });
|
|
2159
|
+
}
|
|
2160
|
+
throw new LanesError("mesh_thread_registration_failed", `Work Mesh lane registration failed; lane ${lane.lane_id} was marked failed.`, { lane_id: lane.lane_id, state: lane.state });
|
|
2093
2161
|
}
|
|
2094
|
-
throw new LanesError("mesh_thread_registration_failed", `Work Mesh lane registration failed; lane ${lane.lane_id} was marked failed.`, { lane_id: lane.lane_id, state: lane.state });
|
|
2095
2162
|
}
|
|
2096
2163
|
}
|
|
2097
2164
|
// Thread registration runs after persistence; anchor the reservation after
|
|
@@ -2137,8 +2204,9 @@ async function runCreate(ctx, opts) {
|
|
|
2137
2204
|
runCompaction: ctx.runCompaction,
|
|
2138
2205
|
locateTranscript: ctx.locateTranscript,
|
|
2139
2206
|
});
|
|
2140
|
-
if (meshCompany)
|
|
2141
|
-
await emitLaneStartedForStories(ctx, meshCompany, started, started.thread_id);
|
|
2207
|
+
if (meshCompany) {
|
|
2208
|
+
createStoryWarnings.push(...await emitLaneStartedForStories(ctx, meshCompany, started, started.thread_id));
|
|
2209
|
+
}
|
|
2142
2210
|
}
|
|
2143
2211
|
else if (outpostId) {
|
|
2144
2212
|
started = await dispatchCreatedOutpostLane(ctx, {
|
|
@@ -2174,7 +2242,7 @@ async function runCreate(ctx, opts) {
|
|
|
2174
2242
|
project_id: started.project_id,
|
|
2175
2243
|
story_id: started.story_id,
|
|
2176
2244
|
stories: laneStories(started),
|
|
2177
|
-
story_warning:
|
|
2245
|
+
story_warning: combinedStoryWarning(started, createStoryWarnings),
|
|
2178
2246
|
thread_id: started.thread_id ?? null,
|
|
2179
2247
|
senior: started.senior,
|
|
2180
2248
|
depth: started.depth,
|
|
@@ -4138,6 +4206,17 @@ async function ensureStoryThread(ctx, lane, projectId, storyId = lane.story_id)
|
|
|
4138
4206
|
return lane;
|
|
4139
4207
|
return ensureLaneThreadRecord(ctx, lane, projectId, storyId);
|
|
4140
4208
|
}
|
|
4209
|
+
async function ensureStoryThreadForTransition(ctx, lane, projectId, storyId) {
|
|
4210
|
+
try {
|
|
4211
|
+
return { lane: await ensureStoryThread(ctx, lane, projectId, storyId) };
|
|
4212
|
+
}
|
|
4213
|
+
catch (err) {
|
|
4214
|
+
const warning = storyNotOnBoardWarning(err);
|
|
4215
|
+
if (warning === undefined)
|
|
4216
|
+
throw err;
|
|
4217
|
+
return { lane, warning };
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4141
4220
|
async function ensureLaneThreadRecord(ctx, lane, projectId = lane.project_id, storyId = lane.story_id, laneStatus = lane.state) {
|
|
4142
4221
|
const company = lane.mesh_company ?? lane.company;
|
|
4143
4222
|
if (!company)
|
|
@@ -4185,8 +4264,12 @@ function sameCommittedStory(current, expected, projectId, storyId) {
|
|
|
4185
4264
|
async function commitStoryTransition(ctx, before, next, projectId, storyId, event, status, payload = {}) {
|
|
4186
4265
|
try {
|
|
4187
4266
|
await emitStoryTransition(ctx, next, projectId, storyId, event, status, payload);
|
|
4267
|
+
return undefined;
|
|
4188
4268
|
}
|
|
4189
4269
|
catch (err) {
|
|
4270
|
+
const warning = storyNotOnBoardWarning(err);
|
|
4271
|
+
if (warning !== undefined)
|
|
4272
|
+
return warning;
|
|
4190
4273
|
try {
|
|
4191
4274
|
const current = readLane(ctx.hqRoot(), next.lane_id);
|
|
4192
4275
|
if (!sameCommittedStory(current, next, projectId, storyId)) {
|
|
@@ -4231,14 +4314,26 @@ async function runStoryAdd(ctx, laneId, storyId, opts) {
|
|
|
4231
4314
|
const normalizedStoryId = storyId.trim();
|
|
4232
4315
|
if (!normalizedStoryId)
|
|
4233
4316
|
throw new LanesError("missing_story", "<story-id> is required", {});
|
|
4317
|
+
const company = lane.mesh_company ?? lane.company;
|
|
4318
|
+
const warnings = [];
|
|
4319
|
+
if (company) {
|
|
4320
|
+
const warning = await storyBoardWarning(ctx, company, projectId, [normalizedStoryId]);
|
|
4321
|
+
if (warning !== undefined)
|
|
4322
|
+
warnings.push(warning);
|
|
4323
|
+
}
|
|
4234
4324
|
const at = ctx.now().toISOString();
|
|
4235
|
-
|
|
4325
|
+
const thread = await ensureStoryThreadForTransition(ctx, lane, projectId, normalizedStoryId);
|
|
4326
|
+
lane = thread.lane;
|
|
4327
|
+
if (thread.warning !== undefined)
|
|
4328
|
+
warnings.push(thread.warning);
|
|
4236
4329
|
const before = lane;
|
|
4237
4330
|
const next = casUpdateLane(hqRoot, laneId, (current) => {
|
|
4238
4331
|
assertLaneRunsHereForOperatorMutation(ctx, current, "update story status for");
|
|
4239
4332
|
return addCarriedStory(current, projectId, normalizedStoryId, at);
|
|
4240
4333
|
});
|
|
4241
|
-
await commitStoryTransition(ctx, before, next, projectId, normalizedStoryId, "lane_started", "in_progress");
|
|
4334
|
+
const transitionWarning = await commitStoryTransition(ctx, before, next, projectId, normalizedStoryId, "lane_started", "in_progress");
|
|
4335
|
+
if (transitionWarning !== undefined)
|
|
4336
|
+
warnings.push(transitionWarning);
|
|
4242
4337
|
const finalLane = readLane(hqRoot, laneId);
|
|
4243
4338
|
printJson({
|
|
4244
4339
|
ok: true,
|
|
@@ -4247,7 +4342,7 @@ async function runStoryAdd(ctx, laneId, storyId, opts) {
|
|
|
4247
4342
|
project_id: projectId,
|
|
4248
4343
|
story_id: normalizedStoryId,
|
|
4249
4344
|
status: "in_progress",
|
|
4250
|
-
story_warning:
|
|
4345
|
+
story_warning: combinedStoryWarning(finalLane, warnings),
|
|
4251
4346
|
lane: finalLane,
|
|
4252
4347
|
});
|
|
4253
4348
|
}
|
|
@@ -4264,15 +4359,21 @@ async function runStoryStart(ctx, laneId, storyId, opts) {
|
|
|
4264
4359
|
});
|
|
4265
4360
|
}
|
|
4266
4361
|
const at = ctx.now().toISOString();
|
|
4267
|
-
|
|
4362
|
+
const warnings = [];
|
|
4363
|
+
const thread = await ensureStoryThreadForTransition(ctx, lane, target.projectId, target.storyId);
|
|
4364
|
+
lane = thread.lane;
|
|
4365
|
+
if (thread.warning !== undefined)
|
|
4366
|
+
warnings.push(thread.warning);
|
|
4268
4367
|
const before = lane;
|
|
4269
4368
|
const next = casUpdateLane(hqRoot, laneId, (current) => {
|
|
4270
4369
|
assertLaneRunsHereForOperatorMutation(ctx, current, "update story status for");
|
|
4271
4370
|
return updateCarriedStory(current, target.projectId, target.storyId, "in_progress", at);
|
|
4272
4371
|
});
|
|
4273
|
-
await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_started", "in_progress");
|
|
4372
|
+
const transitionWarning = await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_started", "in_progress");
|
|
4373
|
+
if (transitionWarning !== undefined)
|
|
4374
|
+
warnings.push(transitionWarning);
|
|
4274
4375
|
const finalLane = readLane(hqRoot, laneId);
|
|
4275
|
-
printJson({ ok: true, action: "story.start", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "in_progress", story_warning:
|
|
4376
|
+
printJson({ ok: true, action: "story.start", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "in_progress", story_warning: combinedStoryWarning(finalLane, warnings), lane: finalLane });
|
|
4276
4377
|
}
|
|
4277
4378
|
async function runStoryBlock(ctx, laneId, storyId, opts) {
|
|
4278
4379
|
const hqRoot = ctx.hqRoot();
|
|
@@ -4290,15 +4391,21 @@ async function runStoryBlock(ctx, laneId, storyId, opts) {
|
|
|
4290
4391
|
if (!reason)
|
|
4291
4392
|
throw new LanesError("missing_block_reason", "--reason is required", {});
|
|
4292
4393
|
const at = ctx.now().toISOString();
|
|
4293
|
-
|
|
4394
|
+
const warnings = [];
|
|
4395
|
+
const thread = await ensureStoryThreadForTransition(ctx, lane, target.projectId, target.storyId);
|
|
4396
|
+
lane = thread.lane;
|
|
4397
|
+
if (thread.warning !== undefined)
|
|
4398
|
+
warnings.push(thread.warning);
|
|
4294
4399
|
const before = lane;
|
|
4295
4400
|
const next = casUpdateLane(hqRoot, laneId, (current) => {
|
|
4296
4401
|
assertLaneRunsHereForOperatorMutation(ctx, current, "update story status for");
|
|
4297
4402
|
return updateCarriedStory(current, target.projectId, target.storyId, "blocked", at, { blocked_reason: reason });
|
|
4298
4403
|
});
|
|
4299
|
-
await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_blocked", "blocked", { blocked_reason: reason });
|
|
4404
|
+
const transitionWarning = await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_blocked", "blocked", { blocked_reason: reason });
|
|
4405
|
+
if (transitionWarning !== undefined)
|
|
4406
|
+
warnings.push(transitionWarning);
|
|
4300
4407
|
const finalLane = readLane(hqRoot, laneId);
|
|
4301
|
-
printJson({ ok: true, action: "story.block", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "blocked", blocked_reason: reason, story_warning:
|
|
4408
|
+
printJson({ ok: true, action: "story.block", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "blocked", blocked_reason: reason, story_warning: combinedStoryWarning(finalLane, warnings), lane: finalLane });
|
|
4302
4409
|
}
|
|
4303
4410
|
async function runStoryDone(ctx, laneId, storyId, opts) {
|
|
4304
4411
|
const hqRoot = ctx.hqRoot();
|
|
@@ -4323,7 +4430,11 @@ async function runStoryDone(ctx, laneId, storyId, opts) {
|
|
|
4323
4430
|
});
|
|
4324
4431
|
}
|
|
4325
4432
|
const at = ctx.now().toISOString();
|
|
4326
|
-
|
|
4433
|
+
const warnings = [];
|
|
4434
|
+
const thread = await ensureStoryThreadForTransition(ctx, lane, target.projectId, target.storyId);
|
|
4435
|
+
lane = thread.lane;
|
|
4436
|
+
if (thread.warning !== undefined)
|
|
4437
|
+
warnings.push(thread.warning);
|
|
4327
4438
|
const before = lane;
|
|
4328
4439
|
const next = casUpdateLane(hqRoot, laneId, (current) => {
|
|
4329
4440
|
assertLaneRunsHereForOperatorMutation(ctx, current, "update story status for");
|
|
@@ -4332,9 +4443,11 @@ async function runStoryDone(ctx, laneId, storyId, opts) {
|
|
|
4332
4443
|
verified_by: current.senior,
|
|
4333
4444
|
});
|
|
4334
4445
|
});
|
|
4335
|
-
await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_done", "done", { summary: "Senior verification complete" });
|
|
4446
|
+
const transitionWarning = await commitStoryTransition(ctx, before, next, target.projectId, target.storyId, "lane_done", "done", { summary: "Senior verification complete" });
|
|
4447
|
+
if (transitionWarning !== undefined)
|
|
4448
|
+
warnings.push(transitionWarning);
|
|
4336
4449
|
const finalLane = readLane(hqRoot, laneId);
|
|
4337
|
-
printJson({ ok: true, action: "story.done", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "done", verified: true, story_warning:
|
|
4450
|
+
printJson({ ok: true, action: "story.done", lane_id: laneId, project_id: target.projectId, story_id: target.storyId, status: "done", verified: true, story_warning: combinedStoryWarning(finalLane, warnings), lane: finalLane });
|
|
4338
4451
|
}
|
|
4339
4452
|
/**
|
|
4340
4453
|
* Registration state of the drain hook in the lane's account home, read the
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
* of opening a browser nobody is watching, and the watcher records
|
|
43
43
|
* `mesh_event_failed` and moves on. No credential file is read here.
|
|
44
44
|
*/
|
|
45
|
+
import { LanesError } from "./errors.js";
|
|
45
46
|
import type { LaneCompanyRef, LaneEnvelope, LaneRecord, TerminalLaneState } from "./types.js";
|
|
46
47
|
export declare const LANE_MESH_EVENTS: readonly ["lane_started", "lane_progress", "lane_question", "lane_question_at_user", "lane_ask", "lane_blocked", "lane_done", "lane_failed", "lane_interrupted", "lane_cancelled", "lane_killed"];
|
|
47
48
|
export type LaneMeshEvent = (typeof LANE_MESH_EVENTS)[number];
|
|
@@ -73,6 +74,8 @@ export interface LaneMesh {
|
|
|
73
74
|
ensureLaneThread?: (company: LaneCompanyRef, lane: LaneRecord, laneStatus?: string, signal?: AbortSignal) => Promise<string>;
|
|
74
75
|
appendThreadEvent: (company: LaneCompanyRef, threadId: string, event: LaneMeshEvent, payload: Record<string, unknown>, signal?: AbortSignal) => Promise<void>;
|
|
75
76
|
patchStoryStatus: (company: LaneCompanyRef, projectId: string, storyId: string, status: string) => Promise<void>;
|
|
77
|
+
/** Read-only Board membership check before a command writes lane state. */
|
|
78
|
+
assertProjectStoriesOnBoard?: (company: LaneCompanyRef, projectId: string, storyIds: readonly string[]) => Promise<void>;
|
|
76
79
|
}
|
|
77
80
|
export interface CreateLaneMeshOptions {
|
|
78
81
|
/** False for detached callers (the watcher). See the token note above. */
|
|
@@ -88,6 +91,7 @@ export interface CreateLaneMeshOptions {
|
|
|
88
91
|
status: string;
|
|
89
92
|
}) => Promise<void>;
|
|
90
93
|
}
|
|
94
|
+
export declare function storyNotOnBoardError(company: LaneCompanyRef, projectId: string, storyId: string): LanesError;
|
|
91
95
|
export declare function createLaneMesh(opts?: CreateLaneMeshOptions): LaneMesh;
|
|
92
96
|
/** Resolve the explicit mesh attribution before falling back to the lane tenant. */
|
|
93
97
|
export declare function laneMeshCompany(lane: Pick<LaneRecord, "company" | "mesh_company">): LaneCompanyRef | undefined;
|
|
@@ -220,6 +220,31 @@ function isProjectViewNotFound(error) {
|
|
|
220
220
|
return (candidate.code === "PROJECT_VIEW_NOT_FOUND" ||
|
|
221
221
|
(typeof candidate.message === "string" && candidate.message.includes("PROJECT_VIEW_NOT_FOUND")));
|
|
222
222
|
}
|
|
223
|
+
function isUnknownProjectStory(error) {
|
|
224
|
+
if (!error || typeof error !== "object")
|
|
225
|
+
return false;
|
|
226
|
+
const candidate = error;
|
|
227
|
+
return (candidate.status === 400 &&
|
|
228
|
+
candidate.code === "PROJECT_VIEW_INVALID" &&
|
|
229
|
+
typeof candidate.message === "string" &&
|
|
230
|
+
candidate.message.includes("Unknown story"));
|
|
231
|
+
}
|
|
232
|
+
function shellQuote(value) {
|
|
233
|
+
return "'" + value.replace(/'/g, "'\\''") + "'";
|
|
234
|
+
}
|
|
235
|
+
export function storyNotOnBoardError(company, projectId, storyId) {
|
|
236
|
+
const command = "hq mesh project ensure " + shellQuote(projectId) +
|
|
237
|
+
" --company " + shellQuote(company.slug) +
|
|
238
|
+
" --stories-file '<prd.json>'";
|
|
239
|
+
const message = "Story " + JSON.stringify(storyId) + " is not on the Work Mesh Board for project " +
|
|
240
|
+
JSON.stringify(projectId) + ". Add it to the project PRD, then run: " + command;
|
|
241
|
+
return new LanesError("story_not_on_board", message, {
|
|
242
|
+
message,
|
|
243
|
+
project_id: projectId,
|
|
244
|
+
story_id: storyId,
|
|
245
|
+
command,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
223
248
|
function isAlreadyRegistered(error) {
|
|
224
249
|
if (!error || typeof error !== "object")
|
|
225
250
|
return false;
|
|
@@ -293,18 +318,61 @@ export function createLaneMesh(opts = {}) {
|
|
|
293
318
|
senior: { kind: lane.senior.kind, id: lane.senior.id },
|
|
294
319
|
laneVersion: lane.version,
|
|
295
320
|
};
|
|
296
|
-
|
|
297
|
-
|
|
321
|
+
try {
|
|
322
|
+
const ensured = await ensureLaneMeshThread(tok, resolved, lane.project_id, descriptor, isMeshLaneStatus(laneStatus) ? laneStatus : "running", signal);
|
|
323
|
+
return ensured.threadId;
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
if (lane.story_id && isUnknownProjectStory(error)) {
|
|
327
|
+
throw storyNotOnBoardError(company, lane.project_id, lane.story_id);
|
|
328
|
+
}
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
298
331
|
},
|
|
299
332
|
async appendThreadEvent(company, threadId, event, payload, signal) {
|
|
300
333
|
const wire = toWireThreadEvent(event, payload);
|
|
301
334
|
const tok = await token();
|
|
302
335
|
await appendThreadEvent(tok, company.uid, threadId, wire.eventKind, wire.payload, signal);
|
|
303
336
|
},
|
|
337
|
+
async assertProjectStoriesOnBoard(company, projectId, storyIds) {
|
|
338
|
+
if (storyIds.length === 0)
|
|
339
|
+
return;
|
|
340
|
+
const tok = await token();
|
|
341
|
+
let view;
|
|
342
|
+
try {
|
|
343
|
+
view = await getProjectView(tok, company.uid, projectId);
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
// A missing Board has a separate, established repair path in
|
|
347
|
+
// patchStoryStatus. Keep it available; an existing Board is strict.
|
|
348
|
+
if (isProjectViewNotFound(error))
|
|
349
|
+
return;
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
if (view.companyUid !== company.uid || view.projectId !== projectId) {
|
|
353
|
+
throw new LanesError("project_board_scope_mismatch", "Work Mesh returned a Board for a different company or project", { project_id: projectId });
|
|
354
|
+
}
|
|
355
|
+
for (const storyId of storyIds) {
|
|
356
|
+
if (!view.stories.some((story) => story.id === storyId)) {
|
|
357
|
+
throw storyNotOnBoardError(company, projectId, storyId);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
304
361
|
async patchStoryStatus(company, projectId, storyId, status) {
|
|
305
362
|
const tok = await token();
|
|
363
|
+
const patch = async () => {
|
|
364
|
+
try {
|
|
365
|
+
await patchStoryStatus(tok, company.uid, projectId, storyId, status);
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (isUnknownProjectStory(error)) {
|
|
369
|
+
throw storyNotOnBoardError(company, projectId, storyId);
|
|
370
|
+
}
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
};
|
|
306
374
|
try {
|
|
307
|
-
await
|
|
375
|
+
await patch();
|
|
308
376
|
}
|
|
309
377
|
catch (error) {
|
|
310
378
|
if (!isProjectViewNotFound(error))
|
|
@@ -316,7 +384,7 @@ export function createLaneMesh(opts = {}) {
|
|
|
316
384
|
storyId,
|
|
317
385
|
status,
|
|
318
386
|
});
|
|
319
|
-
await
|
|
387
|
+
await patch();
|
|
320
388
|
}
|
|
321
389
|
},
|
|
322
390
|
};
|