spur-board 0.24.0 → 0.25.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/dist/cli.mjs +3 -3
- package/dist/{client-B1u-1YVS.mjs → client-D3vmFo39.mjs} +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{config-BuftCWGz.mjs → config-CYLh25BZ.mjs} +2 -2
- package/dist/daemon.mjs +362 -199
- package/dist/mcp.mjs +3 -3
- package/dist/{src-lQGgnLLD.mjs → src-Ron2NABC.mjs} +2 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { G as SLACK_BOT_SCOPES, P as ERRORS, U as configSchema, W as requiredSecretKeys, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-
|
|
2
|
-
import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-
|
|
1
|
+
import { G as SLACK_BOT_SCOPES, P as ERRORS, U as configSchema, W as requiredSecretKeys, l as roleCanUseOperation, r as SYSTEMD_SERVICE_SETTINGS, u as OPERATIONS } from "./src-Ron2NABC.mjs";
|
|
2
|
+
import { a as errorExitCode, i as CliError, n as requestOperation, o as renderCliError, r as requestTokenEnrollment, s as escapeTerminalControls } from "./client-D3vmFo39.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./config-CYLh25BZ.mjs";
|
|
4
4
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
5
5
|
import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
6
6
|
import { homedir, hostname, userInfo } from "node:os";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as errorContextSchema, I as errorEnvelopeSchema, L as successEnvelopeSchema, P as ERRORS, f as renderJsonError } from "./src-
|
|
1
|
+
import { F as errorContextSchema, I as errorEnvelopeSchema, L as successEnvelopeSchema, P as ERRORS, f as renderJsonError } from "./src-Ron2NABC.mjs";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { request } from "node:http";
|
package/dist/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-
|
|
1
|
+
import { n as requestOperation, r as requestTokenEnrollment, t as fetchCatalogVersion } from "./client-D3vmFo39.mjs";
|
|
2
2
|
export { fetchCatalogVersion, requestOperation, requestTokenEnrollment };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { U as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-
|
|
2
|
-
import { i as CliError, t as fetchCatalogVersion } from "./client-
|
|
1
|
+
import { U as configSchema, c as buildCatalogSnapshot, u as OPERATIONS } from "./src-Ron2NABC.mjs";
|
|
2
|
+
import { i as CliError, t as fetchCatalogVersion } from "./client-D3vmFo39.mjs";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
package/dist/daemon.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, G as SLACK_BOT_SCOPES, H as RESERVED_PROJECT, L as successEnvelopeSchema, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, S as SESSION_HEALTH_STATES, T as prRefSchema, U as configSchema, V as DEFAULT_SLACK_COMMAND, W as requiredSecretKeys, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as DEFAULT_LINK } from "./src-
|
|
1
|
+
import { A as errorCodeOf, C as SESSION_STATUSES, D as ticketFactsSchema, E as sessionFactsSchema, G as SLACK_BOT_SCOPES, H as RESERVED_PROJECT, L as successEnvelopeSchema, M as parseRef$1, N as taskKeySchema, O as actorIdSchema, P as ERRORS, S as SESSION_HEALTH_STATES, T as prRefSchema, U as configSchema, V as DEFAULT_SLACK_COMMAND, W as requiredSecretKeys, _ as interactionRefSchema, a as batchSchema, b as EVENT_KINDS, c as buildCatalogSnapshot, d as renderHttpProblem, g as inboundEventSchema, h as conversationRefSchema, i as AdapterError, j as parseActorId, k as encodeActorId, l as roleCanUseOperation, m as SPACE_IDS, n as BOARD_TICK_MS, o as entityRefSchema, s as sourceCursorSchema, t as assertNever, u as OPERATIONS, v as messageRefSchema, w as prFactsSchema, x as eventPayloadSchemas, y as userIdSchema, z as DEFAULT_LINK } from "./src-Ron2NABC.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { closeSync, existsSync, fstatSync, fsyncSync, ftruncateSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeSync } from "node:fs";
|
|
@@ -8382,15 +8382,17 @@ function renderBody(key, text) {
|
|
|
8382
8382
|
}
|
|
8383
8383
|
/**
|
|
8384
8384
|
* A distinct semantic ring. Transport retries reuse this row and its text. A restarted series
|
|
8385
|
-
* (`series` > 0)
|
|
8386
|
-
*
|
|
8385
|
+
* (`series` > 0), a ring after the task was archived (`archives` > 0) and a ring after a move
|
|
8386
|
+
* killed an earlier one (`moves` > 0) get their own keys, so a cancelled ring does not block its
|
|
8387
|
+
* replacement; unsuffixed keys stay as before.
|
|
8387
8388
|
*/
|
|
8388
8389
|
async function enqueueDoorbell(trx, input) {
|
|
8389
8390
|
const series = input.series ?? 0;
|
|
8390
8391
|
const archives = input.archives ?? 0;
|
|
8392
|
+
const moves = input.moves ?? 0;
|
|
8391
8393
|
const row = await insertOutbox(trx, {
|
|
8392
8394
|
kind: "doorbell",
|
|
8393
|
-
dedupeKey: `doorbell:${String(input.notificationId)}:${input.session}:${String(input.ring)}${series > 0 ? `:s${String(series)}` : ""}${archives > 0 ? `:a${String(archives)}` : ""}`,
|
|
8395
|
+
dedupeKey: `doorbell:${String(input.notificationId)}:${input.session}:${String(input.ring)}${series > 0 ? `:s${String(series)}` : ""}${archives > 0 ? `:a${String(archives)}` : ""}${moves > 0 ? `:m${String(moves)}` : ""}`,
|
|
8394
8396
|
payload: {
|
|
8395
8397
|
notificationId: input.notificationId,
|
|
8396
8398
|
ring: input.ring,
|
|
@@ -8684,18 +8686,6 @@ async function enqueueConversationClose(trx, input) {
|
|
|
8684
8686
|
closed_at: input.at.toISOString()
|
|
8685
8687
|
}).where("block_id", "=", input.blockId).where("state", "=", "open").execute();
|
|
8686
8688
|
}
|
|
8687
|
-
async function enqueueInboundDoorbell(trx, input) {
|
|
8688
|
-
await insertOutbox(trx, {
|
|
8689
|
-
kind: "doorbell",
|
|
8690
|
-
dedupeKey: input.key,
|
|
8691
|
-
payload: {
|
|
8692
|
-
session: input.session,
|
|
8693
|
-
text: input.text
|
|
8694
|
-
},
|
|
8695
|
-
parent: null,
|
|
8696
|
-
at: input.at
|
|
8697
|
-
});
|
|
8698
|
-
}
|
|
8699
8689
|
//#endregion
|
|
8700
8690
|
//#region ../core/src/app/feed.ts
|
|
8701
8691
|
/** The struck summary is capped so the edit stays one message part. */
|
|
@@ -9150,21 +9140,101 @@ function listenApiServer(app, port) {
|
|
|
9150
9140
|
});
|
|
9151
9141
|
}
|
|
9152
9142
|
//#endregion
|
|
9143
|
+
//#region ../core/src/app/block-thread.ts
|
|
9144
|
+
function orchestrator(config, task) {
|
|
9145
|
+
const name = config.projects.find((project) => project.id === task.project)?.columns.find((column) => column.id === task.column)?.orchestrator;
|
|
9146
|
+
return name === void 0 || name === "none" ? null : name;
|
|
9147
|
+
}
|
|
9148
|
+
function authorRole(config, task, actor) {
|
|
9149
|
+
if (actor === "operator") return "operator";
|
|
9150
|
+
const parsed = parseActorId(actor);
|
|
9151
|
+
if (parsed?.actor === "agent" && config.projects.some((project) => project.spurProjects.some((spur) => spur.name === parsed.actorRef.project && spur.role === "operator"))) return "operator";
|
|
9152
|
+
if (parsed?.actor !== "agent") return "worker";
|
|
9153
|
+
if (parsed.actorRef.project === orchestrator(config, task)) return `orchestrator:${task.column}`;
|
|
9154
|
+
return parsed.actorRef.project === curatorProject(config, task.project) ? "curator" : "worker";
|
|
9155
|
+
}
|
|
9156
|
+
function personaRole(role) {
|
|
9157
|
+
const addressee = parseAddressee(role);
|
|
9158
|
+
switch (addressee.kind) {
|
|
9159
|
+
case "operator": return "board";
|
|
9160
|
+
case "worker": return "worker";
|
|
9161
|
+
case "curator":
|
|
9162
|
+
case "orchestrator": return "orchestrator";
|
|
9163
|
+
default: return assertNever(addressee);
|
|
9164
|
+
}
|
|
9165
|
+
}
|
|
9166
|
+
function personaFor(config, task, actor) {
|
|
9167
|
+
if (actor === "system") return {
|
|
9168
|
+
name: "board",
|
|
9169
|
+
role: "board"
|
|
9170
|
+
};
|
|
9171
|
+
if (actor === "operator") return {
|
|
9172
|
+
name: "operator",
|
|
9173
|
+
role: "board"
|
|
9174
|
+
};
|
|
9175
|
+
const parsed = parseActorId(actor);
|
|
9176
|
+
if (parsed?.actor !== "agent") throw new Error("Invalid actor");
|
|
9177
|
+
return {
|
|
9178
|
+
name: parsed.actorRef.project,
|
|
9179
|
+
role: personaRole(authorRole(config, task, actor))
|
|
9180
|
+
};
|
|
9181
|
+
}
|
|
9182
|
+
async function queueBlockOpen(trx, task, block, ctx, config) {
|
|
9183
|
+
if (authorRole(config, task, block.author) === "operator") return;
|
|
9184
|
+
const comments = await trx.selectFrom("comment").select(["id", "author"]).where("block_id", "=", block.id).orderBy("id").execute();
|
|
9185
|
+
if (await enqueueConversationOpen(trx, {
|
|
9186
|
+
blockId: block.id,
|
|
9187
|
+
commentId: comments[0]?.id ?? null,
|
|
9188
|
+
persona: personaFor(config, task, comments[0]?.author ?? block.author),
|
|
9189
|
+
at: new Date(ctx.at)
|
|
9190
|
+
}) === null) return;
|
|
9191
|
+
for (const comment of comments.slice(1)) await enqueueConversationReply(trx, {
|
|
9192
|
+
commentId: comment.id,
|
|
9193
|
+
persona: personaFor(config, task, comment.author),
|
|
9194
|
+
at: new Date(ctx.at)
|
|
9195
|
+
});
|
|
9196
|
+
}
|
|
9197
|
+
//#endregion
|
|
9153
9198
|
//#region ../core/src/app/doorbells.ts
|
|
9199
|
+
const UNANSWERED = "unanswered";
|
|
9154
9200
|
async function journal$2(trx, notification, kind, payload, at) {
|
|
9155
9201
|
await emit(trx, kind, (await trx.selectFrom("task").select("project").where("id", "=", notification.task_id).executeTakeFirstOrThrow()).project, notification.task_id, at.toISOString(), payload);
|
|
9156
9202
|
}
|
|
9157
|
-
/**
|
|
9203
|
+
/**
|
|
9204
|
+
* The one rule for who a board event rings. A doorbell means someone is waiting for your action,
|
|
9205
|
+
* so a party that caused the event, or that the Slack thread already reaches, gets no row.
|
|
9206
|
+
*/
|
|
9207
|
+
async function applyDoorbellPolicy(trx, event, at) {
|
|
9208
|
+
switch (event.kind) {
|
|
9209
|
+
case "block_opened":
|
|
9210
|
+
if (!(parseActorId(event.block.author)?.actor === "agent" && event.block.addressee_role === event.authorRole)) await registerBlockNotification(trx, event.block, at);
|
|
9211
|
+
return;
|
|
9212
|
+
case "block_escalated":
|
|
9213
|
+
await closeBlockNotification(trx, event.block.id, at);
|
|
9214
|
+
await registerBlockNotification(trx, event.block, at);
|
|
9215
|
+
return;
|
|
9216
|
+
case "answer":
|
|
9217
|
+
await registerAnswerNotification(trx, event, at);
|
|
9218
|
+
return;
|
|
9219
|
+
case "block_removed":
|
|
9220
|
+
await registerRemovedNotification(trx, event.block, at);
|
|
9221
|
+
return;
|
|
9222
|
+
case "block_closed_by_addressee":
|
|
9223
|
+
case "task_comment": return;
|
|
9224
|
+
default: assertNever(event);
|
|
9225
|
+
}
|
|
9226
|
+
}
|
|
9227
|
+
/** Register a block for its agent addressee; the Slack thread carries an operator's. */
|
|
9158
9228
|
async function registerBlockNotification(trx, block, at) {
|
|
9159
|
-
if (block.addressee_role
|
|
9229
|
+
if (block.addressee_role === "operator") return;
|
|
9160
9230
|
await trx.insertInto("notification").values({
|
|
9161
|
-
source_key: `block:${String(block.id)}
|
|
9231
|
+
source_key: `block:${String(block.id)}:${block.addressee_role}`,
|
|
9162
9232
|
kind: "block",
|
|
9163
9233
|
task_id: block.task_id,
|
|
9164
9234
|
block_id: block.id,
|
|
9165
9235
|
comment_id: null,
|
|
9166
9236
|
revision: null,
|
|
9167
|
-
role:
|
|
9237
|
+
role: block.addressee_role,
|
|
9168
9238
|
author_session: null,
|
|
9169
9239
|
recipient_session: null,
|
|
9170
9240
|
next_at: at.toISOString(),
|
|
@@ -9174,11 +9244,32 @@ async function registerBlockNotification(trx, block, at) {
|
|
|
9174
9244
|
created_at: at.toISOString()
|
|
9175
9245
|
}).onConflict((oc) => oc.column("source_key").doNothing()).execute();
|
|
9176
9246
|
}
|
|
9177
|
-
/** Register
|
|
9178
|
-
async function
|
|
9179
|
-
if (
|
|
9247
|
+
/** Register a one-ring notice that a block its addressee held was closed by someone else. */
|
|
9248
|
+
async function registerRemovedNotification(trx, block, at) {
|
|
9249
|
+
if (block.addressee_role === "operator") return;
|
|
9250
|
+
await trx.insertInto("notification").values({
|
|
9251
|
+
source_key: `removed:${String(block.id)}`,
|
|
9252
|
+
kind: "removed",
|
|
9253
|
+
task_id: block.task_id,
|
|
9254
|
+
block_id: block.id,
|
|
9255
|
+
comment_id: null,
|
|
9256
|
+
revision: null,
|
|
9257
|
+
role: block.addressee_role,
|
|
9258
|
+
author_session: null,
|
|
9259
|
+
recipient_session: null,
|
|
9260
|
+
next_at: at.toISOString(),
|
|
9261
|
+
last_outbox_id: null,
|
|
9262
|
+
acked_at: null,
|
|
9263
|
+
exhausted_at: null,
|
|
9264
|
+
created_at: at.toISOString()
|
|
9265
|
+
}).onConflict((oc) => oc.column("source_key").doNothing()).execute();
|
|
9266
|
+
}
|
|
9267
|
+
/** Register an answer or clarification for the question's author, unless the author wrote it. */
|
|
9268
|
+
async function registerAnswerNotification(trx, input, at) {
|
|
9180
9269
|
const parsed = parseActorId(input.block.author);
|
|
9181
|
-
if (parsed?.actor !== "agent") return;
|
|
9270
|
+
if (parsed?.actor !== "agent" || input.actor === input.block.author) return;
|
|
9271
|
+
const actor = parseActorId(input.actor);
|
|
9272
|
+
if (resolvedByProject(input.authorRole) && actor?.actor === "agent" && actor.actorRef.project === parsed.actorRef.project) return;
|
|
9182
9273
|
await trx.insertInto("notification").values({
|
|
9183
9274
|
source_key: `comment:${String(input.commentId)}:${String(input.revision)}`,
|
|
9184
9275
|
kind: "answer",
|
|
@@ -9186,46 +9277,110 @@ async function registerAnswerNotification(trx, input) {
|
|
|
9186
9277
|
block_id: input.block.id,
|
|
9187
9278
|
comment_id: input.commentId,
|
|
9188
9279
|
revision: input.revision,
|
|
9189
|
-
role:
|
|
9280
|
+
role: input.authorRole,
|
|
9190
9281
|
author_session: parsed.actorRef.session,
|
|
9191
9282
|
recipient_session: null,
|
|
9192
|
-
next_at:
|
|
9283
|
+
next_at: at.toISOString(),
|
|
9193
9284
|
last_outbox_id: null,
|
|
9194
9285
|
acked_at: null,
|
|
9195
9286
|
exhausted_at: null,
|
|
9196
|
-
created_at:
|
|
9287
|
+
created_at: at.toISOString()
|
|
9197
9288
|
}).onConflict((oc) => oc.column("source_key").doNothing()).execute();
|
|
9198
9289
|
}
|
|
9290
|
+
/**
|
|
9291
|
+
* Moves a block to a new addressee, for `block.escalate` and for a ring series that ended: the
|
|
9292
|
+
* journal row, the old notification's end, the new one and the Slack thread, in the caller's
|
|
9293
|
+
* transaction.
|
|
9294
|
+
*/
|
|
9295
|
+
async function moveBlockToAddressee(trx, input) {
|
|
9296
|
+
const { task, block, to, reason, ctx, config } = input;
|
|
9297
|
+
const updated = await trx.updateTable("block").set({ addressee_role: to }).where("id", "=", block.id).returningAll().executeTakeFirstOrThrow();
|
|
9298
|
+
await emit(trx, "block_escalated", task.project, task.id, ctx.at, {
|
|
9299
|
+
block: `B${String(block.id)}`,
|
|
9300
|
+
from: block.addressee_role,
|
|
9301
|
+
to,
|
|
9302
|
+
...reason === void 0 ? {} : { reason }
|
|
9303
|
+
}, ctx.actor);
|
|
9304
|
+
await applyDoorbellPolicy(trx, {
|
|
9305
|
+
kind: "block_escalated",
|
|
9306
|
+
block: updated
|
|
9307
|
+
}, new Date(ctx.at));
|
|
9308
|
+
await queueBlockOpen(trx, task, updated, ctx, config);
|
|
9309
|
+
return updated;
|
|
9310
|
+
}
|
|
9311
|
+
async function sessionById(trx, id) {
|
|
9312
|
+
return trx.selectFrom("session_snapshot").selectAll().where("id", "=", id).executeTakeFirst();
|
|
9313
|
+
}
|
|
9199
9314
|
async function liveSession(trx, id) {
|
|
9200
|
-
const row = await trx
|
|
9315
|
+
const row = await sessionById(trx, id);
|
|
9201
9316
|
return row?.ended_at === null && row.state !== "killed" && row.state !== "stopped" ? row : void 0;
|
|
9202
9317
|
}
|
|
9203
|
-
/**
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
}
|
|
9214
|
-
/**
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
if (
|
|
9222
|
-
|
|
9318
|
+
/** Spur lifecycle states of a session that can no longer read a ring. */
|
|
9319
|
+
const FINISHED_STATES = [
|
|
9320
|
+
"killed",
|
|
9321
|
+
"stopped",
|
|
9322
|
+
"errored",
|
|
9323
|
+
"completed"
|
|
9324
|
+
];
|
|
9325
|
+
/** Stricter than `liveSession`: a role resolved by Spur project must also be in Spur's list. */
|
|
9326
|
+
function liveInProject(session) {
|
|
9327
|
+
return session.ended_at === null && session.absent_since === null && !FINISHED_STATES.includes(session.state);
|
|
9328
|
+
}
|
|
9329
|
+
/** Roles whose recipient is any session of a configured Spur project, not one linked session. */
|
|
9330
|
+
function resolvedByProject(role) {
|
|
9331
|
+
const { kind } = parseAddressee(role);
|
|
9332
|
+
return kind === "curator" || kind === "orchestrator";
|
|
9333
|
+
}
|
|
9334
|
+
/** Orders later times first and missing times last. */
|
|
9335
|
+
function laterFirst(left, right) {
|
|
9336
|
+
if (left === right) return 0;
|
|
9337
|
+
if (left === null) return 1;
|
|
9338
|
+
if (right === null) return -1;
|
|
9339
|
+
return right - left;
|
|
9340
|
+
}
|
|
9341
|
+
/** The newest live session of a Spur project, then the most recently active, then by id. */
|
|
9342
|
+
async function bestProjectSession(trx, project) {
|
|
9343
|
+
if (project === null) return void 0;
|
|
9344
|
+
const rows = await trx.selectFrom("session_snapshot").selectAll().select(sql`json_extract(detail, '$.lastActivityAt')`.as("last_activity")).where("spur_project", "=", project).where("ended_at", "is", null).where("absent_since", "is", null).where("state", "not in", FINISHED_STATES).execute();
|
|
9345
|
+
const activity = (value) => value === null ? null : Date.parse(value);
|
|
9346
|
+
return rows.sort((left, right) => laterFirst(Date.parse(left.first_seen), Date.parse(right.first_seen)) || laterFirst(activity(left.last_activity), activity(right.last_activity)) || (left.id < right.id ? -1 : 1))[0];
|
|
9347
|
+
}
|
|
9348
|
+
/** The newest live session linked to a task in a role. */
|
|
9349
|
+
async function linkedSession(trx, taskId, role) {
|
|
9350
|
+
const links = await trx.selectFrom("link").select("session_id").where("task_id", "=", taskId).where("entity", "=", "session").where("role", "=", role).where("banned", "=", 0).orderBy("created_at", "desc").execute();
|
|
9223
9351
|
for (const link of links) {
|
|
9224
9352
|
if (link.session_id === null) continue;
|
|
9225
9353
|
const session = await liveSession(trx, link.session_id);
|
|
9226
9354
|
if (session !== void 0) return session;
|
|
9227
9355
|
}
|
|
9228
9356
|
}
|
|
9357
|
+
async function taskProject(trx, taskId) {
|
|
9358
|
+
return (await trx.selectFrom("task").select("project").where("id", "=", taskId).executeTakeFirstOrThrow()).project;
|
|
9359
|
+
}
|
|
9360
|
+
/** The Spur project orchestrating a column; null when no agent project does. */
|
|
9361
|
+
function columnOrchestratorProject(config, projectId, column) {
|
|
9362
|
+
const name = config.projects.find((project) => project.id === projectId)?.columns.find((entry) => entry.id === column)?.orchestrator;
|
|
9363
|
+
return name === void 0 || name === "none" || name === "operator" ? null : name;
|
|
9364
|
+
}
|
|
9365
|
+
/** Select the current live recipient for a semantic notification. */
|
|
9366
|
+
async function selectNotificationRecipient(trx, n, config) {
|
|
9367
|
+
const addressee = parseAddressee(n.role);
|
|
9368
|
+
switch (addressee.kind) {
|
|
9369
|
+
case "curator": return bestProjectSession(trx, curatorProject(config, await taskProject(trx, n.task_id)));
|
|
9370
|
+
case "orchestrator": {
|
|
9371
|
+
const author = n.author_session === null ? void 0 : await sessionById(trx, n.author_session);
|
|
9372
|
+
if (author !== void 0 && liveInProject(author)) return author;
|
|
9373
|
+
return await linkedSession(trx, n.task_id, "orchestrator") ?? bestProjectSession(trx, columnOrchestratorProject(config, await taskProject(trx, n.task_id), addressee.column));
|
|
9374
|
+
}
|
|
9375
|
+
case "worker":
|
|
9376
|
+
case "operator": {
|
|
9377
|
+
const author = n.author_session === null ? void 0 : await liveSession(trx, n.author_session);
|
|
9378
|
+
if (author !== void 0 || addressee.kind === "operator") return author;
|
|
9379
|
+
return linkedSession(trx, n.task_id, "worker");
|
|
9380
|
+
}
|
|
9381
|
+
default: return assertNever(addressee);
|
|
9382
|
+
}
|
|
9383
|
+
}
|
|
9229
9384
|
/** The operator item kind raised when a notification's rings are exhausted. */
|
|
9230
9385
|
function exhaustedItemKind(n) {
|
|
9231
9386
|
return n.kind === "answer" ? "answer_undelivered" : "worker_not_reading";
|
|
@@ -9246,11 +9401,49 @@ async function restartNotification(trx, sourceKey, at) {
|
|
|
9246
9401
|
}).where("source_key", "=", sourceKey).where("acked_at", "is", null).where("exhausted_at", "is not", null).returning("id").executeTakeFirst() === void 0) throw new CommandError("retry_not_applicable", "The doorbell was read or is still ringing; close the item instead.");
|
|
9247
9402
|
}
|
|
9248
9403
|
/**
|
|
9249
|
-
* Ends a ring
|
|
9250
|
-
*
|
|
9251
|
-
*
|
|
9252
|
-
|
|
9253
|
-
|
|
9404
|
+
* Ends a notification's ring series. A curator block moves to the operator; a removal or a ring
|
|
9405
|
+
* with no session to name ends alone; anything else raises the operator item, whose Retry restarts
|
|
9406
|
+
* the series (`restartNotification`). Every end journals `doorbell_undelivered`.
|
|
9407
|
+
*/
|
|
9408
|
+
async function endNotification(trx, n, task, end) {
|
|
9409
|
+
const { session, reason, at, config } = end;
|
|
9410
|
+
await trx.updateTable("notification").set({ exhausted_at: at.toISOString() }).where("id", "=", n.id).execute();
|
|
9411
|
+
const addressee = parseAddressee(n.role);
|
|
9412
|
+
if (n.kind === "block" && addressee.kind === "curator") await moveBlockToAddressee(trx, {
|
|
9413
|
+
task,
|
|
9414
|
+
block: await trx.selectFrom("block").selectAll().where("id", "=", n.block_id).executeTakeFirstOrThrow(),
|
|
9415
|
+
to: "operator",
|
|
9416
|
+
reason,
|
|
9417
|
+
ctx: {
|
|
9418
|
+
actor: "system",
|
|
9419
|
+
at: at.toISOString()
|
|
9420
|
+
},
|
|
9421
|
+
config
|
|
9422
|
+
});
|
|
9423
|
+
else if (n.kind !== "removed" && session !== null) {
|
|
9424
|
+
const blockRef = `block B${String(n.block_id)} on ${task.key}`;
|
|
9425
|
+
const answer = `Answer to ${blockRef} was not`;
|
|
9426
|
+
const holder = `${addressee.kind} ${session}`;
|
|
9427
|
+
await raiseItem(trx, {
|
|
9428
|
+
itemKey: exhaustedItemKey(n),
|
|
9429
|
+
kind: exhaustedItemKind(n),
|
|
9430
|
+
text: reason === UNANSWERED ? n.kind === "answer" ? `${answer} read` : `${holder} is not reading ${blockRef}` : n.kind === "answer" ? `${answer} delivered: ${reason}` : `${holder} did not get ${blockRef}: ${reason}`,
|
|
9431
|
+
url: taskUrl(task, config),
|
|
9432
|
+
taskId: task.id,
|
|
9433
|
+
blockId: n.block_id,
|
|
9434
|
+
at
|
|
9435
|
+
});
|
|
9436
|
+
}
|
|
9437
|
+
await journal$2(trx, n, "doorbell_undelivered", {
|
|
9438
|
+
doorbell: `N${String(n.id)}`,
|
|
9439
|
+
reason
|
|
9440
|
+
}, at);
|
|
9441
|
+
}
|
|
9442
|
+
/**
|
|
9443
|
+
* Ends a ring Spur will not take (a permanent rejection, or no answer for the retry window). A
|
|
9444
|
+
* ring that is no longer its notification's last row (the recipient changed while it was in
|
|
9445
|
+
* flight) ends alone. An inbound author ring has no notification: it ends like an author found
|
|
9446
|
+
* unavailable at enqueue.
|
|
9254
9447
|
*/
|
|
9255
9448
|
async function ringUndelivered(trx, input) {
|
|
9256
9449
|
const { at, reason } = input;
|
|
@@ -9274,21 +9467,24 @@ async function ringUndelivered(trx, input) {
|
|
|
9274
9467
|
}
|
|
9275
9468
|
const n = await trx.selectFrom("notification").selectAll().where("id", "=", input.notificationId).executeTakeFirst();
|
|
9276
9469
|
if (n === void 0 || n.acked_at !== null || n.exhausted_at !== null || n.last_outbox_id !== input.outboxId) return;
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
text: n.kind === "answer" ? `Answer to block B${String(n.block_id)} on ${task.key} was not delivered: ${reason}` : `worker ${input.session} did not get block B${String(n.block_id)} on ${task.key}: ${reason}`,
|
|
9283
|
-
url: taskUrl(task, input.config),
|
|
9284
|
-
taskId: task.id,
|
|
9285
|
-
blockId: n.block_id,
|
|
9286
|
-
at
|
|
9470
|
+
await endNotification(trx, n, await trx.selectFrom("task").selectAll().where("id", "=", n.task_id).executeTakeFirstOrThrow(), {
|
|
9471
|
+
session: input.session,
|
|
9472
|
+
reason,
|
|
9473
|
+
at,
|
|
9474
|
+
config: input.config
|
|
9287
9475
|
});
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9476
|
+
}
|
|
9477
|
+
/** Why a notification with no recipient ends now, or null when it stays due for a next session. */
|
|
9478
|
+
function noRecipientEnd(n) {
|
|
9479
|
+
if (n.kind === "removed" || n.kind === "answer" && n.role === "operator") return "no live addressee";
|
|
9480
|
+
return n.kind === "block" && n.role === "curator" ? "no live curator session" : null;
|
|
9481
|
+
}
|
|
9482
|
+
/** A ring never carries comment or reason text: only where to look. */
|
|
9483
|
+
async function ringText(trx, n, task, ring) {
|
|
9484
|
+
const suffix = `(N${String(n.id)}-${String(ring)})`;
|
|
9485
|
+
if (n.kind !== "removed") return `${task.key} block B${String(n.block_id)}: check board inbox ${suffix}`;
|
|
9486
|
+
const block = await trx.selectFrom("block").select("unblocked_by").where("id", "=", n.block_id).executeTakeFirstOrThrow();
|
|
9487
|
+
return `${task.key} block B${String(n.block_id)} was removed by ${block.unblocked_by ?? "system"}; see board task ${task.key} ${suffix}`;
|
|
9292
9488
|
}
|
|
9293
9489
|
/** Notifications reconcile looks at: unacked, not exhausted, due, on a task not archived. */
|
|
9294
9490
|
function dueNotifications(db, at) {
|
|
@@ -9306,11 +9502,19 @@ async function reconcileDueDoorbells(store, config, at) {
|
|
|
9306
9502
|
async function reconcileDoorbells(trx, at, config) {
|
|
9307
9503
|
const due = await dueNotifications(trx, at).selectAll("notification").orderBy("notification.id").execute();
|
|
9308
9504
|
for (const n of due) {
|
|
9309
|
-
const session = await selectNotificationRecipient(trx, n);
|
|
9505
|
+
const session = await selectNotificationRecipient(trx, n, config);
|
|
9506
|
+
const keepsRings = resolvedByProject(n.role);
|
|
9310
9507
|
if (session === void 0) {
|
|
9311
|
-
|
|
9508
|
+
const reason = noRecipientEnd(n);
|
|
9509
|
+
if (reason !== null) await endNotification(trx, n, await trx.selectFrom("task").selectAll().where("id", "=", n.task_id).executeTakeFirstOrThrow(), {
|
|
9510
|
+
session: null,
|
|
9511
|
+
reason,
|
|
9512
|
+
at,
|
|
9513
|
+
config
|
|
9514
|
+
});
|
|
9515
|
+
else if (n.recipient_session !== null) await trx.updateTable("notification").set({
|
|
9312
9516
|
recipient_session: null,
|
|
9313
|
-
rings: 0,
|
|
9517
|
+
rings: keepsRings ? n.rings : 0,
|
|
9314
9518
|
last_outbox_id: null
|
|
9315
9519
|
}).where("id", "=", n.id).execute();
|
|
9316
9520
|
continue;
|
|
@@ -9323,11 +9527,11 @@ async function reconcileDoorbells(trx, at, config) {
|
|
|
9323
9527
|
state: "dead",
|
|
9324
9528
|
last_error: "recipient changed"
|
|
9325
9529
|
}).where("id", "=", lastOutbox).where("state", "=", "pending").execute();
|
|
9326
|
-
rings = 0;
|
|
9530
|
+
if (!keepsRings) rings = 0;
|
|
9327
9531
|
lastOutbox = null;
|
|
9328
9532
|
await trx.updateTable("notification").set({
|
|
9329
9533
|
recipient_session: session.id,
|
|
9330
|
-
rings
|
|
9534
|
+
rings,
|
|
9331
9535
|
last_outbox_id: null
|
|
9332
9536
|
}).where("id", "=", n.id).execute();
|
|
9333
9537
|
}
|
|
@@ -9336,28 +9540,20 @@ async function reconcileDoorbells(trx, at, config) {
|
|
|
9336
9540
|
if (row?.state === "pending" || row?.state === "in_flight") continue;
|
|
9337
9541
|
}
|
|
9338
9542
|
const task = await trx.selectFrom("task").selectAll().where("id", "=", n.task_id).executeTakeFirstOrThrow();
|
|
9339
|
-
const itemKey = exhaustedItemKey(n);
|
|
9340
9543
|
if (rings >= 3) {
|
|
9341
|
-
await
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
taskId: task.id,
|
|
9347
|
-
blockId: n.block_id,
|
|
9348
|
-
at
|
|
9544
|
+
await endNotification(trx, n, task, {
|
|
9545
|
+
session: session.id,
|
|
9546
|
+
reason: UNANSWERED,
|
|
9547
|
+
at,
|
|
9548
|
+
config
|
|
9349
9549
|
});
|
|
9350
|
-
await trx.updateTable("notification").set({ exhausted_at: at.toISOString() }).where("id", "=", n.id).execute();
|
|
9351
|
-
await journal$2(trx, n, "doorbell_undelivered", {
|
|
9352
|
-
doorbell: `N${String(n.id)}`,
|
|
9353
|
-
reason: "unanswered"
|
|
9354
|
-
}, at);
|
|
9355
9550
|
continue;
|
|
9356
9551
|
}
|
|
9357
|
-
const raised = await trx.selectFrom("operator_item").select((eb) => eb.fn.max("raise_no").as("series")).where("item_key", "=",
|
|
9552
|
+
const raised = await trx.selectFrom("operator_item").select((eb) => eb.fn.max("raise_no").as("series")).where("item_key", "=", exhaustedItemKey(n)).executeTakeFirst();
|
|
9358
9553
|
const archived = await trx.selectFrom("event").select((eb) => eb.fn.countAll().as("count")).where("task_id", "=", n.task_id).where("kind", "=", "task_archived").executeTakeFirst();
|
|
9554
|
+
const killed = keepsRings ? await trx.selectFrom("outbox").select((eb) => eb.fn.countAll().as("count")).where("kind", "=", "doorbell").where("state", "=", "dead").where(sql`json_extract(payload, '$.notificationId')`, "=", n.id).executeTakeFirst() : void 0;
|
|
9359
9555
|
const ring = rings + 1;
|
|
9360
|
-
const text =
|
|
9556
|
+
const text = await ringText(trx, n, task, ring);
|
|
9361
9557
|
const outboxId = await enqueueDoorbell(trx, {
|
|
9362
9558
|
notificationId: n.id,
|
|
9363
9559
|
ring,
|
|
@@ -9365,7 +9561,8 @@ async function reconcileDoorbells(trx, at, config) {
|
|
|
9365
9561
|
text,
|
|
9366
9562
|
at,
|
|
9367
9563
|
series: raised?.series ?? 0,
|
|
9368
|
-
archives: archived?.count ?? 0
|
|
9564
|
+
archives: archived?.count ?? 0,
|
|
9565
|
+
moves: killed?.count ?? 0
|
|
9369
9566
|
});
|
|
9370
9567
|
await trx.updateTable("notification").set({ last_outbox_id: outboxId }).where("id", "=", n.id).execute();
|
|
9371
9568
|
}
|
|
@@ -9381,7 +9578,8 @@ async function recordRingDelivery(trx, notificationId, ring, session, at, config
|
|
|
9381
9578
|
];
|
|
9382
9579
|
await trx.updateTable("notification").set({
|
|
9383
9580
|
rings: ring,
|
|
9384
|
-
next_at: new Date(at.getTime() + (pauses[ring - 1] ?? 0)).toISOString()
|
|
9581
|
+
next_at: new Date(at.getTime() + (pauses[ring - 1] ?? 0)).toISOString(),
|
|
9582
|
+
...n.kind === "removed" ? { acked_at: at.toISOString() } : {}
|
|
9385
9583
|
}).where("id", "=", notificationId).execute();
|
|
9386
9584
|
await journal$2(trx, n, "doorbell_rung", {
|
|
9387
9585
|
doorbell: `N${String(n.id)}`,
|
|
@@ -9390,10 +9588,10 @@ async function recordRingDelivery(trx, notificationId, ring, session, at, config
|
|
|
9390
9588
|
}, at);
|
|
9391
9589
|
}
|
|
9392
9590
|
/** Confirm that a queued ring still belongs to a live, idle, unread recipient. */
|
|
9393
|
-
async function ringStillCurrent(trx, notificationId, sessionId) {
|
|
9591
|
+
async function ringStillCurrent(trx, notificationId, sessionId, config) {
|
|
9394
9592
|
const n = await trx.selectFrom("notification").selectAll().where("id", "=", notificationId).executeTakeFirst();
|
|
9395
9593
|
if (n === void 0 || n.acked_at !== null || n.exhausted_at !== null || n.recipient_session !== sessionId) return "dead";
|
|
9396
|
-
const session = await selectNotificationRecipient(trx, n);
|
|
9594
|
+
const session = await selectNotificationRecipient(trx, n, config);
|
|
9397
9595
|
if (session?.id !== sessionId) return "dead";
|
|
9398
9596
|
return session.state === "working" ? "defer" : "send";
|
|
9399
9597
|
}
|
|
@@ -9417,7 +9615,7 @@ async function acknowledgeNotification(trx, input) {
|
|
|
9417
9615
|
const notices = await query.orderBy("id", "desc").execute();
|
|
9418
9616
|
const n = notices[0];
|
|
9419
9617
|
if (n === void 0) return false;
|
|
9420
|
-
if (!await notificationAddressedTo(trx, n, input.actor)) throw new CommandError("forbidden", "Only the addressed task role can acknowledge.");
|
|
9618
|
+
if (!await notificationAddressedTo(trx, n, input.actor, input.config)) throw new CommandError("forbidden", "Only the addressed task role can acknowledge.");
|
|
9421
9619
|
for (const notice of notices) {
|
|
9422
9620
|
await trx.updateTable("notification").set({ acked_at: input.at.toISOString() }).where("id", "=", notice.id).execute();
|
|
9423
9621
|
await journal$2(trx, notice, "doorbell_read", { doorbell: `N${String(notice.id)}` }, input.at);
|
|
@@ -9426,13 +9624,30 @@ async function acknowledgeNotification(trx, input) {
|
|
|
9426
9624
|
}
|
|
9427
9625
|
return true;
|
|
9428
9626
|
}
|
|
9429
|
-
/**
|
|
9430
|
-
async function notificationAddressedTo(trx, n, actor) {
|
|
9627
|
+
/** Decides who may list and acknowledge an inbox notice, by the role it is addressed to. */
|
|
9628
|
+
async function notificationAddressedTo(trx, n, actor, config) {
|
|
9431
9629
|
const parsed = parseActorId(actor);
|
|
9432
9630
|
if (parsed?.actor !== "agent") return false;
|
|
9433
|
-
const
|
|
9434
|
-
const
|
|
9435
|
-
|
|
9631
|
+
const { project, session } = parsed.actorRef;
|
|
9632
|
+
const addressee = parseAddressee(n.role);
|
|
9633
|
+
switch (addressee.kind) {
|
|
9634
|
+
case "curator": return project === curatorProject(config, await taskProject(trx, n.task_id));
|
|
9635
|
+
case "orchestrator": return project === columnOrchestratorProject(config, await taskProject(trx, n.task_id), addressee.column) || await hasLiveLink(trx, n.task_id, "orchestrator", session);
|
|
9636
|
+
case "operator": return session === n.author_session;
|
|
9637
|
+
case "worker": return workerNotificationAddressedTo(trx, n, session, config);
|
|
9638
|
+
default: return assertNever(addressee);
|
|
9639
|
+
}
|
|
9640
|
+
}
|
|
9641
|
+
async function sessionLink(trx, taskId, role, session) {
|
|
9642
|
+
return trx.selectFrom("link").select("id").where("task_id", "=", taskId).where("entity", "=", "session").where("role", "=", role).where("banned", "=", 0).where("session_id", "=", session).executeTakeFirst();
|
|
9643
|
+
}
|
|
9644
|
+
async function hasLiveLink(trx, taskId, role, session) {
|
|
9645
|
+
return await sessionLink(trx, taskId, role, session) !== void 0 && await liveSession(trx, session) !== void 0;
|
|
9646
|
+
}
|
|
9647
|
+
/** The selected worker while it lives; before the first ring, the author or a linked worker. */
|
|
9648
|
+
async function workerNotificationAddressedTo(trx, n, session, config) {
|
|
9649
|
+
if (n.recipient_session === null) return session === n.author_session || await sessionLink(trx, n.task_id, "worker", session) !== void 0;
|
|
9650
|
+
return await liveSession(trx, n.recipient_session) !== void 0 ? session === n.recipient_session : (await selectNotificationRecipient(trx, n, config))?.id === session;
|
|
9436
9651
|
}
|
|
9437
9652
|
async function closeBlockNotification(trx, blockId, at) {
|
|
9438
9653
|
const closed = await trx.updateTable("notification").set({ acked_at: at.toISOString() }).where("block_id", "=", blockId).where("kind", "=", "block").where("acked_at", "is", null).returning(["kind", "source_key"]).execute();
|
|
@@ -9553,59 +9768,6 @@ function commentView(comment, task) {
|
|
|
9553
9768
|
async function journal$1(trx, task, ctx, kind, payload) {
|
|
9554
9769
|
await emit(trx, kind, task.project, task.id, ctx.at, payload, ctx.actor);
|
|
9555
9770
|
}
|
|
9556
|
-
function orchestrator(config, task) {
|
|
9557
|
-
const name = config.projects.find((project) => project.id === task.project)?.columns.find((column) => column.id === task.column)?.orchestrator;
|
|
9558
|
-
return name === void 0 || name === "none" ? null : name;
|
|
9559
|
-
}
|
|
9560
|
-
function authorRole(config, task, actor) {
|
|
9561
|
-
if (actor === "operator") return "operator";
|
|
9562
|
-
const parsed = parseActorId(actor);
|
|
9563
|
-
if (parsed?.actor === "agent" && config.projects.some((project) => project.spurProjects.some((spur) => spur.name === parsed.actorRef.project && spur.role === "operator"))) return "operator";
|
|
9564
|
-
if (parsed?.actor !== "agent") return "worker";
|
|
9565
|
-
if (parsed.actorRef.project === orchestrator(config, task)) return `orchestrator:${task.column}`;
|
|
9566
|
-
return parsed.actorRef.project === curatorProject(config, task.project) ? "curator" : "worker";
|
|
9567
|
-
}
|
|
9568
|
-
function personaRole(role) {
|
|
9569
|
-
const addressee = parseAddressee(role);
|
|
9570
|
-
switch (addressee.kind) {
|
|
9571
|
-
case "operator": return "board";
|
|
9572
|
-
case "worker": return "worker";
|
|
9573
|
-
case "curator":
|
|
9574
|
-
case "orchestrator": return "orchestrator";
|
|
9575
|
-
default: return assertNever(addressee);
|
|
9576
|
-
}
|
|
9577
|
-
}
|
|
9578
|
-
function personaFor(config, task, actor) {
|
|
9579
|
-
if (actor === "system") return {
|
|
9580
|
-
name: "board",
|
|
9581
|
-
role: "board"
|
|
9582
|
-
};
|
|
9583
|
-
if (actor === "operator") return {
|
|
9584
|
-
name: "operator",
|
|
9585
|
-
role: "board"
|
|
9586
|
-
};
|
|
9587
|
-
const parsed = parseActorId(actor);
|
|
9588
|
-
if (parsed?.actor !== "agent") throw new Error("Invalid actor");
|
|
9589
|
-
return {
|
|
9590
|
-
name: parsed.actorRef.project,
|
|
9591
|
-
role: personaRole(authorRole(config, task, actor))
|
|
9592
|
-
};
|
|
9593
|
-
}
|
|
9594
|
-
async function queueBlockOpen(trx, task, block, ctx, config) {
|
|
9595
|
-
if (authorRole(config, task, block.author) === "operator") return;
|
|
9596
|
-
const comments = await trx.selectFrom("comment").select(["id", "author"]).where("block_id", "=", block.id).orderBy("id").execute();
|
|
9597
|
-
if (await enqueueConversationOpen(trx, {
|
|
9598
|
-
blockId: block.id,
|
|
9599
|
-
commentId: comments[0]?.id ?? null,
|
|
9600
|
-
persona: personaFor(config, task, comments[0]?.author ?? block.author),
|
|
9601
|
-
at: new Date(ctx.at)
|
|
9602
|
-
}) === null) return;
|
|
9603
|
-
for (const comment of comments.slice(1)) await enqueueConversationReply(trx, {
|
|
9604
|
-
commentId: comment.id,
|
|
9605
|
-
persona: personaFor(config, task, comment.author),
|
|
9606
|
-
at: new Date(ctx.at)
|
|
9607
|
-
});
|
|
9608
|
-
}
|
|
9609
9771
|
async function hasWorker(trx, task) {
|
|
9610
9772
|
return await trx.selectFrom("link").select("id").where("task_id", "=", task.id).where("entity", "=", "session").where("role", "=", "worker").where("banned", "=", 0).executeTakeFirst() !== void 0;
|
|
9611
9773
|
}
|
|
@@ -9644,13 +9806,14 @@ async function addComment(trx, task, block, text, ctx, addressee, config, source
|
|
|
9644
9806
|
comment: commentId(row.id),
|
|
9645
9807
|
addressee
|
|
9646
9808
|
});
|
|
9647
|
-
|
|
9809
|
+
await applyDoorbellPolicy(trx, block === void 0 ? { kind: "task_comment" } : {
|
|
9810
|
+
kind: "answer",
|
|
9648
9811
|
block,
|
|
9649
9812
|
commentId: row.id,
|
|
9650
9813
|
revision: row.revision,
|
|
9651
9814
|
authorRole: authorRole(config, task, block.author),
|
|
9652
|
-
|
|
9653
|
-
});
|
|
9815
|
+
actor: ctx.actor
|
|
9816
|
+
}, new Date(ctx.at));
|
|
9654
9817
|
if (block !== void 0 && source === void 0) await enqueueConversationReply(trx, {
|
|
9655
9818
|
commentId: row.id,
|
|
9656
9819
|
persona: personaFor(config, task, ctx.actor),
|
|
@@ -9683,7 +9846,11 @@ async function openBlock(trx, task, type, reason, ctx, config) {
|
|
|
9683
9846
|
type,
|
|
9684
9847
|
addressee
|
|
9685
9848
|
});
|
|
9686
|
-
await
|
|
9849
|
+
await applyDoorbellPolicy(trx, {
|
|
9850
|
+
kind: "block_opened",
|
|
9851
|
+
block: row,
|
|
9852
|
+
authorRole: authorRole(config, task, ctx.actor)
|
|
9853
|
+
}, new Date(ctx.at));
|
|
9687
9854
|
return row;
|
|
9688
9855
|
}
|
|
9689
9856
|
/** Unblocks one block with its journal entry, thread close, doorbell close and item clears. */
|
|
@@ -9734,7 +9901,7 @@ async function recordInboundBlockMessage(trx, input) {
|
|
|
9734
9901
|
block: answered ? await closeOpenBlock(trx, task, block, ctx, "done", null) : block,
|
|
9735
9902
|
task,
|
|
9736
9903
|
answered,
|
|
9737
|
-
|
|
9904
|
+
authorRole: authorRole(input.config, task, block.author)
|
|
9738
9905
|
};
|
|
9739
9906
|
}
|
|
9740
9907
|
/** Uses the same revision and acknowledgment rule as the catalog comment.edit mutation. */
|
|
@@ -9757,13 +9924,14 @@ async function editInboundComment(trx, input) {
|
|
|
9757
9924
|
});
|
|
9758
9925
|
if (next.clarification && updated.block_id !== null) {
|
|
9759
9926
|
const block = await trx.selectFrom("block").selectAll().where("id", "=", updated.block_id).executeTakeFirstOrThrow();
|
|
9760
|
-
|
|
9927
|
+
await applyDoorbellPolicy(trx, {
|
|
9928
|
+
kind: "answer",
|
|
9761
9929
|
block,
|
|
9762
9930
|
commentId: updated.id,
|
|
9763
9931
|
revision: updated.revision,
|
|
9764
9932
|
authorRole: authorRole(input.config, task, block.author),
|
|
9765
|
-
|
|
9766
|
-
});
|
|
9933
|
+
actor: input.actor
|
|
9934
|
+
}, new Date(input.at));
|
|
9767
9935
|
}
|
|
9768
9936
|
return updated;
|
|
9769
9937
|
}
|
|
@@ -9827,16 +9995,13 @@ function createBlockMutations(config) {
|
|
|
9827
9995
|
if (!next.changed) return { block: blockView(block, task) };
|
|
9828
9996
|
const target = await authorizationTarget(trx, task, block);
|
|
9829
9997
|
if (!holdsBlock(config, ctx.actor, target)) return { block: blockView(block, task) };
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
block
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
await queueBlockOpen(trx, task, updated, ctx, config);
|
|
9838
|
-
await registerBlockNotification(trx, updated, new Date(ctx.at));
|
|
9839
|
-
return { block: blockView(updated, task) };
|
|
9998
|
+
return { block: blockView(await moveBlockToAddressee(trx, {
|
|
9999
|
+
task,
|
|
10000
|
+
block,
|
|
10001
|
+
to: next.addressee,
|
|
10002
|
+
ctx,
|
|
10003
|
+
config
|
|
10004
|
+
}), task) };
|
|
9840
10005
|
}
|
|
9841
10006
|
},
|
|
9842
10007
|
answer: {
|
|
@@ -9874,7 +10039,12 @@ function createBlockMutations(config) {
|
|
|
9874
10039
|
actor: ctx.actor
|
|
9875
10040
|
}));
|
|
9876
10041
|
if (input.mode === "withdraw") await addComment(trx, task, block, input.answer, ctx, block.addressee_role, config);
|
|
9877
|
-
|
|
10042
|
+
const updated = await closeOpenBlock(trx, task, block, ctx, decision.outcome, decision.outcomeReason);
|
|
10043
|
+
await applyDoorbellPolicy(trx, input.mode === "done" || holdsBlock(config, ctx.actor, await authorizationTarget(trx, task, block)) ? { kind: "block_closed_by_addressee" } : {
|
|
10044
|
+
kind: "block_removed",
|
|
10045
|
+
block: updated
|
|
10046
|
+
}, new Date(ctx.at));
|
|
10047
|
+
return { block: blockView(updated, task) };
|
|
9878
10048
|
}
|
|
9879
10049
|
},
|
|
9880
10050
|
add: {
|
|
@@ -9930,7 +10100,8 @@ function createBlockMutations(config) {
|
|
|
9930
10100
|
if (!await acknowledgeNotification(trx, {
|
|
9931
10101
|
blockId: found(await blockById(trx, entry.id)).id,
|
|
9932
10102
|
actor: ctx.actor,
|
|
9933
|
-
at: new Date(ctx.at)
|
|
10103
|
+
at: new Date(ctx.at),
|
|
10104
|
+
config
|
|
9934
10105
|
})) throw new CommandError("not_found", "No unread block notification.");
|
|
9935
10106
|
continue;
|
|
9936
10107
|
}
|
|
@@ -9941,7 +10112,8 @@ function createBlockMutations(config) {
|
|
|
9941
10112
|
commentId: comment.id,
|
|
9942
10113
|
revision,
|
|
9943
10114
|
actor: ctx.actor,
|
|
9944
|
-
at: new Date(ctx.at)
|
|
10115
|
+
at: new Date(ctx.at),
|
|
10116
|
+
config
|
|
9945
10117
|
});
|
|
9946
10118
|
await trx.updateTable("comment").set({ acked_revision: revision }).where("id", "=", comment.id).execute();
|
|
9947
10119
|
await journal$1(trx, task, ctx, "comment_acked", {
|
|
@@ -10459,7 +10631,7 @@ function createSender(options) {
|
|
|
10459
10631
|
};
|
|
10460
10632
|
}
|
|
10461
10633
|
if (c.body.kind === "doorbell" && c.body.payload.notificationId !== void 0) {
|
|
10462
|
-
const status = await ringStillCurrent(trx, c.body.payload.notificationId, c.body.payload.session);
|
|
10634
|
+
const status = await ringStillCurrent(trx, c.body.payload.notificationId, c.body.payload.session, options.config);
|
|
10463
10635
|
if (status === "dead") {
|
|
10464
10636
|
await kill(trx, [c.id], "notification no longer current");
|
|
10465
10637
|
return {
|
|
@@ -11418,7 +11590,7 @@ function createTaskQueries(config) {
|
|
|
11418
11590
|
const task = await trx.selectFrom("task").selectAll().where("id", "=", notice.task_id).executeTakeFirst();
|
|
11419
11591
|
if (task === void 0 || !projects.has(task.project)) continue;
|
|
11420
11592
|
seen.add(notice.comment_id);
|
|
11421
|
-
if (!await notificationAddressedTo(trx, notice, actor)) continue;
|
|
11593
|
+
if (!await notificationAddressedTo(trx, notice, actor, config)) continue;
|
|
11422
11594
|
const comment = await trx.selectFrom("comment").selectAll().where("id", "=", notice.comment_id).executeTakeFirst();
|
|
11423
11595
|
if (comment === void 0 || comment.acked_revision === comment.revision) continue;
|
|
11424
11596
|
comments.push(commentView(comment, task));
|
|
@@ -12356,6 +12528,14 @@ function createObservationCore(deps) {
|
|
|
12356
12528
|
kind: "session",
|
|
12357
12529
|
id: link.session_id
|
|
12358
12530
|
}]) : [];
|
|
12531
|
+
const curators = config.projects.flatMap((project) => project.spurProjects.filter((spur) => spur.role === "curator").map((spur) => spur.name));
|
|
12532
|
+
if (source === "spur" && curators.length > 0) {
|
|
12533
|
+
const rows = await store.db.selectFrom("session_snapshot").select("id").where("spur_project", "in", curators).where("ended_at", "is", null).execute();
|
|
12534
|
+
sessions.push(...rows.map((row) => ({
|
|
12535
|
+
kind: "session",
|
|
12536
|
+
id: row.id
|
|
12537
|
+
})));
|
|
12538
|
+
}
|
|
12359
12539
|
const misses = await store.db.selectFrom("source_miss").selectAll().where("source", "=", source).execute();
|
|
12360
12540
|
return {
|
|
12361
12541
|
observe: {
|
|
@@ -12799,34 +12979,16 @@ async function skip(trx, input) {
|
|
|
12799
12979
|
async function linkedComment(trx, event) {
|
|
12800
12980
|
return trx.selectFrom("comment").selectAll().where("conversation_ref", "=", event.conversation).where("message_ref", "=", event.message).executeTakeFirst();
|
|
12801
12981
|
}
|
|
12982
|
+
/** The answer's notification is already registered; this raises the item when nobody can read it. */
|
|
12802
12983
|
async function ringAuthor(trx, input) {
|
|
12803
12984
|
const key = `doorbell:comment:${String(input.comment.id)}:revision:${String(input.comment.revision)}`;
|
|
12804
12985
|
const parsed = parseActorId(input.block.author);
|
|
12805
|
-
if (parsed?.actor === "agent")
|
|
12806
|
-
|
|
12986
|
+
if (parsed?.actor === "agent") {
|
|
12987
|
+
if (await selectNotificationRecipient(trx, {
|
|
12807
12988
|
task_id: input.task.id,
|
|
12808
|
-
role:
|
|
12989
|
+
role: input.authorRole,
|
|
12809
12990
|
author_session: parsed.actorRef.session
|
|
12810
|
-
});
|
|
12811
|
-
await registerAnswerNotification(trx, {
|
|
12812
|
-
block: input.block,
|
|
12813
|
-
commentId: input.comment.id,
|
|
12814
|
-
revision: input.comment.revision,
|
|
12815
|
-
authorRole: "worker",
|
|
12816
|
-
at: new Date(input.at)
|
|
12817
|
-
});
|
|
12818
|
-
if (recipient !== void 0) return;
|
|
12819
|
-
} else {
|
|
12820
|
-
const session = await trx.selectFrom("session_snapshot").select(["id", "ended_at"]).where("id", "=", parsed.actorRef.session).executeTakeFirst();
|
|
12821
|
-
if (session !== void 0 && session.ended_at === null) {
|
|
12822
|
-
await enqueueInboundDoorbell(trx, {
|
|
12823
|
-
key,
|
|
12824
|
-
session: session.id,
|
|
12825
|
-
text: `Answer for ${input.task.key} block B${String(input.block.id)}; read board task ${input.task.key}`,
|
|
12826
|
-
at: new Date(input.at)
|
|
12827
|
-
});
|
|
12828
|
-
return;
|
|
12829
|
-
}
|
|
12991
|
+
}, input.config) !== void 0) return;
|
|
12830
12992
|
}
|
|
12831
12993
|
await journal(trx, {
|
|
12832
12994
|
kind: "doorbell_undelivered",
|
|
@@ -12898,8 +13060,9 @@ function createInbound(input) {
|
|
|
12898
13060
|
block: recorded.block,
|
|
12899
13061
|
task: recorded.task,
|
|
12900
13062
|
comment: recorded.comment,
|
|
12901
|
-
|
|
12902
|
-
at
|
|
13063
|
+
authorRole: recorded.authorRole,
|
|
13064
|
+
at,
|
|
13065
|
+
config
|
|
12903
13066
|
});
|
|
12904
13067
|
return { status: "applied" };
|
|
12905
13068
|
}
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-
|
|
2
|
-
import { i as CliError, n as requestOperation } from "./client-
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-
|
|
1
|
+
import { P as ERRORS, p as renderMcpError, u as OPERATIONS } from "./src-Ron2NABC.mjs";
|
|
2
|
+
import { i as CliError, n as requestOperation } from "./client-D3vmFo39.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./config-CYLh25BZ.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { z } from "zod";
|