@wirecat/cli-core 0.727.0 → 0.729.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 +37 -0
- package/dist/cli/documents/file-mirrors.d.ts +70 -0
- package/dist/cli/documents/file-mirrors.js +718 -0
- package/dist/cli/documents/index.d.ts +2 -1
- package/dist/cli/documents/index.js +2 -1
- package/dist/cli/documents/library.d.ts +44 -2
- package/dist/cli/documents/library.js +62 -12
- package/dist/cli/documents/sync.d.ts +26 -0
- package/dist/cli/documents/sync.js +67 -53
- package/dist/domain/providers.d.ts +7 -2
- package/dist/domain/providers.js +13 -5
- package/dist/errors/reasons.js +10 -0
- package/dist/search/account-list.js +9 -5
- package/dist/services/search-all.js +12 -2
- package/dist/services/search-kind.js +6 -5
- package/dist/store/sqlite/ref-accounts.js +10 -6
- package/dist/tracker/cli/index.d.ts +6 -0
- package/dist/tracker/cli/index.js +185 -49
- package/package.json +2 -2
|
@@ -12,6 +12,7 @@ export { addDocumentCatalogCommands, CATALOG_FIELDS, type CatalogTree, type Cata
|
|
|
12
12
|
export { addLocalDocumentCommands, type ImportedDocument, type LocalDocumentCommands } from "./documents.js";
|
|
13
13
|
export { type FileConflictCommands, type FileConflictConnection, fileConflictsCommand } from "./file-conflicts.js";
|
|
14
14
|
export { addFileEditCommands, type FileEditCommands } from "./file-edit.js";
|
|
15
|
+
export { type FileMirrorCommands, type FileMirrorRemote, type FileMirrorWrite, fileMirrorsCommand, } from "./file-mirrors.js";
|
|
15
16
|
export { addFileUpdateCommand, type FileUpdateCommands, type FileUpdatePort } from "./file-update.js";
|
|
16
17
|
export { addDocumentFolderCommands, type DocumentFolderCommands } from "./folders.js";
|
|
17
18
|
export { addDocumentHistoryCommands, DOCUMENT_HISTORY_SETTINGS, type DocumentHistoryCommands, type DocumentHistoryPort, keepVersionsForDays, } from "./history.js";
|
|
@@ -41,6 +42,6 @@ export interface DocumentCommands<S> {
|
|
|
41
42
|
* `search`, `catalog`, the knowledge groups and, when given, `mirrors`, in that order. Answers the `documents` group, for the CLI's live subcommands.
|
|
42
43
|
*/
|
|
43
44
|
export declare const addDocumentCommands: <S>(program: Command, options: DocumentCommands<S>) => Command;
|
|
44
|
-
export { claimDocumentAccount, type DocumentLibraryOptions, type DocumentLibraryTools, type DocumentSourceRun, type DocumentWarning, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
45
|
+
export { claimDocumentAccount, type DocumentLibraryOptions, type DocumentLibraryTools, type DocumentSourceRun, type DocumentSyncOutcome, type DocumentSyncStep, type DocumentWarning, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
45
46
|
export { type DocumentCall, type DocumentFileMap, type DocumentManifest, parseDocumentManifest, } from "./manifest/manifest.js";
|
|
46
47
|
export { type DocumentManifestSourceOptions, type DocumentManifestTools, type DocumentSlots, documentSourceFromManifest, type ManifestDocumentSource, } from "./manifest/source.js";
|
|
@@ -10,6 +10,7 @@ export { addDocumentCatalogCommands, CATALOG_FIELDS, catalogId, catalogOutput, c
|
|
|
10
10
|
export { addLocalDocumentCommands } from "./documents.js";
|
|
11
11
|
export { fileConflictsCommand } from "./file-conflicts.js";
|
|
12
12
|
export { addFileEditCommands } from "./file-edit.js";
|
|
13
|
+
export { fileMirrorsCommand, } from "./file-mirrors.js";
|
|
13
14
|
export { addFileUpdateCommand } from "./file-update.js";
|
|
14
15
|
export { addDocumentFolderCommands } from "./folders.js";
|
|
15
16
|
export { addDocumentHistoryCommands, DOCUMENT_HISTORY_SETTINGS, keepVersionsForDays, } from "./history.js";
|
|
@@ -37,6 +38,6 @@ export const addDocumentCommands = (program, options) => {
|
|
|
37
38
|
addDocumentMirrorCommands(program, { ...shared, ...options.mirrors });
|
|
38
39
|
return documents;
|
|
39
40
|
};
|
|
40
|
-
export { claimDocumentAccount, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
41
|
+
export { claimDocumentAccount, documentLibrary, documentLibraryCommands, documentProfile, } from "./library.js";
|
|
41
42
|
export { parseDocumentManifest, } from "./manifest/manifest.js";
|
|
42
43
|
export { documentSourceFromManifest, } from "./manifest/source.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ErrorCode } from "@wirecat/cli-base";
|
|
2
|
+
import type { NextStep } from "@wirecat/cli-base/standards";
|
|
2
3
|
import { Command } from "commander";
|
|
3
|
-
import type { Deadline } from "../../background/budget.js";
|
|
4
|
+
import type { Deadline, RunBudget } from "../../background/budget.js";
|
|
4
5
|
import { type documentIngestion, type FeedlessDocumentSource, type SourceContent, type SourceFile, type SourceStatePort } from "../../documents.js";
|
|
5
6
|
import type { ProviderEntry } from "../../domain/providers.js";
|
|
6
7
|
import type { AppIdentity } from "../../ports/app.js";
|
|
@@ -10,7 +11,8 @@ import { baseContext } from "../context.js";
|
|
|
10
11
|
import { type Body } from "../envelope.js";
|
|
11
12
|
import { ProfileTokenStore } from "../profile-token.js";
|
|
12
13
|
import type { DocumentKnowledgePort } from "./knowledge.js";
|
|
13
|
-
import type
|
|
14
|
+
import { type DocumentSyncAnswer } from "./sync.js";
|
|
15
|
+
import { type DocumentWords } from "./words.js";
|
|
14
16
|
type Resolve = Parameters<typeof baseContext>[1];
|
|
15
17
|
type Ingestion<M extends SourceFile> = ReturnType<typeof documentIngestion<M>>;
|
|
16
18
|
/** Something a source met on its way and went on past: one per file, gathered into the answer's issues. */
|
|
@@ -102,6 +104,46 @@ export declare const documentProfile: <M extends SourceFile>(app: AppIdentity, e
|
|
|
102
104
|
* it was synced from.
|
|
103
105
|
*/
|
|
104
106
|
export declare const claimDocumentAccount: (app: AppIdentity, env: NodeJS.ProcessEnv, profile: string, account: string, tokens: Pick<ProfileTokenStore, "read">) => void;
|
|
107
|
+
/** The documents half of a `sync` another group mounts, as the shared `sync` would have answered it. */
|
|
108
|
+
export interface DocumentSyncOutcome {
|
|
109
|
+
/** The shared `sync`'s answer, its warnings included; `skipped` when the profile has nothing to sync. */
|
|
110
|
+
item: (DocumentSyncAnswer & {
|
|
111
|
+
warnings: unknown[];
|
|
112
|
+
}) | {
|
|
113
|
+
skipped: string;
|
|
114
|
+
};
|
|
115
|
+
meta: {
|
|
116
|
+
complete?: false;
|
|
117
|
+
issues?: {
|
|
118
|
+
code: ErrorCode;
|
|
119
|
+
reason: string;
|
|
120
|
+
source: string;
|
|
121
|
+
}[];
|
|
122
|
+
};
|
|
123
|
+
next: NextStep[];
|
|
124
|
+
diagnostics: string[];
|
|
125
|
+
}
|
|
126
|
+
/** Runs the documents sync inside the command another group mounted as `sync`. */
|
|
127
|
+
export type DocumentSyncStep = (command: Command, args: {
|
|
128
|
+
rescan?: boolean;
|
|
129
|
+
embed?: boolean;
|
|
130
|
+
budget: RunBudget;
|
|
131
|
+
deadline?: Deadline;
|
|
132
|
+
/** The account the other group's part synced; the documents of another account of it are refused. */
|
|
133
|
+
account?: {
|
|
134
|
+
provider: string;
|
|
135
|
+
account: string;
|
|
136
|
+
};
|
|
137
|
+
}) => Promise<DocumentSyncOutcome>;
|
|
138
|
+
/**
|
|
139
|
+
* `documentLibraryCommands` without its `sync`, and that sync as a step, for a CLI whose own `sync` brings the
|
|
140
|
+
* documents too: linear-cli's tracker `sync` (`addTrackerCommands({ documents })`), so the owner and Desktop keep one
|
|
141
|
+
* `<cli> sync`.
|
|
142
|
+
*/
|
|
143
|
+
export declare const documentLibrary: <M extends SourceFile>(options: DocumentLibraryOptions<M>) => {
|
|
144
|
+
commands: Command[];
|
|
145
|
+
sync: DocumentSyncStep;
|
|
146
|
+
};
|
|
105
147
|
/**
|
|
106
148
|
* cli-core's shared `folders`, `sync`, `status`, `documents`, `search`, `catalog` and knowledge groups over a CLI's
|
|
107
149
|
* document source, its files under the CLI's state folder and the shared store. The CLI gives the source, how it
|
|
@@ -26,7 +26,8 @@ import { addDocumentHistoryCommands, keepVersionsForDays } from "./history.js";
|
|
|
26
26
|
import { addDocumentKnowledgeCommands } from "./knowledge.js";
|
|
27
27
|
import { factItem, memoryItem } from "./queries.js";
|
|
28
28
|
import { addDocumentSearchCommand } from "./search.js";
|
|
29
|
-
import { addDocumentSyncCommands } from "./sync.js";
|
|
29
|
+
import { addDocumentSyncCommands, DOCUMENT_SYNC_LIMIT, documentSyncPart, } from "./sync.js";
|
|
30
|
+
import { wordsOf } from "./words.js";
|
|
30
31
|
const readJson = (path) => {
|
|
31
32
|
try {
|
|
32
33
|
return JSON.parse(readFileSync(path, "utf8"));
|
|
@@ -136,17 +137,21 @@ export const claimDocumentAccount = (app, env, profile, account, tokens) => {
|
|
|
136
137
|
};
|
|
137
138
|
const DOCUMENT_REF = /^document:[1-9]\d*$/u;
|
|
138
139
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
140
|
+
* `documentLibraryCommands` without its `sync`, and that sync as a step, for a CLI whose own `sync` brings the
|
|
141
|
+
* documents too: linear-cli's tracker `sync` (`addTrackerCommands({ documents })`), so the owner and Desktop keep one
|
|
142
|
+
* `<cli> sync`.
|
|
142
143
|
*/
|
|
143
|
-
export const
|
|
144
|
+
export const documentLibrary = (options) => libraryOf(options, false);
|
|
145
|
+
const libraryOf = (options, withSync) => {
|
|
144
146
|
const { app } = options;
|
|
145
147
|
const holder = new Command(app.command);
|
|
146
148
|
// The shared helpers take no command, so each run's command is caught as it starts; an MCP server builds the tree
|
|
147
149
|
// anew for every call.
|
|
148
150
|
let running;
|
|
149
151
|
let warnings = [];
|
|
152
|
+
// Set while another group's `sync` runs the documents step: a named run leaves the answer's run_id to that sync.
|
|
153
|
+
let sideRun;
|
|
154
|
+
let expected;
|
|
150
155
|
const command = () => {
|
|
151
156
|
if (!running)
|
|
152
157
|
throw new CliError("configuration_error", "a shared documents port ran outside a command");
|
|
@@ -189,15 +194,18 @@ export const documentLibraryCommands = (options) => {
|
|
|
189
194
|
};
|
|
190
195
|
const locked = (write, fn) => write ? files().locked(fn) : fn(() => undefined);
|
|
191
196
|
const writes = () => metaOf(command()).effects?.local === "write";
|
|
192
|
-
const
|
|
197
|
+
const warningIssues = () => {
|
|
193
198
|
const seen = new Set();
|
|
194
|
-
|
|
199
|
+
return warnings.flatMap((warning) => {
|
|
195
200
|
const key = `${warning.code}:${warning.reason}`;
|
|
196
201
|
if (seen.has(key))
|
|
197
202
|
return [];
|
|
198
203
|
seen.add(key);
|
|
199
204
|
return [{ code: warning.code, reason: warning.reason, source: options.provider.name }];
|
|
200
205
|
});
|
|
206
|
+
};
|
|
207
|
+
const output = (body) => {
|
|
208
|
+
const issues = warningIssues();
|
|
201
209
|
renderAnswer(command(), outputFor(command()), {
|
|
202
210
|
...body,
|
|
203
211
|
...(issues.length ? { meta: { ...body.meta, issues: [...(body.meta?.issues ?? []), ...issues] } } : {}),
|
|
@@ -221,7 +229,7 @@ export const documentLibraryCommands = (options) => {
|
|
|
221
229
|
};
|
|
222
230
|
const withSource = (body, deadline) => {
|
|
223
231
|
refuseOffline(command(), options.service);
|
|
224
|
-
return context().run((events) => body(known(options.source(command(), events, { warn: (one) => warnings.push(one), ...(deadline ? { deadline } : {}) }))));
|
|
232
|
+
return context().run((events) => body(known(options.source(command(), events, { warn: (one) => warnings.push(one), ...(deadline ? { deadline } : {}) }))), sideRun === undefined ? {} : { name: sideRun });
|
|
225
233
|
};
|
|
226
234
|
const errorOf = (error) => isCliError(error)
|
|
227
235
|
? error
|
|
@@ -328,6 +336,9 @@ export const documentLibraryCommands = (options) => {
|
|
|
328
336
|
const chosen = roots();
|
|
329
337
|
const synced = await withSource(async (source) => {
|
|
330
338
|
const live = await source.identity();
|
|
339
|
+
if (expected !== undefined && live !== expected)
|
|
340
|
+
throw new CliError("configuration_error", `the documents are signed in as ${options.service} account ${live}, not ${expected}, the account the ` +
|
|
341
|
+
`rest of this sync read; sign in again with one account (\`${app.command} ${name} session start\`)`, { reason: "documents.other-account" });
|
|
331
342
|
claimDocumentAccount(app, env(), name, live, tokens());
|
|
332
343
|
return files().locked((assertHeld) => withStore(true, async (store) => {
|
|
333
344
|
const result = await syncDocuments({
|
|
@@ -528,10 +539,49 @@ export const documentLibraryCommands = (options) => {
|
|
|
528
539
|
writesOwnerFiles(find(folders, "add"));
|
|
529
540
|
if (options.browse)
|
|
530
541
|
annotate(find(folders, "browse"), { partial: true });
|
|
542
|
+
const start = (action, side, account) => {
|
|
543
|
+
running = action;
|
|
544
|
+
warnings = [];
|
|
545
|
+
sideRun = side;
|
|
546
|
+
expected = account;
|
|
547
|
+
};
|
|
531
548
|
for (const group of holder.commands)
|
|
532
|
-
group.hook("preAction", (_group, action) =>
|
|
533
|
-
|
|
534
|
-
|
|
549
|
+
group.hook("preAction", (_group, action) => start(action));
|
|
550
|
+
const sync = async (action, { rescan, embed, budget, deadline, account }) => {
|
|
551
|
+
start(action, `${environmentOf(action).agent ? "mcp " : ""}sync documents`, account?.provider === options.provider.name ? account.account : undefined);
|
|
552
|
+
const held = files().state("").read();
|
|
553
|
+
// With no folder chosen and nothing kept, a sync would only ask who is signed in; a held copy still runs, so the
|
|
554
|
+
// documents of folders removed since leave it.
|
|
555
|
+
if (!roots().length && !Object.keys(held.documents).length && !held.pending && !files().walkUnderWay())
|
|
556
|
+
return { item: { skipped: "no folders chosen" }, meta: {}, next: [], diagnostics: [] };
|
|
557
|
+
const item = await groups.sync.sync({
|
|
558
|
+
limit: DOCUMENT_SYNC_LIMIT,
|
|
559
|
+
budget,
|
|
560
|
+
...(rescan ? { rescan } : {}),
|
|
561
|
+
...(embed ? { embed } : {}),
|
|
562
|
+
...(deadline ? { deadline } : {}),
|
|
563
|
+
});
|
|
564
|
+
const timeout = action.optsWithGlobals().timeout;
|
|
565
|
+
const part = documentSyncPart(item, {
|
|
566
|
+
again: `${app.command} ${profile()} sync`,
|
|
567
|
+
source: wordsOf(options.words).source,
|
|
568
|
+
resume: { ...(timeout === undefined ? {} : { timeout }), ...(embed ? { embed: true } : {}) },
|
|
569
|
+
longer: {},
|
|
535
570
|
});
|
|
536
|
-
|
|
571
|
+
// The other group's answer names its parts by what they sync, as `tracker` and `documents`.
|
|
572
|
+
const issues = [...(part.meta.issues ?? []), ...warningIssues()].map((one) => ({ ...one, source: "documents" }));
|
|
573
|
+
return {
|
|
574
|
+
item: item,
|
|
575
|
+
meta: { ...part.meta, ...(issues.length ? { complete: false, issues } : {}) },
|
|
576
|
+
next: part.next,
|
|
577
|
+
diagnostics: part.diagnostics,
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
return { commands: holder.commands.filter((one) => withSync || one.name() !== "sync"), sync };
|
|
537
581
|
};
|
|
582
|
+
/**
|
|
583
|
+
* cli-core's shared `folders`, `sync`, `status`, `documents`, `search`, `catalog` and knowledge groups over a CLI's
|
|
584
|
+
* document source, its files under the CLI's state folder and the shared store. The CLI gives the source, how it
|
|
585
|
+
* files a document and its words. Returned as commands to add to the program.
|
|
586
|
+
*/
|
|
587
|
+
export const documentLibraryCommands = (options) => libraryOf(options, true).commands;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { NextStep } from "@wirecat/cli-base/standards";
|
|
1
2
|
import type { Command } from "commander";
|
|
2
3
|
import type { Deadline, RunBudget } from "../../background/budget.js";
|
|
3
4
|
import { type Body } from "../envelope.js";
|
|
4
5
|
import { type DocumentWords } from "./words.js";
|
|
6
|
+
/** The documents one sync reads when `--limit` does not say. */
|
|
7
|
+
export declare const DOCUMENT_SYNC_LIMIT = 200;
|
|
5
8
|
export interface DocumentSyncArgs {
|
|
6
9
|
limit: number;
|
|
7
10
|
rescan?: boolean;
|
|
@@ -45,5 +48,28 @@ export interface DocumentSyncCommands {
|
|
|
45
48
|
/** What `status` answers: the last sync, imported documents and pending work, from local files only. */
|
|
46
49
|
status(): object | Promise<object>;
|
|
47
50
|
}
|
|
51
|
+
/** What a documents sync's answer tells its caller: its meta, the steps to go on and the lines for the person. */
|
|
52
|
+
export interface DocumentSyncPart {
|
|
53
|
+
meta: {
|
|
54
|
+
complete?: false;
|
|
55
|
+
issues?: {
|
|
56
|
+
code: "provider_error";
|
|
57
|
+
reason: "sync.partial";
|
|
58
|
+
source: string;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
next: NextStep[];
|
|
62
|
+
diagnostics: string[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `resume` and `longer` are the arguments of the same sync again and of a longer one, beside the ones each adds:
|
|
66
|
+
* a CLI whose `sync` takes other options than the shared one names its own.
|
|
67
|
+
*/
|
|
68
|
+
export declare const documentSyncPart: (result: DocumentSyncAnswer, words: {
|
|
69
|
+
again: string;
|
|
70
|
+
source: string;
|
|
71
|
+
resume: Record<string, unknown>;
|
|
72
|
+
longer: Record<string, unknown>;
|
|
73
|
+
}) => DocumentSyncPart;
|
|
48
74
|
/** `sync` into the shared store and `status` of the local copy, for the selected profile. */
|
|
49
75
|
export declare const addDocumentSyncCommands: (program: Command, helpers: DocumentSyncCommands) => Command[];
|
|
@@ -5,6 +5,8 @@ import { honoursDryRun } from "../dry-run-guard.js";
|
|
|
5
5
|
import { FETCH, LOCAL_READ } from "../effects.js";
|
|
6
6
|
import { itemOf } from "../envelope.js";
|
|
7
7
|
import { examples, positive, wordsOf } from "./words.js";
|
|
8
|
+
/** The documents one sync reads when `--limit` does not say. */
|
|
9
|
+
export const DOCUMENT_SYNC_LIMIT = 200;
|
|
8
10
|
/** `embedNotes`' answer says enrichment never had the time to send a batch. */
|
|
9
11
|
const enrichmentOutOfTime = (embeddings) => {
|
|
10
12
|
const enrichment = typeof embeddings === "object" && embeddings !== null && "enrichment" in embeddings
|
|
@@ -12,6 +14,57 @@ const enrichmentOutOfTime = (embeddings) => {
|
|
|
12
14
|
: undefined;
|
|
13
15
|
return enrichment?.reason_id === "enrichment.deadline" && enrichment.enriched === 0;
|
|
14
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* `resume` and `longer` are the arguments of the same sync again and of a longer one, beside the ones each adds:
|
|
19
|
+
* a CLI whose `sync` takes other options than the shared one names its own.
|
|
20
|
+
*/
|
|
21
|
+
export const documentSyncPart = (result, words) => {
|
|
22
|
+
const unfinished = result.complete === false || result.pending > 0;
|
|
23
|
+
const moved = (result.walk?.listed ?? 0) > 0 ||
|
|
24
|
+
[result.saved, result.names_only, result.removed, result.unchanged].some((count) => (count ?? 0) > 0);
|
|
25
|
+
// The same sync again, never --rescan, which would start the pass over; a run that moved nothing gets no step.
|
|
26
|
+
const resume = unfinished && !result.errors.length && moved
|
|
27
|
+
? [
|
|
28
|
+
{
|
|
29
|
+
kind: "command",
|
|
30
|
+
step: "sync.run",
|
|
31
|
+
command: "sync",
|
|
32
|
+
args: words.resume,
|
|
33
|
+
why: "the sync stopped before the end of its pass; running it again goes on from there",
|
|
34
|
+
safe_to_auto_execute: true,
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
: [];
|
|
38
|
+
// Enrichment starts a batch only when it ends before the deadline; one that never had the time would not move in
|
|
39
|
+
// a run like this one either, so the step asks for a longer run and is not run unasked.
|
|
40
|
+
const longer = enrichmentOutOfTime(result.embeddings)
|
|
41
|
+
? [
|
|
42
|
+
{
|
|
43
|
+
kind: "command",
|
|
44
|
+
step: "sync.longer",
|
|
45
|
+
command: "sync",
|
|
46
|
+
args: { ...words.longer, embed: true, timeout: "15m" },
|
|
47
|
+
why: "enrichment needs more time than this run had left, so it sent nothing; run this in a terminal, " +
|
|
48
|
+
"where a sync may take 15 minutes",
|
|
49
|
+
safe_to_auto_execute: false,
|
|
50
|
+
},
|
|
51
|
+
]
|
|
52
|
+
: [];
|
|
53
|
+
const diagnostics = result.walk
|
|
54
|
+
? [`${result.walk.folders_left} folders remain to list; run ${words.again} again\n`]
|
|
55
|
+
: result.errors.length || result.pending
|
|
56
|
+
? [`${result.pending} source operations remain; run ${words.again} again\n`]
|
|
57
|
+
: [];
|
|
58
|
+
return {
|
|
59
|
+
meta: result.errors.length
|
|
60
|
+
? { complete: false, issues: [{ code: "provider_error", reason: "sync.partial", source: words.source }] }
|
|
61
|
+
: unfinished
|
|
62
|
+
? { complete: false }
|
|
63
|
+
: {},
|
|
64
|
+
next: [...resume, ...longer],
|
|
65
|
+
diagnostics,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
15
68
|
const addDocumentSyncCommandsDefinition = (program, helpers) => {
|
|
16
69
|
const { output } = helpers;
|
|
17
70
|
const wording = wordsOf(helpers.words);
|
|
@@ -24,66 +77,27 @@ const addDocumentSyncCommandsDefinition = (program, helpers) => {
|
|
|
24
77
|
.description("import what changed in the chosen folders, and finish an unfinished sync; " +
|
|
25
78
|
`one sync walks about ${helpers.maxEntries} entries under the chosen folders, saves where it stopped, and ` +
|
|
26
79
|
"the next sync goes on from there"), [`${prefix} sync`, `${prefix} sync --rescan --limit 500`])
|
|
27
|
-
.option("--limit <n>", text.syncLimit, positive,
|
|
80
|
+
.option("--limit <n>", text.syncLimit, positive, DOCUMENT_SYNC_LIMIT)
|
|
28
81
|
.option("--rescan", "read every chosen folder again instead of only what changed; each --rescan starts the walk over, so run it " +
|
|
29
82
|
"once and continue with a plain sync")
|
|
30
83
|
.option("--embed", "also index pending text for meaning search, with a model already downloaded")
|
|
31
84
|
.action(async (args, command) => {
|
|
32
85
|
const deadline = environmentOf(command).deadline?.();
|
|
33
86
|
const result = await helpers.sync({ ...args, budget: runBudgetOf(command), ...(deadline ? { deadline } : {}) });
|
|
34
|
-
const unfinished = result.complete === false || result.pending > 0;
|
|
35
|
-
const moved = (result.walk?.listed ?? 0) > 0 ||
|
|
36
|
-
[result.saved, result.names_only, result.removed, result.unchanged].some((count) => (count ?? 0) > 0);
|
|
37
|
-
const again = `${wording.app} ${helpers.profile()} sync`;
|
|
38
87
|
const timeout = command.optsWithGlobals().timeout;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
safe_to_auto_execute: true,
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
: [];
|
|
56
|
-
// Enrichment starts a batch only when it ends before the deadline; one that never had the time would not move in
|
|
57
|
-
// a run like this one either, so the step asks for a longer run and is not run unasked.
|
|
58
|
-
const longer = enrichmentOutOfTime(result.embeddings)
|
|
59
|
-
? [
|
|
60
|
-
{
|
|
61
|
-
kind: "command",
|
|
62
|
-
step: "sync.longer",
|
|
63
|
-
command: "sync",
|
|
64
|
-
args: { limit: args.limit, embed: true, timeout: "15m" },
|
|
65
|
-
why: "enrichment needs more time than this run had left, so it sent nothing; run this in a terminal, " +
|
|
66
|
-
"where a sync may take 15 minutes",
|
|
67
|
-
safe_to_auto_execute: false,
|
|
68
|
-
},
|
|
69
|
-
]
|
|
70
|
-
: [];
|
|
71
|
-
const next = [...resume, ...longer];
|
|
72
|
-
output(itemOf(result, {
|
|
73
|
-
meta: result.errors.length
|
|
74
|
-
? {
|
|
75
|
-
complete: false,
|
|
76
|
-
issues: [{ code: "provider_error", reason: "sync.partial", source: wording.source }],
|
|
77
|
-
}
|
|
78
|
-
: unfinished
|
|
79
|
-
? { complete: false }
|
|
80
|
-
: {},
|
|
81
|
-
next,
|
|
82
|
-
}));
|
|
83
|
-
if (result.walk)
|
|
84
|
-
helpers.diagnostic(`${result.walk.folders_left} folders remain to list; run ${again} again\n`);
|
|
85
|
-
else if (result.errors.length || result.pending)
|
|
86
|
-
helpers.diagnostic(`${result.pending} source operations remain; run ${again} again\n`);
|
|
88
|
+
const part = documentSyncPart(result, {
|
|
89
|
+
again: `${wording.app} ${helpers.profile()} sync`,
|
|
90
|
+
source: wording.source,
|
|
91
|
+
resume: {
|
|
92
|
+
limit: args.limit,
|
|
93
|
+
...(timeout === undefined ? {} : { timeout }),
|
|
94
|
+
...(args.embed ? { embed: true } : {}),
|
|
95
|
+
},
|
|
96
|
+
longer: { limit: args.limit },
|
|
97
|
+
});
|
|
98
|
+
output(itemOf(result, { meta: part.meta, next: part.next }));
|
|
99
|
+
for (const line of part.diagnostics)
|
|
100
|
+
helpers.diagnostic(line);
|
|
87
101
|
if (result.errors.length)
|
|
88
102
|
throw new CliError("provider_error", "sync completed partially; failed operations remain pending", {
|
|
89
103
|
reason: "sync.partial",
|
|
@@ -46,8 +46,8 @@ export declare const folderProviderSql: (column?: string) => string;
|
|
|
46
46
|
export declare const folderProviderOf: (format: "obsidian" | "markdown") => "obsidian" | "local";
|
|
47
47
|
/**
|
|
48
48
|
* Providers whose account holds documents the way a notes folder does: one account per remote principal, its
|
|
49
|
-
* files as `documents` rows. Any registry entry
|
|
50
|
-
* keeps its documents beside its other records instead.
|
|
49
|
+
* files as `documents` rows. Any registry entry holding `documents` that a sync fills, as its first kind or beside
|
|
50
|
+
* another (Linear's tracker); an import-only one (`import`) keeps its documents beside its other records instead.
|
|
51
51
|
*/
|
|
52
52
|
export declare const documentAccountProviders: () => string[];
|
|
53
53
|
export declare const isDocumentAccountProvider: (provider: unknown) => boolean;
|
|
@@ -103,6 +103,11 @@ export declare const kindsIn: (provider: Provider) => readonly Kind[];
|
|
|
103
103
|
export declare const importedOf: (entry: ProviderEntry, held: ProviderEntry | undefined) => boolean;
|
|
104
104
|
/** Whether a provider's accounts hold only what imports wrote: the one place a records import writes messages and events. */
|
|
105
105
|
export declare const isImportedProvider: (provider: Provider) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* A documents account that holds another kind too, as Linear's holds a tracker's copy: listed and grouped under its
|
|
108
|
+
* own key for that kind, and as `notes:<id>` for its documents.
|
|
109
|
+
*/
|
|
110
|
+
export declare const alsoListedByKey: (provider: Provider) => boolean;
|
|
106
111
|
/** Whether a provider's accounts hold `kind`: what a search lane picks its accounts by. */
|
|
107
112
|
export declare const holdsKind: (provider: Provider, kind: Kind) => boolean;
|
|
108
113
|
/** `holdsKind`, with a provider no entry names counted as a messenger, as `kindOf` counts it. */
|
package/dist/domain/providers.js
CHANGED
|
@@ -22,8 +22,9 @@ export const PROVIDERS = [
|
|
|
22
22
|
// Google Meet has no tool of its own: its meetings are gcal's, since every meeting is on the calendar.
|
|
23
23
|
{ name: "google-meet", kind: "meetings", aliases: [], command: "gcal" },
|
|
24
24
|
{ name: "google-drive", kind: "documents", aliases: [] },
|
|
25
|
-
// Seeded: linear-cli registers no entry, and without one its accounts would count as a messenger's.
|
|
26
|
-
|
|
25
|
+
// Seeded: linear-cli registers no entry, and without one its accounts would count as a messenger's. One sign-in holds
|
|
26
|
+
// the issues and the documents, so the account is a tracker's and a documents account at once.
|
|
27
|
+
{ name: "linear", kind: "tracker", kinds: ["tracker", "documents"], aliases: [], command: "linear" },
|
|
27
28
|
// Its meetings come from the notes Telemost mails (`keeper@telemost.yandex.ru`), read by a mail rule.
|
|
28
29
|
{ name: "telemost", kind: "meetings", aliases: [] },
|
|
29
30
|
// A phone export's records: its SMS and its calls in the one account the import names.
|
|
@@ -60,10 +61,12 @@ export const folderProviderSql = (column = "provider") => `${column} IN (${FOLDE
|
|
|
60
61
|
export const folderProviderOf = (format) => format === "markdown" ? "local" : "obsidian";
|
|
61
62
|
/**
|
|
62
63
|
* Providers whose account holds documents the way a notes folder does: one account per remote principal, its
|
|
63
|
-
* files as `documents` rows. Any registry entry
|
|
64
|
-
* keeps its documents beside its other records instead.
|
|
64
|
+
* files as `documents` rows. Any registry entry holding `documents` that a sync fills, as its first kind or beside
|
|
65
|
+
* another (Linear's tracker); an import-only one (`import`) keeps its documents beside its other records instead.
|
|
65
66
|
*/
|
|
66
|
-
export const documentAccountProviders = () => registry
|
|
67
|
+
export const documentAccountProviders = () => registry
|
|
68
|
+
.filter((entry) => kindsOfEntry(entry).includes("documents") && entry.imported !== true)
|
|
69
|
+
.map(({ name }) => name);
|
|
67
70
|
export const isDocumentAccountProvider = (provider) => typeof provider === "string" && documentAccountProviders().includes(provider);
|
|
68
71
|
/** The documents account providers as a SQL list, for `IN (…)`; names are checked words, so they need no binding. */
|
|
69
72
|
export const documentAccountProvidersSql = () => documentAccountProviders()
|
|
@@ -235,6 +238,11 @@ export const importedOf = (entry, held) => {
|
|
|
235
238
|
};
|
|
236
239
|
/** Whether a provider's accounts hold only what imports wrote: the one place a records import writes messages and events. */
|
|
237
240
|
export const isImportedProvider = (provider) => registry.find(({ name }) => name === provider)?.imported === true;
|
|
241
|
+
/**
|
|
242
|
+
* A documents account that holds another kind too, as Linear's holds a tracker's copy: listed and grouped under its
|
|
243
|
+
* own key for that kind, and as `notes:<id>` for its documents.
|
|
244
|
+
*/
|
|
245
|
+
export const alsoListedByKey = (provider) => isDocumentAccountProvider(provider) && kindsIn(provider).some((kind) => kind !== "documents");
|
|
238
246
|
/** Whether a provider's accounts hold `kind`: what a search lane picks its accounts by. */
|
|
239
247
|
export const holdsKind = (provider, kind) => kindsIn(provider).includes(kind);
|
|
240
248
|
/** `holdsKind`, with a provider no entry names counted as a messenger, as `kindOf` counts it. */
|
package/dist/errors/reasons.js
CHANGED
|
@@ -240,6 +240,11 @@ const OTHERS = [
|
|
|
240
240
|
["profile.busy", "provider_unavailable", "another sync or write holds this profile's local copy"],
|
|
241
241
|
["profile.account-taken", "conflict", "another profile here already uses this provider account"],
|
|
242
242
|
["profile.other-account", "conflict", "this profile's copy was synced from another provider account"],
|
|
243
|
+
[
|
|
244
|
+
"documents.other-account",
|
|
245
|
+
"configuration_error",
|
|
246
|
+
"the documents are signed in as another account than the tracker copy of the same provider",
|
|
247
|
+
],
|
|
243
248
|
["profile.not-synced", "not_found", "the profile has no local copy yet; sync it first"],
|
|
244
249
|
["provider.failed", "provider_error", "a read from the provider failed"],
|
|
245
250
|
["identity.none", "not_found", "the provider shows no accounts on a document"],
|
|
@@ -266,6 +271,11 @@ const OTHERS = [
|
|
|
266
271
|
"the email could not be read again, so its skipped attachments have no text",
|
|
267
272
|
],
|
|
268
273
|
["mirror.partial", "provider_error", "some mirrored files were not synced"],
|
|
274
|
+
[
|
|
275
|
+
"mirror.stopped",
|
|
276
|
+
"timeout",
|
|
277
|
+
"the mirror's run reached its deadline before it was done; run it again with more time",
|
|
278
|
+
],
|
|
269
279
|
["mirror.none", "not_found", "the profile has no mirrors; add one with mirrors add"],
|
|
270
280
|
["mirror.not-found", "not_found", "no such mirror in this profile; see mirrors list"],
|
|
271
281
|
validation("mirror.not-folder", "the path to mirror is not a folder"),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { ADDED_PROVIDER, INTERNAL_NOTES, isDocumentAccountProvider, isFolderProvider, isKind, kindIn, kindOf, kindsIn, providerNamed, providers as registered, UNKNOWN_PROVIDER, } from "../domain/providers.js";
|
|
2
|
+
import { ADDED_PROVIDER, alsoListedByKey, INTERNAL_NOTES, isDocumentAccountProvider, isFolderProvider, isKind, kindIn, kindOf, kindsIn, providerNamed, providers as registered, UNKNOWN_PROVIDER, } from "../domain/providers.js";
|
|
3
3
|
import { isBotProvider } from "./query.js";
|
|
4
4
|
/** Store-wide: every profile, tg, MAX and memo reads the same groups. */
|
|
5
5
|
export const ACCOUNT_GROUPS = "accountGroups";
|
|
@@ -30,13 +30,15 @@ const describe = (accounts) => accounts.map(({ provider, account, name }) => `${
|
|
|
30
30
|
export const listedHolds = (account, kind) => (account.kinds ?? (account.kind === undefined ? [] : [account.kind])).includes(kind);
|
|
31
31
|
/** The app running knows its own provider is a messenger, entry or not. */
|
|
32
32
|
const kindHere = (provider, running) => provider === running.provider ? kindOf(provider) : kindIn(provider);
|
|
33
|
+
// A documents account's documents are listed as `notes:<id>`, so its own key keeps only the other kinds it holds.
|
|
34
|
+
const listedKinds = (provider) => kindsIn(provider).filter((kind) => kind !== "documents" || !isDocumentAccountProvider(provider));
|
|
33
35
|
const kindsOfHere = (provider, running) => {
|
|
34
|
-
const kinds =
|
|
36
|
+
const kinds = listedKinds(provider);
|
|
35
37
|
return { kind: kindHere(provider, running), ...(kinds.length > 1 ? { kinds } : {}) };
|
|
36
38
|
};
|
|
37
39
|
const heldOf = (stored, running) => [
|
|
38
40
|
...stored
|
|
39
|
-
.filter(({ provider }) => kindIn(provider) !== "notes" && !isDocumentAccountProvider(provider))
|
|
41
|
+
.filter(({ provider }) => kindIn(provider) !== "notes" && (!isDocumentAccountProvider(provider) || alsoListedByKey(provider)))
|
|
40
42
|
.map(({ provider, account, name }) => ({ provider, account, name, ...kindsOfHere(provider, running) })),
|
|
41
43
|
{ provider: "notes", account: INTERNAL_NOTES, name: null, kind: "notes" },
|
|
42
44
|
...stored
|
|
@@ -80,7 +82,9 @@ const providerOf = (prefix, held, { running, profiles }) => {
|
|
|
80
82
|
const profilesOf = (provider, profiles) => Object.values(profiles).flatMap((named) => Object.entries(named).filter(([, key]) => key.provider === provider));
|
|
81
83
|
const accountOf = (prefix, ref, held, context) => {
|
|
82
84
|
const provider = providerOf(prefix, held, context);
|
|
83
|
-
if (isDocumentAccountProvider(provider) &&
|
|
85
|
+
if (isDocumentAccountProvider(provider) &&
|
|
86
|
+
!alsoListedByKey(provider) &&
|
|
87
|
+
!context.profiles[prefix.toLowerCase()]?.[ref]) {
|
|
84
88
|
const stored = storedAs(held, { provider, account: ref })[0];
|
|
85
89
|
if (stored)
|
|
86
90
|
return stored;
|
|
@@ -147,7 +151,7 @@ const accountsOfWord = (word, held, context) => {
|
|
|
147
151
|
return Object.keys(recorded).map((profile) => accountOf(word, profile, held, context));
|
|
148
152
|
const provider = providerOf(word, held, context);
|
|
149
153
|
if (isDocumentAccountProvider(provider) || isFolderProvider(provider))
|
|
150
|
-
return storedAs(held, { provider, account: "" });
|
|
154
|
+
return [...held.filter((one) => one.provider === provider), ...storedAs(held, { provider, account: "" })];
|
|
151
155
|
return held.filter((one) => one.provider === provider);
|
|
152
156
|
};
|
|
153
157
|
const isDocumentAccount = ({ stored }) => stored !== undefined && isDocumentAccountProvider(stored.provider);
|
|
@@ -4,7 +4,7 @@ import { crmViewerOf } from "../crm/index.js";
|
|
|
4
4
|
import { hitFiles } from "../domain/attachments.js";
|
|
5
5
|
import { parseLocator } from "../domain/locator.js";
|
|
6
6
|
import { senderIsMe } from "../domain/models.js";
|
|
7
|
-
import { holdsKind, INTERNAL_NOTES } from "../domain/providers.js";
|
|
7
|
+
import { holdsKind, INTERNAL_NOTES, isDocumentAccountProvider } from "../domain/providers.js";
|
|
8
8
|
import { trackerTitleOf } from "../domain/tracker.js";
|
|
9
9
|
import { runEmbedders } from "../embeddings/embed.js";
|
|
10
10
|
import { chosenTextModel } from "../embeddings/models.js";
|
|
@@ -92,7 +92,8 @@ const strictWords = (text) => {
|
|
|
92
92
|
const accountKeyOf = ({ provider, account }) => `${provider}\u0000${account}`;
|
|
93
93
|
/** `--source` as the accounts each kind reads; a kind it names no account of is skipped, not read in full. */
|
|
94
94
|
const sourceScope = async (store, account, source, asked, messenger) => {
|
|
95
|
-
const
|
|
95
|
+
const context = await listContextOf(store, account, messenger.app);
|
|
96
|
+
const entries = entriesOfList(source, context);
|
|
96
97
|
// Any provider's import may write business data, so its accounts are the ones that hold some, whatever their kind.
|
|
97
98
|
const imported = asked.includes("business")
|
|
98
99
|
? new Set((await store.business.accounts()).map(accountKeyOf))
|
|
@@ -104,10 +105,19 @@ const sourceScope = async (store, account, source, asked, messenger) => {
|
|
|
104
105
|
const holds = (resource, one) => resource === "business"
|
|
105
106
|
? holdsBusiness(one)
|
|
106
107
|
: listedHolds(one, resource) || (resource === "notes" && holdsDocuments(one));
|
|
108
|
+
// A documents account named by its own key (`linear:user-1`, whose tracker copy is listed so) is read by the notes
|
|
109
|
+
// lane as the `notes:<id>` it is also listed as, so naming it both ways reads it once.
|
|
110
|
+
const asNotes = (one) => {
|
|
111
|
+
if (!isDocumentAccountProvider(one.provider))
|
|
112
|
+
return one;
|
|
113
|
+
const stored = context.held.find(({ provider, account }) => provider === one.provider && account === one.account);
|
|
114
|
+
return stored ? { provider: "notes", account: String(stored.id) } : one;
|
|
115
|
+
};
|
|
107
116
|
const named = (resource) => [
|
|
108
117
|
...new Map(entries
|
|
109
118
|
.flatMap(({ accounts }) => accounts)
|
|
110
119
|
.filter((one) => holds(resource, one))
|
|
120
|
+
.map((one) => (resource === "notes" ? asNotes(one) : one))
|
|
111
121
|
.map(({ provider, account }) => [`${provider}\u0000${account}`, { provider, account }])).values(),
|
|
112
122
|
];
|
|
113
123
|
const scope = Object.fromEntries(asked.map((resource) => [resource, named(resource)]));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { holdsKindOf, isDocumentAccountProvider, isFolderProvider, isKind, providerNamed } from "../domain/providers.js";
|
|
2
|
+
import { alsoListedByKey, holdsKindOf, isDocumentAccountProvider, isFolderProvider, isKind, providerNamed, } from "../domain/providers.js";
|
|
3
3
|
import { envName } from "../ports/app.js";
|
|
4
4
|
import { entriesOfList, fitting, isAccountList, keyOf, } from "../search/account-list.js";
|
|
5
5
|
import { ALL, groupEntries, groupMembership, hasGroup, OWNER_NOTES } from "../search/groups.js";
|
|
@@ -36,13 +36,14 @@ export const listContextOf = async (store, account, app, stored, env) => {
|
|
|
36
36
|
if (!members)
|
|
37
37
|
throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
|
|
38
38
|
const only = new Set([...members, OWNER_NOTES].map(keyOf));
|
|
39
|
-
// A notes folder or a documents account is held under its own key but listed as `notes:<store id
|
|
39
|
+
// A notes folder or a documents account is held under its own key but listed as `notes:<store id>`; one that holds
|
|
40
|
+
// another kind too (Linear's tracker copy) is also listed under its own key.
|
|
40
41
|
const listedAs = (one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider)
|
|
41
|
-
? { provider: "notes", account: String(one.id) }
|
|
42
|
-
: one;
|
|
42
|
+
? [{ provider: "notes", account: String(one.id) }, ...(alsoListedByKey(one.provider) ? [one] : [])]
|
|
43
|
+
: [one];
|
|
43
44
|
return {
|
|
44
45
|
...context,
|
|
45
|
-
held: held.filter((one) => only.has(keyOf(
|
|
46
|
+
held: held.filter((one) => listedAs(one).some((key) => only.has(keyOf(key)))),
|
|
46
47
|
groups: { [lock]: groups[lock] ?? [] },
|
|
47
48
|
membership: {
|
|
48
49
|
groups: { [lock]: members },
|