spur-board 0.60.0 → 0.62.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/{chunk-DQwj2UTj.mjs → chunk-Czc8fVqW.mjs} +1 -1
- package/dist/{chunk-CLjE9L59.mjs → chunk-CzdGYlBy.mjs} +40 -2
- package/dist/{chunk-BLpo-8dp.mjs → chunk-DyPssI65.mjs} +2 -2
- package/dist/cli.mjs +3 -3
- package/dist/client.mjs +1 -1
- package/dist/daemon.mjs +426 -53
- package/dist/mcp.mjs +3 -3
- package/dist/migrations/0020_block_addressee_spur.sql +3 -0
- package/package.json +1 -1
- package/skills/spur-board/references/commands.md +1 -1
- package/skills/spur-board/references/how-board-works.md +19 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as errorEnvelopeSchema, Q as errorContextSchema, S as renderJsonError, X as ERRORS, c as tokenRequestStatusSchema, o as tokenRequestResultSchema, tt as successEnvelopeSchema } from "./chunk-
|
|
1
|
+
import { $ as errorEnvelopeSchema, Q as errorContextSchema, S as renderJsonError, X as ERRORS, c as tokenRequestStatusSchema, o as tokenRequestResultSchema, tt as successEnvelopeSchema } from "./chunk-CzdGYlBy.mjs";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { request } from "node:http";
|
|
@@ -295,6 +295,7 @@ const spurProject = z.strictObject({
|
|
|
295
295
|
"curator",
|
|
296
296
|
"orchestrator"
|
|
297
297
|
]).describe("worker: sessions of this Spur project may link to this project's tasks through their PR or branch. operator: sessions act as the operator. orchestrator: sessions execute named columns and never become task workers. curator: sessions answer the questions no column orchestrator takes and escalate the rest to the operator; a board project has at most one."),
|
|
298
|
+
shortName: z.string().regex(/^[a-z0-9][a-z0-9_-]{0,31}$/, "Expected a short name of lowercase letters, digits, _ and -, starting with a letter or digit, at most 32 characters").optional().describe("The name the operator types as @<shortName> at the start of a new message in the orchestrators channel to start a conversation with this Spur project's live session. Unique across the board."),
|
|
298
299
|
displayName: nonEmpty.max(80).optional().describe("The name a curator's answer lines in the feed are posted under. Defaults to the Spur project name. Only for a curator."),
|
|
299
300
|
icon: z.string().regex(/^:[a-z0-9_+'-]+:$/, "Expected an emoji shortcode such as :owl:").optional().describe("The emoji shortcode, such as :owl:, shown on a curator's answer lines in the feed instead of the curator icon. Only for a curator.")
|
|
300
301
|
});
|
|
@@ -479,11 +480,32 @@ function rejectSharedSpurProjects(items, ctx) {
|
|
|
479
480
|
});
|
|
480
481
|
});
|
|
481
482
|
}
|
|
483
|
+
/** A `shortName` addresses one Spur project, so it is unique across every board project. */
|
|
484
|
+
function rejectSharedShortNames(items, ctx) {
|
|
485
|
+
const seen = /* @__PURE__ */ new Set();
|
|
486
|
+
items.forEach((project, i) => {
|
|
487
|
+
project.spurProjects.forEach(({ shortName }, j) => {
|
|
488
|
+
if (shortName === void 0) return;
|
|
489
|
+
if (seen.has(shortName)) ctx.addIssue({
|
|
490
|
+
code: "custom",
|
|
491
|
+
path: [
|
|
492
|
+
i,
|
|
493
|
+
"spurProjects",
|
|
494
|
+
j,
|
|
495
|
+
"shortName"
|
|
496
|
+
],
|
|
497
|
+
message: `Duplicate short name: ${JSON.stringify(shortName)}`
|
|
498
|
+
});
|
|
499
|
+
seen.add(shortName);
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
}
|
|
482
503
|
/** The board config file. Every object rejects unknown keys; no key holds a secret. */
|
|
483
504
|
const configSchema = z.strictObject({
|
|
484
505
|
projects: z.array(projectSchema).min(1).superRefine((items, ctx) => {
|
|
485
506
|
rejectDuplicates(items, "id", "project id", ctx);
|
|
486
507
|
rejectSharedSpurProjects(items, ctx);
|
|
508
|
+
rejectSharedShortNames(items, ctx);
|
|
487
509
|
}).describe("Board projects, at least one. Each reads tasks from one tracker and PRs from its repos. A Spur project can be listed under only one board project."),
|
|
488
510
|
operator: z.strictObject({ slack: nonEmpty.describe("Slack user ID of the operator, such as U0123456789. Slack commands, button presses and messages from anyone else are denied. A feed line the operator resolves names this user.") }),
|
|
489
511
|
slack: z.strictObject({
|
|
@@ -493,7 +515,8 @@ const configSchema = z.strictObject({
|
|
|
493
515
|
channels: z.strictObject({
|
|
494
516
|
orchestrators: nonEmpty.optional().describe("Slack channel ID, such as C0123456789, where the board opens a thread for each block addressed to the operator by someone else. Once either channel is set, the daemon does not start without the other channel and SLACK_BOT_TOKEN, and without SLACK_APP_TOKEN it reads nothing from Slack."),
|
|
495
517
|
feed: nonEmpty.optional().describe("Slack channel ID where the board posts a line for each curator answer, each newly installed version, each revoked operator token, each `/board tokens` list and each operator item, with the buttons the operator presses. Operator items about failed Slack posts, transport health, undelivered answers and ended workers, and those shown as operator blocks, get no feed line. A line whose item clears before it is first sent, such as an expired token request, is dropped. Set it together with orchestrators.")
|
|
496
|
-
}).prefault({})
|
|
518
|
+
}).prefault({}),
|
|
519
|
+
defaultAddressee: z.string().optional().describe("The shortName of the Spur project that gets a new orchestrators-channel message which does not start with a known @<shortName>. Without it, such a message gets one reply listing the valid prefixes. Ignored when no shortName is configured.")
|
|
497
520
|
}).prefault({}),
|
|
498
521
|
thresholds: z.strictObject({
|
|
499
522
|
staleMultiplier: z.number().min(1).default(3).describe("A source with no complete poll for this many of its poll intervals turns blind stale. board status marks that source, and an operator item whose fact is older than that, as stale."),
|
|
@@ -542,6 +565,14 @@ const configSchema = z.strictObject({
|
|
|
542
565
|
maxEpisodeMs: durationMs(3e5, "Longest a host-load episode lasts before error flags resume")
|
|
543
566
|
}).prefault({})
|
|
544
567
|
}).prefault({})
|
|
568
|
+
}).superRefine((config, ctx) => {
|
|
569
|
+
const addressee = config.slack.defaultAddressee;
|
|
570
|
+
if (addressee === void 0) return;
|
|
571
|
+
if (!config.projects.some((project) => project.spurProjects.some(({ shortName }) => shortName === addressee))) ctx.addIssue({
|
|
572
|
+
code: "custom",
|
|
573
|
+
path: ["slack", "defaultAddressee"],
|
|
574
|
+
message: `Unknown short name ${JSON.stringify(addressee)}: set it as projects[].spurProjects[].shortName first`
|
|
575
|
+
});
|
|
545
576
|
});
|
|
546
577
|
/** Recognized names in the private secrets.env file; values never belong in config.yaml. */
|
|
547
578
|
const SECRET_ENV_KEYS = [
|
|
@@ -1590,6 +1621,11 @@ const text$1 = z.string();
|
|
|
1590
1621
|
const sourceUrl = z.url();
|
|
1591
1622
|
/** Configured board space for an interaction, or null when it came from outside. */
|
|
1592
1623
|
const sourceSpace = z.enum(SPACE_IDS).nullable();
|
|
1624
|
+
/**
|
|
1625
|
+
* Configured board space of a conversation's first message, set only when `rootMessage` equals
|
|
1626
|
+
* `message`; a reply in a conversation carries none.
|
|
1627
|
+
*/
|
|
1628
|
+
const firstMessageSpace = sourceSpace.optional();
|
|
1593
1629
|
const messageEventSchema = z.strictObject({
|
|
1594
1630
|
kind: z.literal("message"),
|
|
1595
1631
|
dedupeKey,
|
|
@@ -1600,6 +1636,7 @@ const messageEventSchema = z.strictObject({
|
|
|
1600
1636
|
author: userIdSchema,
|
|
1601
1637
|
text: text$1,
|
|
1602
1638
|
at: at$1,
|
|
1639
|
+
sourceSpace: firstMessageSpace,
|
|
1603
1640
|
originKey: z.string().min(1).optional()
|
|
1604
1641
|
});
|
|
1605
1642
|
/** `message` is the original message, `text` the new text and `at` the edit time. */
|
|
@@ -1671,6 +1708,7 @@ const mentionEventSchema = z.strictObject({
|
|
|
1671
1708
|
author: userIdSchema,
|
|
1672
1709
|
text: text$1,
|
|
1673
1710
|
at: at$1,
|
|
1711
|
+
sourceSpace: firstMessageSpace,
|
|
1674
1712
|
originKey: z.string().min(1).optional()
|
|
1675
1713
|
});
|
|
1676
1714
|
/** History may be missing. Without `conversation` the gap covers the whole gateway. */
|
|
@@ -3260,7 +3298,7 @@ const OPERATIONS = [
|
|
|
3260
3298
|
defineOperation({
|
|
3261
3299
|
id: "block.answer",
|
|
3262
3300
|
kind: "mutation",
|
|
3263
|
-
description: "Answer a question
|
|
3301
|
+
description: "Answer a question; the block closes unless it is an operator conversation.",
|
|
3264
3302
|
mcp: {
|
|
3265
3303
|
whenToUse: "Answer an open question.",
|
|
3266
3304
|
whenNotToUse: "Use block_unblock to close without an answer."
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ as buildCatalogSnapshot, ct as plainHttpAllowed, st as configSchema, y as OPERATIONS } from "./chunk-
|
|
2
|
-
import { o as CliError, t as fetchCatalogVersion } from "./chunk-
|
|
1
|
+
import { _ as buildCatalogSnapshot, ct as plainHttpAllowed, st as configSchema, y as OPERATIONS } from "./chunk-CzdGYlBy.mjs";
|
|
2
|
+
import { o as CliError, t as fetchCatalogVersion } from "./chunk-Czc8fVqW.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/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { G as actorIdSchema, X as ERRORS, a as requestHashOf, ft as SLACK_BOT_SCOPES, lt as requiredSecretKeys, r as remoteDoctorReportSchema, st as configSchema, tt as successEnvelopeSchema, u as SYSTEMD_SERVICE_SETTINGS, v as roleCanUseOperation, y as OPERATIONS } from "./chunk-
|
|
1
|
+
import { G as actorIdSchema, X as ERRORS, a as requestHashOf, ft as SLACK_BOT_SCOPES, lt as requiredSecretKeys, r as remoteDoctorReportSchema, st as configSchema, tt as successEnvelopeSchema, u as SYSTEMD_SERVICE_SETTINGS, v as roleCanUseOperation, y as OPERATIONS } from "./chunk-CzdGYlBy.mjs";
|
|
2
2
|
import { t as apiBaseUrl } from "./chunk-DAMwWWmT.mjs";
|
|
3
|
-
import { a as requestTokenEnrollment, c as renderCliError, i as requestSkillReload, l as escapeTerminalControls, n as fetchTokenStatus, o as CliError, r as requestOperation, s as errorExitCode } from "./chunk-
|
|
4
|
-
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, f as tokenInFolder, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./chunk-
|
|
3
|
+
import { a as requestTokenEnrollment, c as renderCliError, i as requestSkillReload, l as escapeTerminalControls, n as fetchTokenStatus, o as CliError, r as requestOperation, s as errorExitCode } from "./chunk-Czc8fVqW.mjs";
|
|
4
|
+
import { a as memoryVerdictCache, c as loadClientConfig, d as resolveDaemonAddress, f as tokenInFolder, i as fileVerdictCache, l as loadEnrollmentConfig, n as cliPackageVersion, o as configFile, s as dataDirectory, t as checkCatalog, u as readConfiguredPort } from "./chunk-DyPssI65.mjs";
|
|
5
5
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
6
6
|
import { accessSync, chmodSync, closeSync, constants, cpSync, existsSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
7
7
|
import { homedir, hostname, userInfo } from "node:os";
|
package/dist/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-
|
|
1
|
+
import { a as requestTokenEnrollment, i as requestSkillReload, n as fetchTokenStatus, r as requestOperation, t as fetchCatalogVersion } from "./chunk-Czc8fVqW.mjs";
|
|
2
2
|
export { fetchCatalogVersion, fetchTokenStatus, requestOperation, requestSkillReload, requestTokenEnrollment };
|
package/dist/daemon.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as EVENT_KINDS, B as ringMarker, D as interactionRefSchema, E as inboundEventSchema, F as SESSION_STATUSES, G as actorIdSchema, H as ticketFactsSchema, I as isExternalAuthor, J as parseActorId, K as encodeActorId, L as parseRingMarker, M as PR_STATES, N as REVIEW_STATES, O as messageRefSchema, P as SESSION_HEALTH_STATES, R as prFactsSchema, T as conversationRefSchema, U as JIRA_PROJECT_KEY, V as sessionFactsSchema, W as REF_NUMBER, X as ERRORS, Y as parseRef$1, Z as err, _ as buildCatalogSnapshot, a as requestHashOf, at as DEFAULT_SLACK_COMMAND, b as turnHandedSchema, c as tokenRequestStatusSchema, ct as plainHttpAllowed, d as AdapterError, dt as DISPATCHER_MODES, et as ok, f as batchSchema, ft as SLACK_BOT_SCOPES, g as trackerSourceId, h as sourceCursorSchema, i as TOKEN_REQUEST_LIMITS, j as eventPayloadSchemas, k as userIdSchema, l as BOARD_TICK_MS, lt as requiredSecretKeys, m as prSourceId, n as doctorReportSchema, o as tokenRequestResultSchema, ot as RESERVED_PROJECT, p as entityRefSchema, pt as TASK_HOLDS, q as errorCodeOf, rt as DEFAULT_LINK, s as tokenRequestSchema, st as configSchema, t as assertNever, tt as successEnvelopeSchema, ut as COLUMN_IDS, v as roleCanUseOperation, w as SPACE_IDS, x as renderHttpProblem, y as OPERATIONS, z as prRefSchema } from "./chunk-
|
|
1
|
+
import { A as EVENT_KINDS, B as ringMarker, D as interactionRefSchema, E as inboundEventSchema, F as SESSION_STATUSES, G as actorIdSchema, H as ticketFactsSchema, I as isExternalAuthor, J as parseActorId, K as encodeActorId, L as parseRingMarker, M as PR_STATES, N as REVIEW_STATES, O as messageRefSchema, P as SESSION_HEALTH_STATES, R as prFactsSchema, T as conversationRefSchema, U as JIRA_PROJECT_KEY, V as sessionFactsSchema, W as REF_NUMBER, X as ERRORS, Y as parseRef$1, Z as err, _ as buildCatalogSnapshot, a as requestHashOf, at as DEFAULT_SLACK_COMMAND, b as turnHandedSchema, c as tokenRequestStatusSchema, ct as plainHttpAllowed, d as AdapterError, dt as DISPATCHER_MODES, et as ok, f as batchSchema, ft as SLACK_BOT_SCOPES, g as trackerSourceId, h as sourceCursorSchema, i as TOKEN_REQUEST_LIMITS, j as eventPayloadSchemas, k as userIdSchema, l as BOARD_TICK_MS, lt as requiredSecretKeys, m as prSourceId, n as doctorReportSchema, o as tokenRequestResultSchema, ot as RESERVED_PROJECT, p as entityRefSchema, pt as TASK_HOLDS, q as errorCodeOf, rt as DEFAULT_LINK, s as tokenRequestSchema, st as configSchema, t as assertNever, tt as successEnvelopeSchema, ut as COLUMN_IDS, v as roleCanUseOperation, w as SPACE_IDS, x as renderHttpProblem, y as OPERATIONS, z as prRefSchema } from "./chunk-CzdGYlBy.mjs";
|
|
2
2
|
import { t as apiBaseUrl } from "./chunk-DAMwWWmT.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -543,6 +543,8 @@ function matches(rule, actor, target, config) {
|
|
|
543
543
|
case "column-orchestrator": return target.task !== null && orchestrator$1(actor, target, config, target.task.column);
|
|
544
544
|
case "block-addressee": {
|
|
545
545
|
if (target.block === null) return false;
|
|
546
|
+
const spur = target.block.addressee_spur_project ?? null;
|
|
547
|
+
if (spur !== null) return parsed?.actor === "agent" && parsed.actorRef.project === spur;
|
|
546
548
|
const addressee = parseAddressee(target.block.addressee_role);
|
|
547
549
|
switch (addressee.kind) {
|
|
548
550
|
case "operator": return isOperator(actor, config);
|
|
@@ -8542,7 +8544,8 @@ const ITEM_KINDS = [
|
|
|
8542
8544
|
"turn",
|
|
8543
8545
|
"anomaly",
|
|
8544
8546
|
"cycle_limit",
|
|
8545
|
-
"course_check"
|
|
8547
|
+
"course_check",
|
|
8548
|
+
"conversation_waiting"
|
|
8546
8549
|
];
|
|
8547
8550
|
const ITEM_POLICY = {
|
|
8548
8551
|
token_request: {
|
|
@@ -8671,6 +8674,15 @@ const ITEM_POLICY = {
|
|
|
8671
8674
|
buttons: "item",
|
|
8672
8675
|
reconciled: false,
|
|
8673
8676
|
block: true
|
|
8677
|
+
},
|
|
8678
|
+
/** An operator conversation whose ring waits for a live session of its Spur project. */
|
|
8679
|
+
conversation_waiting: {
|
|
8680
|
+
retry: "none",
|
|
8681
|
+
feed: false,
|
|
8682
|
+
priority: 4,
|
|
8683
|
+
buttons: "item",
|
|
8684
|
+
reconciled: true,
|
|
8685
|
+
block: false
|
|
8674
8686
|
}
|
|
8675
8687
|
};
|
|
8676
8688
|
/** Guards a stored kind: the column is free text and old or hand-written rows may hold others. */
|
|
@@ -8783,6 +8795,7 @@ const OUTBOX_KINDS = [
|
|
|
8783
8795
|
"conversation.open",
|
|
8784
8796
|
"conversation.reply",
|
|
8785
8797
|
"conversation.close",
|
|
8798
|
+
"conversation.notice",
|
|
8786
8799
|
"feed.line",
|
|
8787
8800
|
"feed.line.edit",
|
|
8788
8801
|
"doorbell"
|
|
@@ -8792,6 +8805,7 @@ const KIND_SPACE = {
|
|
|
8792
8805
|
"conversation.open": "orchestrators",
|
|
8793
8806
|
"conversation.reply": "orchestrators",
|
|
8794
8807
|
"conversation.close": "orchestrators",
|
|
8808
|
+
"conversation.notice": "orchestrators",
|
|
8795
8809
|
"feed.line": "feed",
|
|
8796
8810
|
"feed.line.edit": "feed",
|
|
8797
8811
|
doorbell: null
|
|
@@ -8801,6 +8815,7 @@ const KIND_PRIORITY = {
|
|
|
8801
8815
|
"conversation.open": 0,
|
|
8802
8816
|
"conversation.reply": 0,
|
|
8803
8817
|
"conversation.close": 1,
|
|
8818
|
+
"conversation.notice": 0,
|
|
8804
8819
|
"feed.line": 2,
|
|
8805
8820
|
"feed.line.edit": 2,
|
|
8806
8821
|
doorbell: 0
|
|
@@ -8824,6 +8839,13 @@ const closePayload = z.strictObject({
|
|
|
8824
8839
|
});
|
|
8825
8840
|
const openPayload = closePayload.extend({ title: z.string().min(1) });
|
|
8826
8841
|
const replyPayload = closePayload.extend({ commentId: id });
|
|
8842
|
+
/** A board reply in a thread the operator started that opened no block; `key` names the board. */
|
|
8843
|
+
const noticePayload = z.strictObject({
|
|
8844
|
+
key: z.string().min(1),
|
|
8845
|
+
text: z.string().min(1),
|
|
8846
|
+
persona,
|
|
8847
|
+
targetConversation: conversationRefSchema
|
|
8848
|
+
});
|
|
8827
8849
|
const feedLineEditPayload = z.strictObject({
|
|
8828
8850
|
key: z.string().min(1),
|
|
8829
8851
|
text: z.string(),
|
|
@@ -8871,11 +8893,28 @@ const exchange = z.strictObject({
|
|
|
8871
8893
|
answeredBy: z.string().min(1),
|
|
8872
8894
|
outcome: z.literal("unblocked")
|
|
8873
8895
|
});
|
|
8896
|
+
/** One piece of a feed line: plain text, or a command shown as code on one line. */
|
|
8897
|
+
const segment = z.discriminatedUnion("kind", [z.strictObject({
|
|
8898
|
+
kind: z.literal("text"),
|
|
8899
|
+
text: z.string()
|
|
8900
|
+
}), z.strictObject({
|
|
8901
|
+
kind: z.literal("code"),
|
|
8902
|
+
text: z.string().regex(/^[^\n]+$/)
|
|
8903
|
+
})]);
|
|
8904
|
+
/** The plain summary of `segments`: what is scanned, stored on the item and struck. */
|
|
8905
|
+
function feedText(segments) {
|
|
8906
|
+
return segments.map((part) => part.text).join("");
|
|
8907
|
+
}
|
|
8908
|
+
/** `segments`, when set, is the line's rich form of `text`; a mismatch is never sent. */
|
|
8874
8909
|
const feedLineWithLinkPayload = feedLinePayload.extend({
|
|
8875
8910
|
itemId: id.optional(),
|
|
8876
8911
|
url: z.url().optional(),
|
|
8877
8912
|
actions: z.array(actionPayload).optional(),
|
|
8878
|
-
exchange: exchange.optional()
|
|
8913
|
+
exchange: exchange.optional(),
|
|
8914
|
+
segments: z.array(segment).optional()
|
|
8915
|
+
}).refine((line) => line.segments === void 0 || line.text === feedText(line.segments), {
|
|
8916
|
+
message: "text does not match segments",
|
|
8917
|
+
path: ["text"]
|
|
8879
8918
|
});
|
|
8880
8919
|
const doorbellPayload = z.strictObject({
|
|
8881
8920
|
session: z.string().min(1),
|
|
@@ -8899,6 +8938,10 @@ const outboxBodySchema = z.discriminatedUnion("kind", [
|
|
|
8899
8938
|
kind: z.literal("conversation.close"),
|
|
8900
8939
|
payload: closePayload
|
|
8901
8940
|
}),
|
|
8941
|
+
z.strictObject({
|
|
8942
|
+
kind: z.literal("conversation.notice"),
|
|
8943
|
+
payload: noticePayload
|
|
8944
|
+
}),
|
|
8902
8945
|
z.strictObject({
|
|
8903
8946
|
kind: z.literal("feed.line"),
|
|
8904
8947
|
payload: feedLineWithLinkPayload
|
|
@@ -9072,7 +9115,8 @@ async function enqueueFeedLine(trx, input) {
|
|
|
9072
9115
|
itemId: input.itemId,
|
|
9073
9116
|
taskId: input.taskId ?? void 0,
|
|
9074
9117
|
...input.url === "" ? {} : { url: input.url },
|
|
9075
|
-
actions: input.actions
|
|
9118
|
+
actions: input.actions,
|
|
9119
|
+
...input.segments === void 0 ? {} : { segments: input.segments }
|
|
9076
9120
|
},
|
|
9077
9121
|
parent: null,
|
|
9078
9122
|
at: input.at
|
|
@@ -9114,7 +9158,8 @@ async function enqueueBoardFeedLine(trx, input) {
|
|
|
9114
9158
|
role: "board"
|
|
9115
9159
|
},
|
|
9116
9160
|
itemKey: input.itemKey,
|
|
9117
|
-
...input.actions === void 0 ? {} : { actions: input.actions }
|
|
9161
|
+
...input.actions === void 0 ? {} : { actions: input.actions },
|
|
9162
|
+
...input.segments === void 0 ? {} : { segments: input.segments }
|
|
9118
9163
|
},
|
|
9119
9164
|
parent: null,
|
|
9120
9165
|
at: input.at
|
|
@@ -9233,17 +9278,28 @@ async function blockPost(trx, row, payload, rule) {
|
|
|
9233
9278
|
const taskId = "taskId" in payload && typeof payload.taskId === "number" ? payload.taskId : null;
|
|
9234
9279
|
const blockId = "blockId" in payload && typeof payload.blockId === "number" ? payload.blockId : null;
|
|
9235
9280
|
const task = taskId === null ? null : await trx.selectFrom("task").selectAll().where("id", "=", taskId).executeTakeFirstOrThrow();
|
|
9281
|
+
const head = `text on ${safeKey} not sent: looks like a secret (${rule}), read `;
|
|
9282
|
+
const segments = typeof payload.key === "string" && safeKey === payload.key ? [{
|
|
9283
|
+
kind: "text",
|
|
9284
|
+
text: head
|
|
9285
|
+
}, {
|
|
9286
|
+
kind: "code",
|
|
9287
|
+
text: `board task ${safeKey}`
|
|
9288
|
+
}] : void 0;
|
|
9236
9289
|
await raiseItemWith(trx, {
|
|
9237
9290
|
itemKey: `secret-post:${createHash("sha256").update(row.dedupeKey).digest("hex")}`,
|
|
9238
9291
|
kind: "post_blocked",
|
|
9239
|
-
text:
|
|
9292
|
+
text: `${head}board task ${safeKey}`,
|
|
9240
9293
|
url: task === null ? "" : taskUrl(task, scanConfig()),
|
|
9241
9294
|
taskId,
|
|
9242
9295
|
blockId,
|
|
9243
9296
|
at: row.at,
|
|
9244
9297
|
rule,
|
|
9245
9298
|
source: row.kind
|
|
9246
|
-
}, enqueueFeedLine)
|
|
9299
|
+
}, segments === void 0 ? enqueueFeedLine : (t, line) => enqueueFeedLine(t, {
|
|
9300
|
+
...line,
|
|
9301
|
+
segments
|
|
9302
|
+
}));
|
|
9247
9303
|
}
|
|
9248
9304
|
/**
|
|
9249
9305
|
* Scans a stored gateway row's payload again before it is resent, with the rules used at
|
|
@@ -9344,10 +9400,17 @@ async function enqueueConversationOpen(trx, input) {
|
|
|
9344
9400
|
if (row.inserted && input.commentId !== null) await markCommentPending(trx, input.commentId);
|
|
9345
9401
|
return row.id;
|
|
9346
9402
|
}
|
|
9403
|
+
/** The thread an operator conversation was started in; undefined for every other block. */
|
|
9404
|
+
async function operatorThread(trx, blockId) {
|
|
9405
|
+
const row = await trx.selectFrom("conversation").innerJoin("block", "block.id", "conversation.block_id").select("conversation.ref").where("conversation.block_id", "=", blockId).where("block.addressee_spur_project", "is not", null).orderBy("conversation.created_at").executeTakeFirst();
|
|
9406
|
+
return row === void 0 ? void 0 : conversationRefSchema.parse(row.ref);
|
|
9407
|
+
}
|
|
9347
9408
|
/**
|
|
9348
9409
|
* Writes the `conversation.reply` row of a later comment on a block whose open row exists.
|
|
9349
9410
|
* The row waits for the thread's latest open, reply or close row. Returns null and writes
|
|
9350
|
-
* nothing when there is no such row or it is dead: a dead thread takes no more replies.
|
|
9411
|
+
* nothing when there is no such row or it is dead: a dead thread takes no more replies. A block
|
|
9412
|
+
* with no open row, an operator conversation, replies in its registered thread
|
|
9413
|
+
* (`targetConversation`), after its earlier replies.
|
|
9351
9414
|
*/
|
|
9352
9415
|
async function enqueueConversationReply(trx, input) {
|
|
9353
9416
|
const comment = await trx.selectFrom("comment").select([
|
|
@@ -9363,20 +9426,22 @@ async function enqueueConversationReply(trx, input) {
|
|
|
9363
9426
|
"conversation.reply",
|
|
9364
9427
|
"conversation.close"
|
|
9365
9428
|
]).where(sql`json_extract(payload, '$.blockId')`, "=", blockId).orderBy("id", "desc").limit(1).executeTakeFirst();
|
|
9366
|
-
|
|
9429
|
+
const started = await operatorThread(trx, blockId);
|
|
9430
|
+
if (tail === void 0 && started === void 0 || tail?.state === "dead") return null;
|
|
9367
9431
|
const payload = {
|
|
9368
9432
|
key: (await rowSubject(trx, comment)).key,
|
|
9369
9433
|
text: comment.text,
|
|
9370
9434
|
persona: input.persona,
|
|
9371
9435
|
taskId: comment.task_id,
|
|
9372
9436
|
blockId,
|
|
9373
|
-
commentId: comment.id
|
|
9437
|
+
commentId: comment.id,
|
|
9438
|
+
...started === void 0 ? {} : { targetConversation: started }
|
|
9374
9439
|
};
|
|
9375
9440
|
const row = await insertOutbox(trx, {
|
|
9376
9441
|
kind: "conversation.reply",
|
|
9377
9442
|
dedupeKey: `conversation.reply:comment:${String(comment.id)}`,
|
|
9378
9443
|
payload,
|
|
9379
|
-
parent: tail
|
|
9444
|
+
parent: tail?.id ?? null,
|
|
9380
9445
|
at: input.at
|
|
9381
9446
|
});
|
|
9382
9447
|
if (row.inserted) await markCommentPending(trx, comment.id);
|
|
@@ -9430,6 +9495,29 @@ async function enqueueConversationClose(trx, input) {
|
|
|
9430
9495
|
closed_at: input.at.toISOString()
|
|
9431
9496
|
}).where("block_id", "=", input.blockId).where("state", "=", "open").execute();
|
|
9432
9497
|
}
|
|
9498
|
+
/**
|
|
9499
|
+
* Posts one board line in a thread the operator started that opened nothing, such as the list of
|
|
9500
|
+
* valid addressees. It names no block or comment; each thread gets it once.
|
|
9501
|
+
*/
|
|
9502
|
+
async function enqueueConversationNotice(trx, input) {
|
|
9503
|
+
const hash = createHash("sha256").update(input.conversation).digest("hex");
|
|
9504
|
+
const payload = {
|
|
9505
|
+
key: "board",
|
|
9506
|
+
text: input.text,
|
|
9507
|
+
persona: {
|
|
9508
|
+
name: "board",
|
|
9509
|
+
role: "board"
|
|
9510
|
+
},
|
|
9511
|
+
targetConversation: input.conversation
|
|
9512
|
+
};
|
|
9513
|
+
await insertOutbox(trx, {
|
|
9514
|
+
kind: "conversation.notice",
|
|
9515
|
+
dedupeKey: `conversation.notice:ref:${hash}`,
|
|
9516
|
+
payload,
|
|
9517
|
+
parent: null,
|
|
9518
|
+
at: input.at
|
|
9519
|
+
});
|
|
9520
|
+
}
|
|
9433
9521
|
//#endregion
|
|
9434
9522
|
//#region ../core/src/app/block-thread.ts
|
|
9435
9523
|
function orchestrator(config, task) {
|
|
@@ -9614,6 +9702,29 @@ function resolvedLine(by, at, config) {
|
|
|
9614
9702
|
}
|
|
9615
9703
|
];
|
|
9616
9704
|
}
|
|
9705
|
+
/**
|
|
9706
|
+
* A feed line: its key, linked when it has a url, then its segments, or its text, as a quote.
|
|
9707
|
+
*/
|
|
9708
|
+
function feedLineBody(payload) {
|
|
9709
|
+
const { key, url, text, segments } = payload;
|
|
9710
|
+
return [{
|
|
9711
|
+
kind: "paragraph",
|
|
9712
|
+
children: [url === void 0 ? {
|
|
9713
|
+
kind: "text",
|
|
9714
|
+
text: key
|
|
9715
|
+
} : {
|
|
9716
|
+
kind: "link",
|
|
9717
|
+
url,
|
|
9718
|
+
text: key
|
|
9719
|
+
}]
|
|
9720
|
+
}, {
|
|
9721
|
+
kind: "quote",
|
|
9722
|
+
children: segments ?? [{
|
|
9723
|
+
kind: "text",
|
|
9724
|
+
text
|
|
9725
|
+
}]
|
|
9726
|
+
}];
|
|
9727
|
+
}
|
|
9617
9728
|
/** A cleared line: its key line, the struck summary and who resolved it when; no actions. */
|
|
9618
9729
|
function resolvedFeedBody(payload, config) {
|
|
9619
9730
|
const { key, url, text, resolved } = payload;
|
|
@@ -9854,6 +9965,10 @@ async function registerRemovedNotification(trx, block, at) {
|
|
|
9854
9965
|
}
|
|
9855
9966
|
/** Register an answer or clarification for the question's author, unless the author wrote it. */
|
|
9856
9967
|
async function registerAnswerNotification(trx, input, at) {
|
|
9968
|
+
if (input.block.addressee_spur_project !== null) {
|
|
9969
|
+
await registerConversationFollowUp(trx, input, at);
|
|
9970
|
+
return;
|
|
9971
|
+
}
|
|
9857
9972
|
const parsed = parseActorId(input.block.author);
|
|
9858
9973
|
if (parsed?.actor !== "agent" || input.actor === input.block.author) return;
|
|
9859
9974
|
const actor = parseActorId(input.actor);
|
|
@@ -9876,6 +9991,37 @@ async function registerAnswerNotification(trx, input, at) {
|
|
|
9876
9991
|
}).onConflict((oc) => oc.column("source_key").doNothing()).execute();
|
|
9877
9992
|
}
|
|
9878
9993
|
/**
|
|
9994
|
+
* Register the addressee's ring for an operator's follow-up in an open operator conversation. An
|
|
9995
|
+
* agent's answer rings nobody: the operator reads it in the thread.
|
|
9996
|
+
*/
|
|
9997
|
+
async function registerConversationFollowUp(trx, input, at) {
|
|
9998
|
+
if (input.actor !== "operator" || input.block.state !== "open") return;
|
|
9999
|
+
await trx.insertInto("notification").values({
|
|
10000
|
+
source_key: `comment:${String(input.commentId)}:${String(input.revision)}`,
|
|
10001
|
+
kind: "answer",
|
|
10002
|
+
task_id: input.block.task_id,
|
|
10003
|
+
block_id: input.block.id,
|
|
10004
|
+
comment_id: input.commentId,
|
|
10005
|
+
revision: input.revision,
|
|
10006
|
+
role: input.block.addressee_role,
|
|
10007
|
+
author_session: null,
|
|
10008
|
+
recipient_session: null,
|
|
10009
|
+
next_at: at.toISOString(),
|
|
10010
|
+
last_outbox_id: null,
|
|
10011
|
+
acked_at: null,
|
|
10012
|
+
exhausted_at: null,
|
|
10013
|
+
created_at: at.toISOString()
|
|
10014
|
+
}).onConflict((oc) => oc.column("source_key").doNothing()).execute();
|
|
10015
|
+
}
|
|
10016
|
+
/**
|
|
10017
|
+
* The Spur project an operator conversation's notification is addressed to, or null for every
|
|
10018
|
+
* other notification. It routes the ring before the role does.
|
|
10019
|
+
*/
|
|
10020
|
+
async function conversationTarget(trx, n) {
|
|
10021
|
+
if (n.block_id === void 0 || n.block_id === null) return null;
|
|
10022
|
+
return (await trx.selectFrom("block").select("addressee_spur_project").where("id", "=", n.block_id).executeTakeFirst())?.addressee_spur_project ?? null;
|
|
10023
|
+
}
|
|
10024
|
+
/**
|
|
9879
10025
|
* Register the worker's ring for a course note: the curator's answer to a course check, copied to
|
|
9880
10026
|
* the task. It names the course block, and until its first ring is delivered the worker's other
|
|
9881
10027
|
* rings on the task stay held (`courseHold`), so the worker reads the decision first.
|
|
@@ -9904,10 +10050,15 @@ const courseBlocks = (eb) => eb.selectFrom("operator_item").select("operator_ite
|
|
|
9904
10050
|
* Whether a worker notification is held by a course check on its task. Two holds apply: while a
|
|
9905
10051
|
* `course_check` item is active, and, once it clears with a note, until the note's first ring is
|
|
9906
10052
|
* delivered to any session, so the note rings first. A course note is a worker `answer`
|
|
9907
|
-
* notification on a course check's block. Other roles and `cycle_limit`
|
|
10053
|
+
* notification on a course check's block. Other roles, operator conversations and `cycle_limit`
|
|
10054
|
+
* items hold no ring.
|
|
9908
10055
|
*/
|
|
9909
10056
|
function courseHold(eb) {
|
|
9910
|
-
return eb.and([
|
|
10057
|
+
return eb.and([
|
|
10058
|
+
eb("notification.role", "=", "worker"),
|
|
10059
|
+
eb.not(eb.exists(eb.selectFrom("block").select("block.id").whereRef("block.id", "=", "notification.block_id").where("block.addressee_spur_project", "is not", null))),
|
|
10060
|
+
eb.or([eb.exists(eb.selectFrom("operator_item").select("operator_item.id").where("operator_item.kind", "=", "course_check").whereRef("operator_item.task_id", "=", "notification.task_id").where("operator_item.cleared_at", "is", null)), eb.and([eb.not(eb.and([eb("notification.kind", "=", "answer"), eb("notification.block_id", "in", courseBlocks(eb))])), eb.exists(eb.selectFrom("notification as note").select("note.id").whereRef("note.task_id", "=", "notification.task_id").where("note.role", "=", "worker").where("note.kind", "=", "answer").where("note.block_id", "in", courseBlocks(eb)).where("note.rings", "=", 0).where("note.acked_at", "is", null).where("note.exhausted_at", "is", null).where((inner) => inner.not(inner.exists(inner.selectFrom("outbox").select("outbox.id").where(sql`+outbox.state`, "=", "done").where("outbox.dedupe_key", ">", sql`'doorbell:' || ${sql.ref("note.id")} || ':'`).where("outbox.dedupe_key", "<", sql`'doorbell:' || ${sql.ref("note.id")} || ';'`)))))])])
|
|
10061
|
+
]);
|
|
9911
10062
|
}
|
|
9912
10063
|
/**
|
|
9913
10064
|
* Moves a block to a new addressee, for `block.escalate` and for a ring series that ended: the
|
|
@@ -10011,6 +10162,8 @@ function columnOrchestratorProject(config, projectId, column) {
|
|
|
10011
10162
|
*/
|
|
10012
10163
|
async function selectNotificationRecipient(trx, n, config) {
|
|
10013
10164
|
if (n.kind === "turn_reminder") return n.author_session === null ? void 0 : liveSession(trx, n.author_session);
|
|
10165
|
+
const target = await conversationTarget(trx, n);
|
|
10166
|
+
if (target !== null) return bestProjectSession(trx, target);
|
|
10014
10167
|
const addressee = parseAddressee(n.role);
|
|
10015
10168
|
switch (addressee.kind) {
|
|
10016
10169
|
case "curator": return curatorSession(trx, config, await noticeProject(trx, n));
|
|
@@ -10059,7 +10212,7 @@ async function endNotification(trx, n, subject, end) {
|
|
|
10059
10212
|
if (n.rings === 0) await releaseAfterCourseNote(trx, n, at);
|
|
10060
10213
|
const addressee = parseAddressee(n.role);
|
|
10061
10214
|
const { task } = subject;
|
|
10062
|
-
if (n.kind === "block" && task !== null && (addressee.kind === "curator" || session === null)) await moveBlockToAddressee(trx, {
|
|
10215
|
+
if (n.kind === "block" && task !== null && (addressee.kind === "curator" || session === null) && await conversationTarget(trx, n) === null) await moveBlockToAddressee(trx, {
|
|
10063
10216
|
task,
|
|
10064
10217
|
block: await trx.selectFrom("block").selectAll().where("id", "=", noticeBlockId(n)).executeTakeFirstOrThrow(),
|
|
10065
10218
|
to: "operator",
|
|
@@ -10128,9 +10281,10 @@ async function ringUndelivered(trx, input) {
|
|
|
10128
10281
|
* Why a notification with no recipient ends now, or null when it stays due for a next session. A
|
|
10129
10282
|
* curator block, and an orchestrator block of a course check, end with `session: null`, which
|
|
10130
10283
|
* `endNotification` turns into a move to the operator. A worker's answer on a project-level block
|
|
10131
|
-
* goes only to the session that asked.
|
|
10284
|
+
* goes only to the session that asked. An operator conversation's notification never ends here.
|
|
10132
10285
|
*/
|
|
10133
10286
|
async function noRecipientEnd(trx, n) {
|
|
10287
|
+
if (await conversationTarget(trx, n) !== null) return null;
|
|
10134
10288
|
if (n.kind === "removed" || n.kind === "turn_reminder" || n.kind === "answer" && n.role === "operator" || n.kind === "answer" && n.role === "worker" && n.task_id === null) return "no live addressee";
|
|
10135
10289
|
if (n.kind !== "block") return null;
|
|
10136
10290
|
if (n.role === "curator") return "no live curator session";
|
|
@@ -10168,7 +10322,7 @@ async function reconcileDoorbells(trx, at, config) {
|
|
|
10168
10322
|
const due = await dueNotifications(trx, at).selectAll("notification").orderBy("notification.id").execute();
|
|
10169
10323
|
for (const n of due) {
|
|
10170
10324
|
const session = await selectNotificationRecipient(trx, n, config);
|
|
10171
|
-
const keepsRings = resolvedByProject(n.role);
|
|
10325
|
+
const keepsRings = resolvedByProject(n.role) || await conversationTarget(trx, n) !== null;
|
|
10172
10326
|
if (session === void 0) {
|
|
10173
10327
|
const reason = await noRecipientEnd(trx, n);
|
|
10174
10328
|
if (reason !== null) await endNotification(trx, n, await rowSubject(trx, n), {
|
|
@@ -10351,6 +10505,8 @@ async function notificationAddressedTo(trx, n, actor, config) {
|
|
|
10351
10505
|
const parsed = parseActorId(actor);
|
|
10352
10506
|
if (parsed?.actor !== "agent") return false;
|
|
10353
10507
|
const { project, session } = parsed.actorRef;
|
|
10508
|
+
const target = await conversationTarget(trx, n);
|
|
10509
|
+
if (target !== null) return project === target;
|
|
10354
10510
|
const addressee = parseAddressee(n.role);
|
|
10355
10511
|
switch (addressee.kind) {
|
|
10356
10512
|
case "curator": return project === curatorProject(config, await noticeProject(trx, n));
|
|
@@ -10384,8 +10540,26 @@ async function closeBlockNotification(trx, blockId, at, actor) {
|
|
|
10384
10540
|
async function closeTurnNotification(trx, turnId, at) {
|
|
10385
10541
|
await closeOwnedNotifications(trx, "turn", turnId, at, "system");
|
|
10386
10542
|
}
|
|
10543
|
+
/**
|
|
10544
|
+
* Ends an operator conversation's block and follow-up rings, whoever answered or closed it: the
|
|
10545
|
+
* operation's grant already chose the actor. Exhaustion items are cleared by `actor`, and each
|
|
10546
|
+
* follow-up comment is marked read at its current revision.
|
|
10547
|
+
*/
|
|
10548
|
+
async function ackConversationNotifications(trx, blockId, at, actor) {
|
|
10549
|
+
const answers = await trx.selectFrom("notification").select("comment_id").where("block_id", "=", blockId).where("kind", "=", "answer").where("acked_at", "is", null).execute();
|
|
10550
|
+
await closeOwnedNotifications(trx, "conversation", blockId, at, actor);
|
|
10551
|
+
for (const { comment_id: id } of answers) {
|
|
10552
|
+
if (id === null) continue;
|
|
10553
|
+
await trx.updateTable("comment").set((eb) => ({ acked_revision: eb.ref("revision") })).where("id", "=", id).execute();
|
|
10554
|
+
}
|
|
10555
|
+
}
|
|
10556
|
+
const OWNED_KINDS = {
|
|
10557
|
+
block: ["block"],
|
|
10558
|
+
conversation: ["block", "answer"],
|
|
10559
|
+
turn: ["turn", "turn_reminder"]
|
|
10560
|
+
};
|
|
10387
10561
|
async function closeOwnedNotifications(trx, kind, ownerId, at, actor) {
|
|
10388
|
-
const closed = await trx.updateTable("notification").set({ acked_at: at.toISOString() }).where(kind === "
|
|
10562
|
+
const closed = await trx.updateTable("notification").set({ acked_at: at.toISOString() }).where(kind === "turn" ? "turn_id" : "block_id", "=", ownerId).where("kind", "in", OWNED_KINDS[kind]).where("acked_at", "is", null).returning(["kind", "source_key"]).execute();
|
|
10389
10563
|
for (const row of closed) {
|
|
10390
10564
|
const item = await trx.selectFrom("operator_item").select("id").where("item_key", "=", exhaustedItemKey(row)).where("cleared_at", "is", null).executeTakeFirst();
|
|
10391
10565
|
if (item !== void 0) await clearItem(trx, item.id, at, actor);
|
|
@@ -10712,11 +10886,18 @@ async function postTokenList(trx, input) {
|
|
|
10712
10886
|
}
|
|
10713
10887
|
const shown = rows.slice(0, lines.length);
|
|
10714
10888
|
const hidden = rows.length - shown.length;
|
|
10715
|
-
|
|
10889
|
+
const segments = hidden > 0 ? [{
|
|
10890
|
+
kind: "text",
|
|
10891
|
+
text: [...lines, `${String(hidden)} more: `].join("\n")
|
|
10892
|
+
}, {
|
|
10893
|
+
kind: "code",
|
|
10894
|
+
text: "board token list"
|
|
10895
|
+
}] : void 0;
|
|
10716
10896
|
await enqueueBoardFeedLine(trx, {
|
|
10717
10897
|
dedupeKey: `feed.line:token-list:${input.key}`,
|
|
10718
10898
|
itemKey: `token-list:${input.key}`,
|
|
10719
|
-
text: lines.join("\n"),
|
|
10899
|
+
text: segments === void 0 ? lines.join("\n") : feedText(segments),
|
|
10900
|
+
...segments === void 0 ? {} : { segments },
|
|
10720
10901
|
title: "Operator tokens",
|
|
10721
10902
|
actions: shown.map(({ row }) => revokeAction(row.item_id, row.name, `Revoke ${capPoints(row.name, LABEL_NAME)}`)),
|
|
10722
10903
|
at: input.at
|
|
@@ -11438,7 +11619,8 @@ async function subjectTarget(trx, subject, block) {
|
|
|
11438
11619
|
block: block === void 0 ? null : {
|
|
11439
11620
|
type: block.type,
|
|
11440
11621
|
author: block.author,
|
|
11441
|
-
addressee_role: block.addressee_role
|
|
11622
|
+
addressee_role: block.addressee_role,
|
|
11623
|
+
addressee_spur_project: block.addressee_spur_project
|
|
11442
11624
|
},
|
|
11443
11625
|
workers
|
|
11444
11626
|
}
|
|
@@ -11595,8 +11777,11 @@ async function addComment(trx, subject, block, text, ctx, addressee, config, opt
|
|
|
11595
11777
|
});
|
|
11596
11778
|
return row;
|
|
11597
11779
|
}
|
|
11598
|
-
/**
|
|
11599
|
-
|
|
11780
|
+
/**
|
|
11781
|
+
* Opens a block; a project-level block, which has no task to route by, goes to the operator. An
|
|
11782
|
+
* operator conversation names the Spur project it is addressed to, which routes its rings.
|
|
11783
|
+
*/
|
|
11784
|
+
async function openBlock(trx, subject, type, reason, ctx, config, addressee, addresseeSpurProject) {
|
|
11600
11785
|
const { task } = subject;
|
|
11601
11786
|
addressee ??= task === null ? "operator" : await routeBlock(trx, task, {
|
|
11602
11787
|
type,
|
|
@@ -11616,7 +11801,8 @@ async function openBlock(trx, subject, type, reason, ctx, config, addressee) {
|
|
|
11616
11801
|
repeat_of: null,
|
|
11617
11802
|
unblocked_by: null,
|
|
11618
11803
|
unblocked_at: null,
|
|
11619
|
-
created_at: ctx.at
|
|
11804
|
+
created_at: ctx.at,
|
|
11805
|
+
addressee_spur_project: addresseeSpurProject ?? null
|
|
11620
11806
|
}).returningAll().executeTakeFirstOrThrow();
|
|
11621
11807
|
await journal$1(trx, subject, ctx, "block_opened", {
|
|
11622
11808
|
block: blockId$1(row.id),
|
|
@@ -11718,7 +11904,8 @@ async function closeOpenBlock(trx, subject, block, ctx, outcome, outcomeReason,
|
|
|
11718
11904
|
actor: ctx.actor,
|
|
11719
11905
|
at: new Date(ctx.at)
|
|
11720
11906
|
});
|
|
11721
|
-
await closeBlockNotification(trx, block.id, new Date(ctx.at), ctx.actor);
|
|
11907
|
+
if (block.addressee_spur_project === null) await closeBlockNotification(trx, block.id, new Date(ctx.at), ctx.actor);
|
|
11908
|
+
else await ackConversationNotifications(trx, block.id, new Date(ctx.at), ctx.actor);
|
|
11722
11909
|
const items = await trx.selectFrom("operator_item").selectAll().where("kind", "in", ["post_blocked", ...BLOCK_ITEM_KINDS]).where("block_id", "=", block.id).where("cleared_at", "is", null).execute();
|
|
11723
11910
|
if (subject.task !== null && ctx.actor !== "system" && (outcome === "done" || outcome === "reason") && items.some((item) => item.kind === "course_check")) await forwardCourseNote(trx, subject.task, block, ctx, outcome === "reason" ? outcomeReason : null, answer);
|
|
11724
11911
|
for (const item of items) if (item.kind === "post_blocked") await clearItem(trx, item.id, new Date(ctx.at), ctx.actor);
|
|
@@ -11732,7 +11919,17 @@ async function closeBlockIfOpen(trx, blockId, ctx, outcome, outcomeReason) {
|
|
|
11732
11919
|
if (block === void 0) return;
|
|
11733
11920
|
await closeOpenBlock(trx, await blockSubject(trx, block), block, ctx, outcome, outcomeReason);
|
|
11734
11921
|
}
|
|
11735
|
-
/**
|
|
11922
|
+
/** The thread messages that close an operator conversation, compared after trimming. */
|
|
11923
|
+
const CLOSE_COMMANDS = /* @__PURE__ */ new Set([
|
|
11924
|
+
"close",
|
|
11925
|
+
"✅",
|
|
11926
|
+
":white_check_mark:"
|
|
11927
|
+
]);
|
|
11928
|
+
/**
|
|
11929
|
+
* Applies an operator message to the block selected by its conversation, without echoing it. The
|
|
11930
|
+
* first message answers and closes a block; on an operator conversation it is a follow-up that
|
|
11931
|
+
* rings the addressee, and only the close command closes it.
|
|
11932
|
+
*/
|
|
11736
11933
|
async function recordInboundBlockMessage(trx, input) {
|
|
11737
11934
|
const block = await trx.selectFrom("block").selectAll().where("id", "=", input.blockId).executeTakeFirstOrThrow();
|
|
11738
11935
|
const subject = await blockSubject(trx, block);
|
|
@@ -11740,7 +11937,9 @@ async function recordInboundBlockMessage(trx, input) {
|
|
|
11740
11937
|
actor: "operator",
|
|
11741
11938
|
at: input.at
|
|
11742
11939
|
};
|
|
11743
|
-
const
|
|
11940
|
+
const conversation = block.addressee_spur_project !== null;
|
|
11941
|
+
const closes = conversation && block.state === "open" && CLOSE_COMMANDS.has(input.text.trim());
|
|
11942
|
+
const answered = block.state === "open" && !conversation;
|
|
11744
11943
|
if (answered) {
|
|
11745
11944
|
if (subject.task !== null) active(subject.task);
|
|
11746
11945
|
rule(() => {
|
|
@@ -11748,16 +11947,53 @@ async function recordInboundBlockMessage(trx, input) {
|
|
|
11748
11947
|
});
|
|
11749
11948
|
}
|
|
11750
11949
|
return {
|
|
11751
|
-
comment: await addComment(trx, subject, block, input.text, ctx, authorRole(input.config, subject, block.author), input.config, {
|
|
11752
|
-
|
|
11753
|
-
|
|
11754
|
-
|
|
11755
|
-
|
|
11950
|
+
comment: await addComment(trx, subject, block, input.text, ctx, authorRole(input.config, subject, block.author), input.config, {
|
|
11951
|
+
source: {
|
|
11952
|
+
conversationRef: input.conversationRef,
|
|
11953
|
+
messageRef: input.messageRef
|
|
11954
|
+
},
|
|
11955
|
+
ringsAuthor: !closes
|
|
11956
|
+
}),
|
|
11957
|
+
block: answered || closes ? await closeOpenBlock(trx, subject, block, ctx, "done", null) : block,
|
|
11756
11958
|
subject,
|
|
11757
11959
|
answered,
|
|
11758
11960
|
authorRole: authorRole(input.config, subject, block.author)
|
|
11759
11961
|
};
|
|
11760
11962
|
}
|
|
11963
|
+
/**
|
|
11964
|
+
* `text` without a leading `@<shortName>` token and the space after it; a text that is only the
|
|
11965
|
+
* token stays whole. An operator conversation's reason is its opening text stripped this way.
|
|
11966
|
+
*/
|
|
11967
|
+
function stripShortName(text, shortName) {
|
|
11968
|
+
const prefix = /^@(\S+)\s*/.exec(text);
|
|
11969
|
+
if (prefix?.[1] !== shortName) return text;
|
|
11970
|
+
const rest = text.slice(prefix[0].length);
|
|
11971
|
+
return rest.length === 0 ? text : rest;
|
|
11972
|
+
}
|
|
11973
|
+
/**
|
|
11974
|
+
* An edit of an open operator conversation's opening message: the block reason follows the new
|
|
11975
|
+
* text, and an addressee that already read the conversation is rung once more. Target and scope
|
|
11976
|
+
* stay as opened.
|
|
11977
|
+
*/
|
|
11978
|
+
async function reviseConversationOpening(trx, updated, input, subject) {
|
|
11979
|
+
if (updated.block_id === null) return;
|
|
11980
|
+
const block = await trx.selectFrom("block").selectAll().where("id", "=", updated.block_id).executeTakeFirstOrThrow();
|
|
11981
|
+
const spur = block.addressee_spur_project;
|
|
11982
|
+
if (spur === null || block.state !== "open") return;
|
|
11983
|
+
if ((await trx.selectFrom("comment").select("id").where("block_id", "=", block.id).orderBy("id").executeTakeFirstOrThrow()).id !== updated.id) return;
|
|
11984
|
+
const shortName = input.config.projects.flatMap((project) => project.spurProjects).find((entry) => entry.name === spur)?.shortName;
|
|
11985
|
+
const reason = shortName === void 0 ? updated.text : stripShortName(updated.text, shortName);
|
|
11986
|
+
const revised = await trx.updateTable("block").set({ reason }).where("id", "=", block.id).returningAll().executeTakeFirstOrThrow();
|
|
11987
|
+
if (await trx.selectFrom("notification").select("id").where("block_id", "=", block.id).where("kind", "in", ["block", "answer"]).where("acked_at", "is", null).executeTakeFirst() !== void 0) return;
|
|
11988
|
+
await applyDoorbellPolicy(trx, {
|
|
11989
|
+
kind: "answer",
|
|
11990
|
+
block: revised,
|
|
11991
|
+
commentId: updated.id,
|
|
11992
|
+
revision: updated.revision,
|
|
11993
|
+
authorRole: authorRole(input.config, subject, block.author),
|
|
11994
|
+
actor: input.actor
|
|
11995
|
+
}, new Date(input.at));
|
|
11996
|
+
}
|
|
11761
11997
|
/** Uses the same revision and acknowledgment rule as the catalog comment.edit mutation. */
|
|
11762
11998
|
async function editInboundComment(trx, input) {
|
|
11763
11999
|
const subject = await rowSubject(trx, input.comment);
|
|
@@ -11781,6 +12017,7 @@ async function editInboundComment(trx, input) {
|
|
|
11781
12017
|
actor: input.actor
|
|
11782
12018
|
}, new Date(input.at));
|
|
11783
12019
|
}
|
|
12020
|
+
await reviseConversationOpening(trx, updated, input, subject);
|
|
11784
12021
|
return updated;
|
|
11785
12022
|
}
|
|
11786
12023
|
/** The task's tracker title, or undefined when no readable snapshot has one; never throws. */
|
|
@@ -11799,6 +12036,7 @@ async function ticketTitle(trx, task) {
|
|
|
11799
12036
|
/** Posts a curator's answer to the feed; an operator answer is already on the board. */
|
|
11800
12037
|
async function queueCuratorAnswerLine(trx, task, block, answer, note, ctx, config) {
|
|
11801
12038
|
if (parseAddressee(block.addressee_role).kind !== "curator") return;
|
|
12039
|
+
if (block.addressee_spur_project !== null) return;
|
|
11802
12040
|
if (authorRole(config, taskSubject(task), ctx.actor) === "operator") return;
|
|
11803
12041
|
const curator = parseActorId(ctx.actor);
|
|
11804
12042
|
if (curator?.actor !== "agent") return;
|
|
@@ -11886,7 +12124,7 @@ function createBlockMutations(config) {
|
|
|
11886
12124
|
if (input.note !== void 0) await addComment(trx, subject, block, input.note, ctx, block.addressee_role, config, { ringsAuthor: false });
|
|
11887
12125
|
return { block: blockView(block, subject) };
|
|
11888
12126
|
};
|
|
11889
|
-
if (!next.changed || task === null) return unchanged();
|
|
12127
|
+
if (!next.changed || task === null || block.addressee_spur_project !== null) return unchanged();
|
|
11890
12128
|
if (!holdsBlock(config, ctx.actor, target)) return unchanged();
|
|
11891
12129
|
const updated = await moveBlockToAddressee(trx, {
|
|
11892
12130
|
task,
|
|
@@ -11911,9 +12149,11 @@ function createBlockMutations(config) {
|
|
|
11911
12149
|
answerBlock(current$1(block));
|
|
11912
12150
|
});
|
|
11913
12151
|
const role = authorRole(config, subject, block.author);
|
|
12152
|
+
const conversation = block.addressee_spur_project !== null;
|
|
12153
|
+
if (conversation) await ackConversationNotifications(trx, block.id, new Date(ctx.at), ctx.actor);
|
|
11914
12154
|
const comment = await addComment(trx, subject, block, input.text, ctx, role, config);
|
|
11915
12155
|
if (input.note !== void 0) await addComment(trx, subject, block, input.note, ctx, role, config, { ringsAuthor: false });
|
|
11916
|
-
const updated = await closeOpenBlock(trx, subject, block, ctx, "done", null, comment);
|
|
12156
|
+
const updated = conversation ? block : await closeOpenBlock(trx, subject, block, ctx, "done", null, comment);
|
|
11917
12157
|
if (task !== null) await queueCuratorAnswerLine(trx, task, block, comment, input.note, ctx, config);
|
|
11918
12158
|
return {
|
|
11919
12159
|
block: blockView(updated, subject),
|
|
@@ -11923,7 +12163,24 @@ function createBlockMutations(config) {
|
|
|
11923
12163
|
};
|
|
11924
12164
|
const unblock = {
|
|
11925
12165
|
id: "block.unblock",
|
|
11926
|
-
resolveTargets
|
|
12166
|
+
async resolveTargets(trx, input) {
|
|
12167
|
+
const [target] = await blockTarget(trx, input.block);
|
|
12168
|
+
if (target?.kind !== "found" || target.value.block?.addressee_spur_project == null) return [target ?? { kind: "missing" }];
|
|
12169
|
+
const block = {
|
|
12170
|
+
...target.value.block,
|
|
12171
|
+
addressee_role: "operator"
|
|
12172
|
+
};
|
|
12173
|
+
return [{
|
|
12174
|
+
...target,
|
|
12175
|
+
value: {
|
|
12176
|
+
...target.value,
|
|
12177
|
+
block: {
|
|
12178
|
+
...block,
|
|
12179
|
+
addressee_spur_project: null
|
|
12180
|
+
}
|
|
12181
|
+
}
|
|
12182
|
+
}];
|
|
12183
|
+
},
|
|
11927
12184
|
async run(trx, input, ctx) {
|
|
11928
12185
|
const block = found(await blockById(trx, input.block));
|
|
11929
12186
|
const subject = await blockSubject(trx, block);
|
|
@@ -12623,9 +12880,16 @@ function target(claim) {
|
|
|
12623
12880
|
space: KIND_SPACE[body.kind],
|
|
12624
12881
|
title: body.payload.title
|
|
12625
12882
|
};
|
|
12626
|
-
case "conversation.reply": return parent && {
|
|
12883
|
+
case "conversation.reply": return body.payload.targetConversation === void 0 ? parent && {
|
|
12627
12884
|
kind: "reply",
|
|
12628
12885
|
conversation: parent.conversation
|
|
12886
|
+
} : {
|
|
12887
|
+
kind: "reply",
|
|
12888
|
+
conversation: body.payload.targetConversation
|
|
12889
|
+
};
|
|
12890
|
+
case "conversation.notice": return {
|
|
12891
|
+
kind: "reply",
|
|
12892
|
+
conversation: body.payload.targetConversation
|
|
12629
12893
|
};
|
|
12630
12894
|
case "conversation.close": return body.payload.targetConversation === void 0 ? parent && {
|
|
12631
12895
|
kind: "close",
|
|
@@ -12888,23 +13152,16 @@ function createSender(options) {
|
|
|
12888
13152
|
body: body.kind === "feed.line.edit" && body.payload.tokenCard !== void 0 ? tokenCardBody(body.payload.tokenCard, options.config) : body.kind === "feed.line.edit" && body.payload.resolved !== void 0 ? resolvedFeedBody({
|
|
12889
13153
|
...body.payload,
|
|
12890
13154
|
resolved: body.payload.resolved
|
|
12891
|
-
}, options.config) : c.body.kind === "
|
|
12892
|
-
...c.body.payload,
|
|
12893
|
-
exchange: c.body.payload.exchange
|
|
12894
|
-
}) : c.body.kind === "feed.line" && c.body.payload.url !== void 0 ? [{
|
|
13155
|
+
}, options.config) : c.body.kind === "conversation.notice" ? [{
|
|
12895
13156
|
kind: "paragraph",
|
|
12896
|
-
children: [{
|
|
12897
|
-
kind: "link",
|
|
12898
|
-
url: c.body.payload.url,
|
|
12899
|
-
text: c.body.payload.key
|
|
12900
|
-
}]
|
|
12901
|
-
}, {
|
|
12902
|
-
kind: "quote",
|
|
12903
13157
|
children: [{
|
|
12904
13158
|
kind: "text",
|
|
12905
13159
|
text: c.body.payload.text
|
|
12906
13160
|
}]
|
|
12907
|
-
}] :
|
|
13161
|
+
}] : c.body.kind === "feed.line" && c.body.payload.exchange !== void 0 ? exchangeBody({
|
|
13162
|
+
...c.body.payload,
|
|
13163
|
+
exchange: c.body.payload.exchange
|
|
13164
|
+
}) : c.body.kind === "feed.line" ? feedLineBody(c.body.payload) : renderBody(c.body.payload.key, c.body.payload.text),
|
|
12908
13165
|
...(body.kind === "feed.line" || body.kind === "feed.line.edit") && body.payload.actions !== void 0 ? { actions: body.payload.actions } : {}
|
|
12909
13166
|
};
|
|
12910
13167
|
return {
|
|
@@ -12961,7 +13218,7 @@ function createSender(options) {
|
|
|
12961
13218
|
if (body.kind === "doorbell" && body.payload.notificationId !== void 0 && body.payload.ring !== void 0) await recordRingDelivery(trx, body.payload.notificationId, body.payload.ring, body.payload.session, new Date(at), options.config);
|
|
12962
13219
|
return;
|
|
12963
13220
|
case "delivered": {
|
|
12964
|
-
const conversation = body.kind === "conversation.close" ? body.payload.targetConversation ?? outcome.conversation ?? c.parent?.conversation : body.kind === "feed.line.edit" ? c.parent?.conversation : outcome.conversation ?? c.parent?.conversation;
|
|
13221
|
+
const conversation = body.kind === "conversation.close" || body.kind === "conversation.reply" || body.kind === "conversation.notice" ? body.payload.targetConversation ?? outcome.conversation ?? c.parent?.conversation : body.kind === "feed.line.edit" ? c.parent?.conversation : outcome.conversation ?? c.parent?.conversation;
|
|
12965
13222
|
if (conversation === void 0) return postFailed({ last_error: "delivered without a conversation" });
|
|
12966
13223
|
const ref = {
|
|
12967
13224
|
conversation,
|
|
@@ -14414,6 +14671,25 @@ const ANOMALY_FLAGS = /* @__PURE__ */ new Set([
|
|
|
14414
14671
|
"worker_completed",
|
|
14415
14672
|
"worker_lost"
|
|
14416
14673
|
]);
|
|
14674
|
+
/**
|
|
14675
|
+
* The item for an open operator conversation with a ring that waits for a live session of its
|
|
14676
|
+
* Spur project, or undefined while a session can take it or nothing waits.
|
|
14677
|
+
*/
|
|
14678
|
+
async function conversationWaiting(trx, config, block, subject) {
|
|
14679
|
+
const spur = block.addressee_spur_project;
|
|
14680
|
+
if (spur === null) return void 0;
|
|
14681
|
+
if (await trx.selectFrom("notification").select("id").where("block_id", "=", block.id).where("kind", "in", ["block", "answer"]).where("acked_at", "is", null).where("exhausted_at", "is", null).executeTakeFirst() === void 0 || await bestProjectSession(trx, spur) !== void 0) return void 0;
|
|
14682
|
+
const shortName = config.projects.flatMap((project) => project.spurProjects).find((entry) => entry.name === spur)?.shortName ?? spur;
|
|
14683
|
+
return {
|
|
14684
|
+
key: `conversation:${String(block.id)}`,
|
|
14685
|
+
kind: "conversation_waiting",
|
|
14686
|
+
taskId: subject.task?.id ?? null,
|
|
14687
|
+
summary: `${subject.key}: message to @${shortName} waits for a live ${spur} session`,
|
|
14688
|
+
factAt: block.created_at,
|
|
14689
|
+
source: null,
|
|
14690
|
+
priority: ITEM_POLICY.conversation_waiting.priority
|
|
14691
|
+
};
|
|
14692
|
+
}
|
|
14417
14693
|
/** Reconciles every item in the caller's observation or tick transaction. */
|
|
14418
14694
|
async function reconcileItems(trx, config, now, spurComplete, warnSkipped) {
|
|
14419
14695
|
const candidates = [];
|
|
@@ -14496,6 +14772,10 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped) {
|
|
|
14496
14772
|
source: null,
|
|
14497
14773
|
priority: 0
|
|
14498
14774
|
});
|
|
14775
|
+
if (block.addressee_spur_project !== null) {
|
|
14776
|
+
const waiting = await conversationWaiting(trx, config, block, subject);
|
|
14777
|
+
if (waiting !== void 0) candidates.push(waiting);
|
|
14778
|
+
}
|
|
14499
14779
|
if (now - Date.parse(block.created_at) >= config.thresholds.blockOpenMs) candidates.push({
|
|
14500
14780
|
key: `block:${String(block.id)}`,
|
|
14501
14781
|
kind: "board_observation",
|
|
@@ -17254,6 +17534,83 @@ function commandReply(id, value, input) {
|
|
|
17254
17534
|
};
|
|
17255
17535
|
}
|
|
17256
17536
|
//#endregion
|
|
17537
|
+
//#region ../core/src/app/operator-conversation.ts
|
|
17538
|
+
function addressOperatorMessage(text, config) {
|
|
17539
|
+
const spurByShortName = /* @__PURE__ */ new Map();
|
|
17540
|
+
for (const project of config.projects) for (const spur of project.spurProjects) if (spur.shortName !== void 0) spurByShortName.set(spur.shortName, spur.name);
|
|
17541
|
+
if (spurByShortName.size === 0) return null;
|
|
17542
|
+
const prefix = /^@(\S+)\s*/.exec(text);
|
|
17543
|
+
const named = prefix?.[1] === void 0 ? void 0 : spurByShortName.get(prefix[1]);
|
|
17544
|
+
if (prefix?.[1] !== void 0 && named !== void 0) return {
|
|
17545
|
+
spur: named,
|
|
17546
|
+
text: stripShortName(text, prefix[1])
|
|
17547
|
+
};
|
|
17548
|
+
const fallback = config.slack.defaultAddressee;
|
|
17549
|
+
const fallbackSpur = fallback === void 0 ? void 0 : spurByShortName.get(fallback);
|
|
17550
|
+
if (fallbackSpur !== void 0) return {
|
|
17551
|
+
spur: fallbackSpur,
|
|
17552
|
+
text
|
|
17553
|
+
};
|
|
17554
|
+
return { hint: `No addressee. Start with one of: ${[...spurByShortName.keys()].map((name) => `@${name}`).join(", ")}.` };
|
|
17555
|
+
}
|
|
17556
|
+
/**
|
|
17557
|
+
* The open, non-archived task of `project` that the first word of `text` names, with trailing
|
|
17558
|
+
* `?.,:;` dropped; undefined when it names none.
|
|
17559
|
+
*/
|
|
17560
|
+
async function namedTask(trx, config, project, text) {
|
|
17561
|
+
const word = (/^\S+/.exec(text)?.[0] ?? "").replace(/[?.,:;]+$/, "");
|
|
17562
|
+
if (!parseRef$1(word, "task").ok) return void 0;
|
|
17563
|
+
let key;
|
|
17564
|
+
try {
|
|
17565
|
+
const canonical = canonicalKey(config, word);
|
|
17566
|
+
if (canonical.project.id !== project) return void 0;
|
|
17567
|
+
key = canonical.key;
|
|
17568
|
+
} catch {
|
|
17569
|
+
return;
|
|
17570
|
+
}
|
|
17571
|
+
return trx.selectFrom("task").selectAll().where("key", "=", key).where("project", "=", project).where("membership", "!=", "archived").executeTakeFirst();
|
|
17572
|
+
}
|
|
17573
|
+
/**
|
|
17574
|
+
* Opens the conversation an operator's new message starts, or posts the hint in its thread.
|
|
17575
|
+
* Returns false, and writes nothing, when no short name is configured.
|
|
17576
|
+
*/
|
|
17577
|
+
async function openOperatorConversation(trx, input) {
|
|
17578
|
+
const { config } = input;
|
|
17579
|
+
const address = addressOperatorMessage(input.text, config);
|
|
17580
|
+
if (address === null) return false;
|
|
17581
|
+
if ("hint" in address) {
|
|
17582
|
+
await enqueueConversationNotice(trx, {
|
|
17583
|
+
conversation: input.conversation,
|
|
17584
|
+
text: address.hint,
|
|
17585
|
+
at: new Date(input.at)
|
|
17586
|
+
});
|
|
17587
|
+
return true;
|
|
17588
|
+
}
|
|
17589
|
+
const project = config.projects.find((entry) => entry.spurProjects.some((spur) => spur.name === address.spur));
|
|
17590
|
+
if (project === void 0) return false;
|
|
17591
|
+
const role = project.spurProjects.find((spur) => spur.name === address.spur)?.role === "curator" ? "curator" : "worker";
|
|
17592
|
+
const task = await namedTask(trx, config, project.id, address.text);
|
|
17593
|
+
const subject = task === void 0 ? projectSubject(project.id) : taskSubject(task);
|
|
17594
|
+
const ctx = {
|
|
17595
|
+
actor: "operator",
|
|
17596
|
+
at: input.at
|
|
17597
|
+
};
|
|
17598
|
+
const block = await openBlock(trx, subject, "needs_input", address.text, ctx, config, role, address.spur);
|
|
17599
|
+
await insertComment(trx, subject, block.id, address.text, ctx, role, {
|
|
17600
|
+
conversationRef: input.conversation,
|
|
17601
|
+
messageRef: input.message
|
|
17602
|
+
});
|
|
17603
|
+
const conversation = await insertConversation(trx, {
|
|
17604
|
+
gateway: input.gateway,
|
|
17605
|
+
ref: input.conversation,
|
|
17606
|
+
rootMessage: input.rootMessage,
|
|
17607
|
+
at: input.at,
|
|
17608
|
+
blockId: block.id
|
|
17609
|
+
});
|
|
17610
|
+
if (conversation !== void 0) await advanceConversationCursor(trx, conversation, input.message, input.at);
|
|
17611
|
+
return true;
|
|
17612
|
+
}
|
|
17613
|
+
//#endregion
|
|
17257
17614
|
//#region ../core/src/app/inbound.ts
|
|
17258
17615
|
const resultSchema = z.strictObject({
|
|
17259
17616
|
status: z.enum([
|
|
@@ -17365,6 +17722,7 @@ async function linkedComment(trx, event) {
|
|
|
17365
17722
|
}
|
|
17366
17723
|
/** The answer's notification is already registered; this raises the item when nobody can read it. */
|
|
17367
17724
|
async function ringAuthor(trx, input) {
|
|
17725
|
+
if (input.block.addressee_spur_project !== null) return;
|
|
17368
17726
|
if (await trx.selectFrom("operator_item").select("id").where("block_id", "=", input.block.id).where("kind", "in", BLOCK_ITEM_KINDS).executeTakeFirst() !== void 0) return;
|
|
17369
17727
|
const key = `doorbell:comment:${String(input.comment.id)}:revision:${String(input.comment.revision)}`;
|
|
17370
17728
|
const parsed = parseActorId(input.block.author);
|
|
@@ -17436,6 +17794,15 @@ function createInbound(input) {
|
|
|
17436
17794
|
async function processMessage(trx, event, at) {
|
|
17437
17795
|
if (await alreadyApplied(trx, event)) return void 0;
|
|
17438
17796
|
const conversation = await sourceContext(trx, event, at);
|
|
17797
|
+
if (conversation === void 0 && (event.kind === "message" || event.kind === "mention") && event.sourceSpace === "orchestrators" && await openOperatorConversation(trx, {
|
|
17798
|
+
text: event.text,
|
|
17799
|
+
conversation: event.conversation,
|
|
17800
|
+
message: event.message,
|
|
17801
|
+
rootMessage: event.rootMessage,
|
|
17802
|
+
gateway: gateway.kind,
|
|
17803
|
+
at: event.at,
|
|
17804
|
+
config
|
|
17805
|
+
})) return { status: "applied" };
|
|
17439
17806
|
if (conversation?.block_id === null || conversation === void 0) return skip(trx, {
|
|
17440
17807
|
event,
|
|
17441
17808
|
reason: "Unknown board conversation.",
|
|
@@ -22184,11 +22551,14 @@ function normalizeMessage(channel, payload, context) {
|
|
|
22184
22551
|
}
|
|
22185
22552
|
const messageAt = iso(base.ts);
|
|
22186
22553
|
if (messageAt === void 0) return [];
|
|
22554
|
+
const kind = base.threadTs === base.ts && body.includes(`<@${context.bot.userId}>`) ? "mention" : "message";
|
|
22555
|
+
const space = base.threadTs === base.ts ? { sourceSpace: sourceSpace(channel, context.channels) } : {};
|
|
22187
22556
|
const events = [{
|
|
22188
|
-
kind
|
|
22557
|
+
kind,
|
|
22189
22558
|
dedupeKey: `slack:${channel}:${base.ts}`,
|
|
22190
22559
|
...eventBase,
|
|
22191
|
-
at: messageAt
|
|
22560
|
+
at: messageAt,
|
|
22561
|
+
...space
|
|
22192
22562
|
}];
|
|
22193
22563
|
if (editAt !== void 0 && editedTs !== void 0 && body.length > 0) events.push({
|
|
22194
22564
|
kind: "message_edited",
|
|
@@ -22319,7 +22689,7 @@ function gap(conversation) {
|
|
|
22319
22689
|
};
|
|
22320
22690
|
}
|
|
22321
22691
|
/** A scan is driven solely by its request; the core owns cursors and deduplication. */
|
|
22322
|
-
async function* recoverThreads(client, request, botIdentity, now) {
|
|
22692
|
+
async function* recoverThreads(client, request, botIdentity, now, channels) {
|
|
22323
22693
|
const until = now();
|
|
22324
22694
|
const from = request.since.getTime();
|
|
22325
22695
|
if (!Number.isFinite(from) || from > until) return;
|
|
@@ -22358,6 +22728,7 @@ async function* recoverThreads(client, request, botIdentity, now) {
|
|
|
22358
22728
|
if (source === null) continue;
|
|
22359
22729
|
const events = normalizeMessage(addressed.channel, source, {
|
|
22360
22730
|
bot,
|
|
22731
|
+
channels,
|
|
22361
22732
|
root,
|
|
22362
22733
|
rootTs: addressed.threadTs
|
|
22363
22734
|
});
|
|
@@ -22419,9 +22790,11 @@ function createSocket(api, config, botIdentity) {
|
|
|
22419
22790
|
const threadTs = textOf(message.thread_ts) ?? textOf(nested?.thread_ts) ?? textOf(previous?.thread_ts);
|
|
22420
22791
|
const messageTs = textOf(message.ts) ?? textOf(nested?.ts);
|
|
22421
22792
|
const deletedRoot = message.subtype === "message_deleted" && threadTs === textOf(message.deleted_ts);
|
|
22793
|
+
const root = threadTs === void 0 || threadTs === messageTs || deletedRoot ? message : await rootFor(api, channel, threadTs);
|
|
22422
22794
|
events = normalizeMessage(channel, message, {
|
|
22423
22795
|
bot,
|
|
22424
|
-
|
|
22796
|
+
channels: config.channels,
|
|
22797
|
+
root,
|
|
22425
22798
|
...threadTs === void 0 ? {} : { rootTs: threadTs }
|
|
22426
22799
|
});
|
|
22427
22800
|
}
|
|
@@ -22517,7 +22890,7 @@ function createSlackGateway(config) {
|
|
|
22517
22890
|
return {
|
|
22518
22891
|
...delivery,
|
|
22519
22892
|
...socket,
|
|
22520
|
-
recover: (request) => recoverThreads(api, request, botIdentity, config.now),
|
|
22893
|
+
recover: (request) => recoverThreads(api, request, botIdentity, config.now, config.channels),
|
|
22521
22894
|
async respond(interaction, text, options) {
|
|
22522
22895
|
const addressed = parseInteractionRef(interaction);
|
|
22523
22896
|
const rendered = renderResponse(text, options.cliHint);
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { C as renderMcpError, X as ERRORS, y as OPERATIONS } from "./chunk-
|
|
2
|
-
import { o as CliError, r as requestOperation } from "./chunk-
|
|
3
|
-
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-
|
|
1
|
+
import { C as renderMcpError, X as ERRORS, y as OPERATIONS } from "./chunk-CzdGYlBy.mjs";
|
|
2
|
+
import { o as CliError, r as requestOperation } from "./chunk-Czc8fVqW.mjs";
|
|
3
|
+
import { a as memoryVerdictCache, c as loadClientConfig, r as compareCatalogs, t as checkCatalog } from "./chunk-DyPssI65.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
import { z } from "zod";
|
package/package.json
CHANGED
|
@@ -125,7 +125,7 @@ Other errors: `wrong_id_kind`, `not_found`, `block_not_open`, `task_archived`, `
|
|
|
125
125
|
|
|
126
126
|
### `board answer`
|
|
127
127
|
|
|
128
|
-
Purpose: Answer a question
|
|
128
|
+
Purpose: Answer a question; the block closes unless it is an operator conversation.
|
|
129
129
|
Arguments: `<block>`, `<text>`.
|
|
130
130
|
Flags: `--note <value>`, `--key <key>`, `--json`.
|
|
131
131
|
Use when: Answer an open question.
|
|
@@ -114,22 +114,25 @@ ID). Role addresses follow the current session filling the role.
|
|
|
114
114
|
`slack.channels.feed` carries summaries such as curator answers and operator
|
|
115
115
|
items, with exceptions for items represented elsewhere or delivery problems.
|
|
116
116
|
`slack.channels.orchestrators` carries block threads addressed to the operator by
|
|
117
|
-
someone else. Answer in the existing block thread to preserve its task context
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
A
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
someone else. Answer in the existing block thread to preserve its task context.
|
|
118
|
+
|
|
119
|
+
## Slack addressing
|
|
120
|
+
|
|
121
|
+
Once a `projects[].spurProjects[].shortName` is set, a new operator message in
|
|
122
|
+
`slack.channels.orchestrators` starts a conversation. A leading registered
|
|
123
|
+
`@shortName` selects that Spur project and is stripped from the text. With an
|
|
124
|
+
absent or unknown leading name, `slack.defaultAddressee` receives the complete
|
|
125
|
+
text, retaining any unknown prefix; without it the Board replies once with the
|
|
126
|
+
valid prefixes. A mention in the middle, or a Slack `<@U…>` mention, addresses
|
|
127
|
+
nobody; an unknown name causes no lookup error. The operator checks short-name
|
|
128
|
+
collisions with workspace names. A task key right after the prefix attaches the
|
|
129
|
+
conversation to that task.
|
|
130
|
+
|
|
131
|
+
The addressee is rung with the block ID, reads the text in `board inbox` and
|
|
132
|
+
replies in the thread with `board answer`. An operator-role addressee posts as
|
|
133
|
+
`board`, a column orchestrator on its column's task as orchestrator. Each
|
|
134
|
+
operator thread message rings it again; `close` or ✅ in the thread closes it.
|
|
135
|
+
While no live session can take it, `board status` lists it as waiting.
|
|
133
136
|
|
|
134
137
|
## Done follows the ticket
|
|
135
138
|
|