@kana-ai/edgar-ext-slack 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,17 +6,17 @@ The full guide, with the app setup, each setting, each tool and its examples, is
6
6
 
7
7
  ## Parts
8
8
 
9
- | Part | What it does |
10
- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
- | The service | Keeps one Socket Mode connection to Slack while `edgar start` runs. A DM or a mention that names a card (`ENG-42`, or its tracker link) goes on that card and binds its thread to it; any other is a chat (`ctx.runs.chat`), which the built-in `chat` workflow answers in the thread, or opens a card for when it asks for work. A reply answers the newest question that waits; with no question, a reply in the thread of a card, or of the card that the thread is bound to, goes on the card as that person's comment with the thread as its place (`ctx.cards.reply`), with the thread's messages since EDGAR's last one and each Slack thread that it links from the same channel or a public one (a private one is left out, and the person is told). EDGAR says so, and says once when it is still on an earlier reply; a short thank-you gets a short reply instead. It reacts :eyes: on each message it takes (`reactions:write`), and a new chat also gets "On it: reading your message." at once. The stop button cancels the card's runs. Approve, Deny and answer buttons move the run, and Try again starts a failed or stopped run again (`ctx.runs.replay`). |
12
- | The hook `progress` | Takes the run events of every run. A run that a person's words in Slack started (`relayed` on its `run_created`) posts a stage's answer `text` (as Slack formatting, with its sources, a line when it is not sure, and buttons to the card and the run), or the card that a chat opened, in that thread once, says there what each stage of the built-in `answer` workflow starts and does for the person (`edgar_said`), names each stage on the status line, ends its status, says a failed answer in one plain line, and swaps the :eyes: reaction on the person's message for :white_check_mark:, or :x: when the run did not end done. Each card has one thread. A card that came from Slack uses the thread of its message. Any other card gets a thread in `channel`, or in the DM of the first `dm` entry when `channel` is not set: its first message links the card, and each run of the card, a rerun too, replies in it. Each run keeps one progress message in the thread from the moment it waits in a queue or its first stage starts, and its approvals go there; a stage that ends `done` with a `question` in its output, such as a proposal that went on with the option it recommends, posts the question once there, greets the assignee, and says that a reply with the number of another option changes the work, with the metadata `edgar_question` and the run and the stage; a run that ends with no stage, such as a run that a card's event started and that had nothing to do, posts none. A card from Slack also gets the session status (`processing` at the run's start and at each stage's start, `suspended` for an approval, `active` or `closed` at the end). When a run ends, the end note goes in the card's thread, and in the card's thread in the DM of each `dm` entry. A run with no card, such as a scheduled watch, gets no thread and no progress message, and gets an end note only when it does not end `done`. |
13
- | The tool `post_summary` | Posts a run's summary as a person writes it: one sentence with the card and what was done, plain paragraphs, then what to check. Side effect, undone by `delete_message`, found by `find_message`. |
14
- | The tool `dm` | Sends a DM to a person, by Slack user id or by email. Side effect, undone by `delete_message`, found by `find_message`. |
15
- | The tool `ask` | Posts a question with answer buttons, or asks for a reply, and returns `waiting` until a person answers. Side effect with no undo: a person may already have read the question. |
16
- | The tool `delete_message` | Deletes a message that EDGAR posted. A message that is already gone is `done` with `deleted: false`. |
17
- | The tool `find_message` | Finds the message of a `post_summary` or `dm` call by the operation id in its metadata. `skipped` when there is none. |
18
- | The link reader | Reads a Slack thread that a card or its comments link (`read_link`, for `*.slack.com`) into the run's inbox, as `/tmp/inbox/links.md`: its newest 50 messages, oldest first, quoted as the service quotes a linked thread. Only a thread in `channel` or in a public channel is read, because everyone who reads the run may see it; a thread in a private channel, a DM or a group DM is a `forbidden` failure, which the inbox shows in one line. A Slack link that is not a message's permalink, such as a file, is not read. |
19
- | Chat files | A file that a person shares in a chat, such as a screenshot or a log, goes with the chat (`chatFiles`, for `files.slack.com`). The engine fetches it into the run's inbox, as it fetches a card's attachments: with the same byte caps, with secrets masked in a text file, and with `SLACK_BOT_TOKEN` as its bearer token, sent only to `files.slack.com`. A chat reads text and log files, JSON, XML, YAML, PDFs, and PNG, JPEG, GIF or WebP pictures; for any other file, or one Slack gives no download link for, the person gets one short reply that names it. Reading a file needs the `files:read` scope of `slack-app.json`. |
9
+ | Part | What it does |
10
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
11
+ | The service | Keeps one Socket Mode connection to Slack while `edgar start` runs. A DM or a mention that names a card (`ENG-42`, or its tracker link) goes on that card and binds its thread to it; any other is a chat (`ctx.runs.chat`), which the built-in `chat` workflow answers in the thread, or opens a card for when it asks for work. A reply answers the newest question that waits; with no question, a reply in the thread of a card, or of the card that the thread is bound to, goes on the card as that person's comment with the thread as its place (`ctx.cards.reply`), with the thread's messages since EDGAR's last one and each Slack thread that it links from the same channel or a public one (a private one is left out, and the person is told). EDGAR says so, and says once when it is still on an earlier reply; a short thank-you gets a short reply instead. It reacts :eyes: on each message it takes (`reactions:write`), and a new chat also gets "On it: reading your message." at once. The stop button cancels the card's runs. Approve, Deny and answer buttons move the run, and Try again starts a failed or stopped run again (`ctx.runs.replay`). |
12
+ | The hook `progress` | Takes the run events of every run. A run that a person's words in Slack started (`relayed` on its `run_created`) posts a stage's answer `text` (as Slack formatting, with its sources, a line when it is not sure, and buttons to the card and the run), or the card that a chat opened, in that thread once, says there what each stage of the built-in `answer` workflow starts and does for the person (`edgar_said`), names each stage on the status line, ends its status, says a failed answer in one plain line, and swaps the :eyes: reaction on the person's message for :white_check_mark:, or :x: when the run did not end done. Each card has one thread. A card that came from Slack uses the thread of its message. Any other card gets a thread in `channel`, or in the DM of the first `dm` entry when `channel` is not set: its first message links the card, and each run of the card, a rerun too, replies in it. Each run keeps one progress message in the thread from the moment it waits in a queue or its first stage starts, and its approvals go there; a stage that ends `done` with a `question` in its output, such as a proposal that went on with the option it recommends, posts the question once there, greets the assignee, and asks for a reply in the thread, which names the number of another option only when the question lists numbered options, with the metadata `edgar_question` and the run and the stage; a run that ends with no stage, such as a run that a card's event started and that had nothing to do, posts none, and a run whose every stage was skipped, as a workflow that does not apply to the card, posts nothing in the card's thread, deletes the progress message that it showed, if any, and leaves the card's first message as it is. A card from Slack also gets the session status (`processing` at the run's start and at each stage's start, `suspended` for an approval, `active` or `closed` at the end). When a run ends, the end note goes in the card's thread, and in the card's thread in the DM of each `dm` entry. A run with no card, such as a scheduled watch, gets no thread and no progress message, and gets an end note only when it does not end `done`. |
13
+ | The tool `post_summary` | Posts a run's summary as a person writes it: one sentence with the card and what was done, plain paragraphs, then what to check. Side effect, undone by `delete_message`, found by `find_message`. |
14
+ | The tool `dm` | Sends a DM to a person, by Slack user id or by email. Side effect, undone by `delete_message`, found by `find_message`. |
15
+ | The tool `ask` | Posts a question with answer buttons, or asks for a reply, and returns `waiting` until a person answers. Side effect with no undo: a person may already have read the question. |
16
+ | The tool `delete_message` | Deletes a message that EDGAR posted. A message that is already gone is `done` with `deleted: false`. |
17
+ | The tool `find_message` | Finds the message of a `post_summary` or `dm` call by the operation id in its metadata. `skipped` when there is none. |
18
+ | The link reader | Reads a Slack thread that a card or its comments link (`read_link`, for `*.slack.com`) into the run's inbox, as `/tmp/inbox/links.md`: its newest 50 messages, oldest first, quoted as the service quotes a linked thread. Only a thread in `channel` or in a public channel is read, because everyone who reads the run may see it; a thread in a private channel, a DM or a group DM is a `forbidden` failure, which the inbox shows in one line. A Slack link that is not a message's permalink, such as a file, is not read. |
19
+ | Chat files | A file that a person shares in a chat, such as a screenshot or a log, goes with the chat (`chatFiles`, for `files.slack.com`). The engine fetches it into the run's inbox, as it fetches a card's attachments: with the same byte caps, with secrets masked in a text file, and with `SLACK_BOT_TOKEN` as its bearer token, sent only to `files.slack.com`. A chat reads text and log files, JSON, XML, YAML, PDFs, and PNG, JPEG, GIF or WebP pictures; for any other file, or one Slack gives no download link for, the person gets one short reply that names it. Reading a file needs the `files:read` scope of `slack-app.json`. |
20
20
 
21
21
  The text of `post_summary` (`did`, `paragraphs`, `check`), of `dm`, of an `ask` question and of an answer shown back comes from a model, which often copies it from a card or a log. The extension makes `&`, `<` and `>` plain in that text, so it cannot notify a channel (`<!channel>`, `<@U…>`) or show a link whose label hides its address. A plain address still becomes a link in Slack. Known limit: a tool cannot post a link with a label of its own; the card link of `post_summary` is built by the extension. A question that passes the 3,000 characters of a Slack section once its markup is plain is cut on a whole character and ends with `…`. In the other direction, the text of a message from Slack is read back as the person wrote it before it reaches a card or an answer: no mention, a link as its address, and `&amp;`, `&lt;`, `&gt;` as their characters.
22
22
 
@@ -54,7 +54,7 @@ Each message EDGAR writes in Slack, a post, a change of a message or a message o
54
54
 
55
55
  ## The thread of a card and the end note
56
56
 
57
- The first message about a card opens its thread, when a run of the card starts its second stage or has something a person must read: a question, an approval, a pull request, a hand-back, a decision or a failure. Once the card has a thread, each later run of the card, a run that another run started too, joins it from its first stage, so its progress shows at once. A run that ends after one stage with nothing to tell, such as a card that asks EDGAR for nothing, posts nothing in the channel. The message is the card's status and its id as a link to the card with its title, such as ":eyes: Ready for review · ENG-1 Search fails", with the status in bold; then one small line with the card's service, "On behalf of" the person who asked for the work, and "Assignee" with the card's holder; then what the card asks, in at most two lines; then a link button to the card and to each pull request that the run opened. "On behalf of" is a Slack mention when the card came from a Slack message (the writer's user id) or when `people`, `operators` or an email finds the person's Slack user, and the plain name otherwise. The holder is shown only as a Slack mention, so EDGAR's own tracker user is never written. The message changes in place when a run of the card starts to work ("I'm on it"), when its pull request is ready ("Ready for review"), and when it ends, with the title of its end note. A card that came from Slack keeps the person's message as its first message, which EDGAR does not change. The metadata (`edgar_card`) holds the card's link, its id, its title, the newest 20 runs of the card, and what the message shows (`view`), so a change of one part keeps the others. A run finds the card's first message by the card's id, so a card that triage retitles keeps its one thread, and the message takes the new title in place. A first message that keeps no id is found by the card's link, up to the card's id when the tracker puts the title after it, such as `/issue/ENG-1/search-fails`. Each later run of the card adds its number to that metadata and replies in the same thread. Each message of a run finds the thread again by its run number, and a new run by the card's id or link, in the newest 1,000 messages of the channel or the DM, read 200 at a time from the newest and only as far as the page that holds it. Slack's rate limits slow that reading down but never end it as "no thread": a page that still fails fails the event, and the engine hands it again, so a card that has a thread never gets a second one at the top of the channel. The extension keeps no other state. When the first message is no longer among those 1,000 messages, the next run of the card opens a new thread, and a note that comes late opens none.
57
+ The first message about a card opens its thread, when a run of the card starts its second stage or has something a person must read: a question, an approval, a pull request, a hand-back, a decision or a failure. Once the card has a thread, each later run of the card, a run that another run started too, joins it from its first stage, so its progress shows at once. A run that ends after one stage with nothing to tell, such as a card that asks EDGAR for nothing, posts nothing in the channel. The message is the card's status and its id as a link to the card with its title, such as ":eyes: Ready for review · ENG-1 Search fails", with the status in bold; then one small line with the card's service, unless the title already names it, "On behalf of" the person who asked for the work, and "Assignee" with the card's holder; then what the card asks, in at most two lines, with its Markdown as Slack formatting, so a link such as `[label](<https://…>)` is one link, and cut only between words, so a link or a code span is never cut, with " …" at the end of a cut; then a link button to the card and to each pull request that the run opened. "On behalf of" is a Slack mention when the card came from a Slack message (the writer's user id) or when `people`, `operators` or an email finds the person's Slack user, and the plain name otherwise. The holder is shown only as a Slack mention, so EDGAR's own tracker user is never written. The message changes in place when a run of the card starts to work ("I'm on it"), when its pull request is ready ("Ready for review"), and when it ends, with the title of its end note; a run that did no work changes nothing. A card that came from Slack keeps the person's message as its first message, which EDGAR does not change. The metadata (`edgar_card`) holds the card's link, its id, its title, the newest 20 runs of the card, and what the message shows (`view`), so a change of one part keeps the others. A run finds the card's first message by the card's id, so a card that triage retitles keeps its one thread, and the message takes the new title in place. Only the card's newest run, the last that the metadata lists, or a run new to the thread, sets the link and the title, so a run that started before a retitle never brings the old title back. A first message that keeps no id is found by the card's link, up to the card's id when the tracker puts the title after it, such as `/issue/ENG-1/search-fails`. Each later run of the card adds its number to that metadata and replies in the same thread. Each message of a run finds the thread again by its run number, and a new run by the card's id or link, in the newest 1,000 messages of the channel or the DM, read 200 at a time from the newest and only as far as the page that holds it. Slack's rate limits slow that reading down but never end it as "no thread": a page that still fails fails the event, and the engine hands it again, so a card that has a thread never gets a second one at the top of the channel. The extension keeps no other state. When the first message is no longer among those 1,000 messages, the next run of the card opens a new thread, and a note that comes late opens none.
58
58
 
59
59
  An event that reaches the hook 15 minutes or more after it happened, as after a backlog of events or a restart, is late. A late `run_created`, `attempt_started` or `waiting_for_slot` posts nothing and calls Slack for nothing, since that progress is over. A late stage outcome or end note goes only in a thread that the card already has: a run long over never opens a new thread at the top of the channel, for example after a person deleted the card's first message. The log says so for each late end note that finds no thread.
60
60
 
@@ -92,7 +92,7 @@ An event whose `outcome` `endNote` cannot read still ends the progress message a
92
92
 
93
93
  ## The progress message
94
94
 
95
- Each card keeps one status message in its thread, with the metadata `edgar_plan`, and the hook changes it in place for every run of the card: a later run takes the same message over once the run that wrote it is over, so a thread never holds a second status message. A run that starts while another run of the card still works leaves that run's message alone. In a channel or a DM, the hook posts the message at the run's second `attempt_started` event, with the first stage in it, or earlier when a done stage asks a person a question; at the first when the card already has a thread there, which the hook finds by the card's id or link without posting; in the Slack thread of a card that came from Slack, at the first. A run that ends before that leaves no line in the thread, and, when it ends `done` with nothing to tell, no note either. A run that waits in a queue posts it earlier in the Slack thread of its card, at its `waiting_for_slot` event: the first line reads "Queued" with the still hourglass, and the next line says what the run waits on, such as "1 run for ENG-12 is going, which is my limit. I'll start when one ends." for a workflow's `concurrency`, "3 triage runs are going, which is my limit." when the run's input has no value at the key, so it counts with every other such run of its workflow, or "I'm already running 4 steps at once, which is my limit." for the project's `[concurrency]`. The first stage that starts turns the same message into the plan. The `run_created` event posts nothing; for a card from Slack, it sets the session status `processing` with the card's title. Its first line is the status and the card, in a `context` block, so that Slack shows its text and its emoji small; the plain text of the message keeps the same line. Then it has one line for each stage that started, in the order of the starts: the emoji of its state and its label. A stage is added at its `attempt_started` event, so a stage that the run skips or never reaches is never shown, and an outcome `skipped` removes its line. A stage of the built-in workflows has a label in `words.ts`; another stage reads as its name in words. A stage that waits reads "Waiting for CI", "Waiting for a review" or "Waiting for you"; another wait reads "Waiting:" and the label. More than three done steps fold into one line, "<n> steps done". A done stage whose output has the `state` and the `review_state` of a pull request says what people decided in place of its label, on a line of its own beside the folded steps: "The pull request is approved", "The pull request is approved and merged", "The pull request is merged", "A reviewer asked for changes" or "The pull request was closed with no merge". The last line links the run's page, when `console_url` is set, and each pull request that a stage answered with `url` and `number`. While the run is not over, the message has a Stop button (`edgar_stop`, its value the run's id): an operator's press cancels that run with `ctx.runs.stop`, takes the button off the message, and says in the thread who stopped it; a run that is over refuses, and the person who pressed is told why. In Slack the steps are a `plan` block, and the stage that runs also sets the moving status line of the thread with `assistant.threads.setStatus`: the stage's phrase from `status`, else the phrase of a long stage of the built-in workflows in `words.ts`, such as "is working out a plan…" for `propose`, "is writing the change…" for `implement`, "is running the checks…" for `checks` and "is reviewing the change…" for `review`, else "is on it:" and its label. Slack shows it after the app's name. Slack removes that line at the app's next message in the thread, or after 2 minutes.
95
+ Each card keeps one status message in its thread, with the metadata `edgar_plan`, and the hook changes it in place for every run of the card: a later run takes the same message over once the run that wrote it is over, so a thread never holds a second status message. A run that starts while another run of the card still works leaves that run's message alone. In a channel or a DM, the hook posts the message at the run's second `attempt_started` event, with the first stage in it, or earlier when a done stage asks a person a question; at the first when the card already has a thread there, which the hook finds by the card's id or link without posting; in the Slack thread of a card that came from Slack, at the first. A run that ends before that leaves no line in the thread, and, when it ends `done` with nothing to tell, no note either. A run that waits in a queue posts it earlier in the Slack thread of its card, at its `waiting_for_slot` event: the first line reads "Queued" with the still hourglass, and the next line says what the run waits on, such as "1 run for ENG-12 is going, which is my limit. I'll start when one ends." for a workflow's `concurrency`, "3 triage runs are going, which is my limit." when the run's input has no value at the key, so it counts with every other such run of its workflow, or "I'm already running 4 steps at once, which is my limit." for the project's `[concurrency]`. The first stage that starts turns the same message into the plan. The `run_created` event posts nothing; for a card from Slack, it sets the session status `processing` with the card's title. In the Slack thread of a card that came from Slack, its first line is the status and the card, in a `context` block, so that Slack shows its text and its emoji small; the plain text of the message keeps the same line. In the card's own thread, whose first message already says the status and the card, the message starts with its steps, and the status is the title of its `plan` block; a message with no step line, such as a run that ended before a step did, keeps the status alone. Then it has one line for each stage that started, in the order of the starts: the emoji of its state and its label. A stage is added at its `attempt_started` event, so a stage that the run skips or never reaches is never shown, and an outcome `skipped` removes its line. A stage of the built-in workflows has a label in `words.ts`; another stage reads as its name in words. A stage that waits reads "Waiting for CI", "Waiting for a review" or "Waiting for you"; another wait reads "Waiting:" and the label. More than three done steps fold into one line, "<n> steps done". A done stage whose output has the `state` and the `review_state` of a pull request says what people decided in place of its label, on a line of its own beside the folded steps: "The pull request is approved", "The pull request is approved and merged", "The pull request is merged", "A reviewer asked for changes" or "The pull request was closed with no merge". The last line links the run's page, when `console_url` is set, and each pull request that a stage answered with `url` and `number`. While the run is not over, the message has a Stop button (`edgar_stop`, its value the run's id): an operator's press cancels that run with `ctx.runs.stop`, takes the button off the message, and says in the thread who stopped it; a run that is over refuses, and the person who pressed is told why. In Slack the steps are a `plan` block, and the stage that runs also sets the moving status line of the thread with `assistant.threads.setStatus`: the stage's phrase from `status`, else the phrase of a long stage of the built-in workflows in `words.ts`, such as "is working out a plan…" for `propose`, "is writing the change…" for `implement`, "is running the checks…" for `checks` and "is reviewing the change…" for `review`, else "is on it:" and its label. Slack shows it after the app's name. Slack removes that line at the app's next message in the thread, or after 2 minutes.
96
96
 
97
97
  The hook's process ends after some minutes with no work, so the hook keeps nothing that it cannot read again: the progress message holds its own state in its metadata, and the card and the trigger of a run that the process did not see start are read from the run's first event with `runs.read`, which the hook holds the capability `runs:read` for. A run that does not read is one line in the log, and its messages name no card.
98
98
 
@@ -102,7 +102,7 @@ A note that asks for a decision also goes to the DM of the card's assignee, in t
102
102
 
103
103
  The note of a run that opened a pull request also goes to `channel`, when it is set: as a reply in the card's thread there, and nothing at the top of the channel. The extension opens the card's thread in `channel` when the card has none there. Each other note stays in its thread. The note lists each pull request that the run opened on a line of its own, shows the merge risk in a block of its own when it is above low, and has an "Open pull request" button for each pull request beside the card's button; with several pull requests, each button names its pull request, such as "Open pull request api#3".
104
104
 
105
- A question that a done stage leaves open, and a decision or hand-back note, tag the people who can act on it at its start, each once and at most five: the people of the run's `who_can_act` (the stage output's, or the newest one at the run's end), then the requester, then the assignee when Slack knows them. The engine adds to each person it matches in `[people]` (by an id in `ids`, the `email` or the name) their Slack id and email, so the hook tags `ids.slack`, else the user that `users.lookupByEmail` finds; a person with no match is written as text by name or login, never by email, with one log line. A decision note whose question is already in the card's thread (`edgar_question` of the run) posts there one short line instead, with the service, the run, its run time, tokens and cost; a DM still gets the whole note.
105
+ A question that a done stage leaves open, and a decision or hand-back note, tag the people who can act on it at its start, each once and at most five: the people of the run's `who_can_act` (the stage output's, or the newest one at the run's end), then the requester, then the assignee when Slack knows them. The engine adds to each person it matches in `[people]` (by an id in `ids`, the `email` or the name) their Slack id and email, so the hook tags `ids.slack`, else the user that `users.lookupByEmail` finds; a person with no match is written as text by name or login, never by email, with one log line. A decision note whose question is already in the card's thread (`edgar_question` of the run) posts no message there: the question gets one small line at its end, with the run time, the tokens and the cost, and its metadata gets `ended`, so the line is added one time. The run's id is never shown. A DM still gets the whole note.
106
106
 
107
107
  An approval question greets the assignee as the end note does. The hook reads the assignee from the `approval_requested` event itself. The question says what EDGAR wants to do in plain words ("open pull request in github"), why it asks (the tool's approval policy), what each button does, and has the link buttons "Open the card" and "See the run" beside Approve and Deny. The tool's own name and the run are in small text.
108
108
 
@@ -13,9 +13,9 @@ export interface Layout {
13
13
  export declare function stageLabel(stage: string): string;
14
14
  /** The moving line under the thread while `stage` works: its phrase of `[extensions.slack.status]`, else its entry of `MOVING`, else "is on it:" and its label. */
15
15
  export declare function stageStatus(stage: string, settings: Config): string;
16
- /** The progress of a run as one message that changes in place. The first line is the status and the card as a link; once the run is over, the status is the title of its end note's kind, so a card handed to a person never reads as done. 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, the links in small text, and while the run is not over, a Stop button. */
16
+ /** The progress of a run as one message that changes in place. A plan that holds its card's line, as in a thread that a person's message opened, starts with the status and the card as a link; in the card's own thread, whose first message says both, it starts with its steps. Once the run is over, the status is the title of its end note's kind, so a card handed to a person never reads as done. 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 status line, when there is one, in small text, so that its emoji is small too, Slack's plan block with one task card per line, the links in small text, and while the run is not over, a Stop button. */
17
17
  export declare function planLayout(plan: Plan, settings: Config): Layout;
18
- /** Markdown that a model wrote, as Slack's mrkdwn, made plain first so it notifies nobody and hides no link: a heading and `**bold**` as bold, `__text__` as italic, `[label](https://…)` as a link, and a `-` or `*` item as a bullet. A code block keeps its lines as they are. */
18
+ /** Markdown that a model wrote, as Slack's mrkdwn, made plain first so it notifies nobody and hides no link: a heading and `**bold**` as bold, `__text__` as italic, `[label](https://…)` as a link, also with the address or the label in angle brackets, and a `-` or `*` item as a bullet. A code block keeps its lines as they are. */
19
19
  export declare function mrkdwn(markdown: string): string;
20
20
  /** `text` in parts of at most `limit` characters, split between paragraphs, and inside a longer paragraph between lines, else between two characters; never inside an entity. */
21
21
  export declare function parts(text: string, limit?: number): readonly string[];
@@ -48,19 +48,19 @@ export declare function detailsOf(input: unknown): {
48
48
  } | undefined;
49
49
  /** 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. */
50
50
  export declare function askLayout(asked: Asked): Layout;
51
- /** A question that a done stage left open: the people it tags, already written for Slack, on which card, the question made plain with its lines kept, and how to answer it. */
51
+ /** A question that a done stage left open: the people it tags, already written for Slack, on which card, the question made plain with its lines kept, and how to answer it, which names the number of another option only when the question lists numbered options. */
52
52
  export declare function questionLayout(asked: {
53
53
  readonly run: string;
54
54
  readonly card: NoteCard | undefined;
55
55
  readonly users: readonly string[];
56
56
  readonly question: string;
57
57
  }): Layout;
58
- /** The end of a run whose question is already in the thread above: one small line that points to it, with the card's service and what the run used. */
59
- export declare function askedAboveLayout(run: string, note: EndNote): Layout;
58
+ /** What a run used, as one small line that goes under its question when the run ends on it: the run time, the tokens and the cost; no block when the run names none. */
59
+ export declare function usedLayout({ facts }: EndNote): Layout;
60
60
  /** The end note of a run: the status and the card on the first line; what happened, to the person it is for (for a decision or a hand-back, to the people of `tagged`, already written for Slack, when it has any), with who approved the pull request and its merge commit when the note is about that; the options of a decision as a numbered list; the one thing the person does next, which for a step that the engine stopped trying is what to check before the replay; a Try again button on a failed or a stopped run, which starts the run again, and a link button to the card, to each pull request and to the run's page; one small line with on whose behalf EDGAR works (`by`, the line of `behalfLine`), the run time from the start of this run to its end with each wait in it, the tokens and the cost; for a stopped run, who stopped it (`stopper`, already written for Slack) in the sentence and as "Stopped by" in that small line; and the failure as the engine wrote it in small text. A failure with no reason says so. The run's id is never shown: the run's page is a button. With no `note`, the run's outcome did not read, and the note says only that. */
61
61
  export declare function noteLayout(run: string, note: EndNote | undefined, user: string | undefined, by?: string, stopper?: string, tagged?: readonly string[]): Layout;
62
62
  /** On whose behalf EDGAR works and, when the run ran on a person's own key or subscription, on whose, in one phrase when it is the same person; none when the view names neither. */
63
63
  export declare function behalfLine({ by, paid, paid_with }: RootView): string | undefined;
64
- /** The first message of a card's thread, which changes in place with the status of the card's newest run: the emoji and the status in words with the card as a link and its title; one small line with the card's service, who asked for the work and who holds the card; what the card asks, in at most two lines; and a link button to the card and to each pull request to open. A card with no status yet shows only the card. */
64
+ /** The first message of a card's thread, which changes in place with the status of the card's newest run: the emoji and the status in words with the card as a link and its title; one small line with the card's service, unless the title already names it, who asked for the work and who holds the card; what the card asks, in at most two lines, with its Markdown as mrkdwn and cut only between words; and a link button to the card and to each pull request to open. A card with no status yet shows only the card. */
65
65
  export declare function rootLayout(card: NoteCard, view: RootView): Layout;
66
66
  export {};
@@ -110,7 +110,7 @@ function stopOf(run) {
110
110
  const text = { type: "plain_text", text: SAYS.stop };
111
111
  return { type: "button", action_id: "edgar_stop", text, value: run, style: "danger" };
112
112
  }
113
- /** The progress of a run as one message that changes in place. The first line is the status and the card as a link; once the run is over, the status is the title of its end note's kind, so a card handed to a person never reads as done. 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, the links in small text, and while the run is not over, a Stop button. */
113
+ /** The progress of a run as one message that changes in place. A plan that holds its card's line, as in a thread that a person's message opened, starts with the status and the card as a link; in the card's own thread, whose first message says both, it starts with its steps. Once the run is over, the status is the title of its end note's kind, so a card handed to a person never reads as done. 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 status line, when there is one, in small text, so that its emoji is small too, Slack's plan block with one task card per line, the links in small text, and while the run is not over, a Stop button. */
114
114
  export function planLayout(plan, settings) {
115
115
  const over = plan.ended !== undefined;
116
116
  const queued = over || plan.tasks.length > 0 ? undefined : plan.queued;
@@ -140,8 +140,6 @@ export function planLayout(plan, settings) {
140
140
  url,
141
141
  })),
142
142
  ];
143
- const head = headline(what ?? (state === "queued" ? "waits" : state), title, plan.card ?? `run ${plan.run}`);
144
- const links = linksOf(targets);
145
143
  const lines = queued !== undefined
146
144
  ? [
147
145
  PLAN.queued(queued.key, queued.value === undefined ? undefined : escape(queued.value), queued.limit, queued.workflow === undefined ? undefined : escape(queued.workflow)),
@@ -149,6 +147,13 @@ export function planLayout(plan, settings) {
149
147
  : rows.length === 0 && !over
150
148
  ? [PLAN.started]
151
149
  : rows.map((row) => `${EMOJI[row.status]} ${escape(row.label)}`);
150
+ const status = what ?? (state === "queued" ? "waits" : state);
151
+ const head = plan.card !== undefined
152
+ ? headline(status, title, plan.card)
153
+ : lines.length === 0
154
+ ? `${EMOJI[status]} *${title}*`
155
+ : "";
156
+ const links = linksOf(targets);
152
157
  const tasks = rows.map((row) => ({
153
158
  task_id: row.id.slice(0, 255),
154
159
  title: row.label,
@@ -157,14 +162,14 @@ export function planLayout(plan, settings) {
157
162
  return {
158
163
  text: [head, ...lines, links].filter((line) => line !== "").join("\n"),
159
164
  blocks: [
160
- context(head),
165
+ ...(head === "" ? [] : [context(head)]),
161
166
  ...(tasks.length > 0 ? [{ type: "plan", title, tasks }] : lines.map(section)),
162
167
  ...(links === "" ? [] : [context(links)]),
163
168
  ...(over ? [] : [{ type: "actions", elements: [stopOf(plan.run)] }]),
164
169
  ],
165
170
  };
166
171
  }
167
- /** Markdown that a model wrote, as Slack's mrkdwn, made plain first so it notifies nobody and hides no link: a heading and `**bold**` as bold, `__text__` as italic, `[label](https://…)` as a link, and a `-` or `*` item as a bullet. A code block keeps its lines as they are. */
172
+ /** Markdown that a model wrote, as Slack's mrkdwn, made plain first so it notifies nobody and hides no link: a heading and `**bold**` as bold, `__text__` as italic, `[label](https://…)` as a link, also with the address or the label in angle brackets, and a `-` or `*` item as a bullet. A code block keeps its lines as they are. */
168
173
  export function mrkdwn(markdown) {
169
174
  return markdown
170
175
  .split(/(```[\s\S]*?```)/)
@@ -175,7 +180,7 @@ export function mrkdwn(markdown) {
175
180
  .replaceAll(/\*\*(.+?)\*\*/g, "*$1*")
176
181
  .replaceAll(/__(.+?)__/g, "_$1_")
177
182
  .replaceAll(/^(\s*)[-*]\s+/gm, "$1• ")
178
- .replaceAll(/\[([^\]\n]+)\]\((https?:\/\/[^)\s|]+)\)/g, (_, label, url) => `<${url}|${label}>`))
183
+ .replaceAll(/\[([^\]\n]+)\]\((?:&lt;)?(https?:\/\/[^)\s|]+?)(?:&gt;)?\)/g, (_, label, url) => `<${url}|${label.replace(/^&lt;(.+)&gt;$/, "$1")}>`))
179
184
  .join("");
180
185
  }
181
186
  /** `text` in parts of at most `limit` characters, split between paragraphs, and inside a longer paragraph between lines, else between two characters; never inside an entity. */
@@ -347,14 +352,14 @@ export function askLayout(asked) {
347
352
  }
348
353
  /** The most characters of a question that a model wrote, so the question and its words around it fit in one section. */
349
354
  const QUESTION_CHARS = 2400;
350
- /** A question that a done stage left open: the people it tags, already written for Slack, on which card, the question made plain with its lines kept, and how to answer it. */
355
+ /** A question that a done stage left open: the people it tags, already written for Slack, on which card, the question made plain with its lines kept, and how to answer it, which names the number of another option only when the question lists numbered options. */
351
356
  export function questionLayout(asked) {
352
357
  const { run, card } = asked;
353
358
  const name = card === undefined ? `run ${run}` : escape(card.id ?? "this card");
354
359
  const head = headline("waiting", SAYS.questionTitle, card === undefined ? name : cardLine(card, style));
355
360
  const said = greeted(tagsOf(asked.users), SAYS.question(name));
356
361
  const question = cutEscaped(escape(asked.question.trim()), QUESTION_CHARS).text;
357
- const next = `*${SAYS.next}* ${SAYS.questionNext}`;
362
+ const next = `*${SAYS.next}* ${SAYS.questionNext(/^\s*\d+[.)]\s+\S/m.test(question))}`;
358
363
  return {
359
364
  text: [head, said, question, next].join("\n"),
360
365
  blocks: [section(head), section([said, question, next].join("\n"))],
@@ -366,18 +371,14 @@ const names = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
366
371
  function tagsOf(users) {
367
372
  return users.length === 0 ? undefined : names.format(users);
368
373
  }
369
- /** The end of a run whose question is already in the thread above: one small line that points to it, with the card's service and what the run used. */
370
- export function askedAboveLayout(run, note) {
371
- const { card, facts } = note;
374
+ /** What a run used, as one small line that goes under its question when the run ends on it: the run time, the tokens and the cost; no block when the run names none. */
375
+ export function usedLayout({ facts }) {
372
376
  const line = [
373
- `${EMOJI.decision} ${SAYS.askedAbove}`,
374
- ...(card?.service === undefined ? [] : [escape(card.service)]),
375
- `Run ${run}`,
376
377
  ...(facts.took === undefined ? [] : [facts.took]),
377
378
  ...(facts.tokens === undefined ? [] : [`${facts.tokens} tokens`]),
378
379
  ...(facts.cost === undefined ? [] : [facts.cost]),
379
380
  ].join(" · ");
380
- return { text: line, blocks: [context(line)] };
381
+ return { text: line, blocks: line === "" ? [] : [context(line)] };
381
382
  }
382
383
  /** The kinds of end note that say the summary of the run's proposal after their first sentence: what the run did, what it asks, why it handed the card back, what it changed, or what it waits on. A note on what people decided on the pull request says none: the proposal was written before the pull request. */
383
384
  const SUMMED = new Set([
@@ -508,7 +509,36 @@ export function behalfLine({ by, paid, paid_with }) {
508
509
  function isStatus(word) {
509
510
  return Object.hasOwn(STATUS, word);
510
511
  }
511
- /** The first message of a card's thread, which changes in place with the status of the card's newest run: the emoji and the status in words with the card as a link and its title; one small line with the card's service, who asked for the work and who holds the card; what the card asks, in at most two lines; and a link button to the card and to each pull request to open. A card with no status yet shows only the card. */
512
+ /** A word of mrkdwn: a link, a code span and an entity stay whole in it, so a cut between words never breaks one. */
513
+ const WORDS = /(?:<[^>]*>|`[^`\n]*`|\S)+|\s+/g;
514
+ /** Whether `word` opens a bracket, an angle bracket or a code span that it does not close. */
515
+ function unclosed(word) {
516
+ const count = (mark) => word.split(mark).length - 1;
517
+ return (count("[") > count("]") ||
518
+ count("(") > count(")") ||
519
+ count("&lt;") > count("&gt;") ||
520
+ count("`") % 2 === 1);
521
+ }
522
+ /** `markdown` as mrkdwn within `limit` characters, cut only between words, and with " …" when cut. A text that ends in "…" was cut already: its last word is only a part, so it goes, with each word before it that opens what it never closes. */
523
+ function wholeWords(markdown, limit) {
524
+ const before = markdown.trim().endsWith("…");
525
+ const words = mrkdwn(before ? markdown.trim().slice(0, -1) : markdown.trim()).match(WORDS) ?? [];
526
+ const kept = [];
527
+ let length = 0;
528
+ for (const word of words) {
529
+ if (length + word.length > limit - 2)
530
+ break;
531
+ kept.push(word);
532
+ length += word.length;
533
+ }
534
+ const cut = before || kept.length < words.length;
535
+ if (before && kept.length === words.length && !/^\s/.test(kept.at(-1) ?? " "))
536
+ kept.pop();
537
+ while (kept.length > 0 && (/^\s/.test(kept.at(-1) ?? "") || (cut && unclosed(kept.at(-1) ?? ""))))
538
+ kept.pop();
539
+ return cut ? `${kept.join("")} …`.trimStart() : kept.join("");
540
+ }
541
+ /** The first message of a card's thread, which changes in place with the status of the card's newest run: the emoji and the status in words with the card as a link and its title; one small line with the card's service, unless the title already names it, who asked for the work and who holds the card; what the card asks, in at most two lines, with its Markdown as mrkdwn and cut only between words; and a link button to the card and to each pull request to open. A card with no status yet shows only the card. */
512
542
  export function rootLayout(card, view) {
513
543
  const status = view.status !== undefined && isStatus(view.status) ? view.status : undefined;
514
544
  const title = card.id === undefined
@@ -516,12 +546,13 @@ export function rootLayout(card, view) {
516
546
  : `${link(card.url, card.id)} ${escape(card.title)}`;
517
547
  const head = status === undefined ? title : headline(status, STATUS[status], title);
518
548
  const behalf = behalfLine(view);
549
+ const named = card.service !== undefined && card.title.toLowerCase().includes(card.service.toLowerCase());
519
550
  const about = [
520
- ...(card.service === undefined ? [] : [escape(card.service)]),
551
+ ...(card.service === undefined || named ? [] : [escape(card.service)]),
521
552
  ...(behalf === undefined ? [] : [behalf]),
522
553
  ...(view.holder === undefined ? [] : [SAYS.holder(view.holder)]),
523
554
  ].join(" · ");
524
- const ask = view.ask === undefined ? "" : cutEscaped(escape(view.ask), 600).text;
555
+ const ask = view.ask === undefined ? "" : wholeWords(view.ask, 600);
525
556
  const targets = [
526
557
  { id: "card", label: SAYS.card, url: card.url },
527
558
  ...(view.pulls ?? []).slice(0, 3).map(({ url, label }, at, all) => ({
@@ -14,6 +14,8 @@ export declare function mark(kind: "edgar_post" | "edgar_ask" | "edgar_answered"
14
14
  export declare function post(ctx: SlackCtx, channel: string, thread: string | undefined, text: string, extra?: Readonly<Record<string, unknown>>): Promise<Result<z.infer<typeof posted>, Failure>>;
15
15
  /** Changes the message at `ts` to `text` with `extra` fields (blocks, metadata). Blocks that Slack refuses are left out, as `written` says. */
16
16
  export declare function update(ctx: SlackCtx, channel: string, ts: string, text: string, extra?: Readonly<Record<string, unknown>>): Promise<Result<z.infer<typeof posted>, Failure>>;
17
+ /** Deletes the message at `ts`; a message that is already gone is no failure. */
18
+ export declare function remove(ctx: SlackCtx, channel: string, ts: string): Promise<Result<undefined, Failure>>;
17
19
  /** The messages of the thread, or of the channel's newest `HISTORY_PAGE` messages, each with its metadata. */
18
20
  export declare function listed(ctx: SlackCtx, channel: string, thread: string | undefined): Promise<Result<readonly Message[], Failure>>;
19
21
  /** The newest of `all`, by its timestamp, whose metadata is `kind` and passes `match`. */
@@ -28,6 +28,11 @@ export async function post(ctx, channel, thread, text, extra = {}) {
28
28
  export async function update(ctx, channel, ts, text, extra = {}) {
29
29
  return await written(ctx, "chat.update", { channel, ts, text, ...extra });
30
30
  }
31
+ /** Deletes the message at `ts`; a message that is already gone is no failure. */
32
+ export async function remove(ctx, channel, ts) {
33
+ const deleted = await slack(ctx, "chat.delete", { channel, ts }, answer);
34
+ return deleted.ok || deleted.error.kind === "not_found" ? ok(undefined) : deleted;
35
+ }
31
36
  /** The most messages of a channel's history that `findInChannel` reads, newest first, and how many each page of a channel's history holds; Slack advises at most 200 a page. */
32
37
  const HISTORY_MESSAGES = 1000;
33
38
  const HISTORY_PAGE = 200;
@@ -129,7 +129,7 @@ export async function joinedRoot(ctx, channel, card, run, view = {}) {
129
129
  return found.ok ? ok(undefined) : found;
130
130
  return await keepRoot(ctx, channel, card, run, view, found.value);
131
131
  }
132
- /** The card's first message `found` in `channel` written as `rootOf` says, or posted when there is none. */
132
+ /** The card's first message `found` in `channel` written as `rootOf` says, or posted when there is none. Only the card's newest run, the last that the message lists, or a run new to it, sets the card's link and title, so a run that started before a retitle never brings the old title back. */
133
133
  async function keepRoot(ctx, channel, card, run, view, found) {
134
134
  const kept = cardRoot.safeParse(found?.metadata?.event_payload);
135
135
  const runs = kept.success ? kept.data.runs : [];
@@ -137,18 +137,22 @@ async function keepRoot(ctx, channel, card, run, view, found) {
137
137
  const shown = { ...before, ...view };
138
138
  const ts = found?.ts;
139
139
  const same = JSON.stringify(shown) === JSON.stringify(before);
140
- const current = kept.data?.card === card.url && (kept.data.title ?? card.title) === card.title;
140
+ const newest = !kept.success || !runs.includes(run) || runs.at(-1) === run;
141
+ const named = newest
142
+ ? card
143
+ : { ...card, url: kept.data.card, title: kept.data.title ?? card.title };
144
+ const current = kept.data?.card === named.url && (kept.data.title ?? named.title) === named.title;
141
145
  if (ts !== undefined && runs.includes(run) && same && current)
142
146
  return ok(ts);
143
147
  const listed = runs.includes(run) ? runs : [...runs, run].slice(-MAX_RUNS);
144
148
  const metadata = mark("edgar_card", {
145
- card: card.url,
149
+ card: named.url,
146
150
  ...(card.id === undefined ? {} : { id: card.id }),
147
- title: card.title,
151
+ title: named.title,
148
152
  runs: listed,
149
153
  ...(Object.keys(shown).length === 0 ? {} : { view: shown }),
150
154
  });
151
- const { text, blocks } = rootLayout(card, shown);
155
+ const { text, blocks } = rootLayout(named, shown);
152
156
  const written = ts === undefined
153
157
  ? await post(ctx, channel, undefined, text, { metadata, blocks })
154
158
  : await update(ctx, channel, ts, text, { metadata, blocks });
@@ -1,7 +1,7 @@
1
1
  import { cardLine, defineEventHook, done, endNote, noteCard, notePull, ok, runCard, } from "@kana-ai/edgar-sdk";
2
2
  import { apiAccess } from "#api/client";
3
- import { answerLayout, behalfLine, askLayout, askedAboveLayout, noteLayout, planLayout, questionLayout, stageStatus, style, } from "#outbound/layout";
4
- import { findMarked, listed, mark, newestMarked, post, reacted, status, threadStatus, update, waitingRelays, } from "#outbound/messages";
3
+ import { answerLayout, behalfLine, askLayout, noteLayout, planLayout, questionLayout, stageStatus, style, usedLayout, } from "#outbound/layout";
4
+ import { findMarked, listed, mark, newestMarked, post, reacted, remove, status, threadStatus, update, waitingRelays, } from "#outbound/messages";
5
5
  import { cardThread, directOf, homeOf, joinedRoot, mentioned, oneMore, rootOf, stopperOf, taggedOf, threadOf, } from "#outbound/places";
6
6
  import { cutEscaped, escape } from "#outbound/tools";
7
7
  import { ACTED, ANSWER, ANSWER_FLOWS, REPLY, REVIEW_WAIT, SAYS, reviewedLabel, } from "#outbound/words";
@@ -77,7 +77,7 @@ async function beganOf(ctx, event) {
77
77
  }
78
78
  /** The plan of each run whose card's thread does not list it yet: the thread and its status message open at the run's second stage, or at the first one that asks a person, so a run that ends after one stage with nothing to tell leaves no line. A cache and no more: after a restart, the plan starts at the run's next stage. */
79
79
  const held = new Map();
80
- /** Writes the card's one status message in its thread after `change`, and answers the plan. The message is the newest plan of the thread, of whichever run wrote it: a run changes it while the message is its own, and with `first` a run takes it over once the run that wrote it is over, so each run of a card updates the same message in place and the thread never gets a second one; a run that starts while another run of the card still works shows in it when that run ends. With `first`, a thread with no status message gets one, whose first line links the card that the run began with; without it, a run whose message is not its own changes nothing and the answer is `undefined`, so the end of a run that showed no plan posts no empty one. */
80
+ /** Writes the card's one status message in its thread after `change`, and answers the plan. The message is the newest plan of the thread, of whichever run wrote it: a run changes it while the message is its own, and with `first` a run takes it over once the run that wrote it is over, so each run of a card updates the same message in place and the thread never gets a second one; a run that starts while another run of the card still works shows in it when that run ends. With `first`, a thread with no status message gets one, whose first line links the card that the run began with in a thread that a person's message opened, as the card's own thread has a first message that links it; without it, a run whose message is not its own changes nothing and the answer is `undefined`, so the end of a run that showed no plan posts no empty one. */
81
81
  async function replan(ctx, event, place, settings, change, first) {
82
82
  const all = await listed(ctx, place.channel, place.thread);
83
83
  return all.ok ? await replanIn(ctx, event, place, settings, change, all.value, first) : all;
@@ -93,7 +93,9 @@ async function replanIn(ctx, event, place, settings, change, all, first) {
93
93
  if (!own && (first === undefined || !free))
94
94
  return ok(undefined);
95
95
  const kept = planState.safeParse(own ? payload : undefined);
96
- const card = first?.card === undefined ? {} : { card: cardLine(first.card, style) };
96
+ const card = first?.card === undefined || place.origin === undefined
97
+ ? {}
98
+ : { card: cardLine(first.card, style) };
97
99
  const fresh = held.get(event.run) ?? { run: event.run, tasks: [], pulls: [], ...card };
98
100
  held.delete(event.run);
99
101
  const plan = change(kept.success ? kept.data : fresh);
@@ -219,20 +221,29 @@ const asks = new Set([
219
221
  function markOf(note) {
220
222
  return note?.what === "opened" ? "edgar_ready" : "edgar_end";
221
223
  }
222
- /** Posts the note at `place` once: a note with the same mark for the run is not posted again. A note in a thread stays in the thread: nothing is sent to the top of the conversation. With `above`, a thread that already holds a question of the run gets `above` in place of the note, so the question is not asked twice. */
223
- async function noteAt(ctx, place, run, layout, kind, above) {
224
+ /** Posts the note at `place` once: a note with the same mark for the run is not posted again. A note in a thread stays in the thread: nothing is sent to the top of the conversation. With `used`, a thread that already holds a question of the run gets `used` under that question, one time, in place of the note, so the question is not asked twice and the run's end is no message of its own. */
225
+ async function noteAt(ctx, place, run, layout, kind, used) {
224
226
  const { channel, thread } = place;
225
227
  const all = await listed(ctx, channel, thread);
226
228
  if (!all.ok)
227
229
  return all;
228
230
  if (newestMarked(all.value, kind, (p) => p["run"] === run) !== undefined)
229
231
  return ok(undefined);
230
- const asked = above !== undefined &&
231
- thread !== undefined &&
232
- newestMarked(all.value, "edgar_question", (p) => p["run"] === run) !== undefined;
233
- const note = asked ? above : layout;
234
- const sent = await post(ctx, channel, thread, note.text, {
235
- blocks: note.blocks,
232
+ const asked = used === undefined || thread === undefined
233
+ ? undefined
234
+ : newestMarked(all.value, "edgar_question", (p) => p["run"] === run);
235
+ if (asked !== undefined && used !== undefined) {
236
+ const payload = asked.metadata?.event_payload ?? {};
237
+ if (payload["ended"] === true || used.text === "")
238
+ return ok(undefined);
239
+ const blocks = asked.blocks === undefined ? [] : [...asked.blocks, ...used.blocks];
240
+ const metadata = mark("edgar_question", { ...payload, ended: true });
241
+ const text = `${asked.text ?? ""}\n${used.text}`;
242
+ const changed = await update(ctx, channel, asked.ts, text, { blocks, metadata });
243
+ return changed.ok ? ok(undefined) : changed;
244
+ }
245
+ const sent = await post(ctx, channel, thread, layout.text, {
246
+ blocks: layout.blocks,
236
247
  metadata: mark(kind, { run }),
237
248
  });
238
249
  if (!sent.ok)
@@ -345,11 +356,11 @@ async function tell(ctx, event, settings, home, found, note, view, tagged = [])
345
356
  const stopper = by === undefined ? undefined : await stopperOf(ctx, event.run, by, settings);
346
357
  const layout = noteLayout(event.run, note, user, behalfLine(view), stopper, tagged);
347
358
  const asked = endActors.safeParse(event.payload).data?.end.question?.trim();
348
- const above = note?.what === "decision" && asked !== undefined && note.facts.summary === asked
349
- ? askedAboveLayout(event.run, note)
359
+ const used = note?.what === "decision" && asked !== undefined && note.facts.summary === asked
360
+ ? usedLayout(note)
350
361
  : undefined;
351
362
  for (const place of places) {
352
- const sent = await noteAt(ctx, place, event.run, layout, markOf(note), above);
363
+ const sent = await noteAt(ctx, place, event.run, layout, markOf(note), used);
353
364
  if (!sent.ok)
354
365
  return sent;
355
366
  }
@@ -573,7 +584,18 @@ async function relayedEnd(ctx, event, first, at, word) {
573
584
  await threadStatus(ctx, at.channel, at.thread, "");
574
585
  return ok(failed);
575
586
  }
576
- /** The end of a run: the plan marked over when the run showed one, the session status of a Slack thread, and the end note of `noteLayout` at each place of `tell`. A run that already said that its pull request is ready for people, when its review wait started, does not say it again. A run with no card that ends done sends no note, except the first run of a schedule that works again; a done run that showed no plan sends none either, except a note that asks for a decision, is about a pull request or says what the run waits on. A done run with no summary sends none: the plan's first line already says that it is done, and a note with nothing to tell is noise. A decision that a step of the run, or another run, already asked in the card's thread while the run worked is not asked again. A quiet run that ends done, and a run that a stage of another run started whatever its end except a decision, marks its own plan over and removes the moving line under the card's thread, but sends no note, sets no session status and keeps no promise, since the top run of the chain says the end; one that a person's words in Slack started ends with `relayedEnd` alone. A note whose run is in no thread goes in the thread of its card. A failed run of a schedule whose run just before it failed the same way sends nothing. An event whose outcome `endNote` cannot read still ends the plan and the session, and its note says only that the run is over. A run that a person stopped and that showed no status message of its own ends with no note: the person knows, and a stop of many such runs at once must not fill the channel. A late note goes only in a thread that the card already has. */
587
+ /** Whether the run of `run` did no work: none of its stages ended other than skipped, as when no stage applies to the card. A run that does not read did work, with one log line, so its end still shows. */
588
+ async function idle(ctx, run) {
589
+ const read = await ctx.runs.read(run);
590
+ const events = read.ok ? runRead.safeParse(read.value).data?.events : undefined;
591
+ if (events === undefined) {
592
+ ctx.log(`run ${run}: the run did not read, so its end shows as the end of a run that worked`);
593
+ return false;
594
+ }
595
+ return events.every(({ kind, payload }) => kind !== "attempt_outcome" ||
596
+ outcomeRecord.safeParse(payload).data?.outcome.outcome === "skipped");
597
+ }
598
+ /** The end of a run: a done run that did no work, as `idle` says, deletes its own status message from the card's thread and says nothing more, so the card's first message keeps the status of the run that worked; else the plan marked over when the run showed one, the session status of a Slack thread, and the end note of `noteLayout` at each place of `tell`. A run that already said that its pull request is ready for people, when its review wait started, does not say it again. A run with no card that ends done sends no note, except the first run of a schedule that works again; a done run that showed no plan sends none either, except a note that asks for a decision, is about a pull request or says what the run waits on. A done run with no summary sends none: the plan's first line already says that it is done, and a note with nothing to tell is noise. A decision that a step of the run, or another run, already asked in the card's thread while the run worked is not asked again. A quiet run that ends done, and a run that a stage of another run started whatever its end except a decision, marks its own plan over and removes the moving line under the card's thread, but sends no note, sets no session status and keeps no promise, since the top run of the chain says the end; one that a person's words in Slack started ends with `relayedEnd` alone. A note whose run is in no thread goes in the thread of its card. A failed run of a schedule whose run just before it failed the same way sends nothing. An event whose outcome `endNote` cannot read still ends the plan and the session, and its note says only that the run is over. A run that a person stopped and that showed no status message of its own ends with no note: the person knows, and a stop of many such runs at once must not fill the channel. A late note goes only in a thread that the card already has. */
577
599
  async function ended(ctx, event, settings, first) {
578
600
  const note = endNote(event, style, settings.console_url);
579
601
  if (note === undefined)
@@ -606,6 +628,10 @@ async function ended(ctx, event, settings, first) {
606
628
  const all = await listed(ctx, at.channel, found);
607
629
  if (!all.ok)
608
630
  return all;
631
+ if (word === "done" && (await idle(ctx, event.run))) {
632
+ const own = newestMarked(all.value, "edgar_plan", (p) => p["run"] === event.run);
633
+ return own === undefined ? ok(undefined) : await remove(ctx, at.channel, own.ts);
634
+ }
609
635
  const over = (plan) => ({ ...plan, ended: note?.what ?? word });
610
636
  const changed = await replanIn(ctx, event, at, settings, over, all.value);
611
637
  if (!changed.ok)
@@ -687,7 +713,7 @@ const steps = {
687
713
  return ok(undefined);
688
714
  const word = record.data.outcome.outcome;
689
715
  const at = { ...place, thread };
690
- const changed = await replan(ctx, event, at, settings, (p) => afterOutcome(p, stage, event.payload, word), first);
716
+ const changed = await replan(ctx, event, at, settings, (p) => afterOutcome(p, stage, event.payload, word), word === "skipped" ? undefined : first);
691
717
  if (!changed.ok)
692
718
  return changed;
693
719
  const asked = await question(ctx, event, stage, at, settings, first);
@@ -748,6 +774,13 @@ async function take(event, ctx, settings) {
748
774
  : await threadOf(ctx, event, home.value);
749
775
  if (!thread.ok)
750
776
  return thread;
777
+ const word = outcomeRecord.safeParse(event.payload).data?.outcome.outcome;
778
+ if (thread.value === undefined && event.kind === "attempt_outcome" && word === "skipped") {
779
+ const kept = held.get(event.run);
780
+ if (kept !== undefined && event.stage !== null)
781
+ held.set(event.run, withoutTask(kept, event.stage));
782
+ return ok(undefined);
783
+ }
751
784
  const opened = thread.value === undefined &&
752
785
  first.card !== undefined &&
753
786
  event.kind !== "run_created" &&
@@ -761,12 +794,7 @@ async function take(event, ctx, settings) {
761
794
  }
762
795
  /** The card's thread for a step of a run that its thread does not list yet: the card's thread when the card already has one, which `joinedRoot` gives the run, so the run shows from its first stage; else none while `held` keeps the run's plan, and then the thread that `rootOf` opens and gives the run. With no thread yet, the plan is held until the run starts its second stage or a done stage asks a person a question, so a run that ends after one stage with nothing to tell posts no new message at the top of the channel. */
763
796
  async function opening(ctx, event, channel, card, view) {
764
- const base = held.get(event.run) ?? {
765
- run: event.run,
766
- tasks: [],
767
- pulls: [],
768
- card: cardLine(card, style),
769
- };
797
+ const base = held.get(event.run) ?? { run: event.run, tasks: [], pulls: [] };
770
798
  const { stage } = event;
771
799
  const word = outcomeRecord.safeParse(event.payload).data?.outcome.outcome;
772
800
  const wait = waitingForSlot.safeParse(event.payload).data;
@@ -127,11 +127,10 @@ export declare const SAYS: {
127
127
  readonly deny: "Deny";
128
128
  readonly questionTitle: "A question for you";
129
129
  readonly question: (name: string) => string;
130
- readonly questionNext: "Reply in this thread with your answer, or with the number of another option, and I'll change my work to match.";
130
+ readonly questionNext: (options: boolean) => "Reply in this thread with your answer, and I'll carry on from there." | "Reply in this thread with your answer, or with the number of another option, and I'll change my work to match.";
131
131
  readonly askPick: "Pick an answer below, and I'll carry on from there.";
132
132
  readonly askHere: "Reply here when you're ready, and I'll carry on from your answer.";
133
133
  readonly askThread: "Reply in this thread when you're ready, and I'll carry on from your answer.";
134
- readonly askedAbove: "I need your call on the question above";
135
134
  };
136
135
  /** The words of the progress message: the status in words beside the emoji while the run waits its turn and while EDGAR works (once the run is over, the title of its end note's kind in `NOTE`, except a failure, whose status is 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. */
137
136
  export declare const PLAN: {
@@ -324,11 +324,12 @@ export const SAYS = {
324
324
  deny: "Deny",
325
325
  questionTitle: "A question for you",
326
326
  question: (name) => `I have a question on ${name}.`,
327
- questionNext: "Reply in this thread with your answer, or with the number of another option, and I'll change my work to match.",
327
+ questionNext: (options) => options
328
+ ? "Reply in this thread with your answer, or with the number of another option, and I'll change my work to match."
329
+ : "Reply in this thread with your answer, and I'll carry on from there.",
328
330
  askPick: "Pick an answer below, and I'll carry on from there.",
329
331
  askHere: "Reply here when you're ready, and I'll carry on from your answer.",
330
332
  askThread: "Reply in this thread when you're ready, and I'll carry on from your answer.",
331
- askedAbove: "I need your call on the question above",
332
333
  };
333
334
  /** The value EDGAR counts a run under when its input has no value at any field of its workflow's concurrency key. */
334
335
  const NO_VALUE = "null";
@@ -69,10 +69,11 @@ export declare const metadata: z.ZodObject<{
69
69
  event_type: z.ZodString;
70
70
  event_payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
71
71
  }, z.core.$loose>;
72
- /** One message of `conversations.replies` or `conversations.history`. */
72
+ /** One message of `conversations.replies` or `conversations.history`, with its blocks, so a message can change in place and keep them. */
73
73
  export declare const message: z.ZodObject<{
74
74
  ts: z.ZodString;
75
75
  text: z.ZodOptional<z.ZodString>;
76
+ blocks: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
76
77
  user: z.ZodOptional<z.ZodString>;
77
78
  bot_id: z.ZodOptional<z.ZodString>;
78
79
  metadata: z.ZodOptional<z.ZodObject<{
@@ -85,6 +86,7 @@ export declare const messages: z.ZodObject<{
85
86
  messages: z.ZodArray<z.ZodObject<{
86
87
  ts: z.ZodString;
87
88
  text: z.ZodOptional<z.ZodString>;
89
+ blocks: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
88
90
  user: z.ZodOptional<z.ZodString>;
89
91
  bot_id: z.ZodOptional<z.ZodString>;
90
92
  metadata: z.ZodOptional<z.ZodObject<{
@@ -53,10 +53,11 @@ export const metadata = z.looseObject({
53
53
  event_type: z.string(),
54
54
  event_payload: z.record(z.string(), z.unknown()),
55
55
  });
56
- /** One message of `conversations.replies` or `conversations.history`. */
56
+ /** One message of `conversations.replies` or `conversations.history`, with its blocks, so a message can change in place and keep them. */
57
57
  export const message = z.looseObject({
58
58
  ts: z.string(),
59
59
  text: z.string().optional(),
60
+ blocks: z.array(z.record(z.string(), z.unknown())).optional().catch(undefined),
60
61
  user: z.string().optional(),
61
62
  bot_id: z.string().optional(),
62
63
  metadata: metadata.optional(),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "contract": 1,
3
3
  "name": "slack",
4
- "version": "0.1.5",
4
+ "version": "0.1.7",
5
5
  "config_schema": "schemas/config.json",
6
6
  "secrets": [
7
7
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kana-ai/edgar-ext-slack",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "EDGAR extension for Slack: a DM or a mention opens a card, the thread shows each stage, and tools post the summary, send a DM, ask a person and delete a message.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -22,8 +22,8 @@
22
22
  ".": "./dist/src/index.js"
23
23
  },
24
24
  "dependencies": {
25
- "@kana-ai/edgar-contracts": "0.1.5",
26
- "@kana-ai/edgar-sdk": "0.1.5",
25
+ "@kana-ai/edgar-contracts": "0.1.7",
26
+ "@kana-ai/edgar-sdk": "0.1.7",
27
27
  "zod": "4.6.7"
28
28
  },
29
29
  "devDependencies": {