@wirecat/cli-core 0.746.0 → 0.748.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 +27 -0
- package/dist/background/report/schema.js +2 -1
- package/dist/cli/documents/manifest/manifest.d.ts +5 -0
- package/dist/cli/documents/manifest/manifest.js +1 -0
- package/dist/cli/documents/manifest/source.d.ts +1 -1
- package/dist/cli/documents/manifest/source.js +6 -0
- package/dist/crm/cli/activities.js +3 -2
- package/dist/crm/writes.js +27 -4
- package/dist/documents/model.d.ts +8 -0
- package/dist/services/documents/sync.d.ts +7 -1
- package/dist/services/documents/sync.js +33 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,33 @@ 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.748.0 — 24.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A documents source can ask for a full walk every so often.** A manifest's `rescanEvery` (such as `"7d"`) makes a
|
|
13
|
+
plain `sync` walk the chosen folders in full, as `--rescan` does, once that long has passed since the last full
|
|
14
|
+
walk. A Linear document restored from the trash, which neither its changes nor its deletions name, comes back without
|
|
15
|
+
`--rescan`. The sync that starts the walk says why in its answer (`rescan`). Unset, nothing changes.
|
|
16
|
+
([docs](docs/dev/DOCUMENTS.md#a-full-walk-every-so-often))
|
|
17
|
+
|
|
18
|
+
### Changed — may break callers
|
|
19
|
+
|
|
20
|
+
- **`activities create --subject person:<n>` and `organization:<n>` name the copy's record, as `deals show` gives it
|
|
21
|
+
and `people show` reads it.** They named the CRM's id, so in a CRM that numbers its records a reference taken from
|
|
22
|
+
`deals show` put the note on someone else's contact or company. A contact or company by the CRM's id, as
|
|
23
|
+
`people list` prints it, is now `person:crm:<id>`. An id that cannot be a reference, such as Attio's UUIDs, works
|
|
24
|
+
as before. A reference that stands for more than one CRM record is refused with `crm.record-ambiguous`, one the
|
|
25
|
+
copy does not hold with `not_found` naming the `crm:` form.
|
|
26
|
+
|
|
27
|
+
## 0.747.0 — 24.11.2026
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- **A report's `reply` item no longer needs `since`.** A morning digest whose agent could not date one message was
|
|
32
|
+
refused whole: memo kept no `.report.json`, and the delivery said the digest did not come together. Such a reply is
|
|
33
|
+
now kept and shown without "waiting N days"; a `since` that is not a date is still refused.
|
|
34
|
+
|
|
8
35
|
## 0.746.0 — 24.11.2026
|
|
9
36
|
|
|
10
37
|
### Added
|
|
@@ -15,8 +15,9 @@ const TEXT_LIMITS = {
|
|
|
15
15
|
source: 40,
|
|
16
16
|
account: 60,
|
|
17
17
|
};
|
|
18
|
+
// A reply's `since` is optional: an agent that cannot date a message must not lose the whole digest over it.
|
|
18
19
|
const REQUIRED = {
|
|
19
|
-
reply: ["who", "topic", "action"
|
|
20
|
+
reply: ["who", "topic", "action"],
|
|
20
21
|
question: ["who", "topic", "action"],
|
|
21
22
|
task: ["topic"],
|
|
22
23
|
fact: ["topic", "detail"],
|
|
@@ -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
|
|
193
|
-
"organization:<id> by the CRM's id as people list
|
|
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")
|
package/dist/crm/writes.js
CHANGED
|
@@ -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
|
-
/**
|
|
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 (
|
|
529
|
-
|
|
530
|
-
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.748.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",
|