@wirecat/cli-core 0.555.0 → 0.556.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/calendar/mcp/index.d.ts +12 -12
  3. package/dist/cli/config-command.js +64 -2
  4. package/dist/cli/config-issues.d.ts +2 -0
  5. package/dist/cli/config-issues.js +11 -3
  6. package/dist/cli/config-repair.d.ts +26 -0
  7. package/dist/cli/config-repair.js +252 -0
  8. package/dist/cli/messenger/store-maintenance-command.d.ts +1 -1
  9. package/dist/cli/messenger/tasks-analysis-command.d.ts +8 -0
  10. package/dist/cli/messenger/tasks-analysis-command.js +184 -0
  11. package/dist/cli/messenger/tasks-command.js +11 -2
  12. package/dist/cli/steps.js +10 -0
  13. package/dist/entities/index.d.ts +64 -2
  14. package/dist/entities/index.js +5 -2
  15. package/dist/entities/task-results.d.ts +72 -0
  16. package/dist/entities/task-results.js +40 -1
  17. package/dist/errors/reasons.d.ts +1 -1
  18. package/dist/errors/reasons.js +9 -0
  19. package/dist/mail/cli/index.d.ts +1 -0
  20. package/dist/mail/cli/index.js +3 -0
  21. package/dist/mail/cli/marks.d.ts +26 -0
  22. package/dist/mail/cli/marks.js +51 -0
  23. package/dist/mail/cli/review.js +70 -0
  24. package/dist/mail/index.d.ts +1 -0
  25. package/dist/mail/index.js +1 -0
  26. package/dist/mail/marks.d.ts +56 -0
  27. package/dist/mail/marks.js +178 -0
  28. package/dist/sends/permissions.js +1 -0
  29. package/dist/services/task-analysis.d.ts +58 -0
  30. package/dist/services/task-analysis.js +125 -0
  31. package/dist/store/exports.d.ts +2 -2
  32. package/dist/store/index.d.ts +1 -1
  33. package/dist/store/sqlite/email-activity.d.ts +31 -0
  34. package/dist/store/sqlite/email-activity.js +38 -0
  35. package/dist/store/sqlite/emails.d.ts +2 -0
  36. package/dist/store/sqlite/emails.js +1 -0
  37. package/dist/store/sqlite/task-analysis-marks.d.ts +7 -0
  38. package/dist/store/sqlite/task-analysis-marks.js +27 -0
  39. package/dist/store/sync.d.ts +5 -1
  40. package/dist/store/sync.js +4 -0
  41. package/dist/store/types.d.ts +25 -0
  42. package/package.json +1 -1
  43. package/parity.json +29 -0
  44. package/skills/follow-ups/SKILL.md +22 -2
@@ -36,7 +36,37 @@ export interface EmailMarks {
36
36
  /** The mail rule that decided how it is stored, by its id in `rules list`. */
37
37
  ruleId: number | null;
38
38
  }
39
+ /** One email as a processing mark sees it, by its store id; never its text. */
40
+ export interface MarkedEmail {
41
+ id: number;
42
+ externalId: string;
43
+ thread: string;
44
+ /** ms: received, or sent when that is unknown. */
45
+ at: number | null;
46
+ /** ms: when the store saved it first, and last changed it. */
47
+ storedAt: number;
48
+ changedAt: number;
49
+ /** Sent to many: the bulk mailbox or a List-Id. */
50
+ bulk: boolean;
51
+ envelope: boolean;
52
+ /** Stored from its first bytes, not whole yet. */
53
+ partial: boolean;
54
+ draft: boolean;
55
+ }
39
56
  export interface MailActivityStore {
57
+ /**
58
+ * The account's live emails stored after `afterId`, oldest first, at most `limit`, and those of `ids`: what a
59
+ * processing mark reads next. The id is the store's insert order, so mail stored late is never behind the mark.
60
+ */
61
+ emailsAfter(accountId: number, afterId: number, limit: number, ids?: readonly number[]): Promise<MarkedEmail[]>;
62
+ /** The account's newest store id; 0 with no mail. */
63
+ newestEmailId(accountId: number): Promise<number>;
64
+ /** Every `sync_cursors` value of the account whose key starts with `prefix`. */
65
+ statesLike(accountId: number, prefix: string): Promise<{
66
+ key: string;
67
+ value: string;
68
+ at: number;
69
+ }[]>;
40
70
  /** Each live email's marks, by its Message-ID; one the store does not hold is left out. */
41
71
  emailMarks(accountId: number, externalIds: readonly string[]): Promise<Map<string, EmailMarks>>;
42
72
  /**
@@ -59,4 +89,5 @@ export declare const threadEmailIds: (database: CacheDatabase, accountId: number
59
89
  until?: number;
60
90
  }) => number[];
61
91
  export declare const emailMarks: (database: CacheDatabase, accountId: number, externalIds: readonly string[]) => Map<string, EmailMarks>;
92
+ export declare const emailsAfter: (database: CacheDatabase, accountId: number, afterId: number, limit: number, ids?: readonly number[]) => MarkedEmail[];
62
93
  export declare const mailActivity: (database: CacheDatabase) => MailActivityStore;
@@ -65,7 +65,45 @@ export const emailMarks = (database, accountId, externalIds) => {
65
65
  }
66
66
  return marks;
67
67
  };
68
+ const MARKED = `
69
+ SELECT e.id, e.external_id, t.external_id AS thread, coalesce(e.received_at, e.sent_at) AS at, e.created_at,
70
+ e.updated_at, coalesce(e.draft, 0) AS draft, json_extract(e.metadata, '$.partial') IS NOT NULL AS partial,
71
+ coalesce(json_extract(e.headers, '$."list-id"'), json_extract(e.metadata, '$.listId')) IS NOT NULL
72
+ OR EXISTS (SELECT 1 FROM email_mailboxes m JOIN mailboxes b ON b.id = m.mailbox_id
73
+ WHERE m.email_id = e.id AND b.kind = 'bulk') AS bulk,
74
+ EXISTS (SELECT 1 FROM email_mailboxes m JOIN mailboxes b ON b.id = m.mailbox_id
75
+ WHERE m.email_id = e.id AND b.kind = 'envelope') AS envelope
76
+ FROM emails e JOIN email_threads t ON t.id = e.email_thread_id`;
77
+ const markedOf = (row) => ({
78
+ id: Number(row.id),
79
+ externalId: String(row.external_id),
80
+ thread: String(row.thread),
81
+ at: int(row.at),
82
+ storedAt: Number(row.created_at),
83
+ changedAt: Number(row.updated_at),
84
+ bulk: Boolean(row.bulk),
85
+ envelope: Boolean(row.envelope),
86
+ partial: Boolean(row.partial),
87
+ draft: Boolean(row.draft),
88
+ });
89
+ export const emailsAfter = (database, accountId, afterId, limit, ids = []) => {
90
+ const next = database
91
+ .prepare(`${MARKED} WHERE e.id > ? AND e.account_id = ? AND e.deleted_at IS NULL ORDER BY e.id LIMIT ?`)
92
+ .all(afterId, accountId, limit);
93
+ const one = database.prepare(`${MARKED} WHERE e.id = ? AND e.account_id = ? AND e.deleted_at IS NULL`);
94
+ const named = ids.flatMap((id) => {
95
+ const row = one.get(id, accountId);
96
+ return row ? [row] : [];
97
+ });
98
+ return [...named, ...next].map(markedOf);
99
+ };
68
100
  export const mailActivity = (database) => ({
101
+ emailsAfter: async (accountId, afterId, limit, ids) => emailsAfter(database, accountId, afterId, limit, ids),
102
+ newestEmailId: async (accountId) => Number(database.prepare("SELECT max(id) AS id FROM emails WHERE account_id = ?").get(accountId)?.id ?? 0),
103
+ statesLike: async (accountId, prefix) => database
104
+ .prepare("SELECT key, value, updated_at FROM sync_cursors WHERE account_id = ? AND substr(key, 1, ?) = ?")
105
+ .all(accountId, prefix.length, prefix)
106
+ .map((row) => ({ key: String(row.key), value: String(row.value), at: Number(row.updated_at) })),
69
107
  emailMarks: async (accountId, externalIds) => emailMarks(database, accountId, externalIds),
70
108
  threadActivity: async (accountId, since, where) => threadActivity(database, accountId, since, where),
71
109
  });
@@ -269,6 +269,8 @@ export interface MailStore extends PartialMailStore, MailActivityStore {
269
269
  }[]>;
270
270
  /** Live emails of one account by Message-ID, each placed in its thread; an unknown one is left out. */
271
271
  inThreads(accountId: number, externalIds: string[]): Promise<EmailInThread[]>;
272
+ /** Emails by store id, as search hits in the order given; one the store does not hold is left out. */
273
+ emailHits(ids: readonly number[]): Promise<StoredHit[]>;
272
274
  /** A thread's live emails, oldest first, as search hits; `window` keeps those received in (after, until], in ms. */
273
275
  threadHits(accountId: number, thread: string, window?: {
274
276
  after?: number;
@@ -633,6 +633,7 @@ export const mailStoreOver = ({ database, orm, now }, stemmerFor = stemmerCache(
633
633
  return place ? [{ ...place, score }] : [];
634
634
  });
635
635
  },
636
+ emailHits: async (ids) => emailHitsByPk(database, [...ids]),
636
637
  async threadHits(accountId, thread, window) {
637
638
  return emailHitsByPk(database, threadEmailIds(database, accountId, thread, window));
638
639
  },
@@ -0,0 +1,7 @@
1
+ import type { Id } from "../../domain/models.js";
2
+ import type { CacheDatabase } from "../driver.js";
3
+ import type { AccountKey, TaskAnalysisMark, TaskAnalysisMarkWrite } from "../types.js";
4
+ export declare const taskAnalysisMarks: (database: CacheDatabase, account: AccountKey) => TaskAnalysisMark[];
5
+ export declare const taskAnalysisMark: (database: CacheDatabase, account: AccountKey, chatId: Id) => TaskAnalysisMark | undefined;
6
+ /** `checked`: the whole stretch through `checkedThrough` was read just now, by this store's clock. */
7
+ export declare const setTaskAnalysisMark: (database: CacheDatabase, account: AccountKey, { chatId, checked, ...saved }: TaskAnalysisMarkWrite, now: number) => void;
@@ -0,0 +1,27 @@
1
+ // In store_settings beside task_rules_until, so backup and restore carry it and it needs no migration.
2
+ const prefixOf = ({ provider, account }) => `task_analysis:${provider}:${account}:`;
3
+ const markOf = (prefix, row) => ({
4
+ chatId: String(row.key).slice(prefix.length),
5
+ ...JSON.parse(String(row.value)),
6
+ at: new Date(Number(row.at)).toISOString(),
7
+ });
8
+ export const taskAnalysisMarks = (database, account) => {
9
+ const prefix = prefixOf(account);
10
+ return database
11
+ .prepare("SELECT key, value, at FROM store_settings WHERE substr(key, 1, ?) = ? ORDER BY at DESC")
12
+ .all(prefix.length, prefix)
13
+ .map((row) => markOf(prefix, row));
14
+ };
15
+ export const taskAnalysisMark = (database, account, chatId) => {
16
+ const prefix = prefixOf(account);
17
+ const row = database.prepare("SELECT key, value, at FROM store_settings WHERE key = ?").get(prefix + chatId);
18
+ return row ? markOf(prefix, row) : undefined;
19
+ };
20
+ /** `checked`: the whole stretch through `checkedThrough` was read just now, by this store's clock. */
21
+ export const setTaskAnalysisMark = (database, account, { chatId, checked, ...saved }, now) => {
22
+ const checkedAt = checked ? new Date(now).toISOString() : taskAnalysisMark(database, account, chatId)?.checkedAt;
23
+ database
24
+ .prepare("INSERT INTO store_settings (key, value, at) VALUES (?, ?, ?) " +
25
+ "ON CONFLICT (key) DO UPDATE SET value = excluded.value, at = excluded.at")
26
+ .run(prefixOf(account) + chatId, JSON.stringify({ ...saved, checkedAt: checkedAt ?? new Date(now).toISOString() }), now);
27
+ };
@@ -1,6 +1,6 @@
1
1
  import type { Id } from "../domain/models.js";
2
2
  import type { StoreContext } from "./sqlite/open.js";
3
- import type { AccountKey, Delta, Range } from "./types.js";
3
+ import type { AccountKey, Delta, Range, TaskAnalysisMark, TaskAnalysisMarkWrite } from "./types.js";
4
4
  export interface SyncStore {
5
5
  /** What a sync remembered under `name` for this account, and when; a caller encodes a number itself. */
6
6
  syncState(key: AccountKey, name: string): Promise<{
@@ -31,5 +31,9 @@ export interface SyncStore {
31
31
  /** Where the account's last task-rule pass stopped: the newest store time it read. */
32
32
  taskRulesStop(key: AccountKey): Promise<string | null>;
33
33
  setTaskRulesStop(key: AccountKey, until: string): Promise<void>;
34
+ /** Every chat of the account read for tasks, the latest moved first. */
35
+ taskAnalysisMarks(key: AccountKey): Promise<TaskAnalysisMark[]>;
36
+ taskAnalysisMark(key: AccountKey, chatId: Id): Promise<TaskAnalysisMark | undefined>;
37
+ setTaskAnalysisMark(key: AccountKey, mark: TaskAnalysisMarkWrite): Promise<void>;
34
38
  }
35
39
  export declare const syncStoreOver: (context: StoreContext) => SyncStore;
@@ -2,6 +2,7 @@ import { keysOver } from "./keys.js";
2
2
  import * as chatQueries from "./sqlite/chats.js";
3
3
  import * as ranges from "./sqlite/ranges.js";
4
4
  import * as sync from "./sqlite/sync.js";
5
+ import { setTaskAnalysisMark, taskAnalysisMark, taskAnalysisMarks } from "./sqlite/task-analysis-marks.js";
5
6
  import { setTaskRulesStop, taskRulesStop } from "./sqlite/task-rule-stops.js";
6
7
  import { write } from "./sqlite/transaction.js";
7
8
  export const syncStoreOver = (context) => {
@@ -56,5 +57,8 @@ export const syncStoreOver = (context) => {
56
57
  },
57
58
  taskRulesStop: async (key) => taskRulesStop(database, key),
58
59
  setTaskRulesStop: async (key, until) => setTaskRulesStop(database, key, until, context.now()),
60
+ taskAnalysisMarks: async (key) => taskAnalysisMarks(database, key),
61
+ taskAnalysisMark: async (key, chatId) => taskAnalysisMark(database, key, chatId),
62
+ setTaskAnalysisMark: async (key, mark) => setTaskAnalysisMark(database, key, mark, context.now()),
59
63
  };
60
64
  };
@@ -251,3 +251,28 @@ export interface Range {
251
251
  from: number;
252
252
  to: number;
253
253
  }
254
+ /**
255
+ * How far a chat's messages were read for tasks: every stored message sent from `from` through `through`, the one
256
+ * with id `throughId` last. Its own point, so reading a chat, marking it read or another reader's `--new` never
257
+ * moves it.
258
+ */
259
+ export interface TaskAnalysisMark {
260
+ chatId: Id;
261
+ from: string;
262
+ through: string;
263
+ throughId: Id;
264
+ /** Who moved it last: an agent's name or the owner. */
265
+ by: string;
266
+ /**
267
+ * At `checkedAt` every stored message sent from `from` through `checkedThrough` had been read; one saved or edited
268
+ * later inside that stretch (history fetched afterwards) was not.
269
+ */
270
+ checkedAt: string;
271
+ checkedThrough: string;
272
+ /** When it last moved. */
273
+ at: string;
274
+ }
275
+ /** `checked` stamps `checkedAt` with the store's clock; otherwise the mark keeps its earlier one. */
276
+ export type TaskAnalysisMarkWrite = Omit<TaskAnalysisMark, "at" | "checkedAt"> & {
277
+ checked: boolean;
278
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.555.0",
3
+ "version": "0.556.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",
package/parity.json CHANGED
@@ -735,6 +735,9 @@
735
735
  "value": "<on|off>",
736
736
  "meaning": "only the owner may change the name and photo"
737
737
  },
738
+ "--open-new": {
739
+ "meaning": "open a task from a message the chat's task point already passed; without it a read again only updates and closes tasks"
740
+ },
738
741
  "--operation-id": {
739
742
  "value": "<id>",
740
743
  "meaning": "identify a send or creation attempt; message/poll retries reuse it, while an unknown topic creation must never be repeated"
@@ -2763,6 +2766,12 @@
2763
2766
  "config": {
2764
2767
  "in": "all"
2765
2768
  },
2769
+ "config repair": {
2770
+ "in": "all",
2771
+ "options": {
2772
+ "--dry-run": "all"
2773
+ }
2774
+ },
2766
2775
  "config set": {
2767
2776
  "in": "all",
2768
2777
  "options": {
@@ -4816,6 +4825,12 @@
4816
4825
  "tasks": {
4817
4826
  "in": "all"
4818
4827
  },
4828
+ "tasks acknowledge": {
4829
+ "in": "all",
4830
+ "options": {
4831
+ "--since-time": "all"
4832
+ }
4833
+ },
4819
4834
  "tasks add": {
4820
4835
  "in": "all",
4821
4836
  "options": {
@@ -4825,6 +4840,7 @@
4825
4840
  "--due": "all",
4826
4841
  "--into": "all",
4827
4842
  "--new": "all",
4843
+ "--open-new": "all",
4828
4844
  "--remind-time": "all",
4829
4845
  "--title": "all",
4830
4846
  "--type": {
@@ -4931,6 +4947,13 @@
4931
4947
  "--holder": "all"
4932
4948
  }
4933
4949
  },
4950
+ "tasks review": {
4951
+ "in": "all",
4952
+ "options": {
4953
+ "--limit": "all",
4954
+ "--since-time": "all"
4955
+ }
4956
+ },
4934
4957
  "tasks scan": {
4935
4958
  "in": "all",
4936
4959
  "options": {
@@ -4940,6 +4963,12 @@
4940
4963
  "tasks show": {
4941
4964
  "in": "all"
4942
4965
  },
4966
+ "tasks status": {
4967
+ "in": "all",
4968
+ "options": {
4969
+ "--limit": "all"
4970
+ }
4971
+ },
4943
4972
  "tasks unmerge": {
4944
4973
  "in": "all"
4945
4974
  },
@@ -38,6 +38,26 @@ no message text — read all of it:
38
38
 
39
39
  Anything not on the agenda waits for its own date. Do not open it.
40
40
 
41
+ **Every chat keeps its own point of reading for tasks.** `review --new`, `inbox`, the owner reading on the phone
42
+ and other agents all move their own points, so a message they showed is not yet read for tasks. Work from the
43
+ task point instead:
44
+
45
+ ```sh
46
+ {{command}} tasks status --json # per chat: read for tasks through when, how many wait, how many came late
47
+ {{command}} tasks review "<chat>" --json # the messages after the point, oldest first, and the chat's open tasks
48
+ {{command}} tasks acknowledge "<chat>" <message id> # after its tasks are opened, updated or closed: the next review starts after it
49
+ ```
50
+
51
+ For each chat with `waiting` above 0: `tasks review`, then open new tasks, update or close the listed `open_tasks`
52
+ the new messages settle, then run the `next` step the answer gives (`tasks acknowledge`). Acknowledge only what you
53
+ finished; a page with `has_more: true` is followed by the next one. A chat with `late` above 0 got older history
54
+ after it was read: `tasks review "<chat>" --since-time <mark.from>` reads the stretch again (up to 1000 messages),
55
+ and acknowledging that read clears it. A read again only updates and closes tasks: `tasks add` refuses a message the
56
+ point already passed (`task.already-read`) unless it is given `--open-new`, which you pass only when the owner asked
57
+ for tasks from that history. When that answer has `has_more: true` it gives no acknowledge step: the stretch
58
+ is too long to read again in one page, so tell the owner and move on. A chat whose history is not stored yet is fetched by `messages sync` first; `tasks review` reads
59
+ only the store.
60
+
41
61
  **History is not work.** A first sync opens no tasks from old messages (`task_first_pass_per_chat`, 0 by
42
62
  default) and says how many it held. Do not read old chats looking for tasks. Ask the owner which chats to build,
43
63
  then for each: `{{command}} tasks scan "<chat>" --json` lists what would open, and `--yes` opens it. Dig deeper
@@ -103,7 +123,7 @@ stop. The owner sends what they choose.
103
123
 
104
124
  `{{command}} schedule agent follow-ups claude "<prompt>" --at 08:30` runs this every morning. Then you run
105
125
  with the CLI's read-only variable set (`MAX_READ_ONLY=1` for max). The task work above still runs: `tasks scan --yes`,
106
- `add`, `plan`, `link`, `merge`, `unmerge`, `duplicates reject`, `duplicates defer`, `claim`, `release` and `close`
126
+ `acknowledge`, `add`, `plan`, `link`, `merge`, `unmerge`, `duplicates reject`, `duplicates defer`, `claim`, `release` and `close`
107
127
  — but every `tasks close` then waits on the owner as a suggestion, whatever your certainty, and `--as-owner` is
108
128
  refused. Everything else that writes is refused, so do not try: every send, reaction and edit; changes to schedules,
109
129
  settings, the recipient list or auto-replies; tags, contact notes and aliases, saved searches, `tasks reject`. What you print is the report the owner opens; its first line shows in the desktop
@@ -115,7 +135,7 @@ A recipe is a set of flags, not a new command:
115
135
 
116
136
  | Recipe | Command |
117
137
  |---|---|
118
- | Morning sweep | `review --new --json`, then `tasks agenda --json` |
138
+ | Morning sweep | `review --new --json`, then `tasks agenda --json`, then `tasks status --json` and a `tasks review` per waiting chat |
119
139
  | Weekly quiet-chat pass | `tasks agenda --waiting 3d --within 90d --json` |
120
140
  | Groups too, not only people | `tasks agenda "chat_kind:(dialog OR group OR channel)" --json` |
121
141
  | Before a call with someone | `tasks list 'chat:"<chat>" state:open' --json`, then `tasks show` each |