@wirecat/cli-core 0.637.0 → 0.639.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/search/lucene/registry.js +10 -0
- package/dist/sends/pace.js +21 -13
- package/dist/services/agenda.js +8 -1
- package/dist/services/task-rules.js +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/sqlite/knowledge.js +5 -2
- package/dist/store/sqlite/lucene-fields.js +15 -0
- package/dist/store/sqlite/mail-findings.js +24 -0
- package/dist/store/sqlite/task-board.d.ts +4 -2
- package/dist/store/sqlite/task-board.js +5 -3
- package/dist/store/sqlite/task-stats.js +2 -2
- package/dist/store/sqlite/tasks.js +20 -3
- package/dist/store/sqlite/work-tasks.d.ts +7 -3
- package/dist/store/sqlite/work-tasks.js +9 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,38 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.639.0 — 11.11.2026
|
|
9
|
+
|
|
10
|
+
### Changed — may break callers
|
|
11
|
+
|
|
12
|
+
- **A task found in a message takes the fields of a project task.** `store.tasks.edit`, which now takes `TaskEdit`,
|
|
13
|
+
gives it `todo` and `in_progress` and another message kind (question, request, mention, promise), and `{ project }` moves it into an
|
|
14
|
+
owner project under that project's next key. The moved task keeps its id, its old key and its source message, leaves
|
|
15
|
+
its account's task reads, and may then become a bug, feature or chore. A rule does not open a second task from that
|
|
16
|
+
message.
|
|
17
|
+
- **The task board includes found tasks.** `store.tasks.board` and `boardCounts` count every live task, found tasks
|
|
18
|
+
too; `project:*` still narrows to the owner's projects, and the project choices leave the account inboxes out.
|
|
19
|
+
`stats tasks` over projects is unchanged.
|
|
20
|
+
- **An account's open tasks include `todo` and `in_progress`.** `knowledge.taskIds(key, { state: "open" })` and
|
|
21
|
+
`tasks agenda` read every task not closed yet.
|
|
22
|
+
|
|
23
|
+
## 0.638.0 — 11.11.2026
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **`participants_count` in the query language.** `participants_count<10` matches messages in chats of fewer than ten
|
|
28
|
+
people, as the messenger last reported the size; a chat whose size was never reported matches no value. So
|
|
29
|
+
`stats messages show 'kind:private OR (kind:group participants_count<10)'` counts personal conversations and leaves
|
|
30
|
+
big groups out.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- **A new contact from mail needs a name the mail's text adds.** A `new_contact` finding whose name only repeats what the store has from the sender line is refused (`new-contact.sender-line`), and so is one whose name is not in the text of the mail it cites (`new-contact.not-in-text`). A name copied from a header is metadata, not something for the owner to review. Batches already waiting stay as they are until decided.
|
|
35
|
+
- **A clock stepped back no longer leaves a profile waiting for hours.** The request pace now keeps when it wrote its
|
|
36
|
+
file, and corrects a wait written "in the future" by the size of the step: a computer that booted with its clock three hours ahead refused
|
|
37
|
+
every sync for three hours once NTP corrected it. The refusal also stops saying the messenger asked for the wait,
|
|
38
|
+
which it could not know.
|
|
39
|
+
|
|
8
40
|
## 0.637.0 — 11.11.2026
|
|
9
41
|
|
|
10
42
|
### Fixed
|
|
@@ -200,6 +200,16 @@ export const QUERY_FIELDS = [
|
|
|
200
200
|
support: "A1",
|
|
201
201
|
values: ["true", "false"],
|
|
202
202
|
},
|
|
203
|
+
{
|
|
204
|
+
name: "participants_count",
|
|
205
|
+
example: "participants_count<10",
|
|
206
|
+
index: "chats.participants_count",
|
|
207
|
+
aliases: [],
|
|
208
|
+
type: "num",
|
|
209
|
+
operators: [...terms, "range"],
|
|
210
|
+
normalization: "a whole number; a chat whose size the messenger never told matches no value",
|
|
211
|
+
support: "A1",
|
|
212
|
+
},
|
|
203
213
|
{
|
|
204
214
|
name: "has",
|
|
205
215
|
example: "has:file",
|
package/dist/sends/pace.js
CHANGED
|
@@ -25,12 +25,13 @@ export class Pacer {
|
|
|
25
25
|
}
|
|
26
26
|
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
27
27
|
async reserve() {
|
|
28
|
-
const now = this.now();
|
|
29
28
|
if (this.interval === 0)
|
|
30
|
-
return now;
|
|
29
|
+
return this.now();
|
|
31
30
|
return withFileLockAsync(this.path, "the request pace", () => {
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// Inside the lock: read earlier, another process's write would look like a clock step.
|
|
32
|
+
const now = this.now();
|
|
33
|
+
const tat = Math.max(this.read(now), now);
|
|
34
|
+
this.write(tat + this.interval, now);
|
|
34
35
|
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -39,26 +40,33 @@ export class Pacer {
|
|
|
39
40
|
if (this.interval === 0)
|
|
40
41
|
return;
|
|
41
42
|
await withFileLockAsync(this.path, "the request pace", () => {
|
|
42
|
-
const
|
|
43
|
-
this.
|
|
43
|
+
const now = this.now();
|
|
44
|
+
const hold = now + waitMs + this.rate.burst * this.interval;
|
|
45
|
+
this.write(Math.max(this.read(now), hold), now);
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
/** The owner's `flood clear`: every process may go again at once. */
|
|
47
49
|
async reset() {
|
|
48
|
-
await withFileLockAsync(this.path, "the request pace", () => this.write(0));
|
|
50
|
+
await withFileLockAsync(this.path, "the request pace", () => this.write(0, this.now()));
|
|
49
51
|
}
|
|
50
|
-
read() {
|
|
52
|
+
read(now) {
|
|
51
53
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
+
const file = JSON.parse(readFileSync(this.path, "utf8"));
|
|
55
|
+
const tat = Number(file.tat);
|
|
56
|
+
if (!Number.isFinite(tat))
|
|
57
|
+
return 0;
|
|
58
|
+
const at = Number(file.at);
|
|
59
|
+
// Written "in the future" means the clock went back since, as when a machine boots ahead and NTP steps it. What
|
|
60
|
+
// was left of the wait still holds; the absolute time, hours off, does not.
|
|
61
|
+
return Number.isFinite(at) && at > now ? now + Math.max(0, tat - at) : tat;
|
|
54
62
|
}
|
|
55
63
|
catch {
|
|
56
64
|
return 0;
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
|
-
write(tat) {
|
|
67
|
+
write(tat, at) {
|
|
60
68
|
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
61
|
-
writeFileSync(temporary, JSON.stringify({ tat }), { mode: 0o600 });
|
|
69
|
+
writeFileSync(temporary, JSON.stringify({ tat, at }), { mode: 0o600 });
|
|
62
70
|
renameSync(temporary, this.path);
|
|
63
71
|
}
|
|
64
72
|
}
|
|
@@ -89,7 +97,7 @@ export const waitForTurn = async (pacer, options) => {
|
|
|
89
97
|
if (waitMs <= 0)
|
|
90
98
|
return;
|
|
91
99
|
if (waitMs > LONGEST_PACE_WAIT_MS)
|
|
92
|
-
throw new CliError("rate_limited",
|
|
100
|
+
throw new CliError("rate_limited", `this profile's next request to ${name} has to wait ${Math.ceil(waitMs / 1000)} s more — nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
93
101
|
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
94
102
|
const seconds = Math.ceil(waitMs / 1000);
|
|
95
103
|
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
package/dist/services/agenda.js
CHANGED
|
@@ -47,7 +47,14 @@ export const agendaService = (deps, now = Date.now) => ({
|
|
|
47
47
|
const at = now();
|
|
48
48
|
const parts = query ? split(query) : { tasks: undefined, chats: undefined };
|
|
49
49
|
const find = (where) => store.tasks
|
|
50
|
-
.find({
|
|
50
|
+
.find({
|
|
51
|
+
project: inboxKey(taskAccount(account)),
|
|
52
|
+
limit: 500,
|
|
53
|
+
where: {
|
|
54
|
+
sql: `t.status NOT IN ('done', 'dismissed') AND (${where?.sql || "1"})`,
|
|
55
|
+
params: where?.params ?? [],
|
|
56
|
+
},
|
|
57
|
+
})
|
|
51
58
|
.catch((error) => {
|
|
52
59
|
// An account that never had a task has no inbox project yet.
|
|
53
60
|
if (error instanceof Error && "code" in error && error.code === "not_found")
|
|
@@ -70,7 +70,7 @@ export const applyTaskRules = async (review, { store, account, now, categories,
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
-
const hasTask = async (message) => (await store.findBySource(owner, sourceOf(message))).length > 0;
|
|
73
|
+
const hasTask = async (message) => (await store.findBySource(owner, sourceOf(message), { linked: true })).length > 0;
|
|
74
74
|
for (const chat of review.chats) {
|
|
75
75
|
const scope = scopeOf(chat.kind, chat.watched === true);
|
|
76
76
|
if (scope === "none")
|
package/dist/store/index.d.ts
CHANGED
|
@@ -114,6 +114,6 @@ export type { StoreTaskStore } from "./sqlite/tasks.js";
|
|
|
114
114
|
export type { StoredTemplate, TemplateAddress, TemplateHistoryEntry, TemplateStore } from "./sqlite/templates.js";
|
|
115
115
|
export type { TagPreflight, VocabularyAlias, VocabularyAliasReceipt, VocabularyAudit, VocabularyAuditOptions, VocabularyCatalog, VocabularyEntry, VocabularyKind, VocabularyOptions, VocabularyResolution, VocabularyStore, VocabularyTarget, } from "./sqlite/vocabulary.js";
|
|
116
116
|
export type { Wallet, WalletFilter, WalletInput, WalletsStore, WalletUpdate } from "./sqlite/wallets.js";
|
|
117
|
-
export type { BoardCounts, BoardOptions, EditedTask, MovedSubtask, NewWorkTask, RevisionCheck, TaskAssignment, TaskDetails, TaskEvent, TaskFields, TaskMove, TaskMoved, TaskRole, TaskType, WorkTaskType, } from "./sqlite/work-tasks.js";
|
|
117
|
+
export type { BoardCounts, BoardOptions, EditedTask, MovedSubtask, NewWorkTask, RevisionCheck, TaskAssignment, TaskDetails, TaskEdit, TaskEvent, TaskFields, TaskMove, TaskMoved, TaskRole, TaskType, WorkTaskType, } from "./sqlite/work-tasks.js";
|
|
118
118
|
export { TASK_EVENT_KINDS, TASK_ROLES } from "./sqlite/work-tasks.js";
|
|
119
119
|
export { type AccountAccounts, type AccountAttachments, type AccountCounters, type AccountGroupChange, type AccountKey, type AccountMentions, type AccountMessageFilter, type AccountMessages, type AccountPeople, type AccountsStore, type AccountVectors, type AttachmentsStore, type AttachmentTextEntry, type AttachmentView, type ChatActivityCount, type ChatStats, type ChatsStore, type ConversationsStore, type CountersStore, type DeletionScope, type Delta, type FileAttachment, type IdentityRef, type IngestedVia, type LinkedIdentity, type LinkOptions, MENTION_QUERY, MENTION_STATUSES, type MentionsStore, type MessageFilter, type MessageStore, type MessagesStore, OTHER_SOURCES, openStore, type PeopleStore, type PersonFacts, type PersonRecord, type QueriesStore, type Range, type RankedEvidence, type RankedStoreFound, type RankedStoreRow, type RankingEvidenceItem, type RankingEvidenceRequest, type RankingRequest, type RosterStore, type SearchCommand, type SearchesStore, type SearchIndexStore, type SearchRecord, type StoredAccount, type StoredChatFilter, type StoredHit, type StoredSearch, type StoredTag, type StoreOptions, type SyncStore, type TagFilter, type TagsStore, type TagTarget, type TaskAnalysisMark, type TaskAnalysisMarkWrite, type TaskTagTarget, type TextOrigin, type VectorsStore, } from "./store.js";
|
|
@@ -305,12 +305,15 @@ export const knowledgeStoreOver = (context) => {
|
|
|
305
305
|
if (options.sources?.length === 0)
|
|
306
306
|
return { items: [], hasMore: false };
|
|
307
307
|
account(key);
|
|
308
|
+
// Open is every task not closed yet: a found task may be todo or in_progress as well.
|
|
309
|
+
const open = ["open", "todo", "in_progress"];
|
|
310
|
+
const states = options.state === undefined ? null : JSON.stringify(options.state === "open" ? open : [options.state]);
|
|
308
311
|
const rows = database
|
|
309
312
|
.prepare("SELECT t.key, t.package_id AS id FROM tasks t JOIN projects p ON p.id = t.project_id " +
|
|
310
|
-
"WHERE p.key = ? AND t.deleted_at IS NULL AND (? IS NULL OR t.status
|
|
313
|
+
"WHERE p.key = ? AND t.deleted_at IS NULL AND (? IS NULL OR t.status IN (SELECT value FROM json_each(?))) " +
|
|
311
314
|
`${options.sources ? `AND t.source_locator IN (${options.sources.map(() => "?").join(",")}) ` : ""}` +
|
|
312
315
|
"ORDER BY t.created_at, t.id LIMIT ? OFFSET ?")
|
|
313
|
-
.all(inboxKey(taskAccount(key)),
|
|
316
|
+
.all(inboxKey(taskAccount(key)), states, states, ...(options.sources ?? []), limit + 1, offset);
|
|
314
317
|
return { items: rows.slice(0, limit).map((row) => String(row.id ?? row.key)), hasMore: rows.length > limit };
|
|
315
318
|
},
|
|
316
319
|
addAnnotation: async (key, target, text) => {
|
|
@@ -347,6 +347,20 @@ const topic = messengerOnly(({ value }) => always(bound("m.thread_external_id =
|
|
|
347
347
|
/** What `kind:` matches for a chat aliased `c`: private, saved, bot, service, group, channel or unknown. */
|
|
348
348
|
export const PEER_KIND = "CASE WHEN json_extract(c.metadata,'$.peerKind') IN ('private','saved','bot','service','group','channel','unknown') THEN json_extract(c.metadata,'$.peerKind') WHEN c.kind='dialog' AND json_extract(c.metadata,'$.isBot')=1 THEN 'bot' WHEN c.kind='dialog' THEN 'private' ELSE c.kind END";
|
|
349
349
|
const kind = messengerOnly(({ value }) => always(bound(`${PEER_KIND} = ?`, value.toLowerCase())));
|
|
350
|
+
/** How many people a chat has, as the messenger last said; a chat with no known size matches no value. */
|
|
351
|
+
const participantsCount = messengerOnly((node) => {
|
|
352
|
+
const { operator, value, upper } = node;
|
|
353
|
+
const column = "c.participants_count";
|
|
354
|
+
if (operator !== "range")
|
|
355
|
+
return always(bound(`${column} = ?`, Number(value)));
|
|
356
|
+
const conditions = [
|
|
357
|
+
...(value === "*" ? [] : [bound(`${column} ${node.lower_inclusive ? ">=" : ">"} ?`, Number(value))]),
|
|
358
|
+
...(upper === undefined || upper === "*"
|
|
359
|
+
? []
|
|
360
|
+
: [bound(`${column} ${node.upper_inclusive ? "<=" : "<"} ?`, Number(upper))]),
|
|
361
|
+
];
|
|
362
|
+
return always(combine(conditions, "AND"));
|
|
363
|
+
});
|
|
350
364
|
/** A chat the owner muted, until its mute runs out; a chat whose messenger keeps no mute is not muted. */
|
|
351
365
|
const muted = messengerOnly(({ value }) => always(bound(`${value.toLowerCase() === "true" ? "" : "NOT "}(coalesce(c.muted, 0) = 1 AND (c.muted_until IS NULL OR c.muted_until > ?))`, Date.now())));
|
|
352
366
|
const has = ({ value }, { corpus, mail }) => {
|
|
@@ -443,6 +457,7 @@ export const FIELD_COMPILERS = {
|
|
|
443
457
|
topic,
|
|
444
458
|
kind,
|
|
445
459
|
muted,
|
|
460
|
+
participants_count: participantsCount,
|
|
446
461
|
has,
|
|
447
462
|
in: inSourceField,
|
|
448
463
|
to: recipient,
|
|
@@ -28,6 +28,9 @@ const invalid = (message, reason) => {
|
|
|
28
28
|
throw new CliError("validation_error", message, reason ? { reason } : undefined);
|
|
29
29
|
};
|
|
30
30
|
const TEXT_BUDGET = 262144;
|
|
31
|
+
const wordsOf = (text) => fold(text)
|
|
32
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
33
|
+
.filter(Boolean);
|
|
31
34
|
const EMAIL = `SELECT e.id, e.account_id, e.subject, coalesce(e.body_text, '') AS body,
|
|
32
35
|
json_extract(e.metadata, '$.partial') IS NOT NULL AS partial, lower(e.from_address) AS sender,
|
|
33
36
|
coalesce(e.outgoing, lower(e.from_address) = lower(a.external_id)) AS outgoing
|
|
@@ -227,6 +230,26 @@ export const mailFindingsStoreOver = (context) => {
|
|
|
227
230
|
`SELECT 1 FROM email_recipients WHERE email_id IN (${marks}) AND lower(address) = ? LIMIT 1`)
|
|
228
231
|
.get(...ids, address, ...ids, address));
|
|
229
232
|
};
|
|
233
|
+
/** Every name the store already has for `address`: the sender and recipient lines of any mail, its identity, its person. */
|
|
234
|
+
const namesOnRecord = (address) => database
|
|
235
|
+
.prepare("SELECT from_name AS name FROM emails WHERE lower(from_address) = ? AND from_name IS NOT NULL UNION " +
|
|
236
|
+
"SELECT name FROM email_recipients WHERE lower(address) = ? AND name IS NOT NULL UNION " +
|
|
237
|
+
"SELECT i.name FROM identities i WHERE i.provider = 'email' AND lower(i.external_id) = ? AND i.name IS NOT NULL UNION " +
|
|
238
|
+
"SELECT p.name FROM identities i JOIN identity_links l ON l.identity_id = i.id JOIN persons p ON p.id = l.person_id " +
|
|
239
|
+
"WHERE i.provider = 'email' AND lower(i.external_id) = ? AND p.name IS NOT NULL")
|
|
240
|
+
.all(address, address, address, address)
|
|
241
|
+
.map((row) => String(row.name));
|
|
242
|
+
/** The owner ruled a name copied from a sender line is metadata: only one the mail's own text adds is worth asking. */
|
|
243
|
+
const requireBetterName = (finding, read) => {
|
|
244
|
+
const name = wordsOf(finding.name);
|
|
245
|
+
const known = new Set(namesOnRecord(finding.address).flatMap(wordsOf));
|
|
246
|
+
if (name.every((word) => known.has(word)))
|
|
247
|
+
return invalid(`the name of new contact ${finding.address} adds nothing to the name the store has from its mail; leave it out`, "new-contact.sender-line");
|
|
248
|
+
const wanted = ` ${name.join(" ")} `;
|
|
249
|
+
const inText = finding.evidence.some(({ reference }) => ` ${wordsOf(String(read.get(reference)?.body)).join(" ")} `.includes(wanted));
|
|
250
|
+
if (!inText)
|
|
251
|
+
return invalid(`the name of new contact ${finding.address} is not in the text of the mail it cites; leave it out`, "new-contact.not-in-text");
|
|
252
|
+
};
|
|
230
253
|
/** A proposed findings batch that already holds this shop's order with this number. */
|
|
231
254
|
const proposedOrder = (supplierName, number) => {
|
|
232
255
|
const shop = fold(supplierName).trim();
|
|
@@ -289,6 +312,7 @@ export const mailFindingsStoreOver = (context) => {
|
|
|
289
312
|
return invalid(`${finding.address} neither sent nor received the mail finding ${finding.id} cites`);
|
|
290
313
|
if (!identityOfAddress(finding.address))
|
|
291
314
|
throw new CliError("not_found", `no stored contact ${finding.address}`);
|
|
315
|
+
requireBetterName(finding, read);
|
|
292
316
|
return;
|
|
293
317
|
}
|
|
294
318
|
}
|
|
@@ -18,8 +18,10 @@ export declare const dueGroups: (now: number, zone: string) => {
|
|
|
18
18
|
export type DueGroup = keyof ReturnType<typeof dueGroups>;
|
|
19
19
|
/** `now` and `zone` place today; one value per answer, so the list and its counts agree. */
|
|
20
20
|
export declare const projectTaskColumns: (now: number, zone: string, database: CacheDatabase) => ColumnMap;
|
|
21
|
-
/** Live tasks of the owner's projects
|
|
22
|
-
export declare const
|
|
21
|
+
/** Live tasks of the owner's projects, without the tasks found in messages. */
|
|
22
|
+
export declare const PROJECT_SCOPE = "t.deleted_at IS NULL AND t.project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL AND length(key) <> 10)";
|
|
23
|
+
/** Every live task: the owner's projects and the tasks found in messages, which wait in each account's inbox. */
|
|
24
|
+
export declare const BOARD_SCOPE = "t.deleted_at IS NULL AND t.project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL)";
|
|
23
25
|
/** The chosen order first, then priority, age and id, so a page boundary never splits a tie. */
|
|
24
26
|
export declare const boardOrder: (sort: TaskSort, descending: boolean) => string;
|
|
25
27
|
/** The query without its required terms on `name`: a picker counts the choices its own filter hides. */
|
|
@@ -62,7 +62,7 @@ const wordsMatch = (node) => {
|
|
|
62
62
|
};
|
|
63
63
|
const projectWhere = (node) => {
|
|
64
64
|
if (node.operator === "wildcard" && node.value === "*")
|
|
65
|
-
return { sql:
|
|
65
|
+
return { sql: `t.project_id IN (${OWNER_PROJECTS})`, params: [] };
|
|
66
66
|
const id = /^project:(\d+)$/.exec(node.value.trim())?.[1];
|
|
67
67
|
if (id !== undefined)
|
|
68
68
|
return { sql: "t.project_id = ?", params: [Number(id)] };
|
|
@@ -213,8 +213,10 @@ export const projectTaskColumns = (now, zone, database) => ({
|
|
|
213
213
|
},
|
|
214
214
|
},
|
|
215
215
|
});
|
|
216
|
-
/** Live tasks of the owner's projects
|
|
217
|
-
export const
|
|
216
|
+
/** Live tasks of the owner's projects, without the tasks found in messages. */
|
|
217
|
+
export const PROJECT_SCOPE = `t.deleted_at IS NULL AND t.project_id IN (${OWNER_PROJECTS})`;
|
|
218
|
+
/** Every live task: the owner's projects and the tasks found in messages, which wait in each account's inbox. */
|
|
219
|
+
export const BOARD_SCOPE = "t.deleted_at IS NULL AND t.project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL)";
|
|
218
220
|
const STATE_ORDER = `CASE t.status ${TASK_STATES.map((state, at) => `WHEN '${state}' THEN ${at}`).join(" ")} END`;
|
|
219
221
|
/** The chosen order first, then priority, age and id, so a page boundary never splits a tie. */
|
|
220
222
|
export const boardOrder = (sort, descending) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PROJECT_SCOPE } from "./task-board.js";
|
|
2
2
|
const ACCOUNT_SCOPE = "t.package_id IS NOT NULL AND t.deleted_at IS NULL AND t.project_id = ?";
|
|
3
3
|
/** Every statement `stats tasks show` runs, for the query-plan test. */
|
|
4
4
|
export const TASK_STATS_SQL = {
|
|
5
5
|
rows: (board, filter) => "SELECT t.source_group, t.source_kind, t.project_id, t.status, t.created_at, t.closed_at FROM tasks t " +
|
|
6
|
-
`WHERE ${board ?
|
|
6
|
+
`WHERE ${board ? PROJECT_SCOPE : ACCOUNT_SCOPE}${filter} ORDER BY t.created_at, t.id`,
|
|
7
7
|
chat: "SELECT c.external_id AS id, c.title AS name FROM chats c JOIN accounts a ON a.id = c.account_id " +
|
|
8
8
|
"WHERE a.provider = ? AND a.external_id = ? AND c.external_id IN (SELECT value FROM json_each(?))",
|
|
9
9
|
meeting: "SELECT CAST(id AS TEXT) AS id, title AS name FROM meetings WHERE id IN (SELECT value FROM json_each(?))",
|
|
@@ -9,7 +9,7 @@ import { taskSimilarityOver } from "./task-candidates.js";
|
|
|
9
9
|
import { savedTaskCategories, saveTaskCategories, storeTaskCategories, unlistedTaskCategories, } from "./task-category-settings.js";
|
|
10
10
|
import { CLEAR_SUGGESTION, closeSuggestionOf, SUGGESTION_COLUMNS } from "./task-close.js";
|
|
11
11
|
import { taskCloseOver } from "./task-close-store.js";
|
|
12
|
-
import { inboxKey, typedKey } from "./task-keys.js";
|
|
12
|
+
import { INBOX_KEY_LENGTH, inboxKey, typedKey } from "./task-keys.js";
|
|
13
13
|
import { taskPairsOver } from "./task-pairs.js";
|
|
14
14
|
import { taskStatsOver } from "./task-stats.js";
|
|
15
15
|
import { displayTitleOf } from "./task-titles.js";
|
|
@@ -48,8 +48,17 @@ export const inboxProject = ({ database, now }, account, create) => {
|
|
|
48
48
|
export const taskStoreOver = (context) => {
|
|
49
49
|
const { database, now } = context;
|
|
50
50
|
const inbox = (account, create) => inboxProject(context, account, create);
|
|
51
|
-
// A task made here has no package id and may be a type the package does not know; the package never sees it
|
|
52
|
-
|
|
51
|
+
// A task made here has no package id and may be a type the package does not know; the package never sees it,
|
|
52
|
+
// nor a found task the owner moved into a project.
|
|
53
|
+
const select = (where) => database.prepare(`SELECT ${COLUMNS} FROM tasks t JOIN projects p ON p.id = t.project_id WHERE t.package_id IS NOT NULL ` +
|
|
54
|
+
`AND length(p.key) = ${INBOX_KEY_LENGTH} AND ${where}`);
|
|
55
|
+
/** The message kind a task was found as, though it may be a bug or a chore in its project now. */
|
|
56
|
+
const kindFound = (row) => TASK_KINDS.includes(row.type)
|
|
57
|
+
? row.type
|
|
58
|
+
: database
|
|
59
|
+
.prepare("SELECT json_extract(changes, '$.type[0]') AS kind FROM task_events WHERE task_id = ? AND kind = 'type' " +
|
|
60
|
+
"ORDER BY id LIMIT 1")
|
|
61
|
+
.get(Number(row.row_id))?.kind;
|
|
53
62
|
const toTask = (row) => {
|
|
54
63
|
const task = {
|
|
55
64
|
id: String(row.package_id),
|
|
@@ -138,6 +147,14 @@ export const taskStoreOver = (context) => {
|
|
|
138
147
|
.map(toTask);
|
|
139
148
|
if (!linked || own.length > 0)
|
|
140
149
|
return own;
|
|
150
|
+
// A rule must not find a message again once its task moved into a project, so that task still counts as seen.
|
|
151
|
+
const moved = database
|
|
152
|
+
.prepare(`SELECT ${COLUMNS} FROM tasks t JOIN projects p ON p.id = t.project_id WHERE t.package_id IS NOT NULL ` +
|
|
153
|
+
"AND t.source_locator = ? AND EXISTS (SELECT 1 FROM task_events e WHERE e.task_id = t.id " +
|
|
154
|
+
"AND e.kind = 'project' AND json_extract(e.changes, '$.project[0]') = ?) ORDER BY t.created_at, t.id")
|
|
155
|
+
.all(source, `project:${project}`);
|
|
156
|
+
if (moved.length > 0)
|
|
157
|
+
return moved.map((row) => toTask({ ...row, account, type: kindFound(row) }));
|
|
141
158
|
let message;
|
|
142
159
|
try {
|
|
143
160
|
message = thingOf(database, source);
|
|
@@ -44,6 +44,10 @@ export interface TaskFields {
|
|
|
44
44
|
/** The http or https page the task is about, such as an Avito ad; `null` clears it. */
|
|
45
45
|
sourceUrl?: string | null;
|
|
46
46
|
}
|
|
47
|
+
/** What `edit` takes: a task found in a message keeps a message kind until it moves into a project. */
|
|
48
|
+
export type TaskEdit = Omit<TaskFields, "type"> & {
|
|
49
|
+
type?: TaskType;
|
|
50
|
+
};
|
|
47
51
|
export interface NewWorkTask extends Omit<TaskFields, "reason" | "project" | "type"> {
|
|
48
52
|
/** `project:<id>` or the project's key. */
|
|
49
53
|
project: string;
|
|
@@ -184,7 +188,7 @@ export interface TaskEvent {
|
|
|
184
188
|
/** Tasks beyond the package's four message kinds, and the fields the package does not know, on any task. */
|
|
185
189
|
export interface WorkTasks extends TaskRelationsStore {
|
|
186
190
|
create(input: NewWorkTask, by: Author): Promise<TaskDetails>;
|
|
187
|
-
edit(id: string, fields:
|
|
191
|
+
edit(id: string, fields: TaskEdit, by: Author, check?: RevisionCheck): Promise<EditedTask>;
|
|
188
192
|
assign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): Promise<TaskDetails>;
|
|
189
193
|
unassign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): Promise<TaskDetails>;
|
|
190
194
|
/**
|
|
@@ -216,7 +220,7 @@ export interface WorkTasks extends TaskRelationsStore {
|
|
|
216
220
|
comment(id: string, text: string, by: Author): Promise<TaskComment>;
|
|
217
221
|
/** Its comments, oldest first. */
|
|
218
222
|
comments(id: string): Promise<TaskComment[]>;
|
|
219
|
-
/**
|
|
223
|
+
/** Every live task, the found ones too, narrowed by a query over `PROJECT_TASK_FIELDS`. */
|
|
220
224
|
board(query: QueryAst | undefined, options: BoardOptions): Promise<{
|
|
221
225
|
items: TaskDetails[];
|
|
222
226
|
total: number;
|
|
@@ -249,7 +253,7 @@ export declare const checkRevision: (row: Row, expected: number | undefined) =>
|
|
|
249
253
|
type WorkTaskOperations = Omit<WorkTasks, "create" | "assign"> & {
|
|
250
254
|
create(input: NewWorkTask, by: Author): TaskDetails;
|
|
251
255
|
assign(id: string, assignment: TaskAssignment, by: Author, check?: RevisionCheck): TaskDetails;
|
|
252
|
-
editNow(id: string, fields:
|
|
256
|
+
editNow(id: string, fields: TaskEdit, by: Author): TaskDetails;
|
|
253
257
|
};
|
|
254
258
|
export declare const workTaskOperationsOver: (context: StoreContext) => WorkTaskOperations;
|
|
255
259
|
export declare const workTasksOver: (context: StoreContext) => WorkTasks;
|
|
@@ -2,7 +2,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { timezoneOf } from "@wirecat/cli-base/query";
|
|
3
3
|
import { externalIdOf, externalIdText, sourceUrlOf } from "../../domain/external-links.js";
|
|
4
4
|
import { TASK_TYPES, WORK_TASK_TYPES } from "../../domain/knowledge.js";
|
|
5
|
-
import { checkedScore, isClosedState, legacyPriority, PRIORITY_LABELS, priorityBand, priorityLabel, TASK_STATES, } from "../../tasks/index.js";
|
|
5
|
+
import { checkedScore, isClosedState, legacyPriority, PRIORITY_LABELS, priorityBand, priorityLabel, TASK_KINDS, TASK_STATES, } from "../../tasks/index.js";
|
|
6
6
|
import { folded } from "./folded.js";
|
|
7
7
|
import { authorActor } from "./memories.js";
|
|
8
8
|
import { idsOf } from "./merged-persons.js";
|
|
@@ -173,6 +173,7 @@ export const workTaskOperationsOver = (context) => {
|
|
|
173
173
|
const countOf = (where) => Number(database.prepare(`SELECT count(*) AS n FROM tasks t WHERE ${where.sql}`).get(...where.params)?.n ?? 0);
|
|
174
174
|
const rowById = (id) => database.prepare("SELECT * FROM tasks WHERE id = ?").get(id);
|
|
175
175
|
const details = (id) => detailsOf(rowById(id));
|
|
176
|
+
const inInbox = (project) => String(database.prepare("SELECT key FROM projects WHERE id = ?").get(project)?.key).length === INBOX_KEY_LENGTH;
|
|
176
177
|
const onBoard = (task) => Boolean(database.prepare(`SELECT 1 FROM tasks t WHERE t.id = ? AND ${BOARD_SCOPE}`).get(task));
|
|
177
178
|
/** The task takes the target's next number and key; the source's counter never goes back, so its old key stays unique. */
|
|
178
179
|
const moveToProject = (task, before, target, actor, at, detach) => {
|
|
@@ -252,10 +253,6 @@ export const workTaskOperationsOver = (context) => {
|
|
|
252
253
|
if (fields.status !== undefined) {
|
|
253
254
|
if (!TASK_STATES.includes(fields.status))
|
|
254
255
|
throw new CliError("validation_error", `a task's status is one of ${TASK_STATES.join(", ")}`);
|
|
255
|
-
if ((fields.status === "todo" || fields.status === "in_progress") &&
|
|
256
|
-
String(database.prepare("SELECT key FROM projects WHERE id = ?").get(Number(before.project_id))?.key).length ===
|
|
257
|
-
INBOX_KEY_LENGTH)
|
|
258
|
-
throw new CliError("validation_error", "a task from a message is open, done or dismissed; todo and in_progress are for a project task");
|
|
259
256
|
const closed = isClosedState(fields.status);
|
|
260
257
|
const reopened = !closed && isClosedState(String(before.status));
|
|
261
258
|
if (before.status !== fields.status) {
|
|
@@ -297,8 +294,12 @@ export const workTaskOperationsOver = (context) => {
|
|
|
297
294
|
if (fields.category !== undefined)
|
|
298
295
|
change("category", fields.category, "category");
|
|
299
296
|
if (fields.type !== undefined && fields.type !== before.type) {
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
// The task package reads a message kind back, so a task keeps one while it stays in its inbox.
|
|
298
|
+
const found = inInbox(fields.project === undefined ? Number(before.project_id) : projectOf(fields.project));
|
|
299
|
+
const kinds = found ? TASK_KINDS : WORK_TASK_TYPES;
|
|
300
|
+
const what = `a ${found ? "found" : "project"} task's kind is one of ${kinds.join(", ")}`;
|
|
301
|
+
if (!kinds.includes(fields.type) || !onBoard(task))
|
|
302
|
+
throw new CliError("validation_error", what);
|
|
302
303
|
change("type", fields.type, "type");
|
|
303
304
|
bump = true;
|
|
304
305
|
}
|
|
@@ -578,6 +579,7 @@ export const workTaskOperationsOver = (context) => {
|
|
|
578
579
|
.all(...where.params);
|
|
579
580
|
};
|
|
580
581
|
const project = grouped("project", "p.id, p.key, p.name", "JOIN projects p ON p.id = t.project_id", "p.id")
|
|
582
|
+
.filter((row) => String(row.key).length !== INBOX_KEY_LENGTH)
|
|
581
583
|
.map((row) => ({
|
|
582
584
|
value: String(row.key),
|
|
583
585
|
ref: `project:${row.id}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.639.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|