@kana-ai/edgar-ext-slack 0.1.2 → 0.1.4

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.
@@ -1,4 +1,4 @@
1
- import { cardLine } from "@kana-ai/edgar-sdk";
1
+ import { cardLine, cardMention, } from "@kana-ai/edgar-sdk";
2
2
  import { SECTION_CHARS, cutEscaped, escape, link } from "#outbound/tools";
3
3
  import { EMOJI, NOTE, PLAN, SAYS, STAGE, WAITS } from "#outbound/words";
4
4
  /** How Slack writes a link and a text that came from a card, a model or a failure. */
@@ -71,11 +71,9 @@ function greeted(who, sentence) {
71
71
  : `${sentence.charAt(0).toLowerCase()}${sentence.slice(1)}`;
72
72
  return `${SAYS.greet(who)} ${after}`;
73
73
  }
74
- /** The person a message is for, as Slack writes them: a mention of `user`, else the assignee's name as text, else nobody. */
75
- function whoOf(user, assignee) {
76
- if (user !== undefined)
77
- return `<@${user}>`;
78
- return assignee === undefined ? undefined : escape(assignee);
74
+ /** The person a message is for, as a Slack mention of `user`, else nobody: a tracker name with no Slack user, such as EDGAR's own, is never written as text. */
75
+ function whoOf(user) {
76
+ return user === undefined ? undefined : `<@${user}>`;
79
77
  }
80
78
  /** The state of a task card that Slack's plan block knows, for each state of a step. A step that waits is still in progress. */
81
79
  const cardStatus = {
@@ -107,7 +105,8 @@ function rowOf({ stage, state, label }) {
107
105
  /** The progress of a run as one message that changes in place. The first line is the status and the card as a link. Then one short line per step that has started, in the order of its start, with the emoji of its state and its label of `stageLabel`; more than `FOLD` done steps are one line with their count, and a step that says what people decided on the pull request keeps its own line. A stage that was skipped or never started is not in the plan, and a plan that is over leaves out each step that never ended. The last line links the run's page, when the console has an address, and each pull request the run opened. The blocks are the first line in small text, so that its emoji is small too, Slack's plan block with one task card per line, and the links in small text. */
108
106
  export function planLayout(plan, settings) {
109
107
  const over = plan.ended !== undefined;
110
- const state = !over ? "working" : plan.ended === "done" ? "done" : "failed";
108
+ const queued = over || plan.tasks.length > 0 ? undefined : plan.queued;
109
+ const state = queued !== undefined ? "queued" : !over ? "working" : plan.ended === "done" ? "done" : "failed";
111
110
  const shown = plan.tasks.filter((task) => !(over && task.state === "working"));
112
111
  const plain = (task) => task.state === "done" && task.label === undefined;
113
112
  const done = shown.filter(plain);
@@ -127,11 +126,15 @@ export function planLayout(plan, settings) {
127
126
  url,
128
127
  })),
129
128
  ];
130
- const head = headline(state, PLAN.title[state], plan.card ?? `run ${plan.run}`);
129
+ const head = headline(state === "queued" ? "waits" : state, PLAN.title[state], plan.card ?? `run ${plan.run}`);
131
130
  const links = linksOf(targets);
132
- const lines = rows.length === 0 && !over
133
- ? [PLAN.started]
134
- : rows.map((row) => `${EMOJI[row.status]} ${escape(row.label)}`);
131
+ const lines = queued !== undefined
132
+ ? [
133
+ PLAN.queued(queued.key, queued.value === undefined ? undefined : escape(queued.value), queued.limit, queued.workflow === undefined ? undefined : escape(queued.workflow)),
134
+ ]
135
+ : rows.length === 0 && !over
136
+ ? [PLAN.started]
137
+ : rows.map((row) => `${EMOJI[row.status]} ${escape(row.label)}`);
135
138
  const tasks = rows.map((row) => ({
136
139
  task_id: row.id.slice(0, 255),
137
140
  title: row.label,
@@ -157,7 +160,7 @@ function toolWords(tool) {
157
160
  /** The approval question: who it is for and what EDGAR wants to run, the one thing to do, the input, the Approve and Deny buttons beside a link button to the card and to the run's page in the console, and the tool's own name in small text. With no card and no console, the small text says how to see the run. */
158
161
  export function askLayout(asked) {
159
162
  const { run, tool, card, input } = asked;
160
- const who = whoOf(asked.user, asked.assignee);
163
+ const who = whoOf(asked.user);
161
164
  const base = asked.consoleUrl?.replace(/\/$/, "");
162
165
  const page = base === undefined ? undefined : `${base}/needs-a-person`;
163
166
  const targets = [
@@ -202,7 +205,7 @@ export function questionLayout(asked) {
202
205
  const { run, card } = asked;
203
206
  const name = card === undefined ? `run ${run}` : escape(card.id ?? "this card");
204
207
  const head = headline("waiting", SAYS.questionTitle, card === undefined ? name : cardLine(card, style));
205
- const said = greeted(whoOf(asked.user, asked.assignee), SAYS.question(name));
208
+ const said = greeted(whoOf(asked.user), SAYS.question(name));
206
209
  const question = cutEscaped(escape(asked.question.trim()), QUESTION_CHARS).text;
207
210
  const next = `*${SAYS.next}* ${SAYS.questionNext}`;
208
211
  return {
@@ -226,13 +229,16 @@ export function noteLayout(run, note, user) {
226
229
  ? `run ${run}`
227
230
  : `the ${workflow} workflow`
228
231
  : escape(card.id ?? "this card");
229
- const who = whoOf(user, note.assignee);
232
+ const who = whoOf(user);
230
233
  const opened = facts.pulls.filter((pull) => pull.referenced !== true).length;
231
234
  const count = what === "recovered"
232
235
  ? facts.failedBefore
233
236
  : what === "opened" || what === "failed"
234
237
  ? opened
235
238
  : facts.pulls.length;
239
+ const linked = (text) => card?.id === undefined
240
+ ? text
241
+ : text.replaceAll(cardMention(card.id), () => link(card.url, card.id ?? ""));
236
242
  const summary = SUMMED.has(what) && facts.summary !== undefined ? lead(facts.summary) : undefined;
237
243
  const why = what !== "failed"
238
244
  ? undefined
@@ -254,14 +260,14 @@ export function noteLayout(run, note, user) {
254
260
  : [SAYS.approvedBy(escape(names.format(facts.approvedBy)))]),
255
261
  ...(facts.commit === undefined ? [] : [SAYS.commit(escape(facts.commit))]),
256
262
  ...(why === undefined ? [] : [why]),
257
- ...(summary === undefined ? [] : [summary.text]),
263
+ ...(summary === undefined ? [] : [linked(summary.text)]),
258
264
  ...(what === "opened" && facts.risk !== undefined ? [escape(facts.risk)] : []),
259
265
  ...(summary?.cut === true && targets.length > 0 ? [SAYS.more] : []),
260
266
  ].join(" ");
261
267
  const options = what === "decision"
262
268
  ? facts.options
263
269
  .slice(0, MAX_OPTIONS)
264
- .map((option, at) => `${String(at + 1)}. ${lead(option, 300).text}`)
270
+ .map((option, at) => `${String(at + 1)}. ${linked(lead(option, 300).text)}`)
265
271
  : [];
266
272
  const told = what === "failed" && facts.next !== undefined
267
273
  ? SAYS.replay(facts.next, run)
@@ -6,8 +6,8 @@ import { type message, posted } from "#schemas/slack";
6
6
  /** A message EDGAR posted, as Slack lists it. */
7
7
  export type Message = z.infer<typeof message>;
8
8
  /** The metadata of an EDGAR message of `kind`, so a later call can find it. */
9
- export declare function mark(kind: "edgar_post" | "edgar_ask" | "edgar_answered" | "edgar_closed" | "edgar_plan" | "edgar_approval" | "edgar_question" | "edgar_card" | "edgar_ready" | "edgar_end" | "edgar_relayed" | "edgar_relay_done" | "edgar_answer", payload: Readonly<Record<string, unknown>>): {
10
- event_type: "edgar_answer" | "edgar_answered" | "edgar_approval" | "edgar_ask" | "edgar_card" | "edgar_closed" | "edgar_end" | "edgar_plan" | "edgar_post" | "edgar_question" | "edgar_ready" | "edgar_relay_done" | "edgar_relayed";
9
+ export declare function mark(kind: "edgar_post" | "edgar_ask" | "edgar_answered" | "edgar_closed" | "edgar_plan" | "edgar_approval" | "edgar_question" | "edgar_card" | "edgar_ready" | "edgar_end" | "edgar_relayed" | "edgar_relay_done" | "edgar_answer" | "edgar_post_to" | "edgar_post_done", payload: Readonly<Record<string, unknown>>): {
10
+ event_type: "edgar_answer" | "edgar_answered" | "edgar_approval" | "edgar_ask" | "edgar_card" | "edgar_closed" | "edgar_end" | "edgar_plan" | "edgar_post" | "edgar_post_done" | "edgar_post_to" | "edgar_question" | "edgar_ready" | "edgar_relay_done" | "edgar_relayed";
11
11
  event_payload: Readonly<Record<string, unknown>>;
12
12
  };
13
13
  /** Posts `text` with `extra` fields (blocks, metadata) in `channel`, in `thread` when given. Blocks that Slack refuses are left out, as `written` says. */
@@ -36,7 +36,7 @@ export async function mentioned(ctx, run, message, assignee, settings) {
36
36
  const user = await recipient(ctx, entry);
37
37
  if (user.ok && userId.safeParse(user.value).success)
38
38
  return user.value;
39
- ctx.log(`run ${run}: ${message} names ${assignee} with no mention, because users.lookupByEmail gave no user for ${entry} (${user.ok ? "not a user id" : user.error.kind})`);
39
+ ctx.log(`run ${run}: ${message} greets nobody for ${assignee}, because users.lookupByEmail gave no user for ${entry} (${user.ok ? "not a user id" : user.error.kind})`);
40
40
  return undefined;
41
41
  }
42
42
  /** The DM conversation of a `dm` entry, which a card's thread needs to be found again. */
@@ -4,9 +4,9 @@ import { askLayout, noteLayout, planLayout, questionLayout, stageLabel, style, }
4
4
  import { findMarked, listed, mark, newestMarked, post, status, threadStatus, update, waitingRelays, } from "#outbound/messages";
5
5
  import { cardThread, directOf, homeOf, mentioned, oneMore, openThread, rootOf, threadOf, } from "#outbound/places";
6
6
  import { cutEscaped, escape } from "#outbound/tools";
7
- import { ANSWER, ANSWER_FLOWS, PLAN, REVIEW_WAIT, reviewedLabel } from "#outbound/words";
7
+ import { ANSWER, ANSWER_FLOWS, PLAN, REPLY, REVIEW_WAIT, SAYS, reviewedLabel, } from "#outbound/words";
8
8
  import { settingsOf } from "#schemas/config";
9
- import { answerOutcome, approvalRequested, failedOutcome, openedOutcome, outcomeRecord, planState, pullOutcome, questionOutcome, reviewOutcome, runRead, runTrigger, slackOrigin, } from "#schemas/events";
9
+ import { answerOutcome, approvalRequested, failedOutcome, openedOutcome, outcomeRecord, planState, postOutcome, pullOutcome, questionOutcome, reviewOutcome, runRead, runTrigger, slackOrigin, waitingForSlot, } from "#schemas/events";
10
10
  /** The most characters of a call's input an approval question shows; a section's text holds 3,000. */
11
11
  const INPUT_CHARS = 2400;
12
12
  /** A call's input as the text of a code block: markup made plain, no two backticks side by side to end the block, and at most `INPUT_CHARS` characters, cut between two characters and never inside an entity. `cut` says that a part is left out. */
@@ -57,14 +57,17 @@ async function beganOf(ctx, event) {
57
57
  }
58
58
  /** Writes the run's plan message in the card's thread after `change`, and answers the plan. With `first`, a run that has no plan message gets one, whose first line links the card that the run began with; without it, such a run gets none and the answer is `undefined`, so the end of a run that showed no plan posts no empty one. */
59
59
  async function replan(ctx, event, place, settings, change, first) {
60
+ const all = await listed(ctx, place.channel, place.thread);
61
+ return all.ok ? await replanIn(ctx, event, place, settings, change, all.value, first) : all;
62
+ }
63
+ /** `replan` on the messages `all` of the thread, read once by the caller. */
64
+ async function replanIn(ctx, event, place, settings, change, all, first) {
60
65
  const { channel, thread } = place;
61
- const found = await findMarked(ctx, channel, thread, "edgar_plan", (p) => p["run"] === event.run);
62
- if (!found.ok)
63
- return found;
64
- const ts = found.value?.ts;
66
+ const found = newestMarked(all, "edgar_plan", (p) => p["run"] === event.run);
67
+ const ts = found?.ts;
65
68
  if (ts === undefined && first === undefined)
66
69
  return ok(undefined);
67
- const kept = planState.safeParse(found.value?.metadata?.event_payload);
70
+ const kept = planState.safeParse(found?.metadata?.event_payload);
68
71
  const card = first?.card === undefined ? {} : { card: cardLine(first.card, style) };
69
72
  const plan = change(kept.success ? kept.data : { run: event.run, tasks: [], pulls: [], ...card });
70
73
  const { text, blocks } = planLayout(plan, settings);
@@ -131,7 +134,6 @@ async function ask(ctx, event, place, settings, first) {
131
134
  ? undefined
132
135
  : inputBlock(JSON.stringify(input, null, 2)),
133
136
  card: first.card,
134
- assignee,
135
137
  user,
136
138
  consoleUrl: settings.console_url,
137
139
  });
@@ -165,7 +167,6 @@ async function question(ctx, event, stage, place, settings, first) {
165
167
  const { text, blocks } = questionLayout({
166
168
  run,
167
169
  card: first.card,
168
- assignee,
169
170
  user,
170
171
  question: asked,
171
172
  });
@@ -258,6 +259,68 @@ async function tell(ctx, event, settings, home, found, note) {
258
259
  }
259
260
  return ok(undefined);
260
261
  }
262
+ /** Posts once in the card's thread that EDGAR will post the result in the channel that a person asked for, when a done stage's output names one in `post_in`. The message's metadata `edgar_post_to` keeps the channel and the run that heard it, so the end of a later run that is done keeps the promise. */
263
+ async function promise(ctx, event, at) {
264
+ const channel = postOutcome.safeParse(event.payload).data?.outcome.output.post_in;
265
+ if (channel === undefined)
266
+ return ok(undefined);
267
+ const same = (p) => p["channel"] === channel;
268
+ const found = await findMarked(ctx, at.channel, at.thread, "edgar_post_to", same);
269
+ if (!found.ok)
270
+ return found;
271
+ if (found.value !== undefined)
272
+ return ok(undefined);
273
+ const metadata = mark("edgar_post_to", { run: event.run, channel });
274
+ const sent = await post(ctx, at.channel, at.thread, SAYS.willPost(channelText(channel)), {
275
+ metadata,
276
+ });
277
+ return sent.ok ? ok(undefined) : sent;
278
+ }
279
+ /** A Slack channel link, as Slack writes a channel that a person names in a message: `<#C123|name>`. */
280
+ const CHANNEL_LINK = /^<#([A-Z0-9]+)(?:\|[^>]*)?>$/;
281
+ /** The channel to post in for `asked`, the words a person or a model wrote: the id of a channel link, else the name with no `#`, which `chat.postMessage` also takes. */
282
+ function channelOf(asked) {
283
+ return CHANNEL_LINK.exec(asked.trim())?.[1] ?? asked.trim().replace(/^#/, "");
284
+ }
285
+ /** `asked` as a message shows it: a channel link as it is, so Slack shows the channel, and any other words escaped. */
286
+ function channelText(asked) {
287
+ return CHANNEL_LINK.test(asked.trim()) ? asked.trim() : escape(asked);
288
+ }
289
+ /** Posts the end note `layout` in the channel that `marker` names and turns the marker into `edgar_post_done`, which says where the result went, so the result goes there once. A channel that the app is not in, or that Slack cannot find, is said on the marker with how to fix it; any other refusal is the delivery's failure, so the engine hands the event again. */
290
+ async function keepPromise(ctx, at, marker, layout) {
291
+ const payload = marker.metadata?.event_payload ?? {};
292
+ const asked = typeof payload["channel"] === "string" ? payload["channel"] : "";
293
+ const sent = await post(ctx, channelOf(asked), undefined, layout.text, { blocks: layout.blocks });
294
+ if (!sent.ok && sent.error.kind !== "forbidden" && sent.error.kind !== "not_found")
295
+ return sent;
296
+ const shown = channelText(asked);
297
+ const text = sent.ok ? SAYS.posted(shown) : SAYS.notPosted(shown);
298
+ const metadata = mark("edgar_post_done", payload);
299
+ const done = await update(ctx, at.channel, marker.ts, text, { metadata });
300
+ return done.ok ? ok(undefined) : done;
301
+ }
302
+ /** Whether `message` is a question of `run` that no answer reaches once the run is over: an `ask` or an approval, whose key the engine no longer waits on, and, with `stopped`, a question that a done stage left open, since the card closed or a person stopped its work. */
303
+ function staleQuestion(message, run, stopped) {
304
+ const payload = message.metadata?.event_payload ?? {};
305
+ const own = (key) => typeof key === "string" && key.startsWith(`${run}:`);
306
+ const kind = message.metadata?.event_type;
307
+ if (kind === "edgar_ask")
308
+ return own(payload["key"]);
309
+ if (kind === "edgar_approval")
310
+ return own(payload["operation"]);
311
+ return kind === "edgar_question" && stopped && payload["run"] === run;
312
+ }
313
+ /** Edits each question of `run` in the thread `at` that `staleQuestion` finds to say that it is no longer needed, with no buttons, and marks it closed, so nobody spends time on an answer and the next reply goes past it. An edit that Slack refuses is one log line. shortcut: an `ask` posted in another thread than the card's stays up until a reply finds it closed; reaching it needs the place of each ask stored with its key. */
314
+ async function closeQuestions(ctx, at, run, stopped, all) {
315
+ const why = stopped ? REPLY.notNeededStopped : REPLY.notNeededEnded;
316
+ for (const message of all.filter((each) => staleQuestion(each, run, stopped))) {
317
+ const metadata = mark("edgar_closed", { ...message.metadata?.event_payload });
318
+ const text = `${message.text ?? ""}\n\n${why}`;
319
+ const closed = await update(ctx, at.channel, message.ts, text, { blocks: [], metadata });
320
+ if (!closed.ok)
321
+ ctx.log(`run ${run}: the question at ${message.ts} stays up (${closed.error.message})`);
322
+ }
323
+ }
261
324
  /** The note that a pull request is ready for people, at the moment the run starts to wait for their review: the note of a run that opened a pull request, with the card and the assignee that the run began with and the pull requests that the plan holds. */
262
325
  function readyNote(run, first, plan, settings) {
263
326
  const base = settings.console_url?.replace(/\/$/, "");
@@ -364,6 +427,7 @@ async function ended(ctx, event, settings, first) {
364
427
  return home;
365
428
  let planned = false;
366
429
  let found;
430
+ let promised;
367
431
  if (home.value !== undefined) {
368
432
  const thread = await threadOf(ctx, event, home.value);
369
433
  if (!thread.ok)
@@ -371,17 +435,32 @@ async function ended(ctx, event, settings, first) {
371
435
  found = thread.value;
372
436
  if (found !== undefined) {
373
437
  const at = { ...home.value, thread: found };
438
+ const all = await listed(ctx, at.channel, found);
439
+ if (!all.ok)
440
+ return all;
374
441
  const over = (plan) => ({ ...plan, ended: word });
375
- const changed = await replan(ctx, event, at, settings, over);
442
+ const changed = await replanIn(ctx, event, at, settings, over, all.value);
376
443
  if (!changed.ok)
377
444
  return changed;
378
445
  planned = changed.value !== undefined;
446
+ await closeQuestions(ctx, at, event.run, note?.what === "stopped", all.value);
447
+ const marker = word === "done"
448
+ ? newestMarked(all.value, "edgar_post_to", (p) => p["run"] !== event.run)
449
+ : undefined;
450
+ if (marker !== undefined)
451
+ promised = { at, marker };
379
452
  }
380
453
  if (home.value.origin !== undefined) {
381
454
  const close = settings.close_on_done && word === "done";
382
455
  await status(ctx, home.value.origin, close ? "closed" : "active");
383
456
  }
384
457
  }
458
+ if (promised !== undefined) {
459
+ const layout = noteLayout(event.run, note, undefined);
460
+ const kept = await keepPromise(ctx, promised.at, promised.marker, layout);
461
+ if (!kept.ok)
462
+ return kept;
463
+ }
385
464
  const told = note !== undefined && asks.has(note.what);
386
465
  const bare = note?.what === "done" && note.facts.summary === undefined;
387
466
  if (word === "done" && !told && (!planned || bare))
@@ -423,6 +502,9 @@ const steps = {
423
502
  const asked = await question(ctx, event, stage, at, settings, first);
424
503
  if (!asked.ok)
425
504
  return asked;
505
+ const promised = await promise(ctx, event, at);
506
+ if (!promised.ok)
507
+ return promised;
426
508
  const plan = changed.value;
427
509
  if (stage !== REVIEW_WAIT ||
428
510
  word !== "waiting" ||
@@ -432,6 +514,15 @@ const steps = {
432
514
  return await tell(ctx, event, settings, place, thread, readyNote(event.run, first, plan, settings));
433
515
  },
434
516
  approval_requested: async (event, ctx, place, settings, first) => await ask(ctx, event, place, settings, first),
517
+ waiting_for_slot: async (event, ctx, place, settings, first) => {
518
+ const wait = waitingForSlot.safeParse(event.payload);
519
+ const { thread } = place;
520
+ if (!wait.success || thread === undefined)
521
+ return ok(undefined);
522
+ const workflow = first.workflow === undefined ? {} : { workflow: first.workflow };
523
+ const queued = (p) => ({ ...p, queued: { ...wait.data, ...workflow } });
524
+ return await replan(ctx, event, { ...place, thread }, settings, queued, first);
525
+ },
435
526
  };
436
527
  const taken = new Set(Object.keys(steps));
437
528
  function isTaken(kind) {
@@ -476,6 +567,7 @@ export const progress = defineEventHook({
476
567
  "attempt_started",
477
568
  "attempt_outcome",
478
569
  "approval_requested",
570
+ "waiting_for_slot",
479
571
  "run_outcome",
480
572
  ],
481
573
  secrets: apiAccess.secrets,
@@ -55,6 +55,7 @@ async function destination(ctx, input) {
55
55
  /** Every tool of the Slack extension, by the name the manifest gives it. */
56
56
  export const tools = {
57
57
  post_summary: defineTool({
58
+ publishes: true,
58
59
  description: 'Post a run\'s summary as a message to a person. `did` ends the opening sentence "On <card>, I ...", such as "rebuilt the empty search index, so search answers again". Each of `paragraphs` is plain sentences with no heading: what happened and why it matters first, then the change. `check` says what the reader should check or decide',
59
60
  input: postSummaryTool.input,
60
61
  output: postSummaryTool.output,
@@ -73,6 +74,7 @@ export const tools = {
73
74
  },
74
75
  }),
75
76
  dm: defineTool({
77
+ publishes: true,
76
78
  description: "Send a direct message to a person, by Slack user id or by email",
77
79
  input: dmTool.input,
78
80
  output: dmTool.output,
@@ -91,6 +93,7 @@ export const tools = {
91
93
  },
92
94
  }),
93
95
  ask: defineTool({
96
+ publishes: true,
94
97
  description: "Ask a person a question with answer buttons, or for a reply in the thread, and wait for the answer",
95
98
  input: askTool.input,
96
99
  output: askTool.output,
@@ -58,6 +58,9 @@ interface NoteWords {
58
58
  export declare const NOTE: Readonly<Record<EndNote["what"], NoteWords>>;
59
59
  /** The other words of the notes, of the approval question, and of a question of the `ask` tool. */
60
60
  export declare const SAYS: {
61
+ readonly willPost: (channel: string) => string;
62
+ readonly posted: (channel: string) => string;
63
+ readonly notPosted: (channel: string) => string;
61
64
  readonly greet: (who: string) => string;
62
65
  readonly next: "Your move:";
63
66
  readonly replay: (check: string, run: string) => string;
@@ -84,14 +87,16 @@ export declare const SAYS: {
84
87
  readonly askHere: "Reply here when you're ready, and I'll carry on from your answer.";
85
88
  readonly askThread: "Reply in this thread when you're ready, and I'll carry on from your answer.";
86
89
  };
87
- /** The words of the progress message: the status in words beside the emoji while EDGAR works and when the run is over, short because the end note under it says why and what to do, the line of a run with no step yet, the one line that stands for the done steps when there are many, a wait that the built-in table does not know, and the moving line under the thread. */
90
+ /** The words of the progress message: the status in words beside the emoji while the run waits its turn, while EDGAR works and when the run is over, short because the end note under it says why and what to do, the line of a run with no step yet, what a queued run waits on, the one line that stands for the done steps when there are many, a wait that the built-in table does not know, and the moving line under the thread. */
88
91
  export declare const PLAN: {
89
92
  readonly title: {
93
+ readonly queued: "Queued";
90
94
  readonly working: "I'm on it";
91
95
  readonly done: "All done";
92
96
  readonly failed: "Ended early";
93
97
  };
94
98
  readonly started: "I'll show each step here as I go.";
99
+ readonly queued: (key: string, value: string | undefined, limit: number, workflow?: string) => string;
95
100
  readonly folded: (count: number) => string;
96
101
  readonly waiting: (label: string) => string;
97
102
  readonly status: (label: string) => string;
@@ -109,16 +114,20 @@ export declare const REPLY: {
109
114
  readonly notOpened: (why: string) => string;
110
115
  readonly relayed: "Got it, thanks. I've put your reply on the card and I'm reading it now.";
111
116
  readonly relayedNoFile: "Got it, thanks. I've put your words on the card and I'm reading them now. I can't open files from Slack yet, so please add the file to the card too.";
117
+ readonly filesNotRead: (names: readonly string[]) => string;
112
118
  readonly fileOnly: "I can't open files from Slack yet. Could you add the file to the card, or tell me here what it shows?";
113
119
  readonly notAllowed: "Sorry, I can only take replies from people this project allows, so yours didn't go on the card.";
114
120
  readonly notRelayed: (why: string) => string;
115
121
  readonly operatorsAnswer: "Only the project's operators can answer this one, so I've left it open for them.";
116
122
  readonly operatorsStop: "Only the project's operators can stop this work, so I'm carrying on. One of them can press stop.";
117
123
  readonly operatorsChoose: "Only the project's operators can make this call, so I've left the buttons for them.";
118
- readonly noOperators: (user: string) => string;
124
+ readonly toBeLetIn: (user: string) => string;
125
+ readonly notChecked: (why: string) => string;
119
126
  readonly questionClosed: (why: string) => string;
120
127
  readonly answerFailed: (why: string) => string;
121
128
  readonly closed: "I'd stopped waiting on this one before an answer came, so a reply here won't reach me.";
129
+ readonly notNeededStopped: "This isn't needed any more: the card was closed or the work was stopped, so a reply here won't reach me.";
130
+ readonly notNeededEnded: "This isn't needed any more: the run that asked it has ended, so a reply here won't reach me.";
122
131
  readonly answered: (user: string) => string;
123
132
  readonly notStopped: (why: string) => string;
124
133
  readonly notRecorded: (why: string) => string;
@@ -191,6 +191,9 @@ export const NOTE = {
191
191
  };
192
192
  /** The other words of the notes, of the approval question, and of a question of the `ask` tool. */
193
193
  export const SAYS = {
194
+ willPost: (channel) => `I'll post the result in ${channel} when the work is done.`,
195
+ posted: (channel) => `I posted the result in ${channel}.`,
196
+ notPosted: (channel) => `I couldn't post the result in ${channel}: I'm not in that channel, or Slack can't find it. Invite me there with \`/invite\`, then ask again.`,
194
197
  greet: (who) => `Hey ${who},`,
195
198
  next: "Your move:",
196
199
  replay: (check, run) => `${check}, then run \`edgar run replay ${run}\` and I'll give it another go.`,
@@ -219,10 +222,23 @@ export const SAYS = {
219
222
  askHere: "Reply here when you're ready, and I'll carry on from your answer.",
220
223
  askThread: "Reply in this thread when you're ready, and I'll carry on from your answer.",
221
224
  };
222
- /** The words of the progress message: the status in words beside the emoji while EDGAR works and when the run is over, short because the end note under it says why and what to do, the line of a run with no step yet, the one line that stands for the done steps when there are many, a wait that the built-in table does not know, and the moving line under the thread. */
225
+ /** The value EDGAR counts a run under when its input has no value at any field of its workflow's concurrency key. */
226
+ const NO_VALUE = "null";
227
+ /** The words of the progress message: the status in words beside the emoji while the run waits its turn, while EDGAR works and when the run is over, short because the end note under it says why and what to do, the line of a run with no step yet, what a queued run waits on, the one line that stands for the done steps when there are many, a wait that the built-in table does not know, and the moving line under the thread. */
223
228
  export const PLAN = {
224
- title: { working: "I'm on it", done: "All done", failed: "Ended early" },
229
+ title: { queued: "Queued", working: "I'm on it", done: "All done", failed: "Ended early" },
225
230
  started: "I'll show each step here as I go.",
231
+ queued: (key, value, limit, workflow) => {
232
+ const many = (one) => `${String(limit)} ${one}${limit === 1 ? "" : "s"}`;
233
+ const going = `${limit === 1 ? "is" : "are"} going, which is my limit. I'll start when one ends.`;
234
+ if (value === NO_VALUE)
235
+ return `${workflow === undefined ? `${many("run")} of this workflow` : many(`${workflow} run`)} ${going}`;
236
+ if (value !== undefined)
237
+ return `${many("run")} for ${value} ${going}`;
238
+ if (key === "sandboxes")
239
+ return `I already have ${many("run")} open, which is my limit. I'll start when one ends.`;
240
+ return `I'm already running ${many("step")} at once, which is my limit. I'll start when one ends.`;
241
+ },
226
242
  folded: (count) => `${String(count)} steps done`,
227
243
  waiting: (label) => `Waiting: ${label}`,
228
244
  status: (label) => `is on it: ${label}…`,
@@ -240,16 +256,20 @@ export const REPLY = {
240
256
  notOpened: (why) => `Sorry, I couldn't open a card for your message. Here's what went wrong: ${why}`,
241
257
  relayed: "Got it, thanks. I've put your reply on the card and I'm reading it now.",
242
258
  relayedNoFile: "Got it, thanks. I've put your words on the card and I'm reading them now. I can't open files from Slack yet, so please add the file to the card too.",
259
+ filesNotRead: (names) => `I can't read ${names.map((name) => `\`${name}\``).join(", ")}: I read text and log files, JSON, XML, YAML, PDFs, and PNG, JPEG, GIF or WebP pictures.`,
243
260
  fileOnly: "I can't open files from Slack yet. Could you add the file to the card, or tell me here what it shows?",
244
261
  notAllowed: "Sorry, I can only take replies from people this project allows, so yours didn't go on the card.",
245
262
  notRelayed: (why) => `Sorry, I couldn't put your reply on the card. Here's what went wrong: ${why}`,
246
263
  operatorsAnswer: "Only the project's operators can answer this one, so I've left it open for them.",
247
264
  operatorsStop: "Only the project's operators can stop this work, so I'm carrying on. One of them can press stop.",
248
265
  operatorsChoose: "Only the project's operators can make this call, so I've left the buttons for them.",
249
- noOperators: (user) => `This project has no operators yet, so nobody can do this from Slack. To be one, add \`"${user}" = "<your name in [roles] operator>"\` to \`[extensions.slack] operators\` in edgar.toml.`,
266
+ toBeLetIn: (user) => `To be let in, add \`ids = { slack = "${user}" }\` to your \`[people.<name>]\` table in edgar.toml, and your name to \`[roles] operator\`.`,
267
+ notChecked: (why) => `Sorry, I couldn't check whether you can do this, so nothing changed. Here's what went wrong: ${why}`,
250
268
  questionClosed: (why) => `I'd stopped waiting for an answer to this one (${why}), so I closed it and your reply didn't go anywhere. If you'd like me to pick something up in this thread, just mention me.`,
251
269
  answerFailed: (why) => `Sorry, I couldn't take your answer. Here's what went wrong: ${why}`,
252
270
  closed: "I'd stopped waiting on this one before an answer came, so a reply here won't reach me.",
271
+ notNeededStopped: "This isn't needed any more: the card was closed or the work was stopped, so a reply here won't reach me.",
272
+ notNeededEnded: "This isn't needed any more: the run that asked it has ended, so a reply here won't reach me.",
253
273
  answered: (user) => `<@${user}> answered this. Thanks!`,
254
274
  notStopped: (why) => `Sorry, I couldn't stop the work. Here's what went wrong: ${why}`,
255
275
  notRecorded: (why) => `Sorry, I couldn't record your choice. Here's what went wrong: ${why}`,
@@ -6,7 +6,7 @@ export declare const userId: z.ZodString;
6
6
  export declare const channelId: z.ZodString;
7
7
  /** An email address. */
8
8
  export declare const email: z.ZodEmail;
9
- /** The `[extensions.slack]` table. `operators` maps a Slack user to a name in `[roles] operator`; `channel` gets each summary and the thread of each run whose card did not come from Slack; `dm` gets each run's end, by user id or email; `people` maps the name of a card's assignee, as the tracker gives it, to the user id or email of the person the end note mentions; `console_url` is the console the end note links, at an address its readers can open, and with none the note has no link; `status` is the phrase of a stage, by stage name. */
9
+ /** The `[extensions.slack]` table. `operators`, deprecated, maps a Slack user to a name in `[roles] operator`; with it empty, EDGAR decides who may act from `[people]` and `[roles] operator`; `channel` gets each summary and the thread of each run whose card did not come from Slack; `dm` gets each run's end, by user id or email; `people` maps the name of a card's assignee, as the tracker gives it, to the user id or email of the person the end note mentions; `console_url` is the console the end note links, at an address its readers can open, and with none the note has no link; `status` is the phrase of a stage, by stage name. */
10
10
  export declare const config: z.ZodObject<{
11
11
  inbound: z.ZodDefault<z.ZodEnum<{
12
12
  events: "events";
@@ -8,25 +8,71 @@ export const channelId = z.string().regex(/^[CDG][A-Z0-9]{2,}$/);
8
8
  export const email = z.email();
9
9
  /** A person of the Slack workspace, by user id or by email. */
10
10
  const person = z.union([userId, email]);
11
- /** The `[extensions.slack]` table. `operators` maps a Slack user to a name in `[roles] operator`; `channel` gets each summary and the thread of each run whose card did not come from Slack; `dm` gets each run's end, by user id or email; `people` maps the name of a card's assignee, as the tracker gives it, to the user id or email of the person the end note mentions; `console_url` is the console the end note links, at an address its readers can open, and with none the note has no link; `status` is the phrase of a stage, by stage name. */
11
+ /** The `[extensions.slack]` table. `operators`, deprecated, maps a Slack user to a name in `[roles] operator`; with it empty, EDGAR decides who may act from `[people]` and `[roles] operator`; `channel` gets each summary and the thread of each run whose card did not come from Slack; `dm` gets each run's end, by user id or email; `people` maps the name of a card's assignee, as the tracker gives it, to the user id or email of the person the end note mentions; `console_url` is the console the end note links, at an address its readers can open, and with none the note has no link; `status` is the phrase of a stage, by stage name. */
12
12
  export const config = z.strictObject({
13
- inbound: z.enum(["socket", "events"]).default("socket"),
14
- open_card_on: z.array(z.enum(["dm", "mention"])).default(["dm", "mention"]),
15
- card_column: z.string().min(1).default("intake"),
16
- context_messages: z.number().int().min(0).max(100).default(20),
13
+ inbound: z
14
+ .enum(["socket", "events"])
15
+ .default("socket")
16
+ .describe("How Slack reaches EDGAR: socket or events. With events, the service only waits, because EDGAR has no Slack webhook receiver yet. Default socket."),
17
+ open_card_on: z
18
+ .array(z.enum(["dm", "mention"]))
19
+ .default(["dm", "mention"])
20
+ .describe("Which messages open a card: a DM, a mention, or both. Default both."),
21
+ card_column: z
22
+ .string()
23
+ .min(1)
24
+ .default("intake")
25
+ .describe("The engine state of a card that a Slack message opens. Default intake."),
26
+ context_messages: z
27
+ .number()
28
+ .int()
29
+ .min(0)
30
+ .max(100)
31
+ .default(20)
32
+ .describe("How many of the thread's newest messages go onto the card when the message is a mention in a thread, from 0 to 100. Default 20."),
17
33
  allow: z
18
34
  .strictObject({
19
- domains: z.array(z.string().min(1)).default([]),
20
- guests: z.boolean().default(false),
35
+ domains: z
36
+ .array(z.string().min(1))
37
+ .default([])
38
+ .describe("Only a person whose email is in one of these domains opens a card. Default empty: any domain."),
39
+ guests: z
40
+ .boolean()
41
+ .default(false)
42
+ .describe("Whether a guest account may open a card. Default false."),
21
43
  })
22
- .optional(),
23
- operators: z.record(userId, z.string().regex(/^[^\s@]+$/)).default({}),
24
- channel: channelId.optional(),
25
- dm: z.array(person).default([]),
26
- people: z.record(z.string().min(1), person).default({}),
27
- close_on_done: z.boolean().default(false),
28
- console_url: z.url({ protocol: /^https?$/ }).optional(),
29
- status: z.record(z.string(), z.string().min(1)).default({}),
44
+ .optional()
45
+ .describe("Who may open a card; a bot never does. Not set: everyone."),
46
+ operators: z
47
+ .record(userId, z.string().regex(/^[^\s@]+$/))
48
+ .default({})
49
+ .meta({
50
+ deprecated: true,
51
+ description: 'Write each person\'s Slack user id in `[people.<name>] ids = { slack = "U0123ABCD" }` and their name in `[roles] operator` instead; while this table has an entry, it still decides who may answer, approve, deny and stop.',
52
+ }),
53
+ channel: channelId
54
+ .optional()
55
+ .describe("The channel id where post_summary posts when the call names none, where a card that did not come from Slack gets its thread, and where the note of a run that opened a pull request is shown."),
56
+ dm: z
57
+ .array(person)
58
+ .default([])
59
+ .describe("Who gets the end note of each run in a DM, by Slack user id or email. Default none."),
60
+ people: z
61
+ .record(z.string().min(1), person)
62
+ .default({})
63
+ .describe("Who the end note and an approval question mention: the name of a card's assignee, as the tracker gives it, to their Slack user id or email. Default none."),
64
+ close_on_done: z
65
+ .boolean()
66
+ .default(false)
67
+ .describe("With true, a run that ends done sets the Slack session status to closed; otherwise it goes back to active. Default false."),
68
+ console_url: z
69
+ .url({ protocol: /^https?$/ })
70
+ .optional()
71
+ .describe("The console address that the progress message, an approval question and the end note link, at an address their readers can open. Not set: no console link."),
72
+ status: z
73
+ .record(z.string(), z.string().min(1))
74
+ .default({})
75
+ .describe('The phrase of the status line while a stage works, by stage name, such as fix = "is reading the code". A stage with no phrase shows "is on it:" and its label.'),
30
76
  });
31
77
  /** The table of a call, with its defaults; one that does not match is a permanent `invalid`. */
32
78
  export function settingsOf(value) {
@@ -39,6 +39,15 @@ export declare const questionOutcome: z.ZodObject<{
39
39
  }, z.core.$loose>;
40
40
  }, z.core.$loose>;
41
41
  }, z.core.$loose>;
42
+ /** A done stage whose output names the chat channel that a person asked to get the result in: the `post_in` of a classification. */
43
+ export declare const postOutcome: z.ZodObject<{
44
+ outcome: z.ZodObject<{
45
+ outcome: z.ZodLiteral<"done">;
46
+ output: z.ZodObject<{
47
+ post_in: z.ZodString;
48
+ }, z.core.$loose>;
49
+ }, z.core.$loose>;
50
+ }, z.core.$loose>;
42
51
  /** Why a run ended other than done: the message of a `run_outcome` payload. */
43
52
  export declare const failedOutcome: z.ZodObject<{
44
53
  outcome: z.ZodObject<{
@@ -96,6 +105,12 @@ export declare const approvalRequested: z.ZodObject<{
96
105
  input: z.ZodOptional<z.ZodUnknown>;
97
106
  assignee: z.ZodOptional<z.ZodString>;
98
107
  }, z.core.$loose>;
108
+ /** Why a queued run does not start yet, from its `waiting_for_slot` payload: `limit` runs already hold a start for `value`, the value its input has at `key`; with no `value`, the project's `key`, `slots` or `sandboxes`, is full at `limit`. */
109
+ export declare const waitingForSlot: z.ZodObject<{
110
+ key: z.ZodString;
111
+ value: z.ZodOptional<z.ZodString>;
112
+ limit: z.ZodNumber;
113
+ }, z.core.$loose>;
99
114
  /** The state of one stage on the plan message. */
100
115
  export declare const taskState: z.ZodEnum<{
101
116
  done: "done";
@@ -103,10 +118,16 @@ export declare const taskState: z.ZodEnum<{
103
118
  waiting: "waiting";
104
119
  working: "working";
105
120
  }>;
106
- /** The plan of one run, kept in its message's metadata so each event updates it in place: the run's card as the line that links it, each stage that started in the order of its start, each pull request a stage opened, and the outcome word once the run is over. A stage that read what people decided on the pull request has that as its `label`. */
121
+ /** The plan of one run, kept in its message's metadata so each event updates it in place: the run's card as the line that links it, what the run waits on while it is queued with the run's workflow, each stage that started in the order of its start, each pull request a stage opened, and the outcome word once the run is over. A stage that read what people decided on the pull request has that as its `label`. */
107
122
  export declare const planState: z.ZodObject<{
108
123
  run: z.ZodString;
109
124
  card: z.ZodOptional<z.ZodString>;
125
+ queued: z.ZodOptional<z.ZodObject<{
126
+ key: z.ZodString;
127
+ value: z.ZodOptional<z.ZodString>;
128
+ limit: z.ZodNumber;
129
+ workflow: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$loose>>;
110
131
  tasks: z.ZodArray<z.ZodObject<{
111
132
  stage: z.ZodString;
112
133
  state: z.ZodEnum<{