okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Task board host side: dismiss mark, newest problem only, one plain line per run, pending approvals of every chatff18fbb86

main
2.7 KiB51 linesraw
1/**
2 * What a task that ran as the agent shows in Tasks ("Last result"): the agent's own answer, then a short plain list of what it
3 * did, then - if it hit something that needed a person's yes - exactly what that was. Pure, so it is tested without an agent.
4 */
5const clip = (value, max) => {
6  const text = String(value ?? '').replace(/\s+/g, ' ').trim();
7  return text.length > max ? `${text.slice(0, max - 1)}…` : text;
8};
9
10/** One card as a line a person can read. */
11export function cardLine(card) {
12  const what = clip(card.effect || card.preview || card.name, 140);
13  const detail = card.preview && card.effect && card.preview !== card.effect ? ` (${clip(card.preview, 100)})` : '';
14  if (card.state === 'denied') return `- Could not do this by itself: ${what}${detail}. Nothing was changed.`;
15  if (card.state === 'error') return `- Tried: ${what}${detail}. It did not work.`;
16  return `- ${what}${detail}`;
17}
18
19/**
20 * @param {{text:string, cards:Array}} run
21 * @returns {{text:string, attention:string|null, demo:boolean}}
22 */
23export function taskReport({ text, cards }) {
24  const done = cards.filter(c => c.state !== 'proposed');
25  const refused = cards.filter(c => c.state === 'denied');
26  const lines = done.map(cardLine);
27  const answer = String(text ?? '').trim();
28  let out = answer || (cards.length ? 'The task ran.' : 'The task ran and had nothing to report.');
29  if (lines.length) out += `\n\n---\n\n**What it did**\n\n${lines.join('\n')}`;
30  const attention = refused.length
31    ? `This task wanted to change something and needed a yes, which nobody could give while it ran by itself: ${refused.map(c => clip(c.effect || c.name, 100)).join('; ')}. Nothing was changed. Edit the task and let it make changes if you want it to.`
32    : null;
33  if (attention) out += `\n\n> ${attention}`;
34  return { text: out, attention, demo: false };
35}
36
37/**
38 * One plain line for a board card: the first sentence of the answer, with the markdown taken off and the "What it did" list and the
39 * "needed a yes" note left out. '' when there is nothing to say.
40 */
41export function lastLine(text, max = 160) {
42  let body = String(text ?? '').split(/\n\n---\n\n/)[0].replace(/\n\n> [\s\S]*$/, '');
43  body = body.replace(/```[\s\S]*?```/g, ' ').replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/^\s*(#{1,6}|[-*+]|\d+[.)]|>)\s+/gm, '').replace(/[*_`~]/g, '');
44  body = body.replace(/\s+/g, ' ').trim();
45  if (!body) return '';
46  const sentence = /^.*?[.!?](?=\s|$)/.exec(body)?.[0] ?? body;
47  // A very short first sentence ("Done.") says nothing: take the next one too.
48  const two = /^.*?[.!?](?=\s|$)\s*.*?[.!?](?=\s|$)/.exec(body)?.[0] ?? body;
49  const pick = sentence.length < 24 && body.length > sentence.length ? two : sentence;
50  return clip(pick, max);
51}