@wirecat/cli-core 0.747.0 → 0.749.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,37 @@ 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.749.0 — 24.11.2026
9
+
10
+ ### Fixed
11
+
12
+ - **One bad part no longer costs the whole report.** A section, item or health entry that fails the check is left
13
+ out, and the rest is delivered with a last line saying how many were left out ("⚠️ Не показано из-за ошибки
14
+ формата: 2"). `last.json` names them under `report.dropped`, with the reason `report.items-dropped`. Only the
15
+ document's own fields (the JSON, `kind`, `date`, the `sections` list, `tasks`, `scope`) still refuse it. The owner's
16
+ morning digest was lost whole on 2026-11-17 (two meetings) and 2026-11-21..24 (one reply).
17
+ - **A time without an offset is read as local time.** An agent writes a meeting's hour as `2026-11-17T10:00:00`; that
18
+ was refused.
19
+
20
+ ## 0.748.0 — 24.11.2026
21
+
22
+ ### Added
23
+
24
+ - **A documents source can ask for a full walk every so often.** A manifest's `rescanEvery` (such as `"7d"`) makes a
25
+ plain `sync` walk the chosen folders in full, as `--rescan` does, once that long has passed since the last full
26
+ walk. A Linear document restored from the trash, which neither its changes nor its deletions name, comes back without
27
+ `--rescan`. The sync that starts the walk says why in its answer (`rescan`). Unset, nothing changes.
28
+ ([docs](docs/dev/DOCUMENTS.md#a-full-walk-every-so-often))
29
+
30
+ ### Changed — may break callers
31
+
32
+ - **`activities create --subject person:<n>` and `organization:<n>` name the copy's record, as `deals show` gives it
33
+ and `people show` reads it.** They named the CRM's id, so in a CRM that numbers its records a reference taken from
34
+ `deals show` put the note on someone else's contact or company. A contact or company by the CRM's id, as
35
+ `people list` prints it, is now `person:crm:<id>`. An id that cannot be a reference, such as Attio's UUIDs, works
36
+ as before. A reference that stands for more than one CRM record is refused with `crm.record-ambiguous`, one the
37
+ copy does not hold with `not_found` naming the `crm:` form.
38
+
8
39
  ## 0.747.0 — 24.11.2026
9
40
 
10
41
  ### Fixed
@@ -7,6 +7,7 @@ export type ReportChannel = (typeof REPORT_CHANNELS)[number];
7
7
  export type MessageView = ReportView | GapsView | NoticeView;
8
8
  export declare const REPORT_REASONS: {
9
9
  readonly invalid: "delivery.report-invalid";
10
+ readonly dropped: "report.items-dropped";
10
11
  readonly templateFailed: "report.template-failed";
11
12
  readonly templateTags: "report.template-tags";
12
13
  };
@@ -58,6 +59,8 @@ export interface ReportRun {
58
59
  leaks: number;
59
60
  /** The path of the first field that failed the check; nothing was shown. */
60
61
  invalid?: string;
62
+ /** The sections, items and health entries left out because they failed the check; the rest was shown. */
63
+ dropped?: string[];
61
64
  reasons?: string[];
62
65
  }
63
66
  export interface PreparedReport {
@@ -10,6 +10,7 @@ const DEFAULT_LANGUAGE = "en";
10
10
  const LIMITS = { parse: 65_536, memory: 4_000_000, milliseconds: 1_000 };
11
11
  export const REPORT_REASONS = {
12
12
  invalid: "delivery.report-invalid",
13
+ dropped: "report.items-dropped",
13
14
  templateFailed: "report.template-failed",
14
15
  templateTags: "report.template-tags",
15
16
  };
@@ -307,6 +308,24 @@ const INVALID_LINES = {
307
308
  ru: "Сводка не собралась: ошибка формата. Подробности в WireCat.",
308
309
  en: "The report could not be built: format error. Details in WireCat.",
309
310
  };
311
+ const DROPPED_LINES = {
312
+ ru: (count) => `⚠️ Не показано из-за ошибки формата: ${count}. Подробности в WireCat.`,
313
+ en: (count) => `⚠️ Left out for a format error: ${count}. Details in WireCat.`,
314
+ };
315
+ /** The line after a report that lost parts to the check, so a short digest is never read as a whole one. */
316
+ const withDropped = (rendered, line) => {
317
+ if (!line)
318
+ return rendered;
319
+ const last = rendered.telegram.at(-1) ?? "";
320
+ const note = escapeHtml(line);
321
+ const joined = last ? `${last}\n\n${note}` : note;
322
+ const telegram = fits(joined) ? [...rendered.telegram.slice(0, -1), joined] : [...rendered.telegram, note];
323
+ const paragraph = `<p>${note}</p>`;
324
+ const email = rendered.email.trimEnd().endsWith("</div>")
325
+ ? rendered.email.replace(/<\/div>\s*$/, `${paragraph}\n</div>`)
326
+ : `${rendered.email}${paragraph}`;
327
+ return { telegram, email, text: `${rendered.text}\n\n${line}`, terminal: `${rendered.terminal}\n\n${line}` };
328
+ };
310
329
  /**
311
330
  * A run's answer rendered for every route, or `undefined` when it is not a report. An invalid report becomes one
312
331
  * line in the owner's language and is never shown raw.
@@ -352,16 +371,23 @@ export const prepareReport = async (answer, { language, now, timeZone, templates
352
371
  ...(renderings.some((one) => one.templateTags > 0) ? [REPORT_REASONS.templateTags] : []),
353
372
  ];
354
373
  const title = text.text.split("\n")[0] ?? "";
374
+ const { dropped } = parsed;
375
+ if (dropped.length)
376
+ reasons.push(REPORT_REASONS.dropped);
377
+ const lineOf = DROPPED_LINES[shipped] ?? DROPPED_LINES[DEFAULT_LANGUAGE];
378
+ const shown = withDropped({ telegram: telegram.parts, email: email.text, text: text.text, terminal: terminal.text }, dropped.length ? lineOf(dropped.length) : undefined);
355
379
  return {
356
- telegram: telegram.parts,
357
- email: email.text,
358
- text: text.text,
359
- terminal: terminal.text,
380
+ ...shown,
360
381
  document: `${JSON.stringify(reportDocument(parsed.report), null, 2)}\n`,
361
382
  subject: title,
362
383
  notice: [title, parsed.report.summary].filter(Boolean).join("\n"),
363
384
  invalid: false,
364
- run: { language: shipped, leaks: parsed.leaks, ...(reasons.length ? { reasons } : {}) },
385
+ run: {
386
+ language: shipped,
387
+ leaks: parsed.leaks,
388
+ ...(dropped.length ? { dropped } : {}),
389
+ ...(reasons.length ? { reasons } : {}),
390
+ },
365
391
  };
366
392
  };
367
393
  const templateOf = (templates, channel) => {
@@ -100,13 +100,14 @@ export declare const isReportAnswer: (answer: string) => boolean;
100
100
  export type ParsedReport = {
101
101
  report: Report;
102
102
  leaks: number;
103
+ dropped: string[];
103
104
  } | {
104
105
  invalid: string;
105
106
  };
106
107
  /**
107
108
  * A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
108
- * report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
109
- * of the first field that failed, and is never shown. `trusted` is a document a command built from the store: its
109
+ * report (`undefined`) and keeps the Markdown path; a JSON answer whose own fields fail the check is `invalid`, with
110
+ * the path of the first field that failed, and is never shown; a part that fails is left out and named in `dropped`. `trusted` is a document a command built from the store: its
110
111
  * strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
111
112
  */
112
113
  export declare const parseReport: (answer: string, trusted?: boolean) => ParsedReport | undefined;
@@ -46,7 +46,8 @@ export const withoutLeaks = (text) => {
46
46
  class Invalid extends Error {
47
47
  }
48
48
  const DATE = /^\d{4}-\d{2}-\d{2}$/;
49
- const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
49
+ // No offset is the machine's local time, as `Date.parse` reads it: agents write a meeting's "10:00" that way.
50
+ const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/;
50
51
  const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
51
52
  const oneOf = (values, value, at) => {
52
53
  if (!values.includes(value))
@@ -139,10 +140,26 @@ const tasksOf = (value) => {
139
140
  const cut = (text, limit) => (text.length <= limit ? text : `${text.slice(0, limit - 1).trimEnd()}…`);
140
141
  /**
141
142
  * Checks a parsed document and keeps what the renderers may show. Any agent string loses what `withoutLeaks` finds
142
- * and is cut to its limit; a required field left empty by that makes the document invalid, as a missing one does.
143
+ * and is cut to its limit; a required field left empty by that fails its item, as a missing one does. A section,
144
+ * item or health entry that fails is left out and named in `dropped`: one undated reply must not cost the whole
145
+ * digest. Only the document's own fields (format, kind, date, the sections list, tasks, scope) refuse it.
143
146
  */
144
147
  const checked = (document, trusted) => {
145
148
  let leaks = 0;
149
+ const dropped = [];
150
+ const kept = (list, at, check) => list.flatMap((one, index) => {
151
+ const before = leaks;
152
+ try {
153
+ return [check(one, at(index))];
154
+ }
155
+ catch (error) {
156
+ if (!(error instanceof Invalid))
157
+ throw error;
158
+ leaks = before;
159
+ dropped.push(error.message);
160
+ return [];
161
+ }
162
+ });
146
163
  const text = (value, field, at) => {
147
164
  if (value === undefined || value === null)
148
165
  return null;
@@ -163,15 +180,13 @@ const checked = (document, trusted) => {
163
180
  throw new Invalid("date");
164
181
  if (!Array.isArray(document.sections))
165
182
  throw new Invalid("sections");
166
- const sections = document.sections.map((section, s) => {
167
- const at = `sections[${s}]`;
183
+ const sections = kept(document.sections, (s) => `sections[${s}]`, (section, at) => {
168
184
  if (!isObject(section) || !Array.isArray(section.items))
169
185
  throw new Invalid(at);
170
186
  return {
171
187
  kind: oneOf(SECTION_KINDS, section.kind, `${at}.kind`),
172
188
  more: section.more === undefined || section.more === null ? 0 : whole(section.more, `${at}.more`),
173
- items: section.items.map((item, i) => {
174
- const where = `${at}.items[${i}]`;
189
+ items: kept(section.items, (i) => `${at}.items[${i}]`, (item, where) => {
175
190
  if (!isObject(item))
176
191
  throw new Invalid(where);
177
192
  const type = oneOf(ITEM_TYPES, item.type, `${where}.type`);
@@ -211,8 +226,7 @@ const checked = (document, trusted) => {
211
226
  date: document.date,
212
227
  summary: text(document.summary, "summary", "summary"),
213
228
  sections,
214
- health: health.map((entry, h) => {
215
- const at = `health[${h}]`;
229
+ health: kept(health, (h) => `health[${h}]`, (entry, at) => {
216
230
  if (!isObject(entry))
217
231
  throw new Invalid(at);
218
232
  const reason = entry.reason === undefined || entry.reason === null
@@ -238,6 +252,7 @@ const checked = (document, trusted) => {
238
252
  tasks: tasksOf(document.tasks),
239
253
  },
240
254
  leaks,
255
+ dropped,
241
256
  };
242
257
  };
243
258
  /**
@@ -282,8 +297,8 @@ export const isReportAnswer = (answer) => {
282
297
  };
283
298
  /**
284
299
  * A run's answer as a report: one JSON object, bare or as the only fenced `json` block. Text that is neither is not a
285
- * report (`undefined`) and keeps the Markdown path; a JSON answer that fails the check is `invalid`, with the path
286
- * of the first field that failed, and is never shown. `trusted` is a document a command built from the store: its
300
+ * report (`undefined`) and keeps the Markdown path; a JSON answer whose own fields fail the check is `invalid`, with
301
+ * the path of the first field that failed, and is never shown; a part that fails is left out and named in `dropped`. `trusted` is a document a command built from the store: its
287
302
  * strings are the owner's data, such as a CRM title `follow_up`, and lose nothing to the leak patterns.
288
303
  */
289
304
  export const parseReport = (answer, trusted = false) => {
@@ -75,6 +75,11 @@ export interface DocumentManifest {
75
75
  content?: DocumentCall & {
76
76
  markdown: string;
77
77
  };
78
+ /**
79
+ * How often a plain sync walks the chosen folders in full, as `--rescan` does, for a provider whose changes and
80
+ * deletions miss an edit (Linear's restore from the trash): a duration such as `7d` or `12h`. Needs a change feed.
81
+ */
82
+ rescanEvery?: string;
78
83
  /**
79
84
  * A saved document read again though it did not change: one whose `providerMetadata` has no value at `missing`
80
85
  * (a field the source learned to read later, such as authors).
@@ -47,6 +47,7 @@ const schema = v.strictObject({
47
47
  overlapMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))),
48
48
  })),
49
49
  content: v.optional(v.strictObject({ ...callEntries, markdown: dotPath })),
50
+ rescanEvery: v.optional(v.pipe(v.string(), v.regex(/^[1-9]\d*(ms|s|m|h|d)$/, "a duration with a unit, such as 7d"))),
50
51
  reread: v.optional(v.strictObject({ missing: dotPath })),
51
52
  reads: v.optional(v.record(v.pipe(v.string(), v.regex(/^[a-z][A-Za-z0-9]*$/, "a camelCase name")), v.strictObject(callEntries))),
52
53
  });
@@ -10,7 +10,7 @@ export interface DocumentSlots {
10
10
  cursor?: string;
11
11
  }
12
12
  /** A source of a `files` CLI: a change feed when the manifest or a hook gives one. */
13
- export type ManifestDocumentSource<M extends SourceFile = SourceFile> = FeedlessDocumentSource<M> & Partial<Pick<DocumentSource<M>, "startToken" | "changes">>;
13
+ export type ManifestDocumentSource<M extends SourceFile = SourceFile> = FeedlessDocumentSource<M> & Partial<Pick<DocumentSource<M>, "startToken" | "changes" | "rescanEveryMs">>;
14
14
  /** What a hook builds on: the manifest's own calls, and the source the manifest alone describes. */
15
15
  export interface DocumentManifestTools<M extends SourceFile = SourceFile> {
16
16
  manifest: DocumentManifest;
@@ -1,4 +1,5 @@
1
1
  import { CliError, isCliError } from "@wirecat/cli-base";
2
+ import { parseDuration } from "../../../domain/duration.js";
2
3
  import { answerAt as at, nextPage, parameterValue, withValue, } from "../../service-api-manifest.js";
3
4
  import { parseDocumentManifest } from "./manifest.js";
4
5
  const OVERLAP_MS = 10 * 60_000;
@@ -254,6 +255,11 @@ export const documentSourceFromManifest = (input, options) => {
254
255
  throw new CliError("configuration_error", "source manifest: a change feed needs both startToken and changes", {
255
256
  reason: "manifest.invalid",
256
257
  });
258
+ if (manifest.rescanEvery) {
259
+ if (!source.changes)
260
+ throw new CliError("configuration_error", "source manifest: rescanEvery needs a change feed; a source without one walks in full on every sync", { reason: "manifest.invalid" });
261
+ source.rescanEveryMs ??= parseDuration(manifest.rescanEvery, "source manifest: rescanEvery");
262
+ }
257
263
  const { deletions } = manifest;
258
264
  if (deletions) {
259
265
  const changesOf = source.changes;
@@ -189,8 +189,9 @@ const addActivityWrites = (group, options) => {
189
189
  example(write("create", `add a ${kinds.join(" or ")} to records of the CRM, then store the CRM's copy of it when the activities ` +
190
190
  "setting is on")
191
191
  .addArgument(new Argument("<kind>", "what to add").choices(kinds))
192
- .option("--subject <ref>", `a record it is on: ${leads ? "deal:<id> or lead:<id>" : "deal:<id>"} as a list shows it, or person:<id> or ` +
193
- "organization:<id> by the CRM's id as people list and organizations list print it; repeat it for more", (value, previous = []) => [...previous, value],
192
+ .option("--subject <ref>", `a record it is on: ${leads ? "deal:<id>, lead:<id>" : "deal:<id>"}, person:<id> or organization:<id> as a ` +
193
+ "list or deals show gives it, or person:crm:<id> or organization:crm:<id> by the CRM's id as people list " +
194
+ "and organizations list print it; repeat it for more", (value, previous = []) => [...previous, value],
194
195
  // The empty default marks the flag as repeatable, so an agent's tool takes a list.
195
196
  [])
196
197
  .option("--title <title>", task ? "a task's title, needed for a task; a comment's title where the CRM keeps one" : "its title")
@@ -516,7 +516,12 @@ const MOST_SUBJECT = 500;
516
516
  const MOST_BODY = 20_000;
517
517
  const activityInvalid = (message, param) => new CliError("validation_error", message, { reason: "crm.activity-field", ...(param ? { param } : {}) });
518
518
  const activityUnsupported = (what) => new CliError("validation_error", `this CRM does not take ${what}`, { reason: "crm.write-unsupported", sent: false });
519
- /** `deal:12` and `lead:4` by the copy, as `deals list` shows them; a contact or company by the CRM's id. */
519
+ /**
520
+ * Every `kind:<n>` is the copy's reference, as `deals list` and `deals show` give it and `show` reads it: a contact's
521
+ * or company's CRM id under the same form was a different record wherever the CRM numbers its records, so a note went
522
+ * on someone else's company. `person:crm:<id>` names one by the CRM's id; an id no reference can be (Attio's UUIDs)
523
+ * needs no `crm:`.
524
+ */
520
525
  const activityTargetOf = async (context, given) => {
521
526
  const at = given.indexOf(":");
522
527
  const kind = given.slice(0, at);
@@ -525,9 +530,27 @@ const activityTargetOf = async (context, given) => {
525
530
  const copy = await copyOf(context, kind, given.trim());
526
531
  return { kind, externalId: copy.externalId, ref: copy.ref, title: copy.title };
527
532
  }
528
- if ((kind === "person" || kind === "organization") && RECORD_ID.test(id))
529
- return { kind, externalId: id, ref: null, title: null };
530
- throw new CliError("validation_error", `--subject takes deal:<id> or lead:<id> as a list shows it, or person:<id> or organization:<id> by the CRM's id; got ${given}`, { reason: "ref.malformed", param: "--subject" });
533
+ if (kind === "person" || kind === "organization") {
534
+ const crmId = id.startsWith("crm:") ? id.slice(4) : /^\d+$/.test(id) ? undefined : id;
535
+ if (crmId !== undefined && RECORD_ID.test(crmId))
536
+ return { kind, externalId: crmId, ref: null, title: null };
537
+ if (crmId === undefined) {
538
+ const ids = await context.store.crm.externalIdsOf(context.account, given);
539
+ if (ids.length > 1)
540
+ throw new CliError("validation_error", `${given} is ${ids.length} records of the CRM; name one as ${kind}:crm:<id>`, {
541
+ reason: "crm.record-ambiguous",
542
+ param: "--subject",
543
+ candidates: ids.map((one) => ({ id: `${kind}:crm:${one}` })),
544
+ sent: false,
545
+ });
546
+ if (ids[0])
547
+ return { kind, externalId: ids[0], ref: given, title: null };
548
+ throw new CliError("not_found", `the copy holds no ${given}; a ${kind} by the CRM's id, as ${kind === "person" ? "people" : "organizations"} ` +
549
+ `list prints it, is ${kind}:crm:<id>`, { param: "--subject", sent: false });
550
+ }
551
+ }
552
+ throw new CliError("validation_error", `--subject takes deal:<id>, lead:<id>, person:<id> or organization:<id> as the copy's lists and deals show give ` +
553
+ `them, or person:crm:<id> or organization:crm:<id> by the CRM's id; got ${given}`, { reason: "ref.malformed", param: "--subject" });
531
554
  };
532
555
  const activityKeys = async (context, key, owner) => ({
533
556
  key,
@@ -87,6 +87,12 @@ export interface DocumentSource<M extends SourceFile = SourceFile> extends Feedl
87
87
  items: SourceChange<M>[];
88
88
  cursor: string;
89
89
  }>;
90
+ /**
91
+ * For a feed that misses some edits (Linear's restore from the trash leaves `updatedAt` as it was): a plain sync
92
+ * walks the chosen folders in full, as `--rescan` does, once this long has passed since the last full walk ended.
93
+ * Left out, only `--rescan` walks again.
94
+ */
95
+ rescanEveryMs?: number;
90
96
  }
91
97
  /** The feed of a source that has one. */
92
98
  export declare const feedOf: <M extends SourceFile>(source: FeedlessDocumentSource<M>) => DocumentSource<M> | undefined;
@@ -133,6 +139,8 @@ export interface SourceState<M extends SourceFile = SourceFile> {
133
139
  };
134
140
  matched?: string[];
135
141
  lastSync?: string;
142
+ /** When the last full walk of the chosen folders ended: a first sync, a rescan or a changed scope. */
143
+ fullWalkAt?: string;
136
144
  }
137
145
  export interface PictureWriter {
138
146
  save(reference: string, bytes: Uint8Array): Promise<"saved" | "unchanged">;
@@ -1,4 +1,4 @@
1
- import type { SourceFile } from "../../documents/model.js";
1
+ import { type SourceFile } from "../../documents/model.js";
2
2
  import { type WalkStop } from "./plan.js";
3
3
  import type { SyncOptions } from "./ports.js";
4
4
  export declare const KEEP_VERSIONS_FOR_DAYS = 365;
@@ -31,5 +31,11 @@ export interface SyncResult {
31
31
  entries: number;
32
32
  listed: number;
33
33
  };
34
+ /** This call started a full walk on its own: the source's `rescanEveryMs` had passed since the last one. */
35
+ rescan?: {
36
+ why: string;
37
+ every_ms: number;
38
+ last_full_walk: string | null;
39
+ };
34
40
  }
35
41
  export declare const syncDocuments: <M extends SourceFile>(options: SyncOptions<M>) => Promise<SyncResult>;
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { CliError, isCliError } from "@wirecat/cli-base";
3
3
  import { deadlineMargin } from "../../background/budget.js";
4
4
  import { catalogFiles } from "../../documents/catalog.js";
5
+ import { feedOf, } from "../../documents/model.js";
5
6
  import { inScope } from "../../documents/scope.js";
6
7
  import { changedSince, planDocuments, scopeHash } from "./plan.js";
7
8
  import { isPicture as readsAsPicture } from "./scans.js";
@@ -12,9 +13,16 @@ const SETTLE_MS = 10_000;
12
13
  const DAY_MS = 24 * 60 * 60 * 1000;
13
14
  export const KEEP_VERSIONS_FOR_DAYS = 365;
14
15
  const isPicture = (file) => file.mime.startsWith("image/") && file.canDownload;
16
+ const describe = (ms) => ms % DAY_MS === 0
17
+ ? `${ms / DAY_MS} days`
18
+ : ms % 3_600_000 === 0
19
+ ? `${ms / 3_600_000} hours`
20
+ : ms % 60_000 === 0
21
+ ? `${ms / 60_000} minutes`
22
+ : `${ms} ms`;
15
23
  const hashText = (text) => createHash("sha256").update(text).digest("hex");
16
24
  export const syncDocuments = async (options) => {
17
- const { source, index, state: statePort, principal, roots, textLimit: limit, max, signal, rescan = false, pictures = false, assertHeld, errorOf, skipReason, storeVersion: VERSION, query, scans, } = options;
25
+ const { source, index, state: statePort, principal, roots, textLimit: limit, max, signal, rescan: asked = false, pictures = false, assertHeld, errorOf, skipReason, storeVersion: VERSION, query, scans, } = options;
18
26
  if (![max, limit, options.maxEntries].every((value) => Number.isSafeInteger(value) && value > 0))
19
27
  throw new CliError("validation_error", "sync limits must be positive whole numbers");
20
28
  const profile = { principal, roots, picture_search: pictures };
@@ -52,6 +60,28 @@ export const syncDocuments = async (options) => {
52
60
  if (options.profile !== undefined)
53
61
  await index.registerProfile?.(options.profile, principal);
54
62
  const currentScope = scopeHash(profile.roots, query, options.isDocument !== undefined);
63
+ // Only a source whose feed misses something asks for it, and only between walks: the walk it starts drops the
64
+ // cursor, so the calls that go on with that walk are not due again.
65
+ const every = source ? feedOf(source)?.rescanEveryMs : undefined;
66
+ if (every !== undefined && !(Number.isSafeInteger(every) && every > 0))
67
+ throw new CliError("configuration_error", "a source's rescanEveryMs must be a positive whole number");
68
+ const sinceWalk = now() - (state.fullWalkAt ? Date.parse(state.fullWalkAt) : Number.NaN);
69
+ // A walk recorded in the future (a clock set back, a state copied from another machine) would hold it off for good.
70
+ const due = !asked &&
71
+ every !== undefined &&
72
+ state.cursor !== undefined &&
73
+ state.scope === currentScope &&
74
+ !(sinceWalk >= 0 && sinceWalk < every);
75
+ if (due)
76
+ result.rescan = {
77
+ why: state.fullWalkAt === undefined
78
+ ? "no full walk of the chosen folders is recorded; the source's changes miss some edits, such as a restore"
79
+ : `the last full walk finished ${describe(every)} or more ago; the source's changes miss some edits, ` +
80
+ "such as a restore",
81
+ every_ms: every,
82
+ last_full_walk: state.fullWalkAt ?? null,
83
+ };
84
+ const rescan = asked || due;
55
85
  if (state.pending && (state.pending.scope !== currentScope || rescan)) {
56
86
  // Work the new plan cannot see: a file saved to the index before its state was.
57
87
  for (const job of state.pending.jobs)
@@ -317,6 +347,8 @@ export const syncDocuments = async (options) => {
317
347
  result.pending = pending.jobs.length;
318
348
  result.complete = !pending.jobs.length;
319
349
  if (!pending.jobs.length) {
350
+ if (!state.cursor || state.scope !== pending.scope)
351
+ state.fullWalkAt = new Date(now()).toISOString();
320
352
  state.cursor = pending.cursor;
321
353
  state.scope = pending.scope;
322
354
  state.folders = pending.folders;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.747.0",
3
+ "version": "0.749.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",