@wirecat/cli-core 0.638.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 CHANGED
@@ -5,6 +5,21 @@ 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
+
8
23
  ## 0.638.0 — 11.11.2026
9
24
 
10
25
  ### Added
@@ -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({ project: inboxKey(taskAccount(account)), status: "open", limit: 500, ...(where ? { where } : {}) })
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")
@@ -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)), options.state ?? null, options.state ?? null, ...(options.sources ?? []), limit + 1, offset);
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) => {
@@ -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; an account's inbox is listed by its account, never here. */
22
- export declare const BOARD_SCOPE = "t.deleted_at IS NULL AND t.project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL AND length(key) <> 10)";
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: "1", params: [] };
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; an account's inbox is listed by its account, never here. */
217
- export const BOARD_SCOPE = `t.deleted_at IS NULL AND t.project_id IN (${OWNER_PROJECTS})`;
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 { BOARD_SCOPE } from "./task-board.js";
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 ? BOARD_SCOPE : ACCOUNT_SCOPE}${filter} ORDER BY t.created_at, t.id`,
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
- 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 AND ${where}`);
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: TaskFields, by: Author, check?: RevisionCheck): Promise<EditedTask>;
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
- /** The owner's project tasks, every project at once, narrowed by a query over `PROJECT_TASK_FIELDS`. */
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: TaskFields, by: Author): TaskDetails;
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
- if (!WORK_TASK_TYPES.includes(fields.type) || !onBoard(task))
301
- throw new CliError("validation_error", `a project task's kind is one of ${WORK_TASK_TYPES.join(", ")}`);
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.638.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",