@wirecat/cli-core 0.578.0 → 0.580.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,39 @@ 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.580.0 — 05.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`mailFindings.check` tries a whole mail findings batch without staging it.** It makes every check `stage`
13
+ makes, the trial write of each invoice, payment and order included, rolls everything back and answers
14
+ `{ valid, findings, batch, problems }`: one problem per finding that would be refused, with its id, kind, code,
15
+ message and details, and the batch's own problems (`mail-findings.key-used` when the key holds other input). Its
16
+ input is `readMailFindingsJson`, the decoded JSON before validation.
17
+ - **Mail findings name a party the store does not hold yet.** An invoice takes `counterparty_name`, a payment
18
+ `payer_name` and `payee_name`, an order `customer_name`, each with an optional `<party>_email` that sent or
19
+ received a cited email. The owner's accept finds the organization by that address, by its company domain or by
20
+ exact name, or makes a company of that name and joins the address to it; two matches are refused
21
+ (`finance.party`).
22
+
23
+ ### Fixed
24
+
25
+ - **An unknown finding field is named.** The refusal says the field, the finding's id and kind and what that kind
26
+ takes, also in `details` (`fields`, `allowed`, `finding`, `kind`, reason `finding.unknown-field`); it was only
27
+ "unknown mail finding field".
28
+ - **An order is not proposed twice.** Staging an `order` whose shop and number already wait in a proposed mail
29
+ findings batch is refused (`order.proposed`), as one already stored is (`order.duplicate`).
30
+
31
+ ## 0.579.0 — 05.11.2026
32
+
33
+ ### Added
34
+
35
+ - **An agent's new organization is a proposal for the owner: the `organization` proposal kind and
36
+ `proposeOrganization(store, { name, kind, scope? }, by)`.** It is stored in `proposed_actions` as
37
+ `organization_add`, so no schema change; `proposalRegistry` lists it in `review`, and confirming it adds the
38
+ organization (`made: ["organization:<id>"]`), rejecting it adds nothing. The owner still adds one directly with
39
+ `knowledge.addOrganization`. `ORGANIZATION_ADD_KIND` and `OrganizationProposal` are exported from `services`.
40
+
8
41
  ## 0.577.0 — 05.11.2026
9
42
 
10
43
  ### Added
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
10
10
  inputSchema: {
11
11
  type: string;
12
12
  properties: {
13
- limit?: undefined;
14
13
  account_id: {
15
14
  type: string;
16
15
  minimum: number;
17
16
  };
18
17
  query?: undefined;
19
18
  timezone?: undefined;
19
+ limit?: undefined;
20
20
  page?: undefined;
21
21
  event?: undefined;
22
22
  } | {
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
45
45
  };
46
46
  event?: undefined;
47
47
  } | {
48
- limit?: undefined;
49
48
  query?: undefined;
50
49
  timezone?: undefined;
50
+ limit?: undefined;
51
51
  page?: undefined;
52
52
  event: {
53
53
  type: string;
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
58
58
  minimum: number;
59
59
  };
60
60
  } | {
61
- limit?: undefined;
62
61
  query?: undefined;
63
62
  timezone?: undefined;
63
+ limit?: undefined;
64
64
  page?: undefined;
65
65
  event?: undefined;
66
66
  account_id?: undefined;
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
80
80
  inputSchema: {
81
81
  type: string;
82
82
  properties: {
83
- limit?: undefined;
84
83
  account_id: {
85
84
  type: string;
86
85
  minimum: number;
87
86
  };
88
87
  query?: undefined;
89
88
  timezone?: undefined;
89
+ limit?: undefined;
90
90
  page?: undefined;
91
91
  event?: undefined;
92
92
  } | {
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
115
115
  };
116
116
  event?: undefined;
117
117
  } | {
118
- limit?: undefined;
119
118
  query?: undefined;
120
119
  timezone?: undefined;
120
+ limit?: undefined;
121
121
  page?: undefined;
122
122
  event: {
123
123
  type: string;
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
128
128
  minimum: number;
129
129
  };
130
130
  } | {
131
- limit?: undefined;
132
131
  query?: undefined;
133
132
  timezone?: undefined;
133
+ limit?: undefined;
134
134
  page?: undefined;
135
135
  event?: undefined;
136
136
  account_id?: undefined;
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
150
150
  inputSchema: {
151
151
  type: string;
152
152
  properties: {
153
- limit?: undefined;
154
153
  account_id: {
155
154
  type: string;
156
155
  minimum: number;
157
156
  };
158
157
  query?: undefined;
159
158
  timezone?: undefined;
159
+ limit?: undefined;
160
160
  page?: undefined;
161
161
  event?: undefined;
162
162
  } | {
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
185
185
  };
186
186
  event?: undefined;
187
187
  } | {
188
- limit?: undefined;
189
188
  query?: undefined;
190
189
  timezone?: undefined;
190
+ limit?: undefined;
191
191
  page?: undefined;
192
192
  event: {
193
193
  type: string;
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
198
198
  minimum: number;
199
199
  };
200
200
  } | {
201
- limit?: undefined;
202
201
  query?: undefined;
203
202
  timezone?: undefined;
203
+ limit?: undefined;
204
204
  page?: undefined;
205
205
  event?: undefined;
206
206
  account_id?: undefined;
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
220
220
  inputSchema: {
221
221
  type: string;
222
222
  properties: {
223
- limit?: undefined;
224
223
  account_id: {
225
224
  type: string;
226
225
  minimum: number;
227
226
  };
228
227
  query?: undefined;
229
228
  timezone?: undefined;
229
+ limit?: undefined;
230
230
  page?: undefined;
231
231
  event?: undefined;
232
232
  } | {
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
255
255
  };
256
256
  event?: undefined;
257
257
  } | {
258
- limit?: undefined;
259
258
  query?: undefined;
260
259
  timezone?: undefined;
260
+ limit?: undefined;
261
261
  page?: undefined;
262
262
  event: {
263
263
  type: string;
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
268
268
  minimum: number;
269
269
  };
270
270
  } | {
271
- limit?: undefined;
272
271
  query?: undefined;
273
272
  timezone?: undefined;
273
+ limit?: undefined;
274
274
  page?: undefined;
275
275
  event?: undefined;
276
276
  account_id?: undefined;
@@ -2,5 +2,7 @@ import { type MailFindingsInput } from "../mail/findings.js";
2
2
  import { type FindingsInput, type MeetingFindingsInput } from "../meetings/index.js";
3
3
  export declare const parseMeetingFindingsJson: (text: string) => MeetingFindingsInput;
4
4
  export declare const parseEvidenceFindingsJson: (text: string) => FindingsInput;
5
+ /** A mail findings batch as `mail findings add --dry-run` reads it: snake_case JSON, for `mailFindings.check`. */
6
+ export declare const readMailFindingsJson: (text: string) => MailFindingsInput;
5
7
  /** A mail findings batch as `mail findings add` reads it: snake_case JSON, checked for shape before the store. */
6
8
  export declare const parseMailFindingsJson: (text: string) => MailFindingsInput;
@@ -12,6 +12,14 @@ const keys = {
12
12
  due_date: "dueDate",
13
13
  unit_price: "unitPrice",
14
14
  supplier_name: "supplierName",
15
+ counterparty_name: "counterpartyName",
16
+ counterparty_email: "counterpartyEmail",
17
+ payer_name: "payerName",
18
+ payer_email: "payerEmail",
19
+ payee_name: "payeeName",
20
+ payee_email: "payeeEmail",
21
+ customer_name: "customerName",
22
+ customer_email: "customerEmail",
15
23
  order_date: "orderDate",
16
24
  fulfilled_date: "fulfilledDate",
17
25
  external_id: "externalId",
@@ -50,5 +58,7 @@ const parseFindingsJson = (text, label, validate) => {
50
58
  };
51
59
  export const parseMeetingFindingsJson = (text) => parseFindingsJson(text, "meeting findings", validateMeetingFindings);
52
60
  export const parseEvidenceFindingsJson = (text) => parseFindingsJson(text, "evidence findings", validateEvidenceFindings);
61
+ /** A mail findings batch as `mail findings add --dry-run` reads it: snake_case JSON, for `mailFindings.check`. */
62
+ export const readMailFindingsJson = (text) => parseFindingsJson(text, "mail findings", (input) => input);
53
63
  /** A mail findings batch as `mail findings add` reads it: snake_case JSON, checked for shape before the store. */
54
64
  export const parseMailFindingsJson = (text) => parseFindingsJson(text, "mail findings", validateMailFindings);
@@ -75,7 +75,7 @@ export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthori
75
75
  export { type CliEntry, type EntryContext, type EntryIo, openBrowser, startCli } from "./entry.js";
76
76
  export { type AnswerOutput, answerSchema, type Body, type ItemBody, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, type ListBody, type ListInput, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
77
77
  export { withAbort } from "./execution.js";
78
- export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, } from "./findings-input.js";
78
+ export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, readMailFindingsJson, } from "./findings-input.js";
79
79
  export { askSetupQuestions, asksAtStart, type FirstRun, type FirstRunIo, setupAtStart, systemLanguage, } from "./first-run.js";
80
80
  export { checkGuide, checkStep, type GuideOptions, type GuideReference, type GuideStep, loadScenarios, MEMO_SCENARIOS, type Scenario, shellProblems, } from "./guide.js";
81
81
  export { type CommandHelp, commandHelp, commandHelpMarkdown, commandHelpText, exampleReport, type NextChoice, nextUsually, } from "./help/command-help.js";
package/dist/cli/index.js CHANGED
@@ -66,7 +66,7 @@ export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthori
66
66
  export { openBrowser, startCli } from "./entry.js";
67
67
  export { answerSchema, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
68
68
  export { withAbort } from "./execution.js";
69
- export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, } from "./findings-input.js";
69
+ export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, readMailFindingsJson, } from "./findings-input.js";
70
70
  export { askSetupQuestions, asksAtStart, setupAtStart, systemLanguage, } from "./first-run.js";
71
71
  export { checkGuide, checkStep, loadScenarios, MEMO_SCENARIOS, shellProblems, } from "./guide.js";
72
72
  export { commandHelp, commandHelpMarkdown, commandHelpText, exampleReport, nextUsually, } from "./help/command-help.js";
@@ -5988,7 +5988,9 @@ export declare const ENTITIES: {
5988
5988
  }, undefined>, undefined>;
5989
5989
  readonly kind: v.LiteralSchema<"invoice", undefined>;
5990
5990
  readonly direction: v.PicklistSchema<readonly ["receivable", "payable"], undefined>;
5991
- readonly counterparty: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
5991
+ readonly counterparty: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
5992
+ readonly counterparty_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
5993
+ readonly counterparty_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
5992
5994
  readonly currency: v.StringSchema<undefined>;
5993
5995
  readonly lines: v.ArraySchema<v.StrictObjectSchema<{
5994
5996
  readonly description: v.StringSchema<undefined>;
@@ -6011,7 +6013,11 @@ export declare const ENTITIES: {
6011
6013
  readonly kind: v.LiteralSchema<"payment", undefined>;
6012
6014
  readonly direction: v.PicklistSchema<readonly ["in", "out"], undefined>;
6013
6015
  readonly payer: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6016
+ readonly payer_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6017
+ readonly payer_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6014
6018
  readonly payee: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6019
+ readonly payee_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6020
+ readonly payee_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6015
6021
  readonly amount: v.StringSchema<undefined>;
6016
6022
  readonly currency: v.StringSchema<undefined>;
6017
6023
  readonly date: v.StringSchema<undefined>;
@@ -6031,6 +6037,8 @@ export declare const ENTITIES: {
6031
6037
  readonly kind: v.LiteralSchema<"order", undefined>;
6032
6038
  readonly purpose: v.PicklistSchema<readonly ["personal", "business", "client", "other"], undefined>;
6033
6039
  readonly customer: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6040
+ readonly customer_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6041
+ readonly customer_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
6034
6042
  readonly supplier: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
6035
6043
  readonly supplier_name: v.StringSchema<undefined>;
6036
6044
  readonly number: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -93,7 +93,10 @@ export declare const mailFindings: v.StrictObjectSchema<{
93
93
  }, undefined>, undefined>;
94
94
  readonly kind: v.LiteralSchema<"invoice", undefined>;
95
95
  readonly direction: v.PicklistSchema<readonly ["receivable", "payable"], undefined>;
96
- readonly counterparty: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>;
96
+ readonly counterparty: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
97
+ /** A counterparty the store may not hold yet; the owner's accept finds its organization or makes one. */
98
+ readonly counterparty_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
99
+ readonly counterparty_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
97
100
  readonly currency: v.StringSchema<undefined>;
98
101
  readonly lines: v.ArraySchema<v.StrictObjectSchema<{
99
102
  readonly description: v.StringSchema<undefined>;
@@ -116,7 +119,11 @@ export declare const mailFindings: v.StrictObjectSchema<{
116
119
  readonly kind: v.LiteralSchema<"payment", undefined>;
117
120
  readonly direction: v.PicklistSchema<readonly ["in", "out"], undefined>;
118
121
  readonly payer: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
122
+ readonly payer_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
123
+ readonly payer_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
119
124
  readonly payee: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
125
+ readonly payee_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
126
+ readonly payee_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
120
127
  readonly amount: v.StringSchema<undefined>;
121
128
  readonly currency: v.StringSchema<undefined>;
122
129
  readonly date: v.StringSchema<undefined>;
@@ -136,6 +143,8 @@ export declare const mailFindings: v.StrictObjectSchema<{
136
143
  readonly kind: v.LiteralSchema<"order", undefined>;
137
144
  readonly purpose: v.PicklistSchema<readonly ["personal", "business", "client", "other"], undefined>;
138
145
  readonly customer: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
146
+ readonly customer_name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
147
+ readonly customer_email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
139
148
  readonly supplier: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "a reference such as `note:42`">]>, undefined>;
140
149
  readonly supplier_name: v.StringSchema<undefined>;
141
150
  readonly number: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
@@ -55,7 +55,10 @@ const finding = v.variant("kind", [
55
55
  ...base,
56
56
  kind: v.literal("invoice"),
57
57
  direction: v.picklist(INVOICE_DIRECTIONS),
58
- counterparty: reference,
58
+ counterparty: v.optional(reference),
59
+ /** A counterparty the store may not hold yet; the owner's accept finds its organization or makes one. */
60
+ counterparty_name: v.optional(text),
61
+ counterparty_email: v.optional(text),
59
62
  currency: text,
60
63
  lines: v.array(v.strictObject({
61
64
  description: text,
@@ -75,7 +78,11 @@ const finding = v.variant("kind", [
75
78
  kind: v.literal("payment"),
76
79
  direction: v.picklist(MONEY_DIRECTIONS),
77
80
  payer: v.optional(reference),
81
+ payer_name: v.optional(text),
82
+ payer_email: v.optional(text),
78
83
  payee: v.optional(reference),
84
+ payee_name: v.optional(text),
85
+ payee_email: v.optional(text),
79
86
  amount: text,
80
87
  currency: text,
81
88
  date: text,
@@ -89,6 +96,8 @@ const finding = v.variant("kind", [
89
96
  kind: v.literal("order"),
90
97
  purpose: v.picklist(ORDER_PURPOSES),
91
98
  customer: v.optional(reference),
99
+ customer_name: v.optional(text),
100
+ customer_email: v.optional(text),
92
101
  supplier: v.optional(reference),
93
102
  supplier_name: text,
94
103
  number: v.optional(text),
@@ -62,6 +62,9 @@ const OTHERS = [
62
62
  validation("mail-findings.partial", "a cited email is not stored whole yet; cite it once it is"),
63
63
  validation("evidence-findings.dedicated-review", "review evidence findings through the dedicated findings command"),
64
64
  validation("mail-findings.dedicated-review", "review mail findings through the dedicated findings command"),
65
+ validation("mail-findings.invalid", "a checked mail findings batch would be refused; details.problems names why, finding by finding"),
66
+ validation("mail-findings.key-used", "the findings batch key was already used for different input"),
67
+ validation("finding.unknown-field", "a finding has a field its kind does not take"),
65
68
  validation("document.changed", "the document changed while it was read; nothing was saved"),
66
69
  ["document.not-imported", "not_found", "the document is not imported in this source account"],
67
70
  ["extraction.invalid-proposals", "invalid_response", "the model's memory proposals could not be used"],
@@ -200,6 +203,7 @@ const OTHERS = [
200
203
  validation("money.currency", "the currency is not one the store keeps money in"),
201
204
  validation("money.quantity", "the quantity is not a decimal above 0"),
202
205
  validation("order.duplicate", "the shop's order with this number is already stored; change its status instead"),
206
+ validation("order.proposed", "the shop's order with this number already waits for the owner in a findings batch"),
203
207
  validation("order.field", "a field of the order is not valid"),
204
208
  validation("order.source-url", "an order's source URL is not an http or https address"),
205
209
  ["order.not-found", "not_found", "no stored order of that shop has that number"],
@@ -45,8 +45,15 @@ export interface MailNewContactFinding extends Cited {
45
45
  export interface MailInvoiceFinding extends Cited {
46
46
  kind: "invoice";
47
47
  direction: (typeof INVOICE_DIRECTIONS)[number];
48
- /** `person:` or `organization:`. */
49
- counterparty: string;
48
+ /** `person:` or `organization:`; or `counterpartyName`, never both. */
49
+ counterparty?: string;
50
+ /**
51
+ * A party the store may not hold yet: on the owner's accept, the organization its `counterpartyEmail` or that
52
+ * address's domain belongs to, else the one of exactly this name, else a new company of this name.
53
+ */
54
+ counterpartyName?: string;
55
+ /** The party's own address, which a cited email was sent from or to. */
56
+ counterpartyEmail?: string;
50
57
  currency: string;
51
58
  lines: {
52
59
  description: string;
@@ -66,8 +73,13 @@ export interface MailInvoiceFinding extends Cited {
66
73
  export interface MailPaymentFinding extends Cited {
67
74
  kind: "payment";
68
75
  direction: (typeof MONEY_DIRECTIONS)[number];
76
+ /** Each party a reference, or a name and an optional address as an invoice's `counterpartyName` is. */
69
77
  payer?: string;
78
+ payerName?: string;
79
+ payerEmail?: string;
70
80
  payee?: string;
81
+ payeeName?: string;
82
+ payeeEmail?: string;
71
83
  amount: string;
72
84
  currency: string;
73
85
  /** `YYYY-MM-DD`. */
@@ -88,6 +100,9 @@ export interface MailOrderFinding extends Cited {
88
100
  purpose: (typeof ORDER_PURPOSES)[number];
89
101
  /** Whom it is for; the owner when left out. */
90
102
  customer?: string;
103
+ /** A customer the store may not hold yet, as an invoice's `counterpartyName` is. */
104
+ customerName?: string;
105
+ customerEmail?: string;
91
106
  supplier?: string;
92
107
  supplierName: string;
93
108
  number?: string;
@@ -121,9 +136,22 @@ export interface MailFindingsInput {
121
136
  extractor: string;
122
137
  findings: MailFinding[];
123
138
  }
139
+ export declare const validateMailFindings: (input: MailFindingsInput) => MailFindingsInput;
140
+ /** Why one finding, or the batch when `finding` is null, would be refused. */
141
+ export interface MailFindingProblem {
142
+ finding: string | null;
143
+ kind: string | null;
144
+ code: string;
145
+ message: string;
146
+ details?: Record<string, unknown>;
147
+ }
148
+ export declare const mailFindingProblem: (raw: unknown, error: unknown) => MailFindingProblem;
124
149
  /**
125
- * The shape of a mail findings batch: 1–30 findings, each citing 1–8 `msg:email/…` references with fingerprints.
126
- * What needs the store — the fingerprints, partial mail, the per-sender cap, the targets — the store checks.
150
+ * `validateMailFindings` finding by finding: the envelope still refuses the whole batch, but a bad finding no longer
151
+ * hides the next one, so `mail findings add --dry-run` names every problem at once.
127
152
  */
128
- export declare const validateMailFindings: (input: MailFindingsInput) => MailFindingsInput;
153
+ export declare const checkMailFindings: (input: MailFindingsInput) => {
154
+ batch: MailFindingsInput;
155
+ problems: MailFindingProblem[];
156
+ };
129
157
  export declare const mailFindingFingerprint: ({ id: _id, ...finding }: MailFinding) => string;
@@ -1,4 +1,4 @@
1
- import { CliError } from "@wirecat/cli-base";
1
+ import { CliError, isCliError } from "@wirecat/cli-base";
2
2
  import { EXTERNAL_ID_CHARS, externalIdOf, SOURCE_URL_CHARS, sourceUrlOf } from "../domain/external-links.js";
3
3
  import { INVOICE_DIRECTIONS, MONEY_DIRECTIONS } from "../domain/finance.js";
4
4
  import { MEMORY_KINDS, MEMORY_SCOPES } from "../domain/knowledge.js";
@@ -64,8 +64,21 @@ const one = (raw, ids) => {
64
64
  return validateFinding(raw, RULES, ids);
65
65
  if (raw.kind === "task") {
66
66
  const { externalId, sourceUrl, ...task } = raw;
67
+ let checked;
68
+ try {
69
+ checked = validateFinding(task, RULES, ids);
70
+ }
71
+ catch (error) {
72
+ if (!isCliError(error) || error.details.reason !== "finding.unknown-field")
73
+ throw error;
74
+ const allowed = [...error.details.allowed, "external_id", "source_url"];
75
+ throw new CliError("validation_error", error.message.replace(/; it takes .*$/, `; it takes ${allowed.join(", ")}`), {
76
+ ...error.details,
77
+ allowed,
78
+ });
79
+ }
67
80
  return {
68
- ...validateFinding(task, RULES, ids),
81
+ ...checked,
69
82
  ...optional("externalId", externalId, (value) => {
70
83
  const { provider, id } = externalIdOf(findingText(value, EXTERNAL_ID_CHARS + 40));
71
84
  return `${provider}:${id}`;
@@ -81,6 +94,22 @@ const one = (raw, ids) => {
81
94
  return invalid(`${what} is not a reference of the kind it takes: ${text}`);
82
95
  return text;
83
96
  };
97
+ /** A party as a `person:`/`organization:` reference, or as `<field>_name` with an optional `<field>_email`. */
98
+ const party = (field, what) => {
99
+ const [given, name, email] = [raw[field], raw[`${field}Name`], raw[`${field}Email`]];
100
+ if (given !== undefined && name !== undefined)
101
+ return invalid(`${what} is ${field} or ${field}_name, not both`);
102
+ if (email !== undefined && name === undefined)
103
+ return invalid(`${field}_email comes with ${field}_name`);
104
+ return {
105
+ ...optional(field, given, (value) => reference(value, PARTY, what)),
106
+ ...optional(`${field}Name`, name, (value) => word(value, 200)),
107
+ ...optional(`${field}Email`, email, (value) => {
108
+ const address = findingText(value, 320).toLowerCase();
109
+ return ADDRESS.test(address) ? address : invalid(`${field}_email is an email address`);
110
+ }),
111
+ };
112
+ };
84
113
  switch (raw.kind) {
85
114
  case "task_update": {
86
115
  findingFields(raw, ["id", "kind", "task", "change", "dueAt", "detail", "reason", "evidence"], RULES.singular);
@@ -155,6 +184,8 @@ const one = (raw, ids) => {
155
184
  "kind",
156
185
  "direction",
157
186
  "counterparty",
187
+ "counterpartyName",
188
+ "counterpartyEmail",
158
189
  "currency",
159
190
  "lines",
160
191
  "total",
@@ -171,7 +202,7 @@ const one = (raw, ids) => {
171
202
  if (!line || typeof line !== "object")
172
203
  return invalid("an invoice line is an object");
173
204
  const fields = line;
174
- findingFields(fields, ["description", "quantity", "unitPrice", "amount"], "invoice line");
205
+ findingFields(fields, ["description", "quantity", "unitPrice", "amount"], "invoice line", raw);
175
206
  return {
176
207
  description: word(fields.description, 500),
177
208
  ...optional("quantity", fields.quantity, (value) => word(value, 20)),
@@ -183,7 +214,9 @@ const one = (raw, ids) => {
183
214
  id,
184
215
  kind: "invoice",
185
216
  direction: oneOf(raw.direction, INVOICE_DIRECTIONS, "an invoice's direction"),
186
- counterparty: reference(raw.counterparty, PARTY, "an invoice's counterparty"),
217
+ ...(raw.counterparty === undefined && raw.counterpartyName === undefined
218
+ ? invalid("an invoice names its counterparty: counterparty person:N|organization:N, or counterparty_name")
219
+ : party("counterparty", "an invoice's counterparty")),
187
220
  currency: word(raw.currency, 3),
188
221
  lines,
189
222
  ...optional("total", raw.total, (value) => word(value, 30)),
@@ -201,7 +234,11 @@ const one = (raw, ids) => {
201
234
  "kind",
202
235
  "direction",
203
236
  "payer",
237
+ "payerName",
238
+ "payerEmail",
204
239
  "payee",
240
+ "payeeName",
241
+ "payeeEmail",
205
242
  "amount",
206
243
  "currency",
207
244
  "date",
@@ -219,7 +256,7 @@ const one = (raw, ids) => {
219
256
  if (!share || typeof share !== "object")
220
257
  return invalid("an allocation is an invoice and an amount");
221
258
  const fields = share;
222
- findingFields(fields, ["invoice", "amount"], "allocation");
259
+ findingFields(fields, ["invoice", "amount"], "allocation", raw);
223
260
  return {
224
261
  invoice: reference(fields.invoice, INVOICE, "an allocation's invoice"),
225
262
  amount: word(fields.amount, 30),
@@ -230,8 +267,8 @@ const one = (raw, ids) => {
230
267
  id,
231
268
  kind: "payment",
232
269
  direction: oneOf(raw.direction, MONEY_DIRECTIONS, "a payment's direction"),
233
- ...optional("payer", raw.payer, (value) => reference(value, PARTY, "a payment's payer")),
234
- ...optional("payee", raw.payee, (value) => reference(value, PARTY, "a payment's payee")),
270
+ ...party("payer", "a payment's payer"),
271
+ ...party("payee", "a payment's payee"),
235
272
  amount: word(raw.amount, 30),
236
273
  currency: word(raw.currency, 3),
237
274
  date: word(raw.date, 10),
@@ -248,6 +285,8 @@ const one = (raw, ids) => {
248
285
  "kind",
249
286
  "purpose",
250
287
  "customer",
288
+ "customerName",
289
+ "customerEmail",
251
290
  "supplier",
252
291
  "supplierName",
253
292
  "number",
@@ -267,7 +306,7 @@ const one = (raw, ids) => {
267
306
  id,
268
307
  kind: "order",
269
308
  purpose: oneOf(raw.purpose, ORDER_PURPOSES, "an order's purpose"),
270
- ...optional("customer", raw.customer, (value) => reference(value, PARTY, "an order's customer")),
309
+ ...party("customer", "an order's customer"),
271
310
  ...optional("supplier", raw.supplier, (value) => reference(value, PARTY, "an order's supplier")),
272
311
  supplierName: word(raw.supplierName, 200),
273
312
  ...optional("number", raw.number, (value) => word(value, 80)),
@@ -308,10 +347,47 @@ const one = (raw, ids) => {
308
347
  * The shape of a mail findings batch: 1–30 findings, each citing 1–8 `msg:email/…` references with fingerprints.
309
348
  * What needs the store — the fingerprints, partial mail, the per-sender cap, the targets — the store checks.
310
349
  */
350
+ const KEY = /^[a-z0-9][a-z0-9-]{0,39}:[1-9]\d*$/;
351
+ const KEY_SHAPE = "a mail findings key is <holder>:<through_id>, such as mail-triage:9123456";
311
352
  export const validateMailFindings = (input) => {
312
353
  const batch = validateBatch(input, RULES, MAIL_FINDINGS_PER_RUN, one);
313
- if (!/^[a-z0-9][a-z0-9-]{0,39}:[1-9]\d*$/.test(batch.key))
314
- return invalid("a mail findings key is <holder>:<through_id>, such as mail-triage:9123456");
354
+ if (!KEY.test(batch.key))
355
+ return invalid(KEY_SHAPE);
315
356
  return batch;
316
357
  };
358
+ export const mailFindingProblem = (raw, error) => {
359
+ if (!isCliError(error))
360
+ throw error;
361
+ const fields = raw && typeof raw === "object" ? raw : {};
362
+ const details = Object.fromEntries(Object.entries(error.details).filter(([key]) => key !== "finding" && key !== "kind"));
363
+ return {
364
+ finding: typeof fields.id === "string" ? fields.id : null,
365
+ kind: typeof fields.kind === "string" ? fields.kind : null,
366
+ code: error.code,
367
+ message: error.message,
368
+ ...(Object.keys(details).length ? { details } : {}),
369
+ };
370
+ };
371
+ /**
372
+ * `validateMailFindings` finding by finding: the envelope still refuses the whole batch, but a bad finding no longer
373
+ * hides the next one, so `mail findings add --dry-run` names every problem at once.
374
+ */
375
+ export const checkMailFindings = (input) => {
376
+ const problems = [];
377
+ const batch = validateBatch(input, RULES, MAIL_FINDINGS_PER_RUN, (finding, ids) => {
378
+ try {
379
+ return one(finding, ids);
380
+ }
381
+ catch (error) {
382
+ problems.push(mailFindingProblem(finding, error));
383
+ return undefined;
384
+ }
385
+ });
386
+ if (!KEY.test(batch.key))
387
+ problems.push({ finding: null, kind: null, code: "validation_error", message: KEY_SHAPE });
388
+ return {
389
+ batch: { ...batch, findings: batch.findings.filter((one) => one !== undefined) },
390
+ problems,
391
+ };
392
+ };
317
393
  export const mailFindingFingerprint = ({ id: _id, ...finding }) => findingHash(finding);
@@ -65,7 +65,14 @@ export interface FindingsReceipt {
65
65
  }
66
66
  export declare const findingText: (value: unknown, limit: number) => string;
67
67
  export declare const findingHash: (value: unknown) => string;
68
- export declare const findingFields: (value: object, allowed: string[], noun: string) => void;
68
+ /**
69
+ * Refuses a field `allowed` does not list, naming it, the finding it is in and what that kind takes: an agent fixes
70
+ * the batch from the message alone. `of` is the finding a nested object (an invoice line) belongs to.
71
+ */
72
+ export declare const findingFields: (value: object, allowed: string[], noun: string, of?: {
73
+ id?: unknown;
74
+ kind?: unknown;
75
+ }) => void;
69
76
  /** What differs between findings kinds: their wording and what one cited reference must look like. */
70
77
  export interface FindingsRules {
71
78
  /** "meeting findings" */
@@ -12,9 +12,27 @@ export const findingText = (value, limit) => {
12
12
  return value.trim();
13
13
  };
14
14
  export const findingHash = (value) => createHash("sha256").update(JSON.stringify(value)).digest("hex");
15
- export const findingFields = (value, allowed, noun) => {
16
- if (Object.keys(value).some((key) => !allowed.includes(key)))
17
- invalid(`unknown ${noun} field`);
15
+ const snakeCase = (key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
16
+ /**
17
+ * Refuses a field `allowed` does not list, naming it, the finding it is in and what that kind takes: an agent fixes
18
+ * the batch from the message alone. `of` is the finding a nested object (an invoice line) belongs to.
19
+ */
20
+ export const findingFields = (value, allowed, noun, of = value) => {
21
+ const unknown = Object.keys(value).filter((key) => !allowed.includes(key));
22
+ if (!unknown.length)
23
+ return;
24
+ const fields = unknown.map(snakeCase);
25
+ const takes = allowed.map(snakeCase);
26
+ const id = typeof of.id === "string" ? of.id : null;
27
+ const kind = typeof of.kind === "string" ? of.kind : null;
28
+ const where = id || kind ? ` in ${[id, kind && `(${kind})`].filter(Boolean).join(" ")}` : "";
29
+ throw new CliError("validation_error", `unknown ${noun} field${fields.length > 1 ? "s" : ""} ${fields.join(", ")}${where}; it takes ${takes.join(", ")}`, {
30
+ reason: "finding.unknown-field",
31
+ fields,
32
+ allowed: takes,
33
+ ...(id ? { finding: id } : {}),
34
+ ...(kind ? { kind } : {}),
35
+ });
18
36
  };
19
37
  const SUBJECT = /^(person|organization|project):[1-9]\d*$|^task:[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
20
38
  /** A finding's cited evidence: 1–8 distinct references in `rules`' form, each with a 64-hex fingerprint. */