mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The last three of the features other kanban apps call AI, done with plain
code (docs/Features/General/Assistants/Assistants.md):
- Checklists -> From description: the list lines of a card's description
("- ", "* ", "1. ", task boxes; never inside code blocks) previewed, then
made into a checklist - ticked where the line was [x] - or into subtasks
through addSubtaskCard.
- Create cards from action items, on a comment and in the card menu for its
description: "TODO: ...", "- [ ] ..." and "@user ..." lines become cards
at the top of the card's list, linking back to it, with the mentioned
user as member when they are an active board member.
- Global search understands plain phrases in the reader's language - "my
overdue cards", "due this week", "unassigned cards" and seven more - and
runs them as its operators, saying which; a query with an operator in it
is never rewritten.
Checklist from description and Action items are Show on Card rows of Board
Settings / Card and of the Admin Panel's Card fields; Search phrases is an
Admin Panel / Settings / Visibility / Features tick. Translated in every
language.
Thanks to xet7 !
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// Action items from a comment or a description
|
|
// (docs/Features/Cards/Action-Items.md): the "who does what" lines meeting
|
|
// notes end with, which Confluence and Jira find with AI, found here by their
|
|
// shape.
|
|
//
|
|
// Pure, no Meteor. Tests: tests/actionItems.test.cjs.
|
|
|
|
const MAX_ITEMS = 50;
|
|
const MAX_TITLE = 500;
|
|
|
|
const FENCE = /^\s*(```|~~~)/;
|
|
const TODO = /^\s*(?:[-*+]\s+)?TODO\s*:\s*(.+?)\s*$/i;
|
|
const BOX = /^\s*(?:[-*+]\s+)?\[ \]\s+(.+?)\s*$/;
|
|
const MENTION_FIRST = /^\s*(?:[-*+]\s+)?@([\w.-]+)\s+(.+?)\s*$/;
|
|
const LEADING_MENTION = /^@([\w.-]+)\s+(.+)$/;
|
|
|
|
// usernames: the board's active members. A mention of anybody else stays in
|
|
// the title. Returns [{ title, username }].
|
|
function actionItems(text, usernames = []) {
|
|
const members = new Set(usernames);
|
|
const out = [];
|
|
let inFence = false;
|
|
for (const line of String(text || '').split(/\r?\n/)) {
|
|
if (FENCE.test(line)) { inFence = !inFence; continue; }
|
|
if (inFence) continue;
|
|
let body = null;
|
|
let m = TODO.exec(line) || BOX.exec(line);
|
|
if (m) body = m[1];
|
|
else if ((m = MENTION_FIRST.exec(line))) body = `@${m[1]} ${m[2]}`;
|
|
if (!body) continue;
|
|
let username = null;
|
|
const mention = LEADING_MENTION.exec(body);
|
|
if (mention && members.has(mention[1])) {
|
|
username = mention[1];
|
|
body = mention[2];
|
|
}
|
|
const title = body.trim().slice(0, MAX_TITLE);
|
|
if (!title) continue;
|
|
out.push({ title, username });
|
|
if (out.length >= MAX_ITEMS) break;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
module.exports = { MAX_ITEMS, actionItems };
|