@wirecat/cli-core 0.600.0 → 0.601.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 (58) hide show
  1. package/CHANGELOG.md +55 -0
  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/new-file.d.ts +2 -0
  14. package/dist/cli/new-file.js +13 -0
  15. package/dist/cli/program.js +3 -0
  16. package/dist/cli/search-left-out.d.ts +27 -0
  17. package/dist/cli/search-left-out.js +31 -0
  18. package/dist/crm/cli/index.js +2 -7
  19. package/dist/crm/cli/search-all.js +17 -2
  20. package/dist/crm/index.d.ts +1 -1
  21. package/dist/crm/index.js +1 -1
  22. package/dist/crm/writes.d.ts +17 -0
  23. package/dist/crm/writes.js +31 -16
  24. package/dist/errors/reasons.js +15 -0
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/meetings/cli/index.d.ts +14 -0
  28. package/dist/meetings/cli/index.js +18 -6
  29. package/dist/meetings/index.d.ts +1 -1
  30. package/dist/meetings/mcp/index.d.ts +15 -15
  31. package/dist/meetings/pull.d.ts +13 -1
  32. package/dist/meetings/pull.js +34 -8
  33. package/dist/meetings/source.d.ts +5 -0
  34. package/dist/resolve.d.ts +2 -2
  35. package/dist/resolve.js +4 -3
  36. package/dist/services/search-all.d.ts +3 -0
  37. package/dist/services/search-all.js +1 -0
  38. package/dist/speech/local.d.ts +2 -1
  39. package/dist/speech/local.js +12 -1
  40. package/dist/speech/recognize.d.ts +2 -0
  41. package/dist/speech/recognize.js +15 -0
  42. package/dist/store/decision-requests.d.ts +10 -0
  43. package/dist/store/decision-requests.js +16 -0
  44. package/dist/store/index.d.ts +2 -0
  45. package/dist/store/index.js +1 -0
  46. package/dist/store/sqlite/deals.d.ts +3 -1
  47. package/dist/store/sqlite/deals.js +2 -2
  48. package/dist/store/sqlite/decision-requests.d.ts +59 -0
  49. package/dist/store/sqlite/decision-requests.js +111 -0
  50. package/dist/store/sqlite/manifest.js +2 -0
  51. package/dist/store/sqlite/migrations.generated.js +12 -0
  52. package/dist/store/sqlite/schema/decision-requests.d.ts +233 -0
  53. package/dist/store/sqlite/schema/decision-requests.js +20 -0
  54. package/dist/store/sqlite/schema.d.ts +1 -0
  55. package/dist/store/sqlite/schema.js +1 -0
  56. package/dist/store/store.d.ts +3 -0
  57. package/dist/store/store.js +5 -0
  58. package/package.json +2 -2
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"), {
@@ -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";
@@ -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
@@ -1,5 +1,6 @@
1
1
  import { type ErrorCode } from "@wirecat/cli-base";
2
2
  import { type HitFile } from "../domain/attachments.js";
3
+ import type { DealKind } from "../domain/deals.js";
3
4
  import { type MailFields } from "../domain/models.js";
4
5
  import type { MessengerTraits } from "../ports/traits.js";
5
6
  import type { AccountKey, MessageStore } from "../store/store.js";
@@ -104,6 +105,8 @@ export interface SearchAllRequest {
104
105
  signal?: AbortSignal;
105
106
  /** The accounts `--source` chose, per kind; a kind left out reads every account of its own. */
106
107
  scope?: Partial<Record<SearchedResource, AccountKey[]>>;
108
+ /** The CRM kinds `crm` reads; absent, deals and leads. */
109
+ crmKinds?: readonly DealKind[];
107
110
  }
108
111
  export type SearchAllMessenger = Partial<Pick<MessengerTraits, "savedChatId" | "app">> & {
109
112
  /**
@@ -257,6 +257,7 @@ export const searchAll = async (store, account, request, messenger = {}, searchM
257
257
  const found = await store.deals.find({
258
258
  words,
259
259
  anyWord: anyWord || discover,
260
+ ...(request.crmKinds === undefined ? {} : { kinds: request.crmKinds }),
260
261
  limit: Math.min(window + 1, 500),
261
262
  ...(chosen === undefined ? {} : { accounts: chosen }),
262
263
  });
@@ -13,6 +13,7 @@ export interface LocalSpeechRecognitionModel {
13
13
  export interface LocalSpeechBackend {
14
14
  recognize(pcm: Float32Array): string;
15
15
  pieces?(pcm: Float32Array): TimedText[];
16
+ piecesUntil?(pcm: Float32Array, signal: AbortSignal): Promise<TimedText[]>;
16
17
  free(): void;
17
18
  }
18
19
  export interface LocalSpeechRecognizer extends LocalSpeechRecognitionModel {
@@ -34,6 +35,6 @@ export declare const localSpeechRecognitionModel: (id: string) => Readonly<Local
34
35
  * A whole recording, one channel of it, cut at pauses by the voice detector: each piece's text with where it lies,
35
36
  * in seconds. Two channels heard this way merge into a dialogue by `start`. Existing installed models only.
36
37
  */
37
- export declare const recognizeLocalPieces: (id: string, audio: Pcm, options?: Pick<LocalSpeechRecognizerOptions, "directory" | "env" | "open">) => Promise<TimedText[]>;
38
+ export declare const recognizeLocalPieces: (id: string, audio: Pcm, options?: Pick<LocalSpeechRecognizerOptions, "directory" | "env" | "open" | "signal">) => Promise<TimedText[]>;
38
39
  /** Existing installed models only. Synchronous inference cancels between bounded windows. */
39
40
  export declare const openLocalSpeechRecognizer: (id: string, input?: LocalSpeechRecognizerOptions) => Promise<LocalSpeechRecognizer>;
@@ -47,7 +47,18 @@ export const recognizeLocalPieces = async (id, audio, options = {}) => {
47
47
  try {
48
48
  if (!engine.pieces)
49
49
  throw new CliError("configuration_error", "this speech backend gives no timed pieces");
50
- return engine.pieces(toModelRate(audio.samples, audio.rate));
50
+ const pcm = toModelRate(audio.samples, audio.rate);
51
+ const { signal } = options;
52
+ if (!signal)
53
+ return engine.pieces(pcm);
54
+ cancelled(signal);
55
+ try {
56
+ return engine.piecesUntil ? await engine.piecesUntil(pcm, signal) : engine.pieces(pcm);
57
+ }
58
+ catch (error) {
59
+ cancelled(signal);
60
+ throw error;
61
+ }
51
62
  }
52
63
  finally {
53
64
  engine.free();
@@ -10,6 +10,8 @@ export interface Recognizer {
10
10
  recognize(pcm: Float32Array): string;
11
11
  /** Each stretch of speech the voice detector cut, with where it lies; the same input as `recognize`. */
12
12
  pieces?(pcm: Float32Array): TimedText[];
13
+ /** `pieces`, giving the event loop a turn between pieces, so `signal` can stop a long recording between two. */
14
+ piecesUntil?(pcm: Float32Array, signal: AbortSignal): Promise<TimedText[]>;
13
15
  free(): void;
14
16
  }
15
17
  export declare const SAMPLE_RATE = 16000;
@@ -152,11 +152,26 @@ export const openRecognizer = (model, path, vadModel) => {
152
152
  });
153
153
  return heard;
154
154
  };
155
+ // Decoding is synchronous: without a turn of the event loop between pieces no abort could ever be seen.
156
+ const piecesUntil = async (pcm, signal) => {
157
+ const spans = [];
158
+ cut(vad, pcm, (span) => spans.push(span));
159
+ const heard = [];
160
+ for (const { start, end, samples } of spans) {
161
+ await new Promise((resolve) => setImmediate(resolve));
162
+ signal.throwIfAborted();
163
+ const text = piece(samples);
164
+ if (text)
165
+ heard.push({ start, end, text });
166
+ }
167
+ return heard;
168
+ };
155
169
  return {
156
170
  recognize: (pcm) => pieces(pcm)
157
171
  .map(({ text }) => text)
158
172
  .join(" "),
159
173
  pieces,
174
+ piecesUntil,
160
175
  free: () => {
161
176
  vad.free();
162
177
  engine.free();
@@ -0,0 +1,10 @@
1
+ export declare const DECISION_ACTIONS: readonly ["confirm", "reject", "ask-confirm", "ask-reject", "back", "later"];
2
+ export type DecisionAction = (typeof DECISION_ACTIONS)[number];
3
+ /** Seventy-two hours: a press after that finds nothing to take. */
4
+ export declare const DECISION_TTL_MS: number;
5
+ export declare const CALLBACK_PREFIX = "wcr1:";
6
+ export declare const isDecisionToken: (value: unknown) => value is string;
7
+ /** The 27 bytes a button carries: Telegram allows 64. */
8
+ export declare const callbackDataOf: (token: string) => string;
9
+ /** The token in a button's data, or `undefined` for anything else; the data is only ever looked up, never read further. */
10
+ export declare const parseCallbackData: (data: unknown) => string | undefined;
@@ -0,0 +1,16 @@
1
+ export const DECISION_ACTIONS = ["confirm", "reject", "ask-confirm", "ask-reject", "back", "later"];
2
+ /** Seventy-two hours: a press after that finds nothing to take. */
3
+ export const DECISION_TTL_MS = 72 * 60 * 60 * 1000;
4
+ export const CALLBACK_PREFIX = "wcr1:";
5
+ // 16 random bytes in base64url are 22 characters, and the last one carries 2 data bits: only these four can end a token.
6
+ const TOKEN = /^[A-Za-z0-9_-]{21}[AQgw]$/;
7
+ const CALLBACK = /^wcr1:([A-Za-z0-9_-]{21}[AQgw])$/;
8
+ export const isDecisionToken = (value) => typeof value === "string" && TOKEN.test(value);
9
+ /** The 27 bytes a button carries: Telegram allows 64. */
10
+ export const callbackDataOf = (token) => {
11
+ if (!isDecisionToken(token))
12
+ throw new TypeError("not a decision token");
13
+ return `${CALLBACK_PREFIX}${token}`;
14
+ };
15
+ /** The token in a button's data, or `undefined` for anything else; the data is only ever looked up, never read further. */
16
+ export const parseCallbackData = (data) => typeof data === "string" ? CALLBACK.exec(data)?.[1] : undefined;
@@ -10,6 +10,7 @@ export { PAYMENT_DIRECTIONS, PAYMENT_STATES, type Payment, paymentTitle, validat
10
10
  export { CLOSED_STATES, isClosedState, PRIORITY_LABELS, type PriorityLabel, priorityLabel, priorityOf, priorityOption, TASK_STATES, type TaskState, } from "../tasks/index.js";
11
11
  export type { AccountMail, AccountMeetings, AccountStore } from "./account-store.js";
12
12
  export { type DamageExplanation, explainDamage } from "./damage.js";
13
+ export { CALLBACK_PREFIX, callbackDataOf, DECISION_ACTIONS, DECISION_TTL_MS, type DecisionAction, isDecisionToken, parseCallbackData, } from "./decision-requests.js";
13
14
  export { assertMayDecide, DEFAULT_DECISION_POLICY, type Decider, type DecisionPolicy, isOwnerOnlyKind, mayDecide, type Proposer, type Refusal, } from "./decisions.js";
14
15
  export type { DocumentTransferOptions, DocumentTransferPreview, DocumentTransferReceipt, } from "./document-transfer/index.js";
15
16
  export { applyDocumentTransfer, previewDocumentTransfer } from "./document-transfer/index.js";
@@ -38,6 +39,7 @@ export { CATALOG_QUERY } from "./sqlite/catalog.js";
38
39
  export type { ChatMetadata } from "./sqlite/chats.js";
39
40
  export { type CrmCopies, type CrmSaved, type CrmSkipped, crmIdentityId } from "./sqlite/crm.js";
40
41
  export type { Deal, DealFilter, DealInput, DealPerson, DealScope, DealsStore, FunnelStage, Pipeline, PipelineInput, PipelineReport, PipelineStage, } from "./sqlite/deals.js";
42
+ export type { DecisionMessage, DecisionPress, DecisionRefusal, DecisionRequest, DecisionRequestInput, DecisionRequestStore, TakeResult, } from "./sqlite/decision-requests.js";
41
43
  export type { Email, EmailAddress, EmailAttachment, EmailFacts, EmailFilter, EmailInput, EmailInThread, EmailLocationInput, EmailRecipient, EmailRef, EmailThread, EmailVectorHit, FolderEmail, Mailbox, MailboxInput, MailFilter, MailStore, PartialEmail, SenderScore, ThreadDetails, ThreadSave, } from "./sqlite/emails.js";
42
44
  export { EVENT_FIELDS, type EventChunkToEmbed, type EventHit, type EventQuery, type EventSearch, type NearestEvent, } from "./sqlite/event-search.js";
43
45
  export type { EvidenceSource } from "./sqlite/evidence-sources.js";
@@ -4,6 +4,7 @@ export { note } from "../entities/note.js";
4
4
  export { PAYMENT_DIRECTIONS, PAYMENT_STATES, paymentTitle, validatePayment } from "../meetings/index.js";
5
5
  export { CLOSED_STATES, isClosedState, PRIORITY_LABELS, priorityLabel, priorityOf, priorityOption, TASK_STATES, } from "../tasks/index.js";
6
6
  export { explainDamage } from "./damage.js";
7
+ export { CALLBACK_PREFIX, callbackDataOf, DECISION_ACTIONS, DECISION_TTL_MS, isDecisionToken, parseCallbackData, } from "./decision-requests.js";
7
8
  export { assertMayDecide, DEFAULT_DECISION_POLICY, isOwnerOnlyKind, mayDecide, } from "./decisions.js";
8
9
  export { applyDocumentTransfer, previewDocumentTransfer } from "./document-transfer/index.js";
9
10
  export { PRAGMAS } from "./driver.js";
@@ -153,6 +153,8 @@ export interface DealSearch {
153
153
  anyWord?: boolean;
154
154
  /** Only the copies of these CRM accounts; absent, every account's and the owner's own. */
155
155
  accounts?: AccountKey[];
156
+ /** Only these kinds; absent, deals and leads. */
157
+ kinds?: readonly DealKind[];
156
158
  /** 1–500, 100 by default. */
157
159
  limit?: number;
158
160
  }
@@ -217,7 +219,7 @@ export declare const dealOperationsOver: (context: StoreContext) => {
217
219
  add: (input: DealInput) => Deal;
218
220
  get: (reference: string) => Deal;
219
221
  list: (filter?: DealFilter) => Deal[];
220
- find: ({ words, anyWord, accounts, limit }: DealSearch) => Deal[];
222
+ find: ({ words, anyWord, accounts, kinds, limit }: DealSearch) => Deal[];
221
223
  move: (reference: string, { stage, by }: {
222
224
  stage: string;
223
225
  by: Author;