@wirecat/cli-core 0.600.0 → 0.602.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 (80) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/dist/calendar/cli/search-all.js +9 -2
  3. package/dist/cli/app-doctor-command.js +18 -10
  4. package/dist/cli/bot/api-input.js +8 -2
  5. package/dist/cli/context.d.ts +2 -0
  6. package/dist/cli/contract-templates.js +2 -1
  7. package/dist/cli/effects.d.ts +5 -0
  8. package/dist/cli/effects.js +5 -0
  9. package/dist/cli/index.d.ts +2 -1
  10. package/dist/cli/index.js +2 -1
  11. package/dist/cli/messenger/search-answers.d.ts +5 -1
  12. package/dist/cli/messenger/search-answers.js +4 -1
  13. package/dist/cli/messenger/store-maintenance-command.d.ts +2 -0
  14. package/dist/cli/messenger/store-maintenance-command.js +1 -0
  15. package/dist/cli/new-file.d.ts +2 -0
  16. package/dist/cli/new-file.js +13 -0
  17. package/dist/cli/program.js +3 -0
  18. package/dist/cli/search-left-out.d.ts +27 -0
  19. package/dist/cli/search-left-out.js +31 -0
  20. package/dist/cli/store-recover.d.ts +2 -0
  21. package/dist/cli/store-recover.js +2 -0
  22. package/dist/crm/cli/index.js +2 -7
  23. package/dist/crm/cli/search-all.js +17 -2
  24. package/dist/crm/index.d.ts +1 -1
  25. package/dist/crm/index.js +1 -1
  26. package/dist/crm/writes.d.ts +17 -0
  27. package/dist/crm/writes.js +31 -16
  28. package/dist/errors/reasons.js +16 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +1 -1
  31. package/dist/meetings/cli/index.d.ts +14 -0
  32. package/dist/meetings/cli/index.js +18 -6
  33. package/dist/meetings/hit-query.d.ts +2 -0
  34. package/dist/meetings/hit-query.js +2 -0
  35. package/dist/meetings/index.d.ts +2 -2
  36. package/dist/meetings/index.js +1 -1
  37. package/dist/meetings/mcp/index.d.ts +15 -15
  38. package/dist/meetings/pull.d.ts +13 -1
  39. package/dist/meetings/pull.js +34 -8
  40. package/dist/meetings/source.d.ts +5 -0
  41. package/dist/resolve.d.ts +2 -2
  42. package/dist/resolve.js +4 -3
  43. package/dist/search/lucene/plain.d.ts +9 -0
  44. package/dist/search/lucene/plain.js +124 -0
  45. package/dist/services/events-search.js +2 -0
  46. package/dist/services/index.d.ts +1 -0
  47. package/dist/services/index.js +1 -0
  48. package/dist/services/meeting-hit-search.js +3 -2
  49. package/dist/services/messages-archive-search.js +3 -0
  50. package/dist/services/notes-search.js +3 -0
  51. package/dist/services/search-all.d.ts +4 -1
  52. package/dist/services/search-all.js +6 -3
  53. package/dist/speech/local.d.ts +2 -1
  54. package/dist/speech/local.js +12 -1
  55. package/dist/speech/recognize.d.ts +2 -0
  56. package/dist/speech/recognize.js +15 -0
  57. package/dist/store/damage.js +6 -1
  58. package/dist/store/decision-requests.d.ts +10 -0
  59. package/dist/store/decision-requests.js +16 -0
  60. package/dist/store/health.d.ts +15 -0
  61. package/dist/store/health.js +31 -1
  62. package/dist/store/index.d.ts +3 -1
  63. package/dist/store/index.js +1 -0
  64. package/dist/store/recover.d.ts +14 -2
  65. package/dist/store/recover.js +179 -95
  66. package/dist/store/sqlite/deals.d.ts +3 -1
  67. package/dist/store/sqlite/deals.js +2 -2
  68. package/dist/store/sqlite/decision-requests.d.ts +59 -0
  69. package/dist/store/sqlite/decision-requests.js +111 -0
  70. package/dist/store/sqlite/manifest.js +2 -0
  71. package/dist/store/sqlite/meeting-hit-search.js +3 -2
  72. package/dist/store/sqlite/migrations.generated.js +12 -0
  73. package/dist/store/sqlite/schema/decision-requests.d.ts +233 -0
  74. package/dist/store/sqlite/schema/decision-requests.js +20 -0
  75. package/dist/store/sqlite/schema.d.ts +1 -0
  76. package/dist/store/sqlite/schema.js +1 -0
  77. package/dist/store/store.d.ts +3 -0
  78. package/dist/store/store.js +5 -0
  79. package/docs/search/recipes.json +0 -1
  80. package/package.json +2 -2
@@ -1,4 +1,5 @@
1
1
  import { CliError, isCliError } from "@wirecat/cli-base";
2
+ import { foldName } from "../resolve.js";
2
3
  import { guardFor } from "../sends/guard.js";
3
4
  import { guardedWrite } from "../sends/guarded.js";
4
5
  import { keyedGuard } from "../sends/keyed-guard.js";
@@ -120,19 +121,28 @@ const fieldsOf = (input, pipeline, currency) => {
120
121
  }
121
122
  return { fields, stage };
122
123
  };
123
- /** Case, spaces and underscores aside: `lead_source` and `Lead source` are one name, as bitrix24-cli folds them. */
124
- const folded = (name) => name
125
- .trim()
126
- .toLocaleLowerCase()
127
- .replace(/[\s_]+/gu, " ");
124
+ /**
125
+ * A field's code, label or option as the lookup compares them: `foldName` (letter case, composed letters, ё as е),
126
+ * with spaces and underscores aside, so `lead_source` and `Lead source` are one name.
127
+ */
128
+ export const foldFieldName = (name) => foldName(name.trim()).replace(/[\s_]+/gu, " ");
128
129
  const named = ({ code, label }) => ({ code, label });
130
+ /** No field by that name: the fields whose code or label holds it, or is held in it, are its candidates. */
131
+ export const unknownField = (fields, name) => {
132
+ const want = foldFieldName(name);
133
+ const close = fields.filter((field) => [field.code, field.label ?? ""].some((one) => {
134
+ const other = foldFieldName(one);
135
+ return other !== "" && (other.includes(want) || want.includes(other));
136
+ }));
137
+ return new CliError("validation_error", `no custom field is named ${name}${close.length ? "; close ones are in candidates" : ""} — \`fields list\` lists them`, { reason: "field.unknown", param: "--field", candidates: close.map(named) });
138
+ };
129
139
  /** A field by its code or its whole label; two with that label are refused with both, never guessed. */
130
- const fieldNamed = (fields, name) => {
131
- const want = folded(name);
132
- const byCode = fields.find((field) => folded(field.code) === want);
140
+ export const fieldNamed = (fields, name) => {
141
+ const want = foldFieldName(name);
142
+ const byCode = fields.find((field) => foldFieldName(field.code) === want);
133
143
  if (byCode)
134
144
  return byCode;
135
- const labelled = fields.filter((field) => field.label !== null && folded(field.label) === want);
145
+ const labelled = fields.filter((field) => field.label !== null && foldFieldName(field.label) === want);
136
146
  if (labelled.length === 1)
137
147
  return labelled[0];
138
148
  if (labelled.length > 1)
@@ -141,17 +151,15 @@ const fieldNamed = (fields, name) => {
141
151
  param: "--field",
142
152
  candidates: labelled.map(named),
143
153
  });
144
- const close = fields.filter((field) => [field.code, field.label ?? ""].some((one) => {
145
- const other = folded(one);
146
- return other !== "" && (other.includes(want) || want.includes(other));
147
- }));
148
- throw new CliError("validation_error", `no custom field is named ${name}${close.length ? "; close ones are in candidates" : ""} — \`fields list\` lists them`, { reason: "field.unknown", param: "--field", candidates: close.map(named) });
154
+ throw unknownField(fields, name);
149
155
  };
150
- const optionOf = (field, value) => {
156
+ /** A list field's option id, by its id or its whole label; a field with no options takes the value as typed. */
157
+ export const optionOf = (field, value) => {
151
158
  if (!field.options)
152
159
  return value;
160
+ const want = foldFieldName(value);
153
161
  const found = field.options.find((option) => option.id === value.trim()) ??
154
- field.options.find((option) => folded(option.label) === folded(value));
162
+ field.options.find((option) => foldFieldName(option.label) === want);
155
163
  if (!found)
156
164
  throw new CliError("validation_error", `${field.label ?? field.code} has no option ${value}`, {
157
165
  reason: "field.unknown-option",
@@ -161,6 +169,13 @@ const optionOf = (field, value) => {
161
169
  });
162
170
  return found.id;
163
171
  };
172
+ /** `--field` pairs as typed, split at the first `=`; a pair with no key before it is refused. */
173
+ export const fieldPairsOf = (typed) => typed.map((one) => {
174
+ const at = one.indexOf("=");
175
+ if (at <= 0 || one.slice(0, at).trim() === "")
176
+ throw new CliError("validation_error", `--field takes <key>=<value>; got ${one}`, { param: "--field" });
177
+ return [one.slice(0, at), one.slice(at + 1)];
178
+ });
164
179
  /**
165
180
  * `--field` pairs by the synced field definitions: a label to its code, an option to its id, a multiple field's
166
181
  * repeats into a list. A CRM whose definitions are not stored takes codes as typed.
@@ -143,6 +143,7 @@ const OTHERS = [
143
143
  validation("search.server-options", "search --backend server takes neither --exact, --cursor nor --newest"),
144
144
  validation("search.one-backend", "search answers from one backend at a time: archive or server"),
145
145
  ["search.server-not-allowed", "permission_error", "the profile does not allow messages.server-search"],
146
+ ["search.all-denied", "permission_error", "the profile denies every kind search all would read"],
146
147
  validation("search.server-no-criteria", "the query has nothing the server can search, so only the store is read"),
147
148
  ["search.server-unsupported", "provider_error", "this source's server cannot search"],
148
149
  ["search.server-rate-limited", "rate_limited", "the server refused a search as too many requests"],
@@ -163,6 +164,7 @@ const OTHERS = [
163
164
  "recovering the store needs the sqlite3 program, 3.43 or newer, with its .recover command",
164
165
  ],
165
166
  validation("store.recovery-failed", "the recovered store did not pass its check, so the store was left as it was"),
167
+ validation("store.recovering", "another recovery of the store is running; wait for it to finish"),
166
168
  validation("store.changed-during-recovery", "the store was written to during the recovery, so it was left as it was"),
167
169
  [
168
170
  "store.vector-extension-missing",
@@ -254,6 +256,20 @@ const OTHERS = [
254
256
  validation("period.ambiguous", "the period can be read more than one way"),
255
257
  validation("proposal.wrong-state", "the proposal is not in a state that allows this"),
256
258
  validation("proposal.reason-required", "an agent deciding for the owner gives a reason"),
259
+ validation("decision.request-invalid", "a decision request needs its batch, message, owner and distinct known actions"),
260
+ ["decision.token-unknown", "not_found", "no button has this token"],
261
+ ["decision.token-used", "permission_error", "this button was already pressed"],
262
+ [
263
+ "decision.token-cancelled",
264
+ "permission_error",
265
+ "another button of the message was pressed, or the feature was turned off",
266
+ ],
267
+ ["decision.token-expired", "permission_error", "this button is older than 72 hours"],
268
+ [
269
+ "decision.token-mismatch",
270
+ "permission_error",
271
+ "the press came from another chat, message or user than the button was sent to",
272
+ ],
257
273
  validation("proposal.decider-required", "a decision names who decides: the owner or an agent with a reason"),
258
274
  validation("proposal.ids", "the proposal ids cannot be read"),
259
275
  ["proposal.own", "permission_error", "an agent never decides its own proposal"],
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export type { GroupRules } from "./moderation/rules.js";
28
28
  export { defaultRules, ModerationRules, moderationPathFor } from "./moderation/rules.js";
29
29
  export { type OutputOptions, resolveOutput } from "./output.js";
30
30
  export { pollLines, type RenderOptions, renderMessage, renderMessages } from "./render/messages.js";
31
- export { isId, type PeopleLookup, pickChat, pickPerson } from "./resolve.js";
31
+ export { foldName, isId, type PeopleLookup, pickChat, pickPerson } from "./resolve.js";
32
32
  export { atTerminal, type LoginQr, type LoginQrOptions, loginQr, PASTE_QR, } from "./terminal/login-qr.js";
33
33
  export { readSecret, type SecretInput } from "./terminal/prompt.js";
34
34
  export { plainQr, terminalQr } from "./terminal/qr.js";
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ export { act, judge } from "./moderation/check.js";
21
21
  export { defaultRules, ModerationRules, moderationPathFor } from "./moderation/rules.js";
22
22
  export { resolveOutput } from "./output.js";
23
23
  export { pollLines, renderMessage, renderMessages } from "./render/messages.js";
24
- export { isId, pickChat, pickPerson } from "./resolve.js";
24
+ export { foldName, isId, pickChat, pickPerson } from "./resolve.js";
25
25
  export { atTerminal, loginQr, PASTE_QR, } from "./terminal/login-qr.js";
26
26
  export { readSecret } from "./terminal/prompt.js";
27
27
  export { plainQr, terminalQr } from "./terminal/qr.js";
@@ -1,5 +1,6 @@
1
1
  import { type Command } from "commander";
2
2
  import { type ImportFile } from "../import.js";
3
+ import { type MeetingBudget } from "../pull.js";
3
4
  import type { MeetingSource } from "../source.js";
4
5
  import type { MeetingStore } from "../store.js";
5
6
  export interface MeetingCommandDeps {
@@ -9,13 +10,26 @@ export interface MeetingCommandDeps {
9
10
  readFiles?: (folder: string) => Promise<ImportFile[]>;
10
11
  /** The host's file names and how it reads their time, shown in `meetings import --help`. */
11
12
  importHelp?: string;
13
+ /** Writes `meetings export --output`; one that refuses a file that exists, such as `writeNewFile`. */
12
14
  writeFile?: (path: string, content: string) => Promise<void>;
15
+ /**
16
+ * Marks `meetings export`, whose only write is the new file `--output` names: a read without it, over MCP, and
17
+ * under the read-only lock. `writesNewFileOnlyWith` from `@wirecat/cli-core/cli`; pass it with a `writeFile` that
18
+ * never writes over a file.
19
+ */
20
+ newFileOutput?: (command: Command, option: string) => void;
13
21
  write: (value: unknown, format: "json" | "jsonl" | "text") => void;
14
22
  /**
15
23
  * Runs a command that reaches the account inside cli-core's run, so it is recorded and ended by `--timeout`:
16
24
  * `inCommandRun` from `@wirecat/cli-core/cli`. Required, since this module cannot reach the run itself.
17
25
  */
18
26
  inRun: <T>(command: Command, body: () => Promise<T>) => Promise<T>;
27
+ /**
28
+ * The sync's budget from the run's deadline and stop signal: `runBudgetOf` from `@wirecat/cli-core/cli`. Given, the
29
+ * sync is cooperative: it stops between meetings, keeps what it saved and answers `stopped`. Without it the sync
30
+ * keeps the one-shot deadline.
31
+ */
32
+ budgetOf?: (command: Command) => MeetingBudget;
19
33
  now?: () => number;
20
34
  }
21
35
  export { addMeetingPassageCommand, createMeetingPassageCommand, type MeetingPassageFlags, meetingPassageRequest, } from "./passage.js";
@@ -1,4 +1,4 @@
1
- import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
1
+ import { annotate, annotateOption, sharedCommand } from "@wirecat/cli-base/commands";
2
2
  import { defineQuery, fieldsHelp, parseLucene, timezoneOf, validateQuery, zonedMoment } from "@wirecat/cli-base/query";
3
3
  import { InvalidArgumentError, Option } from "commander";
4
4
  import { EVENT_QUERY } from "../event-query.js";
@@ -76,12 +76,18 @@ const addMeetingCommandsDefinition = (program, deps) => {
76
76
  .argument("<meeting>", "stored meeting id", integer)).action(async (id, _opts, command) => {
77
77
  print(await meetingSummaryAnswer(deps.store, id, deps.accountId), command);
78
78
  });
79
- output(annotate(group.command("export"), { effects: LOCAL_WRITE, output: { entity: "meeting_export" } })
79
+ const exporter = output(annotate(group.command("export"), { effects: LOCAL_WRITE, output: { entity: "meeting_export" } })
80
80
  .description("export a meeting as Markdown or one transcript as WebVTT")
81
81
  .argument("<meeting>", "stored meeting id", integer)
82
82
  .addOption(new Option("--format <format>", "export format").choices(["markdown", "vtt"]).default("markdown"))
83
83
  .option("--transcript-id <id>", "export a specific transcript version", integer)
84
- .option("--output <file>", "write content to a file through the host's writer")).action(async (id, opts, command) => {
84
+ .addOption(
85
+ // Not over MCP: an agent would choose where on the owner's disk to write; it gets the content in the answer.
86
+ annotateOption(new Option("--output <file>", "write content to a new file through the host's writer"), {
87
+ mcp: false,
88
+ })));
89
+ deps.newFileOutput?.(exporter, "output");
90
+ exporter.action(async (id, opts, command) => {
85
91
  if (opts.output !== undefined && !opts.output.trim())
86
92
  throw new MeetingError("validation_error", "output path must not be empty");
87
93
  if (opts.output !== undefined && !deps.writeFile)
@@ -117,9 +123,13 @@ const addMeetingCommandsDefinition = (program, deps) => {
117
123
  effects: FETCH,
118
124
  offline: false,
119
125
  output: { entity: "meeting_ingestion" },
120
- }).description("bring the stored meetings up to date from the connected account"))
126
+ // Only a sync that stops itself at its budget may outlive the one-shot deadline.
127
+ ...(deps.budgetOf ? { cooperative: true, partial: true } : {}),
128
+ }).description("bring the stored meetings up to date from the connected account, oldest first; a run that stops before its " +
129
+ "deadline keeps what it saved and the next one goes on from there"))
121
130
  .option("--since-time <time>", "fetch meetings starting at or after this ISO 8601 date or time", date)
122
- .option("--lookback-days <days>", "revisit recent occurrences for late transcripts (0–31)", lookbackDays, 0)
131
+ .option("--lookback-days <days>", "revisit recent occurrences for late transcripts (0–31)", lookbackDays)
132
+ .option("--rescan", "read the last 30 days again, not only what came after the last sync")
123
133
  .action(async (opts, command) => {
124
134
  const source = deps.source;
125
135
  if (!source)
@@ -128,7 +138,9 @@ const addMeetingCommandsDefinition = (program, deps) => {
128
138
  accountId: deps.accountId,
129
139
  since: opts.sinceTime === undefined ? undefined : new Date(opts.sinceTime).toISOString(),
130
140
  now: deps.now?.(),
131
- lookbackMs: opts.lookbackDays * 86400000,
141
+ ...(opts.lookbackDays === undefined ? {} : { lookbackMs: opts.lookbackDays * 86400000 }),
142
+ ...(opts.rescan ? { rescan: true } : {}),
143
+ ...(deps.budgetOf ? { budget: deps.budgetOf(command) } : {}),
132
144
  }), command));
133
145
  });
134
146
  const importCommand = annotate(group.command("import"), {
@@ -4,6 +4,8 @@ import type { MeetingHitSearchRequest } from "./search-store.js";
4
4
  export declare const MOST_LINES_APART = 20;
5
5
  /** The messages query language over meeting text: the same fields, a narrower set of operators. */
6
6
  export declare const MEETING_HIT_QUERY: import("@wirecat/cli-base/query").QueryRegistry;
7
+ /** Every name a meeting search reads as a field, lifted or not; another `word:` there is words. */
8
+ export declare const MEETING_FIELD_NAMES: ReadonlySet<string>;
7
9
  /**
8
10
  * `budget project:RES date>=30d` → the words, and the meetings to look in as filters. A meeting field must be
9
11
  * joined to the words with AND and given once, in the query or as an option. Text the language refuses is left as
@@ -64,6 +64,8 @@ const MEETING_FIELDS = defineQuery({
64
64
  ],
65
65
  });
66
66
  const LIFTED = new Set(["date", "project", "tag", "topic"]);
67
+ /** Every name a meeting search reads as a field, lifted or not; another `word:` there is words. */
68
+ export const MEETING_FIELD_NAMES = new Set(MEETING_FIELDS.fields.map(({ name }) => name));
67
69
  /**
68
70
  * `budget project:RES date>=30d` → the words, and the meetings to look in as filters. A meeting field must be
69
71
  * joined to the words with AND and given once, in the query or as an option. Text the language refuses is left as
@@ -10,7 +10,7 @@ export { linkEvent } from "./events.js";
10
10
  export { exportMeeting, type MeetingExport, type MeetingExportFormat, type MeetingExportOptions, serializeVtt, } from "./export.js";
11
11
  export { type FindingEvidence, type FindingOutcome, findingHash, MEETING_FINDINGS_KIND, type MeetingFactFinding, type MeetingFinding, type MeetingFindingsInput, type MeetingFindingsReceipt, type MeetingTaskFinding, meetingFindingFingerprint, validateMeetingFindings, } from "./findings.js";
12
12
  export { type FactFinding, type Finding, type FindingsInput, type FindingsReceipt, type FindingsRules, findingFields, findingFingerprint, findingId, findingNeeds, findingText, type PaymentFinding, snakeCase, type TaskFinding, validateBatch, validateFinding, validateFindings, validEvidence, } from "./findings-rules.js";
13
- export { liftMeetingFields, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery } from "./hit-query.js";
13
+ export { liftMeetingFields, MEETING_FIELD_NAMES, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery, } from "./hit-query.js";
14
14
  export { type ImportFile, importFiles } from "./import.js";
15
15
  export { MEETING_ISSUES, MEETING_QUERY, type MeetingIssue, type MeetingItem, type MeetingOwner, meeting, meetingIssuesOf, meetingItem, } from "./item.js";
16
16
  export { joinKeyOf, joinUrlWithoutQuery } from "./join-key.js";
@@ -31,7 +31,7 @@ export { readMeetingProjectEvidence } from "./project-evidence.js";
31
31
  export { type MeetingProjectEvidenceAnswer, type MeetingProjectEvidenceItem, meetingProjectEvidence, meetingProjectEvidenceAnswer, } from "./project-evidence-answer.js";
32
32
  export { MEETING_PROJECT_EVIDENCE_QUERY, type MeetingProjectEvidenceRequest, prepareMeetingProjectEvidence, } from "./project-evidence-query.js";
33
33
  export { type MeetingProviderScope, snapshotMeetingScope } from "./provider.js";
34
- export { type PullOptions, pull, type RunReport } from "./pull.js";
34
+ export { type MeetingBudget, type MeetingBudgetStop, type PullOptions, pull, type RunReport } from "./pull.js";
35
35
  export { event, eventItem, meetingCounts, meetingCountsItem, meetingLink, meetingLinkItem, meetingParticipants, meetingPassage, meetingReview, meetingReviewItem, meetingSpeaker, meetingSpeakerItem, meetingStats, meetingStatsItem, } from "./read-answers.js";
36
36
  export type { MeetingContextReadCapabilities, MeetingReadBudget, MeetingReadCapabilities, MeetingReadScope, TranscriptContextInput, TranscriptContextPage, TranscriptPage, TranscriptReadScope, TranscriptRowPage, } from "./read-store.js";
37
37
  export { listed, MeetingError, meetingDetailsAnswer, meetingPeople, meetingSummaryAnswer, meetingTranscriptAnswer, type TranscriptReadOptions, } from "./reads.js";
@@ -7,7 +7,7 @@ export { linkEvent } from "./events.js";
7
7
  export { exportMeeting, serializeVtt, } from "./export.js";
8
8
  export { findingHash, MEETING_FINDINGS_KIND, meetingFindingFingerprint, validateMeetingFindings, } from "./findings.js";
9
9
  export { findingFields, findingFingerprint, findingId, findingNeeds, findingText, snakeCase, validateBatch, validateFinding, validateFindings, validEvidence, } from "./findings-rules.js";
10
- export { liftMeetingFields, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery } from "./hit-query.js";
10
+ export { liftMeetingFields, MEETING_FIELD_NAMES, MEETING_HIT_QUERY, meetingWordsQuery, parseMeetingQuery, } from "./hit-query.js";
11
11
  export { importFiles } from "./import.js";
12
12
  export { MEETING_ISSUES, MEETING_QUERY, meeting, meetingIssuesOf, meetingItem, } from "./item.js";
13
13
  export { joinKeyOf, joinUrlWithoutQuery } from "./join-key.js";
@@ -38,7 +38,6 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
- limit?: undefined;
42
41
  event_id?: undefined;
43
42
  series_id?: undefined;
44
43
  page?: undefined;
@@ -54,11 +53,11 @@ export declare const meetingTools: ({
54
53
  format?: undefined;
55
54
  transcript_id?: undefined;
56
55
  query?: undefined;
56
+ limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
- limit?: undefined;
62
61
  event_id?: undefined;
63
62
  series_id?: undefined;
64
63
  page?: undefined;
@@ -76,11 +75,11 @@ export declare const meetingTools: ({
76
75
  format?: undefined;
77
76
  transcript_id?: undefined;
78
77
  query?: undefined;
78
+ limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
- limit?: undefined;
84
83
  event_id?: undefined;
85
84
  series_id?: undefined;
86
85
  page?: undefined;
@@ -102,6 +101,7 @@ export declare const meetingTools: ({
102
101
  minimum: number;
103
102
  };
104
103
  query?: undefined;
104
+ limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,7 +188,6 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
- limit?: undefined;
192
191
  event_id?: undefined;
193
192
  series_id?: undefined;
194
193
  page?: undefined;
@@ -204,11 +203,11 @@ export declare const meetingTools: ({
204
203
  format?: undefined;
205
204
  transcript_id?: undefined;
206
205
  query?: undefined;
206
+ limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
- limit?: undefined;
212
211
  event_id?: undefined;
213
212
  series_id?: undefined;
214
213
  page?: undefined;
@@ -226,11 +225,11 @@ export declare const meetingTools: ({
226
225
  format?: undefined;
227
226
  transcript_id?: undefined;
228
227
  query?: undefined;
228
+ limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
- limit?: undefined;
234
233
  event_id?: undefined;
235
234
  series_id?: undefined;
236
235
  page?: undefined;
@@ -252,6 +251,7 @@ export declare const meetingTools: ({
252
251
  minimum: number;
253
252
  };
254
253
  query?: undefined;
254
+ limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,7 +338,6 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
- limit?: undefined;
342
341
  event_id?: undefined;
343
342
  series_id?: undefined;
344
343
  page?: undefined;
@@ -354,11 +353,11 @@ export declare const meetingTools: ({
354
353
  format?: undefined;
355
354
  transcript_id?: undefined;
356
355
  query?: undefined;
356
+ limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
- limit?: undefined;
362
361
  event_id?: undefined;
363
362
  series_id?: undefined;
364
363
  page?: undefined;
@@ -376,11 +375,11 @@ export declare const meetingTools: ({
376
375
  format?: undefined;
377
376
  transcript_id?: undefined;
378
377
  query?: undefined;
378
+ limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
- limit?: undefined;
384
383
  event_id?: undefined;
385
384
  series_id?: undefined;
386
385
  page?: undefined;
@@ -402,6 +401,7 @@ export declare const meetingTools: ({
402
401
  minimum: number;
403
402
  };
404
403
  query?: undefined;
404
+ limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,7 +488,6 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
- limit?: undefined;
492
491
  event_id?: undefined;
493
492
  series_id?: undefined;
494
493
  page?: undefined;
@@ -504,11 +503,11 @@ export declare const meetingTools: ({
504
503
  format?: undefined;
505
504
  transcript_id?: undefined;
506
505
  query?: undefined;
506
+ limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
- limit?: undefined;
512
511
  event_id?: undefined;
513
512
  series_id?: undefined;
514
513
  page?: undefined;
@@ -526,11 +525,11 @@ export declare const meetingTools: ({
526
525
  format?: undefined;
527
526
  transcript_id?: undefined;
528
527
  query?: undefined;
528
+ limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
- limit?: undefined;
534
533
  event_id?: undefined;
535
534
  series_id?: undefined;
536
535
  page?: undefined;
@@ -552,6 +551,7 @@ export declare const meetingTools: ({
552
551
  minimum: number;
553
552
  };
554
553
  query?: undefined;
554
+ limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,7 +638,6 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
- limit?: undefined;
642
641
  event_id?: undefined;
643
642
  series_id?: undefined;
644
643
  page?: undefined;
@@ -654,11 +653,11 @@ export declare const meetingTools: ({
654
653
  format?: undefined;
655
654
  transcript_id?: undefined;
656
655
  query?: undefined;
656
+ limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
- limit?: undefined;
662
661
  event_id?: undefined;
663
662
  series_id?: undefined;
664
663
  page?: undefined;
@@ -676,11 +675,11 @@ export declare const meetingTools: ({
676
675
  format?: undefined;
677
676
  transcript_id?: undefined;
678
677
  query?: undefined;
678
+ limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
- limit?: undefined;
684
683
  event_id?: undefined;
685
684
  series_id?: undefined;
686
685
  page?: undefined;
@@ -702,6 +701,7 @@ export declare const meetingTools: ({
702
701
  minimum: number;
703
702
  };
704
703
  query?: undefined;
704
+ limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -11,12 +11,24 @@ export interface RunReport {
11
11
  }[];
12
12
  /** An import whose files all read their start time in one zone names it; files carry no zone of their own. */
13
13
  timezone?: string;
14
+ /** A pull stopped by its budget before every meeting it listed: why, and how many it did not reach. */
15
+ stopped?: MeetingBudgetStop;
16
+ remaining?: number;
17
+ }
18
+ export type MeetingBudgetStop = "requests" | "deadline" | "cancelled";
19
+ /** One meeting more, or why not: `runBudgetOf(command)` from `@wirecat/cli-core/cli` fits. */
20
+ export interface MeetingBudget {
21
+ take(): MeetingBudgetStop | null;
14
22
  }
15
23
  export interface PullOptions {
16
24
  accountId: number;
17
25
  since?: string;
18
26
  now?: number;
19
- /** Revisit recent occurrences; integer milliseconds from 0 through 31 days. Defaults to 0. */
27
+ /** Revisit recent occurrences; integer milliseconds from 0 through 31 days. Defaults to the source's `overlapMs`. */
20
28
  lookbackMs?: number;
29
+ /** Start from 30 days back, not from the cursor. */
30
+ rescan?: boolean;
31
+ /** Asked before each meeting; a stop keeps what is saved and moves the cursor to the first meeting not reached. */
32
+ budget?: MeetingBudget;
21
33
  }
22
34
  export declare const pull: (source: MeetingSource, store: MeetingStore, options: PullOptions) => Promise<RunReport>;
@@ -16,25 +16,51 @@ const participantInput = (p, provider, occurrenceId, position, accountId) => {
16
16
  },
17
17
  };
18
18
  };
19
+ /** A start that does not parse sorts last; its own save reports it. */
20
+ const startOf = (m) => {
21
+ const at = Date.parse(m.occurrence.startedAt);
22
+ return Number.isFinite(at) ? at : Number.POSITIVE_INFINITY;
23
+ };
19
24
  export const pull = async (source, store, options) => {
20
25
  const now = options.now ?? Date.now();
21
- const lookbackMs = options.lookbackMs ?? 0;
22
- if (!Number.isSafeInteger(lookbackMs) || lookbackMs < 0 || lookbackMs > 31 * 86400000)
23
- throw new Error("lookbackMs must be an integer from 0 through 31 days");
24
- const since = options.since ?? (await store.cursor(options.accountId)) ?? new Date(now - 30 * 86400000).toISOString();
26
+ for (const [name, ms] of [
27
+ ["lookbackMs", options.lookbackMs ?? 0],
28
+ ["overlapMs", source.overlapMs ?? 0],
29
+ ])
30
+ if (!Number.isSafeInteger(ms) || ms < 0 || ms > 31 * 86400000)
31
+ throw new Error(`${name} must be an integer from 0 through 31 days`);
32
+ const lookbackMs = Math.max(options.lookbackMs ?? 0, source.overlapMs ?? 0);
33
+ const cursor = options.rescan ? undefined : await store.cursor(options.accountId);
34
+ const since = options.since ?? cursor ?? new Date(now - 30 * 86400000).toISOString();
25
35
  timestamp(since);
26
36
  const report = { meetings: 0, participants: 0, transcriptRows: 0, summaries: 0, warnings: [] };
27
37
  let failed = false;
38
+ /** The start of the first meeting that failed: the cursor of a stopped pull goes no further. */
39
+ let firstFailed;
28
40
  const from = timestamp(since) - lookbackMs;
29
- const meetings = await source.meetings(lookbackMs === 0 ? since : new Date(from).toISOString());
30
- for (const m of meetings) {
41
+ // Oldest first, so a stopped pull leaves everything before its cursor done.
42
+ const meetings = (await source.meetings(lookbackMs === 0 ? since : new Date(from).toISOString())).toSorted((a, b) => startOf(a) - startOf(b));
43
+ for (const [index, m] of meetings.entries()) {
44
+ const stop = options.budget?.take() ?? null;
45
+ if (stop) {
46
+ report.stopped = stop;
47
+ report.remaining = meetings.length - index;
48
+ const reached = Math.min(startOf(m), firstFailed ?? Number.POSITIVE_INFINITY);
49
+ if (Number.isFinite(reached) && reached > timestamp(since))
50
+ await store.setCursor(options.accountId, new Date(reached).toISOString(), now);
51
+ return report;
52
+ }
31
53
  const id = m.occurrence.id;
54
+ const failedHere = () => {
55
+ failed = true;
56
+ firstFailed ??= startOf(m);
57
+ };
32
58
  const read = async (part, call) => {
33
59
  try {
34
60
  return await call();
35
61
  }
36
62
  catch (error) {
37
- failed = true;
63
+ failedHere();
38
64
  const message = error instanceof Error ? error.message : "could not be read";
39
65
  report.warnings.push({ externalId: id, message: `${part}: ${message}` });
40
66
  return undefined;
@@ -138,7 +164,7 @@ export const pull = async (source, store, options) => {
138
164
  report.summaries += summary ? 1 : 0;
139
165
  }
140
166
  catch (error) {
141
- failed = true;
167
+ failedHere();
142
168
  report.warnings.push({ externalId: id, message: error instanceof Error ? error.message : "Meeting pull failed" });
143
169
  }
144
170
  }
@@ -17,6 +17,11 @@ export interface MeetingSource {
17
17
  readonly provider: string;
18
18
  readonly name: string;
19
19
  readonly transcriptFormat?: string;
20
+ /**
21
+ * How far back each sync looks before its cursor, in integer milliseconds up to 31 days: a provider that lists a
22
+ * meeting only once it has ended, or adds its recording later, sets it. 0 when absent; `--lookback-days` widens it.
23
+ */
24
+ readonly overlapMs?: number;
20
25
  meetings(since: string): Promise<SourceMeeting[]>;
21
26
  participants(occurrenceId: string): Promise<SourceParticipant[] | null>;
22
27
  transcript(occurrenceId: string): Promise<TranscriptLine[] | null>;
package/dist/resolve.d.ts CHANGED
@@ -11,8 +11,8 @@ export interface PeopleLookup {
11
11
  export declare const isId: (reference: string) => boolean;
12
12
  /**
13
13
  * A name as matching compares it. A copied emoji often carries a presentation mark (U+FE0F, U+FE0E) or a joiner
14
- * (U+200D) the typed one lacks, and a letter may come composed or as letter plus accent; none of that is a different
15
- * name.
14
+ * (U+200D) the typed one lacks, a letter may come composed or as letter plus accent, and Russian is mostly typed with
15
+ * е for ё; none of that is a different name. Only ё is folded: stripping every mark would also merge й into и.
16
16
  */
17
17
  export declare const foldName: (name: string) => string;
18
18
  /**
package/dist/resolve.js CHANGED
@@ -4,13 +4,14 @@ import { contactReferenceOf } from "./domain/ref-arguments.js";
4
4
  export const isId = (reference) => /^-?\d+$/.test(reference.trim());
5
5
  /**
6
6
  * A name as matching compares it. A copied emoji often carries a presentation mark (U+FE0F, U+FE0E) or a joiner
7
- * (U+200D) the typed one lacks, and a letter may come composed or as letter plus accent; none of that is a different
8
- * name.
7
+ * (U+200D) the typed one lacks, a letter may come composed or as letter plus accent, and Russian is mostly typed with
8
+ * е for ё; none of that is a different name. Only ё is folded: stripping every mark would also merge й into и.
9
9
  */
10
10
  export const foldName = (name) => name
11
11
  .normalize("NFC")
12
12
  .replace(/[\uFE0E\uFE0F\u200D]/g, "")
13
- .toLowerCase();
13
+ .toLowerCase()
14
+ .replaceAll("ё", "е");
14
15
  /**
15
16
  * A name matched as a fragment — and **an ambiguous one is an error, not a guess**: sending to the
16
17
  * wrong conversation is not undoable, so the caller is shown the candidates and asked to be
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Free text as the search reads it: a character the query language takes as syntax where it cannot be syntax — the
3
+ * colon of `10:30` or `HH:MM`, a URL's slashes, an unbalanced quote or bracket — is made literal by quoting the word
4
+ * that holds it, a `word:` that names no search field is that word, and a bare emoji or punctuation mark beside other
5
+ * words is dropped. A query that already reads well comes back unchanged, so this can run again on its own output;
6
+ * field queries and Boolean operators keep their meaning. A field's own mistake (`kind:nonsense`) is left for the
7
+ * search to report. `fields` are the names a list of its own (memories: `text`, `scope`) reads as fields.
8
+ */
9
+ export declare const plainQuery: (text: string, fields?: ReadonlySet<string>) => string;