@wirecat/cli-core 0.576.0 → 0.578.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 (45) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/dist/cli/compact.d.ts +2 -0
  3. package/dist/cli/compact.js +1 -1
  4. package/dist/cli/findings-input.js +2 -0
  5. package/dist/cli/messenger/projects-command.js +2 -0
  6. package/dist/cli/messenger/tasks-command.js +2 -0
  7. package/dist/cli/project-status-rows.d.ts +4 -2
  8. package/dist/cli/project-status-rows.js +13 -29
  9. package/dist/cli/project-status.d.ts +59 -16
  10. package/dist/cli/project-status.js +101 -42
  11. package/dist/domain/external-links.d.ts +13 -0
  12. package/dist/domain/external-links.js +30 -0
  13. package/dist/entities/index.d.ts +15 -0
  14. package/dist/entities/mail-findings.d.ts +6 -0
  15. package/dist/entities/mail-findings.js +6 -0
  16. package/dist/entities/task-results.d.ts +20 -0
  17. package/dist/entities/task-results.js +4 -0
  18. package/dist/entities/task.d.ts +4 -0
  19. package/dist/entities/task.js +4 -0
  20. package/dist/errors/reasons.js +5 -0
  21. package/dist/mail/cli/index.js +2 -1
  22. package/dist/mail/cli/marks.d.ts +6 -0
  23. package/dist/mail/cli/marks.js +69 -1
  24. package/dist/mail/findings.d.ts +2 -0
  25. package/dist/mail/findings.js +15 -1
  26. package/dist/mail/index.d.ts +1 -1
  27. package/dist/mail/index.js +1 -1
  28. package/dist/mail/marks.d.ts +29 -0
  29. package/dist/mail/marks.js +86 -0
  30. package/dist/meetings/findings-rules.d.ts +4 -0
  31. package/dist/services/project-status/signals/index.js +0 -2
  32. package/dist/store/sqlite/email-activity.d.ts +2 -0
  33. package/dist/store/sqlite/email-activity.js +4 -0
  34. package/dist/store/sqlite/findings-core.js +2 -0
  35. package/dist/store/sqlite/manifest.js +1 -0
  36. package/dist/store/sqlite/migrations.generated.js +10 -0
  37. package/dist/store/sqlite/orders.d.ts +4 -0
  38. package/dist/store/sqlite/orders.js +6 -3
  39. package/dist/store/sqlite/schema.d.ts +64 -0
  40. package/dist/store/sqlite/schema.js +5 -0
  41. package/dist/store/sqlite/work-tasks.d.ts +7 -0
  42. package/dist/store/sqlite/work-tasks.js +10 -0
  43. package/package.json +1 -1
  44. package/dist/services/project-status/signals/last-message.d.ts +0 -4
  45. package/dist/services/project-status/signals/last-message.js +0 -22
package/CHANGELOG.md CHANGED
@@ -5,7 +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
- ## Unreleased
8
+ ## 0.577.0 — 05.11.2026
9
+
10
+ ### Added
11
+
12
+ - **Tasks keep their id in an outside service and the page they are about (store version 51).** `tasks.provider`
13
+ and `tasks.external_id` hold a task's id in a service such as Avito, Cian or hh.ru, given and shown as
14
+ `<service>:<id>` (`avito:4512345678`), so ids of two services never collide; several tasks may share one.
15
+ `tasks.source_url` and `orders.source_url` hold the http or https page a task or an order is about, such as an Avito
16
+ ad or an Amazon order; anything else is refused (`task.source-url`, `order.source-url`, `task.external-id`).
17
+ `TaskFields.externalId` and `sourceUrl` set them on create and edit, `null` clears them; `TaskDetails` and the
18
+ `task` entity carry `external_id` and `source_url`; `OrderInput` and `Order` carry `sourceUrl`. Mail findings take
19
+ `external_id` and `source_url` on a `task` and `source_url` on an `order`, and accepting keeps them. `minCompatible`
20
+ stays 34.
21
+ - **The owner moves a holder's mail mark back: `messages reset`.** `--holder <name>` with `--since-time <time>` or
22
+ `--last <n>`, and `--dry-run` to count first; the answer (`mail_mark_reset`) says how many emails the holder reads
23
+ whole again, how many bulk ones come again as excerpts and how many are skipped again. It is owner only: no
24
+ proposal, refused under the read-only lock, for a scheduled holder and for an agent (`mail.reset-owner-only`); a
25
+ holder with no mark yet is `mail.no-mark`. `rewindMark` is the function under it, and `MailActivityStore` gets
26
+ `emailsBefore`.
27
+
28
+ ### Changed — may break callers
29
+
30
+ - **`projects status` fits 4 KB of JSON and 1.5 KB compact on the status fixture (was 11.2 KB and 3.6 KB).** Most of
31
+ it was rows the owner would not call status. Each chat's row now carries what is said once per chat: `last` (the
32
+ newest message's ref, time and sender), `next`, `waiting_since`, `addressed`, `overdue`, and for a chat held in part
33
+ `held` and `sync_command`; the `last_message`, `reply_next` and `coverage` lists are gone, and the `last-message`
34
+ signal with them (reply-next already cites the newest message). Others' questions in a group with no role, and
35
+ others' promises found by words in a group or past the newest one per chat, are counted on the chat's row under
36
+ `unlisted` instead of listed. A listed item drops `signal` and `chat_title`, keeps `evidence` (now plain refs) only
37
+ when it cites more than `ref`, and `who` only when set. `signals` is `{ id: version }`; a chat row leaves out
38
+ `purpose` when one purpose was read, `project` when it is the root, and `attention` when it is 0. `--compact` leaves
39
+ out `project`, `window`, `purposes` and `signals` (new `RowShape.hidden`). The human form is unchanged.
9
40
 
10
41
  ## 0.576.0 — 05.11.2026
11
42
 
@@ -20,6 +20,8 @@ export interface RowShape {
20
20
  sections?: Readonly<Record<string, string>>;
21
21
  /** An item answer's fields printed whole, never cut: a cursor that is pasted back. */
22
22
  whole?: readonly string[];
23
+ /** An item answer's fields left out: bookkeeping an agent reads in `--json` if it ever needs it. */
24
+ hidden?: readonly string[];
23
25
  }
24
26
  export interface CompactOptions {
25
27
  /** IANA zone for times; the answer's `meta.timezone` wins. */
@@ -357,7 +357,7 @@ export const compactText = (body, shape, options, rowsOf = rowsOfEntity()) => {
357
357
  }
358
358
  else if (isFields(body.item)) {
359
359
  const sections = shape.sections ?? {};
360
- const rest = Object.fromEntries(Object.entries(body.item).filter(([name]) => !Object.hasOwn(sections, name)));
360
+ const rest = Object.fromEntries(Object.entries(body.item).filter(([name]) => !Object.hasOwn(sections, name) && !shape.hidden?.includes(name)));
361
361
  lines = blockOf(rest, chars, "", shape.whole).map(guarded);
362
362
  for (const [name, entity] of Object.entries(sections)) {
363
363
  const list = body.item[name];
@@ -14,6 +14,8 @@ const keys = {
14
14
  supplier_name: "supplierName",
15
15
  order_date: "orderDate",
16
16
  fulfilled_date: "fulfilledDate",
17
+ external_id: "externalId",
18
+ source_url: "sourceUrl",
17
19
  };
18
20
  const parseFindingsJson = (text, label, validate) => {
19
21
  if (Buffer.byteLength(text, "utf8") > 65536)
@@ -161,6 +161,8 @@ const statusCommand = (messenger) => answerEntity(annotate(new Command("status")
161
161
  "who replies next, open questions both ways, promises, amounts with their direction, payments recorded, " +
162
162
  "how long each --context-query has been quiet on their side, and how much of the chat is held. Amounts, " +
163
163
  "directions and promises found by words are marked pattern: read the cited message before trusting one. " +
164
+ "Others' questions in a group with no role, and others' word-found promises in a group, are counted on " +
165
+ "the chat's row as unlisted, not listed. " +
164
166
  "Only this profile's account is read; the other linked chats are named, and memo projects status reads them")
165
167
  .argument("<project>", "an existing project's id, key, exact name or alias")
166
168
  .option("--since-time <time>", "how far back: days (60d, at most 730d) or a start date (2026-09-01)", "60d")
@@ -41,6 +41,8 @@ const card = (task) => [
41
41
  `due ${when(task.dueAt)} next check ${when(task.nextCheckAt)} source ${task.source ?? "—"}`,
42
42
  ...(task.priorityLabel === null ? [] : [`priority ${task.priorityLabel}`]),
43
43
  ...(task.agent === null ? [] : [`agent ${task.agent}`]),
44
+ ...(task.externalId === null ? [] : [`external id ${task.externalId}`]),
45
+ ...(task.sourceUrl === null ? [] : [`page ${task.sourceUrl}`]),
44
46
  ...(task.claimedBy === null ? [] : [`claimed by ${task.claimedBy} until ${when(task.claimedUntil)}`]),
45
47
  ...task.assignments.filter((one) => one.role === "assignee").map((one) => `assignee ${one.to}`),
46
48
  ...(task.closeSuggestion === null ? [] : [suggestionLine(task.closeSuggestion)]),
@@ -1,7 +1,9 @@
1
1
  import type { RowShape } from "./compact.js";
2
+ /** Signals of one item per chat, drawn on the chat's row rather than as a list of their own. */
3
+ export declare const ON_CHAT_ROW: ReadonlySet<string>;
2
4
  /**
3
- * The compact row of each status signal's items, by `status.<signal id>`; a signal's file and its row are the two
4
- * places a new signal touches. They live here because a service may not import the CLI's row type.
5
+ * The compact row of each listed status signal's items, by `status.<signal id>`; a signal's file and its row are the
6
+ * two places a new signal touches. They live here because a service may not import the CLI's row type.
5
7
  */
6
8
  export declare const STATUS_SIGNAL_ROWS: Readonly<Record<string, RowShape>>;
7
9
  /** The rest of a `project_status` answer: its chats, open money, chats left out, and failed signals. */
@@ -1,22 +1,14 @@
1
- const where = [{ field: "ref" }, { field: ["chat_title", "chat"] }];
1
+ const where = [{ field: "ref" }];
2
2
  const who = { field: ["who.owner", "who.name"], tag: "you" };
3
+ /** Signals of one item per chat, drawn on the chat's row rather than as a list of their own. */
4
+ export const ON_CHAT_ROW = new Set(["reply-next", "coverage"]);
3
5
  /**
4
- * The compact row of each status signal's items, by `status.<signal id>`; a signal's file and its row are the two
5
- * places a new signal touches. They live here because a service may not import the CLI's row type.
6
+ * The compact row of each listed status signal's items, by `status.<signal id>`; a signal's file and its row are the
7
+ * two places a new signal touches. They live here because a service may not import the CLI's row type.
6
8
  */
7
9
  export const STATUS_SIGNAL_ROWS = {
8
- "status.last-message": { columns: [...where, { field: "at", as: "time" }, who] },
9
- "status.reply-next": {
10
- columns: [
11
- ...where,
12
- { field: "data.next" },
13
- { field: "data.addressed.name" },
14
- { field: "data.waiting_since", as: "day" },
15
- { field: "data.overdue", tag: "overdue" },
16
- ],
17
- },
18
10
  "status.questions": {
19
- columns: [...where, { field: "at", as: "day" }, { field: "data.side" }, who],
11
+ columns: [...where, { field: "at", as: "day" }, who],
20
12
  text: ["data.excerpt"],
21
13
  },
22
14
  "status.promises": {
@@ -50,21 +42,10 @@ export const STATUS_SIGNAL_ROWS = {
50
42
  columns: [
51
43
  ...where,
52
44
  { field: "data.query" },
53
- { field: "data.theirs_last", as: "day" },
54
45
  { field: "data.yours_last", as: "day" },
55
46
  { field: "data.silent_since", as: "day" },
56
47
  ],
57
48
  },
58
- "status.coverage": {
59
- columns: [
60
- { field: "chat" },
61
- { field: "chat_title" },
62
- { field: "data.state" },
63
- { field: "data.held.messages", as: "count", tag: "held" },
64
- { field: "data.held.oldest_at", as: "day" },
65
- { field: "sync_command" },
66
- ],
67
- },
68
49
  "status.children": {
69
50
  columns: [
70
51
  { field: "data.child" },
@@ -82,10 +63,14 @@ export const STATUS_ROWS = {
82
63
  columns: [
83
64
  { field: "chat" },
84
65
  { field: "title" },
85
- { field: "kind" },
86
66
  { field: "role" },
87
- { field: "attention", as: "count", tag: "attention" },
88
- { field: "why" },
67
+ { field: "next", prefix: "next" },
68
+ { field: "addressed.name" },
69
+ { field: "waiting_since", as: "day" },
70
+ { field: "overdue", tag: "overdue" },
71
+ { field: "held.messages", as: "count", tag: "held" },
72
+ { field: "unlisted.questions", as: "count", tag: "questions unlisted" },
73
+ { field: "unlisted.promises", as: "count", tag: "promises unlisted" },
89
74
  ],
90
75
  },
91
76
  "status.money": {
@@ -96,7 +81,6 @@ export const STATUS_ROWS = {
96
81
  { field: "rows", as: "count", tag: "rows" },
97
82
  ],
98
83
  },
99
- "status.signal": { columns: [{ field: "id" }, { field: "version" }] },
100
84
  "status.out-of-scope": {
101
85
  columns: [
102
86
  { field: "chat" },
@@ -18,7 +18,7 @@ export interface ProjectStatusHints {
18
18
  chatId: Id;
19
19
  }, since: string) => NextStep | null;
20
20
  }
21
- /** The `project_status` answer drawn by `--compact`: each signal's list with that signal's row. */
21
+ /** The `project_status` answer drawn by `--compact`: a row per chat, then each listed signal with its own row. */
22
22
  export declare const projectStatusRow: (signals: readonly {
23
23
  id: string;
24
24
  }[]) => RowShape;
@@ -31,10 +31,8 @@ export declare const projectStatusSchema: v.LooseObjectSchema<{
31
31
  readonly since: v.StringSchema<undefined>;
32
32
  readonly until: v.StringSchema<undefined>;
33
33
  }, undefined>;
34
- readonly signals: v.ArraySchema<v.StrictObjectSchema<{
35
- readonly id: v.StringSchema<undefined>;
36
- readonly version: v.NumberSchema<undefined>;
37
- }, undefined>, undefined>;
34
+ /** Each signal's version, so a saved answer says which rules made it. */
35
+ readonly signals: v.RecordSchema<v.StringSchema<undefined>, v.NumberSchema<undefined>, undefined>;
38
36
  readonly money: v.ArraySchema<v.StrictObjectSchema<{
39
37
  readonly direction: v.StringSchema<undefined>;
40
38
  readonly currency: v.NullableSchema<v.StringSchema<undefined>, undefined>;
@@ -46,11 +44,33 @@ export declare const projectStatusSchema: v.LooseObjectSchema<{
46
44
  readonly title: v.NullableSchema<v.StringSchema<undefined>, undefined>;
47
45
  readonly kind: v.StringSchema<undefined>;
48
46
  readonly role: v.NullableSchema<v.StringSchema<undefined>, undefined>;
49
- readonly purpose: v.StringSchema<undefined>;
50
- readonly project: v.StringSchema<undefined>;
47
+ readonly purpose: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
48
+ readonly project: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
51
49
  readonly coverage: v.StringSchema<undefined>;
52
- readonly attention: v.NumberSchema<undefined>;
53
- readonly why: v.NullableSchema<v.StringSchema<undefined>, undefined>;
50
+ readonly attention: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
51
+ readonly why: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
52
+ readonly last: v.OptionalSchema<v.StrictObjectSchema<{
53
+ readonly ref: v.StringSchema<undefined>;
54
+ readonly at: v.StringSchema<undefined>;
55
+ readonly who: v.StrictObjectSchema<{
56
+ readonly ref: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
57
+ readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
58
+ readonly owner: v.BooleanSchema<undefined>;
59
+ }, undefined>;
60
+ }, undefined>, undefined>;
61
+ readonly next: v.OptionalSchema<v.PicklistSchema<["owner", "them", "named", "nobody"], undefined>, undefined>;
62
+ readonly waiting_since: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
63
+ readonly addressed: v.OptionalSchema<v.StrictObjectSchema<{
64
+ readonly ref: v.NullableSchema<v.StringSchema<undefined>, undefined>;
65
+ readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
66
+ }, undefined>, undefined>;
67
+ readonly overdue: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
68
+ readonly held: v.OptionalSchema<v.StrictObjectSchema<{
69
+ readonly messages: v.NumberSchema<undefined>;
70
+ readonly oldest_at: v.NullableSchema<v.StringSchema<undefined>, undefined>;
71
+ }, undefined>, undefined>;
72
+ readonly sync_command: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
73
+ readonly unlisted: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.NumberSchema<undefined>, undefined>, undefined>;
54
74
  }, undefined>, undefined>;
55
75
  readonly purposes: v.UnionSchema<[v.LiteralSchema<"all", undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>;
56
76
  readonly out_of_scope: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
@@ -85,9 +105,8 @@ export declare const projectStatusAnswer: (found: ProjectStatus, hints: ProjectS
85
105
  until: string;
86
106
  };
87
107
  signals: {
88
- id: string;
89
- version: number;
90
- }[];
108
+ [x: string]: number;
109
+ };
91
110
  money: {
92
111
  direction: string;
93
112
  currency: string | null;
@@ -99,11 +118,35 @@ export declare const projectStatusAnswer: (found: ProjectStatus, hints: ProjectS
99
118
  title: string | null;
100
119
  kind: string;
101
120
  role: string | null;
102
- purpose: string;
103
- project: string;
121
+ purpose?: string | undefined;
122
+ project?: string | undefined;
104
123
  coverage: string;
105
- attention: number;
106
- why: string | null;
124
+ attention?: number | undefined;
125
+ why?: string | undefined;
126
+ last?: {
127
+ ref: string;
128
+ at: string;
129
+ who: {
130
+ ref?: string | undefined;
131
+ name: string | null;
132
+ owner: boolean;
133
+ };
134
+ } | undefined;
135
+ next?: "named" | "nobody" | "owner" | "them" | undefined;
136
+ waiting_since?: string | null | undefined;
137
+ addressed?: {
138
+ ref: string | null;
139
+ name: string | null;
140
+ } | undefined;
141
+ overdue?: boolean | undefined;
142
+ held?: {
143
+ messages: number;
144
+ oldest_at: string | null;
145
+ } | undefined;
146
+ sync_command?: string | null | undefined;
147
+ unlisted?: {
148
+ [x: string]: number;
149
+ } | undefined;
107
150
  }[];
108
151
  purposes: "all" | string[];
109
152
  out_of_scope?: {
@@ -1,32 +1,32 @@
1
1
  import * as v from "valibot";
2
2
  import { snakeKeys } from "./envelope.js";
3
3
  import { heldPhrase } from "./messenger/search-answers.js";
4
- import { STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
4
+ import { ON_CHAT_ROW, STATUS_SIGNAL_ROWS } from "./project-status-rows.js";
5
5
  const day = (at) => new Date(at).toISOString().slice(0, 10);
6
6
  const listKey = (signal) => signal.replaceAll("-", "_");
7
7
  const SECTIONS = {
8
- signals: "status.signal",
9
8
  money: "status.money",
10
9
  chats: "status.chat",
11
10
  out_of_scope: "status.out-of-scope",
12
11
  failed: "status.failed",
13
12
  };
14
- /** The `project_status` answer drawn by `--compact`: each signal's list with that signal's row. */
13
+ /** The `project_status` answer drawn by `--compact`: a row per chat, then each listed signal with its own row. */
15
14
  export const projectStatusRow = (signals) => ({
16
15
  columns: [],
16
+ hidden: ["project", "window", "purposes", "signals"],
17
17
  sections: {
18
18
  ...SECTIONS,
19
- ...Object.fromEntries(signals.map(({ id }) => [listKey(id), `status.${id}`])),
19
+ ...Object.fromEntries(signals.flatMap(({ id }) => (ON_CHAT_ROW.has(id) ? [] : [[listKey(id), `status.${id}`]]))),
20
20
  },
21
21
  });
22
+ const who = v.strictObject({ ref: v.optional(v.string()), name: v.nullable(v.string()), owner: v.boolean() });
22
23
  const statusItem = v.looseObject({
23
- signal: v.string(),
24
24
  ref: v.nullable(v.string()),
25
25
  chat: v.nullable(v.string()),
26
- chat_title: v.nullable(v.string()),
27
26
  at: v.nullable(v.string()),
28
- who: v.nullable(v.strictObject({ ref: v.nullable(v.string()), name: v.nullable(v.string()), owner: v.boolean() })),
29
- evidence: v.array(v.strictObject({ ref: v.string(), fingerprint: v.nullable(v.string()) })),
27
+ who: v.optional(who),
28
+ /** Every ref the item cites, when it cites more than `ref`. */
29
+ evidence: v.optional(v.array(v.string())),
30
30
  basis: v.picklist(["store", "fact", "task", "pattern"]),
31
31
  data: v.record(v.string(), v.unknown()),
32
32
  });
@@ -36,18 +36,27 @@ export const projectStatusSchema = v.looseObject({
36
36
  key: v.nullable(v.string()),
37
37
  name: v.string(),
38
38
  window: v.strictObject({ since: v.string(), until: v.string() }),
39
- signals: v.array(v.strictObject({ id: v.string(), version: v.number() })),
39
+ /** Each signal's version, so a saved answer says which rules made it. */
40
+ signals: v.record(v.string(), v.number()),
40
41
  money: v.array(v.strictObject({ direction: v.string(), currency: v.nullable(v.string()), amount: v.string(), rows: v.number() })),
41
42
  chats: v.array(v.strictObject({
42
43
  chat: v.string(),
43
44
  title: v.nullable(v.string()),
44
45
  kind: v.string(),
45
46
  role: v.nullable(v.string()),
46
- purpose: v.string(),
47
- project: v.string(),
47
+ purpose: v.optional(v.string()),
48
+ project: v.optional(v.string()),
48
49
  coverage: v.string(),
49
- attention: v.number(),
50
- why: v.nullable(v.string()),
50
+ attention: v.optional(v.number()),
51
+ why: v.optional(v.string()),
52
+ last: v.optional(v.strictObject({ ref: v.string(), at: v.string(), who })),
53
+ next: v.optional(v.picklist(["owner", "them", "named", "nobody"])),
54
+ waiting_since: v.optional(v.nullable(v.string())),
55
+ addressed: v.optional(v.strictObject({ ref: v.nullable(v.string()), name: v.nullable(v.string()) })),
56
+ overdue: v.optional(v.boolean()),
57
+ held: v.optional(v.strictObject({ messages: v.number(), oldest_at: v.nullable(v.string()) })),
58
+ sync_command: v.optional(v.nullable(v.string())),
59
+ unlisted: v.optional(v.record(v.string(), v.number())),
51
60
  })),
52
61
  purposes: v.union([v.literal("all"), v.array(v.string())]),
53
62
  out_of_scope: v.optional(v.array(v.strictObject({
@@ -130,26 +139,86 @@ const missingOf = (found, hints) => {
130
139
  ...found.failed.map((one) => ({ field: `signal:${one.signal}`, why: one.why })),
131
140
  ];
132
141
  };
133
- const withPlace = (found, hints) => {
134
- const titles = new Map(found.chats.map((chat) => [chat.ref, chat.title]));
135
- const sync = (one) => {
136
- const chat = found.chats.find((each) => each.ref === one.chat);
137
- const step = chat && partial(found, chat) ? hints.sync(chat, day(found.window.since)) : null;
138
- return step ? hints.line(step) : null;
142
+ const whoOf = (one) => one === null ? {} : { who: { ...(one.ref === null ? {} : { ref: one.ref }), name: one.name, owner: one.owner } };
143
+ /** An item as listed: its first ref, every ref only when there are more. */
144
+ const listed = ({ signal: _signal, who, evidence, ...one }) => ({
145
+ ...one,
146
+ ref: evidence[0]?.ref ?? one.chat,
147
+ ...whoOf(who),
148
+ ...(evidence.length > 1 ? { evidence: evidence.map((each) => each.ref) } : {}),
149
+ });
150
+ /**
151
+ * Low signal items, counted on their chat's row instead of listed: questions others ask in a group with no role (a
152
+ * leads group's requests), promises found by words that others wrote in a group, and past the newest one per chat.
153
+ */
154
+ const unlistedOf = (found) => {
155
+ const chats = new Map(found.chats.map((chat) => [chat.ref, chat]));
156
+ const patterned = new Set();
157
+ return new Set(found.items.filter((one) => {
158
+ const chat = one.chat === null ? undefined : chats.get(one.chat);
159
+ if (!chat)
160
+ return false;
161
+ if (one.signal === "questions")
162
+ return one.data.side === "theirs" && chat.role === null && chat.kind !== "dialog";
163
+ if (one.signal !== "promises" || one.basis !== "pattern")
164
+ return false;
165
+ if (chat.kind !== "dialog" && !one.who?.owner)
166
+ return true;
167
+ if (!patterned.has(chat.ref)) {
168
+ patterned.add(chat.ref);
169
+ return false;
170
+ }
171
+ return true;
172
+ }));
173
+ };
174
+ const counted = (items) => {
175
+ const counts = {};
176
+ for (const one of items)
177
+ counts[one.signal] = (counts[one.signal] ?? 0) + 1;
178
+ return counts;
179
+ };
180
+ // The newest held message is the row's `last`.
181
+ const heldOf = (one) => {
182
+ const { messages, oldestAt } = one.data.held;
183
+ return { messages, oldestAt };
184
+ };
185
+ /** A chat with what is said once per chat: its newest message, whose move it is, and how much of it is held. */
186
+ const chatRow = (found, hints, chat, unlisted) => {
187
+ const weight = found.attention.find((one) => one.chat === chat.ref);
188
+ const of = (signal) => found.items.find((one) => one.signal === signal && one.chat === chat.ref);
189
+ const reply = of("reply-next");
190
+ const held = of("coverage");
191
+ const sync = held && partial(found, chat) ? hints.sync(chat, day(found.window.since)) : null;
192
+ const replied = reply?.data;
193
+ return {
194
+ chat: chat.ref,
195
+ title: chat.title,
196
+ kind: chat.kind,
197
+ role: chat.role,
198
+ ...(Array.isArray(found.purposes) && found.purposes.length === 1 ? {} : { purpose: chat.purpose }),
199
+ ...(chat.project === found.project.ref ? {} : { project: chat.project }),
200
+ coverage: chat.coverage.completeness.state,
201
+ ...(weight ? { attention: weight.weight, why: weight.why } : {}),
202
+ ...(reply && replied
203
+ ? {
204
+ last: { ref: reply.evidence[0]?.ref, at: reply.at, ...whoOf(reply.who) },
205
+ next: replied.next,
206
+ ...(replied.next === "nobody" ? {} : { waitingSince: replied.waitingSince }),
207
+ ...(replied.addressed ? { addressed: replied.addressed } : {}),
208
+ ...(replied.overdue ? { overdue: true } : {}),
209
+ }
210
+ : {}),
211
+ ...(held ? { held: heldOf(held), syncCommand: sync ? hints.line(sync) : null } : {}),
212
+ ...(unlisted.length ? { unlisted: counted(unlisted) } : {}),
139
213
  };
140
- return (one) => ({
141
- ...one,
142
- ref: one.evidence[0]?.ref ?? one.chat,
143
- chatTitle: one.chat === null ? null : (titles.get(one.chat) ?? null),
144
- ...(one.signal === "coverage" ? { syncCommand: sync(one) } : {}),
145
- });
146
214
  };
147
215
  /** The answer of `projects status`: the item, two steps at most, what is missing, and the window. */
148
216
  export const projectStatusAnswer = (found, hints) => {
149
- const weights = new Map(found.attention.map((one) => [one.chat, one]));
150
- const place = withPlace(found, hints);
217
+ const unlisted = unlistedOf(found);
151
218
  const lists = Object.fromEntries(found.signals.flatMap(({ id }) => {
152
- const items = found.items.filter((one) => one.signal === id).map(place);
219
+ if (ON_CHAT_ROW.has(id))
220
+ return [];
221
+ const items = found.items.filter((one) => one.signal === id && !unlisted.has(one)).map(listed);
153
222
  return items.length ? [[listKey(id), items]] : [];
154
223
  }));
155
224
  const item = snakeKeys({
@@ -157,19 +226,9 @@ export const projectStatusAnswer = (found, hints) => {
157
226
  key: found.project.key,
158
227
  name: found.project.name,
159
228
  window: found.window,
160
- signals: found.signals,
229
+ signals: Object.fromEntries(found.signals.map(({ id, version }) => [id, version])),
161
230
  money: found.money.open,
162
- chats: found.chats.map((chat) => ({
163
- chat: chat.ref,
164
- title: chat.title,
165
- kind: chat.kind,
166
- role: chat.role,
167
- purpose: chat.purpose,
168
- project: chat.project,
169
- coverage: chat.coverage.completeness.state,
170
- attention: weights.get(chat.ref)?.weight ?? 0,
171
- why: weights.get(chat.ref)?.why ?? null,
172
- })),
231
+ chats: found.chats.map((chat) => chatRow(found, hints, chat, [...unlisted].filter((one) => one.chat === chat.ref))),
173
232
  purposes: found.purposes,
174
233
  ...(found.outOfScope.length
175
234
  ? {
@@ -201,8 +260,8 @@ export const projectStatusAnswer = (found, hints) => {
201
260
  const NEXT_WORDS = { owner: "YOU", them: "them", nobody: "nobody" };
202
261
  const chatLine = (found, chat) => {
203
262
  const of = (signal) => found.items.filter((one) => one.signal === signal && one.chat === chat.ref);
204
- const [last] = of("last-message");
205
- const reply = of("reply-next")[0]?.data;
263
+ const [last] = of("reply-next");
264
+ const reply = last?.data;
206
265
  const head = [
207
266
  `${chat.title ?? chat.ref} (${[chat.role ?? "no role", chat.kind].join(", ")})`,
208
267
  last
@@ -0,0 +1,13 @@
1
+ /** The outside service an external id belongs to: `avito`, `cian`, `amazon`, `hh`. */
2
+ export declare const EXTERNAL_SERVICE: RegExp;
3
+ export declare const EXTERNAL_ID_CHARS = 200;
4
+ export declare const SOURCE_URL_CHARS = 2000;
5
+ export interface ExternalId {
6
+ provider: string;
7
+ id: string;
8
+ }
9
+ /** `avito:4512345678` → the service and its id; the id is everything after the first colon. */
10
+ export declare const externalIdOf: (value: string) => ExternalId;
11
+ export declare const externalIdText: (provider: unknown, id: unknown) => string | null;
12
+ /** An http or https address, as given; anything else is refused, so a stored link always opens a web page. */
13
+ export declare const sourceUrlOf: (value: string, reason?: string) => string;
@@ -0,0 +1,30 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ /** The outside service an external id belongs to: `avito`, `cian`, `amazon`, `hh`. */
3
+ export const EXTERNAL_SERVICE = /^[a-z][a-z0-9-]{0,31}$/;
4
+ export const EXTERNAL_ID_CHARS = 200;
5
+ export const SOURCE_URL_CHARS = 2000;
6
+ /** `avito:4512345678` → the service and its id; the id is everything after the first colon. */
7
+ export const externalIdOf = (value) => {
8
+ const text = value.trim();
9
+ const colon = text.indexOf(":");
10
+ const provider = colon === -1 ? "" : text.slice(0, colon).toLowerCase();
11
+ const id = colon === -1 ? "" : text.slice(colon + 1).trim();
12
+ if (!EXTERNAL_SERVICE.test(provider) || id.length === 0 || id.length > EXTERNAL_ID_CHARS || /\s/.test(id))
13
+ throw new CliError("validation_error", `an external id is <service>:<id>, such as avito:4512345678, at most ${EXTERNAL_ID_CHARS} characters after the colon and no spaces, not "${value}"`, { reason: "task.external-id" });
14
+ return { provider, id };
15
+ };
16
+ export const externalIdText = (provider, id) => provider == null || id == null ? null : `${String(provider)}:${String(id)}`;
17
+ /** An http or https address, as given; anything else is refused, so a stored link always opens a web page. */
18
+ export const sourceUrlOf = (value, reason = "task.source-url") => {
19
+ const text = value.trim();
20
+ let url;
21
+ try {
22
+ url = new URL(text);
23
+ }
24
+ catch {
25
+ url = undefined;
26
+ }
27
+ if (!url || (url.protocol !== "http:" && url.protocol !== "https:") || text.length > SOURCE_URL_CHARS)
28
+ throw new CliError("validation_error", `a source URL is an http or https address of at most ${SOURCE_URL_CHARS} characters, not "${value}"`, { reason });
29
+ return text;
30
+ };
@@ -4303,6 +4303,8 @@ export declare const ENTITIES: {
4303
4303
  readonly account: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
4304
4304
  readonly chat: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>, undefined>;
4305
4305
  readonly source_message: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>, undefined>;
4306
+ readonly external_id: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
4307
+ readonly source_url: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
4306
4308
  readonly priority: v.OptionalSchema<v.NullableSchema<v.NumberSchema<undefined>, undefined>, undefined>;
4307
4309
  readonly priority_label: v.OptionalSchema<v.NullableSchema<v.PicklistSchema<readonly ["low", "medium", "high", "critical"], undefined>, undefined>, undefined>;
4308
4310
  readonly agent: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
@@ -4386,6 +4388,8 @@ export declare const ENTITIES: {
4386
4388
  readonly revision: v.NumberSchema<undefined>;
4387
4389
  readonly parent: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
4388
4390
  readonly source: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4391
+ readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4392
+ readonly source_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4389
4393
  readonly due_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4390
4394
  readonly next_check_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4391
4395
  readonly closed_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
@@ -4500,6 +4504,8 @@ export declare const ENTITIES: {
4500
4504
  readonly revision: v.NumberSchema<undefined>;
4501
4505
  readonly parent: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
4502
4506
  readonly source: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4507
+ readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4508
+ readonly source_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4503
4509
  readonly due_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4504
4510
  readonly next_check_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4505
4511
  readonly closed_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
@@ -4615,6 +4621,8 @@ export declare const ENTITIES: {
4615
4621
  readonly revision: v.NumberSchema<undefined>;
4616
4622
  readonly parent: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
4617
4623
  readonly source: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4624
+ readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4625
+ readonly source_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4618
4626
  readonly due_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4619
4627
  readonly next_check_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4620
4628
  readonly closed_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
@@ -4758,6 +4766,8 @@ export declare const ENTITIES: {
4758
4766
  readonly revision: v.NumberSchema<undefined>;
4759
4767
  readonly parent: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
4760
4768
  readonly source: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4769
+ readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4770
+ readonly source_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4761
4771
  readonly due_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4762
4772
  readonly next_check_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4763
4773
  readonly closed_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
@@ -4866,6 +4876,8 @@ export declare const ENTITIES: {
4866
4876
  readonly revision: v.NumberSchema<undefined>;
4867
4877
  readonly parent: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
4868
4878
  readonly source: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4879
+ readonly external_id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4880
+ readonly source_url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
4869
4881
  readonly due_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4870
4882
  readonly next_check_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4871
4883
  readonly closed_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
@@ -5911,6 +5923,8 @@ export declare const ENTITIES: {
5911
5923
  readonly due_evidence: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>, undefined>;
5912
5924
  readonly assignee: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
5913
5925
  readonly assignee_evidence: v.OptionalSchema<v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>, undefined>;
5926
+ readonly external_id: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
5927
+ readonly source_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
5914
5928
  }, undefined>, v.StrictObjectSchema<{
5915
5929
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
5916
5930
  readonly evidence: v.ArraySchema<v.StrictObjectSchema<{
@@ -6028,6 +6042,7 @@ export declare const ENTITIES: {
6028
6042
  readonly invoice: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6029
6043
  readonly payment: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6030
6044
  readonly project: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6045
+ readonly source_url: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6031
6046
  readonly reason: v.StringSchema<undefined>;
6032
6047
  }, undefined>, v.StrictObjectSchema<{
6033
6048
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;