@wirecat/cli-core 0.411.0 → 0.413.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 +32 -0
- package/dist/cli/bot/command.js +3 -3
- package/dist/cli/bot/messages-sync.d.ts +7 -0
- package/dist/cli/bot/{store.js → messages-sync.js} +4 -5
- package/dist/cli/bot/port.d.ts +3 -3
- package/dist/cli/config-command.js +1 -0
- package/dist/cli/entry.d.ts +59 -0
- package/dist/cli/entry.js +136 -0
- package/dist/cli/first-run.d.ts +1 -1
- package/dist/cli/first-run.js +1 -1
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/messenger/store-maintenance-command.d.ts +1 -1
- package/dist/cli/messenger/tasks-command.js +2 -2
- package/dist/cli/moved.js +1 -0
- package/dist/cli/settings.d.ts +2 -0
- package/dist/cli/settings.js +5 -1
- package/dist/domain/providers.d.ts +25 -3
- package/dist/domain/providers.js +89 -5
- package/dist/entities/index.d.ts +29 -1
- package/dist/entities/index.js +5 -1
- package/dist/entities/knowledge-lists.d.ts +28 -0
- package/dist/entities/knowledge-lists.js +29 -0
- package/dist/errors/reasons.js +16 -1
- package/dist/files/native-writer-lease.js +17 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/oauth/authorize.d.ts +21 -0
- package/dist/oauth/authorize.js +130 -0
- package/dist/oauth/index.d.ts +5 -0
- package/dist/oauth/index.js +4 -0
- package/dist/oauth/keeper.d.ts +41 -0
- package/dist/oauth/keeper.js +136 -0
- package/dist/oauth/provider.d.ts +54 -0
- package/dist/oauth/provider.js +1 -0
- package/dist/oauth/requests.d.ts +11 -0
- package/dist/oauth/requests.js +129 -0
- package/dist/oauth/storage.d.ts +48 -0
- package/dist/oauth/storage.js +197 -0
- package/dist/search/account-list.d.ts +5 -2
- package/dist/search/account-list.js +27 -11
- package/dist/search/query.js +3 -1
- package/dist/sends/permission-aliases.js +1 -0
- package/dist/services/documents/knowledge.d.ts +5 -3
- package/dist/services/documents/knowledge.js +4 -4
- package/dist/services/meeting-links.d.ts +3 -1
- package/dist/services/meeting-links.js +2 -2
- package/dist/services/messages-search.js +15 -3
- package/dist/services/project-gathering.d.ts +2 -0
- package/dist/services/project-gathering.js +18 -2
- package/dist/services/search-all.js +5 -2
- package/dist/store/accounts.d.ts +3 -0
- package/dist/store/accounts.js +2 -0
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +3 -1
- package/dist/store/index.js +2 -0
- package/dist/store/knowledge-query.d.ts +6 -0
- package/dist/store/knowledge-query.js +34 -0
- package/dist/store/providers.d.ts +7 -0
- package/dist/store/providers.js +5 -0
- package/dist/store/sqlite/knowledge.d.ts +5 -4
- package/dist/store/sqlite/knowledge.js +50 -17
- package/dist/store/sqlite/mail-rules.d.ts +2 -1
- package/dist/store/sqlite/mail-rules.js +12 -2
- package/dist/store/sqlite/notes.d.ts +11 -5
- package/dist/store/sqlite/notes.js +9 -2
- package/dist/store/sqlite/open-store.js +2 -0
- package/dist/store/sqlite/providers.d.ts +12 -0
- package/dist/store/sqlite/providers.js +45 -0
- package/dist/store/sqlite/tags.d.ts +1 -1
- package/dist/store/sqlite/tags.js +3 -3
- package/package.json +5 -1
- package/parity.json +31 -35
- package/dist/cli/bot/store.d.ts +0 -7
|
@@ -5,6 +5,7 @@ import { excerpt } from "./excerpt.js";
|
|
|
5
5
|
import { attachNeighbours, documentMatches, } from "./project-gathering-around.js";
|
|
6
6
|
import { decodeCheckpoint, encodeCheckpoint, projectGatheringRequest, projectUnits, seenKey, } from "./project-gathering-request.js";
|
|
7
7
|
const terminal = new Set(["done", "unavailable", "failed"]);
|
|
8
|
+
const PAGE = 20;
|
|
8
9
|
const CONTEXTS = ["person-only", "sender", "linked-chat", "project"];
|
|
9
10
|
const contextOf = (lane) => lane.kinds.includes("linked-chat")
|
|
10
11
|
? "linked-chat"
|
|
@@ -84,6 +85,12 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
84
85
|
const oversized = new Map();
|
|
85
86
|
let stopped = null;
|
|
86
87
|
const open = (u) => !terminal.has(u.state) && u.state !== "read-limited";
|
|
88
|
+
const linkedLanes = new Set(plan.linkedChats.flatMap((c) => (c.lane === null ? [] : [c.lane])));
|
|
89
|
+
// One even share per linked chat plus one for the word and sender lanes, so one busy chat cannot fill a run; never
|
|
90
|
+
// below a page, so every chat still gets its whole first page.
|
|
91
|
+
const linkedLimit = Math.max(PAGE, Math.floor(plan.budgets.maxItems / (linkedLanes.size + 1)));
|
|
92
|
+
const linkedTaken = new Map();
|
|
93
|
+
const capped = new Set();
|
|
87
94
|
/** Records another lane finding a reference this run already returned; true when it had. */
|
|
88
95
|
const again = (ref, lane) => {
|
|
89
96
|
const known = byRef.get(ref);
|
|
@@ -133,11 +140,13 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
133
140
|
byRef.set(item.ref, entry);
|
|
134
141
|
items.push(entry);
|
|
135
142
|
usage.items++;
|
|
143
|
+
if (linkedLanes.has(lane.id))
|
|
144
|
+
linkedTaken.set(lane.id, (linkedTaken.get(lane.id) ?? 0) + 1);
|
|
136
145
|
};
|
|
137
146
|
// A resumed run starts at its shallowest open unit: below it no unit is due, and an empty round would end the run.
|
|
138
147
|
const shallowest = progress.reduce((low, u) => (open(u) ? Math.min(low, u.pages) : low), Number.POSITIVE_INFINITY);
|
|
139
148
|
for (let round = shallowest; !stopped; round++) {
|
|
140
|
-
const due = progress.flatMap((u, index) =>
|
|
149
|
+
const due = progress.flatMap((u, index) => open(u) && u.pages <= round && !capped.has(units[index]?.lane.id ?? "") ? [index] : []);
|
|
141
150
|
if (!due.length)
|
|
142
151
|
break;
|
|
143
152
|
for (const index of due) {
|
|
@@ -145,6 +154,11 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
145
154
|
if (!unit || !state)
|
|
146
155
|
continue;
|
|
147
156
|
signal?.throwIfAborted();
|
|
157
|
+
const room = linkedLanes.has(unit.lane.id) ? linkedLimit - (linkedTaken.get(unit.lane.id) ?? 0) : PAGE;
|
|
158
|
+
if (room <= 0) {
|
|
159
|
+
capped.add(unit.lane.id);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
148
162
|
stopped =
|
|
149
163
|
usage.reads >= plan.budgets.maxReads
|
|
150
164
|
? "reads"
|
|
@@ -187,7 +201,7 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
187
201
|
}
|
|
188
202
|
};
|
|
189
203
|
try {
|
|
190
|
-
let page = await readPage(Math.min(plan.budgets.maxPageBytes, plan.budgets.maxReadBytes - usage.readBytes),
|
|
204
|
+
let page = await readPage(Math.min(plan.budgets.maxPageBytes, plan.budgets.maxReadBytes - usage.readBytes), Math.min(PAGE, room));
|
|
191
205
|
// A large record another lane already returned is not read again; its page already moves past it.
|
|
192
206
|
const big = page.oversized && !again(page.oversized.ref, unit.lane) ? page.oversized : undefined;
|
|
193
207
|
if (big && big.bytes <= CONTEXT_MAX_READ_BYTES) {
|
|
@@ -288,6 +302,8 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
288
302
|
: units.every((unit, index) => unit.lane.id !== lane || progress[index]?.state === "unavailable")
|
|
289
303
|
? "unavailable"
|
|
290
304
|
: "in-scope",
|
|
305
|
+
items: lane === null ? 0 : (linkedTaken.get(lane) ?? 0),
|
|
306
|
+
capped: lane !== null && capped.has(lane),
|
|
291
307
|
})),
|
|
292
308
|
fetch: fetched.map((f, index) => ({ source: index, ...f })),
|
|
293
309
|
index: indexed,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseLocator } from "../domain/locator.js";
|
|
3
|
-
import { INTERNAL_NOTES,
|
|
3
|
+
import { INTERNAL_NOTES, kindIn } from "../domain/providers.js";
|
|
4
4
|
import { excerpt } from "./excerpt.js";
|
|
5
5
|
import { MAX_SEARCH_OFFSET, searchStore } from "./messages-archive-search.js";
|
|
6
6
|
import { notesScopeOf, RRF_K, searchNotes } from "./notes-search.js";
|
|
@@ -55,7 +55,10 @@ export const searchAll = async (store, account, request, messenger = {}, searchM
|
|
|
55
55
|
hasMore ||= found.hasMore;
|
|
56
56
|
const read = found.coverage?.accounts ??
|
|
57
57
|
given ??
|
|
58
|
-
(await store.accounts.accounts()).filter(({ provider }) =>
|
|
58
|
+
(await store.accounts.accounts()).filter(({ provider }) => kindIn(provider) === kind);
|
|
59
|
+
for (const one of found.skipped ?? [])
|
|
60
|
+
if (!skipped.some(({ source }) => source === one.source))
|
|
61
|
+
skipped.push(one);
|
|
59
62
|
accounts.push(...read.map(({ provider, account }) => ({ resource: kind, provider, account })));
|
|
60
63
|
return found.items.map((hit) => {
|
|
61
64
|
const at = parseLocator(hit.locator);
|
package/dist/store/accounts.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderEntry } from "../domain/providers.js";
|
|
1
2
|
import { type AccountGroups, type Profiles } from "../search/account-list.js";
|
|
2
3
|
import type { StoreContext } from "./sqlite/open.js";
|
|
3
4
|
import type { AccountKey, StoredAccount } from "./types.js";
|
|
@@ -29,6 +30,8 @@ export interface AccountsStore extends AccountAccounts {
|
|
|
29
30
|
profiles(): Promise<Profiles>;
|
|
30
31
|
/** Records which account a profile of `app` is; a no-op when the store already says so. */
|
|
31
32
|
saveProfile(app: string, profile: string, key: AccountKey): Promise<void>;
|
|
33
|
+
/** Writes a CLI's provider entry for every tool on this store to read; see `registerProvider`. */
|
|
34
|
+
registerProvider(entry: ProviderEntry): Promise<void>;
|
|
32
35
|
}
|
|
33
36
|
export declare const accountAccountsOver: (context: StoreContext) => AccountAccounts;
|
|
34
37
|
export declare const accountsStoreOver: (context: StoreContext, keyed: AccountAccounts) => AccountsStore;
|
package/dist/store/accounts.js
CHANGED
|
@@ -3,6 +3,7 @@ import { keysOver } from "./keys.js";
|
|
|
3
3
|
import { accountGroupsOf, profilesOf, saveProfile } from "./sqlite/account-groups.js";
|
|
4
4
|
import * as accounts from "./sqlite/accounts.js";
|
|
5
5
|
import { linkOwnIdentities } from "./sqlite/own-identities.js";
|
|
6
|
+
import { registerProvider } from "./sqlite/providers.js";
|
|
6
7
|
import { linkInbox } from "./sqlite/tasks.js";
|
|
7
8
|
import { write } from "./sqlite/transaction.js";
|
|
8
9
|
export const accountAccountsOver = (context) => {
|
|
@@ -34,6 +35,7 @@ export const accountsStoreOver = (context, keyed) => {
|
|
|
34
35
|
accountGroups: async () => accountGroupsOf(database),
|
|
35
36
|
profiles: async () => profilesOf(database),
|
|
36
37
|
saveProfile: async (app, profile, key) => write(database, () => saveProfile(database, app, profile, key, context.now())),
|
|
38
|
+
registerProvider: async (entry) => registerProvider(database, entry, context.now()),
|
|
37
39
|
saveAccountGroup: async (name, members) => write(database, () => {
|
|
38
40
|
const groups = accountGroupsOf(database);
|
|
39
41
|
if (members === undefined)
|
package/dist/store/exports.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type { AccountCounters, CountersStore } from "./counters.js";
|
|
|
8
8
|
export type { AccountMentions, MentionsStore } from "./mentions.js";
|
|
9
9
|
export type { AccountMessages, MessagesStore } from "./messages.js";
|
|
10
10
|
export type { AccountPeople, PeopleStore } from "./people.js";
|
|
11
|
+
export { registerProvider } from "./providers.js";
|
|
11
12
|
export type { QueriesStore } from "./queries.js";
|
|
12
13
|
export type { RosterStore } from "./roster.js";
|
|
13
14
|
export type { SearchIndexStore } from "./search-index.js";
|
package/dist/store/exports.js
CHANGED
package/dist/store/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES
|
|
|
3
3
|
export type { TagConsolidationOptions, TagConsolidationPreview, TagConsolidationStore, } from "../domain/tag-consolidation.js";
|
|
4
4
|
export type { TagRedirectIndex, TagRedirectResolution, TagRedirectSnapshot } from "../domain/tag-redirects.js";
|
|
5
5
|
export { createTagRedirectIndex } from "../domain/tag-redirects.js";
|
|
6
|
+
export { note } from "../entities/note.js";
|
|
6
7
|
export type { FindingEvidence, FindingOutcome, MeetingFactFinding, MeetingFinding, MeetingFindingsInput, MeetingFindingsReceipt, MeetingTaskFinding, } from "../meetings/index.js";
|
|
7
8
|
export type { AccountMail, AccountMeetings, AccountStore } from "./account-store.js";
|
|
8
9
|
export type { DocumentTransferOptions, DocumentTransferPreview, DocumentTransferReceipt, } from "./document-transfer/index.js";
|
|
@@ -10,6 +11,7 @@ export { applyDocumentTransfer, previewDocumentTransfer } from "./document-trans
|
|
|
10
11
|
export type { CacheDatabase, CacheStatement, OpenDatabase, SqlValue } from "./driver.js";
|
|
11
12
|
export { PRAGMAS } from "./driver.js";
|
|
12
13
|
export { EVIDENCE_FINDINGS_KIND, type EvidenceFindingsBatch, type EvidenceFindingsDecider, type EvidenceFindingsReceipt, type EvidenceFindingsStore, validateEvidenceFindings, } from "./evidence-findings.js";
|
|
14
|
+
export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
|
|
13
15
|
export type { MeetingFindingsBatch, MeetingFindingsStore } from "./meeting-findings.js";
|
|
14
16
|
export { MIGRATIONS, type Migration, migrate } from "./migrations.js";
|
|
15
17
|
export { openCache } from "./open.js";
|
|
@@ -41,7 +43,7 @@ export type { AttachmentInput } from "./sqlite/meetings.js";
|
|
|
41
43
|
export type { Author, MemoriesStore, Memory, MemoryInput } from "./sqlite/memories.js";
|
|
42
44
|
export type { NoteIndexState } from "./sqlite/note-index.js";
|
|
43
45
|
export { type NearestNote, NOTE_FIELDS, type NoteChunkToEmbed, type NoteHit, type NoteQuery, type NoteSearch, } from "./sqlite/note-search.js";
|
|
44
|
-
export type { FileNoteInput, Link, LinkInput, Note, NoteFolder, NotesStore, NoteTag, } from "./sqlite/notes.js";
|
|
46
|
+
export type { FileNoteInput, Link, LinkInput, LinkListFilter, Note, NoteFolder, NotesStore, NoteTag, } from "./sqlite/notes.js";
|
|
45
47
|
export type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
|
|
46
48
|
export type { ProposalInput, ProposedAction, ProposedActionsStore } from "./sqlite/proposed-actions.js";
|
|
47
49
|
export { PROPOSAL_STATUSES } from "./sqlite/proposed-actions.js";
|
package/dist/store/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { FACT_STATUSES, FACT_TYPES, MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES, TASK_TYPES, WORK_TASK_TYPES, } from "../domain/knowledge.js";
|
|
2
2
|
export { createTagRedirectIndex } from "../domain/tag-redirects.js";
|
|
3
|
+
export { note } from "../entities/note.js";
|
|
3
4
|
export { applyDocumentTransfer, previewDocumentTransfer } from "./document-transfer/index.js";
|
|
4
5
|
export { PRAGMAS } from "./driver.js";
|
|
5
6
|
export { EVIDENCE_FINDINGS_KIND, validateEvidenceFindings, } from "./evidence-findings.js";
|
|
7
|
+
export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
|
|
6
8
|
export { MIGRATIONS, migrate } from "./migrations.js";
|
|
7
9
|
export { openCache } from "./open.js";
|
|
8
10
|
export { storePath } from "./path.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type QueryRegistry } from "@wirecat/cli-base/query";
|
|
2
|
+
import { organization, project, reminder } from "../entities/knowledge-lists.js";
|
|
3
|
+
export { organization, project, reminder };
|
|
4
|
+
export declare const ORGANIZATIONS_QUERY: QueryRegistry;
|
|
5
|
+
export declare const PROJECTS_QUERY: QueryRegistry;
|
|
6
|
+
export declare const REMINDERS_QUERY: QueryRegistry;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { queryFieldsOf } from "@wirecat/cli-base/query";
|
|
2
|
+
import { organization, project, reminder } from "../entities/knowledge-lists.js";
|
|
3
|
+
export { organization, project, reminder };
|
|
4
|
+
export const ORGANIZATIONS_QUERY = {
|
|
5
|
+
entity: "organization",
|
|
6
|
+
backend: "sql",
|
|
7
|
+
fields: queryFieldsOf(organization, {
|
|
8
|
+
native: ["id", "kind", "scope", "created_at"],
|
|
9
|
+
examples: { id: "id:1", kind: "kind:company", scope: "scope:work", created_at: "created_at>=2026-01-01" },
|
|
10
|
+
}),
|
|
11
|
+
};
|
|
12
|
+
export const PROJECTS_QUERY = {
|
|
13
|
+
entity: "project",
|
|
14
|
+
backend: "sql",
|
|
15
|
+
fields: queryFieldsOf(project, {
|
|
16
|
+
native: ["id", "key", "type", "organization_id", "scope", "created_at"],
|
|
17
|
+
examples: {
|
|
18
|
+
id: "id:1",
|
|
19
|
+
key: "key:SMP",
|
|
20
|
+
type: "type:work",
|
|
21
|
+
organization_id: "organization_id:1",
|
|
22
|
+
scope: "scope:work",
|
|
23
|
+
created_at: "created_at>=2026-01-01",
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
export const REMINDERS_QUERY = {
|
|
28
|
+
entity: "reminder",
|
|
29
|
+
backend: "sql",
|
|
30
|
+
fields: queryFieldsOf(reminder, {
|
|
31
|
+
native: ["id", "state", "due_at", "revision"],
|
|
32
|
+
examples: { id: "id:1", state: "state:pending", due_at: "due_at>=2026-01-01", revision: "revision>1" },
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProviderEntry } from "../domain/providers.js";
|
|
2
|
+
import type { MessageStore } from "./store.js";
|
|
3
|
+
/**
|
|
4
|
+
* A CLI's entry, written into the store on every run so cli-core in every other CLI knows its provider's kind and
|
|
5
|
+
* aliases. Two entries that disagree on a kind, or an alias another provider already has, are an error.
|
|
6
|
+
*/
|
|
7
|
+
export declare const registerProvider: (store: Pick<MessageStore, "accounts">, entry: ProviderEntry) => Promise<void>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CLI's entry, written into the store on every run so cli-core in every other CLI knows its provider's kind and
|
|
3
|
+
* aliases. Two entries that disagree on a kind, or an alias another provider already has, are an error.
|
|
4
|
+
*/
|
|
5
|
+
export const registerProvider = (store, entry) => store.accounts.registerProvider(entry);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { QueryAst } from "@wirecat/cli-base/query";
|
|
1
2
|
import type { AccountKey } from "../types.js";
|
|
2
3
|
import { RELATION_KINDS } from "./link-kinds.js";
|
|
3
4
|
import { type MeetingProjectsStore } from "./meeting-projects.js";
|
|
@@ -130,7 +131,7 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore {
|
|
|
130
131
|
id: string;
|
|
131
132
|
removed: true;
|
|
132
133
|
}>;
|
|
133
|
-
tags(key: KnowledgeScope, target: KnowledgeTarget): Promise<string[]>;
|
|
134
|
+
tags(key: KnowledgeScope, target: KnowledgeTarget, tag?: string): Promise<string[]>;
|
|
134
135
|
addTags(key: KnowledgeScope, target: KnowledgeTarget, tags: string[]): Promise<string[]>;
|
|
135
136
|
removeTags(key: KnowledgeScope, target: KnowledgeTarget, tags: string[]): Promise<string[]>;
|
|
136
137
|
/**
|
|
@@ -163,7 +164,7 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore {
|
|
|
163
164
|
name: string;
|
|
164
165
|
scope?: Organization["scope"];
|
|
165
166
|
}): Promise<Organization>;
|
|
166
|
-
organizations(): Promise<Organization[]>;
|
|
167
|
+
organizations(query?: QueryAst): Promise<Organization[]>;
|
|
167
168
|
/** A project; its key is made from the name when none is given. */
|
|
168
169
|
addProject(input: {
|
|
169
170
|
name: string;
|
|
@@ -173,7 +174,7 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore {
|
|
|
173
174
|
scope?: Project["scope"];
|
|
174
175
|
description?: string;
|
|
175
176
|
}): Promise<Project>;
|
|
176
|
-
projects(): Promise<Project[]>;
|
|
177
|
+
projects(query?: QueryAst): Promise<Project[]>;
|
|
177
178
|
relate(key: KnowledgeScope, input: {
|
|
178
179
|
from: string;
|
|
179
180
|
to: string;
|
|
@@ -190,7 +191,7 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore {
|
|
|
190
191
|
}>;
|
|
191
192
|
confirmRelation(key: KnowledgeScope, id: string): Promise<KnowledgeRelation>;
|
|
192
193
|
schedule(key: AccountKey, task: string, dueAt: string, timezone: string): Promise<Reminder>;
|
|
193
|
-
reminders(key: AccountKey): Promise<Reminder[]>;
|
|
194
|
+
reminders(key: AccountKey, query?: QueryAst): Promise<Reminder[]>;
|
|
194
195
|
cancelReminder(key: AccountKey, id: string): Promise<Reminder>;
|
|
195
196
|
snoozeReminder(key: AccountKey, id: string, dueAt: string, revision: number): Promise<Reminder>;
|
|
196
197
|
claimReminders(key: AccountKey, options?: {
|
|
@@ -9,6 +9,7 @@ import { ownerPerson } from "./actors.js";
|
|
|
9
9
|
import { linkKind, RELATION_KINDS } from "./link-kinds.js";
|
|
10
10
|
import { meetingProjectsStoreOver } from "./meeting-projects.js";
|
|
11
11
|
import { insertLink, linkOf } from "./notes.js";
|
|
12
|
+
import { queryFilter } from "./query-filter.js";
|
|
12
13
|
import { addTags as addThingTags, canonicalTagNamed, createTag, labelsOf, removeTags as removeThingTags, setMainTopic, } from "./tags.js";
|
|
13
14
|
import { TASK_KEY_PREFIXES } from "./task-keys.js";
|
|
14
15
|
import { inboxKey, taskAccountOf, taskIdOf, taskRowOf } from "./tasks.js";
|
|
@@ -153,10 +154,10 @@ export const knowledgeStoreOver = (context) => {
|
|
|
153
154
|
? parseReference(formatReference({ type: "folder", id: target.id, path: target.path ?? null })).path
|
|
154
155
|
: null;
|
|
155
156
|
/** A subfolder's labels: `labelled` links from the folder, anchored at the path, to each tag. */
|
|
156
|
-
const subfolderLabels = (folder, path) => database
|
|
157
|
+
const subfolderLabels = (folder, path, tag) => database
|
|
157
158
|
.prepare("SELECT t.name FROM links l JOIN tags t ON t.id = l.to_id WHERE l.from_type = 'account' AND l.from_id = ? " +
|
|
158
|
-
`AND l.kind = ${linkKind("labelled")} AND l.to_type = 'tag' AND l.anchor = ? ORDER BY t.name`)
|
|
159
|
-
.all(folder, path)
|
|
159
|
+
`AND l.kind = ${linkKind("labelled")} AND l.to_type = 'tag' AND l.anchor = ?${tag === undefined ? "" : " AND t.name = ?"} ORDER BY t.name`)
|
|
160
|
+
.all(folder, path, ...(tag === undefined ? [] : [tag]))
|
|
160
161
|
.map((row) => String(row.name));
|
|
161
162
|
const annotationOf = (row) => {
|
|
162
163
|
const thing = storedThing(row.notable_type, row.notable_id);
|
|
@@ -335,12 +336,15 @@ export const knowledgeStoreOver = (context) => {
|
|
|
335
336
|
database.prepare("DELETE FROM notes WHERE id=?").run(Number(id));
|
|
336
337
|
return { id, removed: true };
|
|
337
338
|
},
|
|
338
|
-
tags: async (key, target) => {
|
|
339
|
+
tags: async (key, target, tag) => {
|
|
339
340
|
const { thing, state } = resolve(key, target);
|
|
340
341
|
if (!thing || state !== "available")
|
|
341
342
|
return [];
|
|
342
343
|
const path = subfolder(target);
|
|
343
|
-
|
|
344
|
+
const name = tag === undefined ? undefined : canonicalTagName(tag);
|
|
345
|
+
return path === null
|
|
346
|
+
? labelsOf(database, thing, name).map(({ tag }) => tag)
|
|
347
|
+
: subfolderLabels(thing.id, path, name);
|
|
344
348
|
},
|
|
345
349
|
addTags: async (key, target, tags) => {
|
|
346
350
|
const thing = available(key, target);
|
|
@@ -418,10 +422,19 @@ export const knowledgeStoreOver = (context) => {
|
|
|
418
422
|
.get(oneOf(kind, ORGANIZATION_KINDS, "an organization's kind"), textOf(name, 200), oneOf(scope, SCOPES, "a scope"), at, at);
|
|
419
423
|
return organizationOf(row);
|
|
420
424
|
},
|
|
421
|
-
organizations: async () =>
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
+
organizations: async (query) => {
|
|
426
|
+
const where = query &&
|
|
427
|
+
queryFilter(query, {
|
|
428
|
+
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
429
|
+
kind: { type: "enum", sql: "kind" },
|
|
430
|
+
scope: { type: "enum", sql: "scope" },
|
|
431
|
+
created_at: { type: "time", sql: "created_at" },
|
|
432
|
+
});
|
|
433
|
+
return database
|
|
434
|
+
.prepare(`SELECT * FROM organizations WHERE deleted_at IS NULL${where ? ` AND (${where.sql})` : ""} ORDER BY name, id LIMIT 500`)
|
|
435
|
+
.all(...(where?.params ?? []))
|
|
436
|
+
.map(organizationOf);
|
|
437
|
+
},
|
|
425
438
|
addProject: async ({ name, key, type = "other", organization, scope = "personal", description }) => write(database, () => {
|
|
426
439
|
const title = textOf(name, 200);
|
|
427
440
|
const organizationId = organization === undefined
|
|
@@ -475,10 +488,21 @@ export const knowledgeStoreOver = (context) => {
|
|
|
475
488
|
.get(chosen, title, description === undefined ? null : textOf(description, 2000), oneOf(type, PROJECT_TYPES, "a project's type"), organizationId, oneOf(scope, SCOPES, "a scope"), at, at);
|
|
476
489
|
return projectOf(row);
|
|
477
490
|
}),
|
|
478
|
-
projects: async () =>
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
491
|
+
projects: async (query) => {
|
|
492
|
+
const where = query &&
|
|
493
|
+
queryFilter(query, {
|
|
494
|
+
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
495
|
+
key: { type: "kw", sql: "key" },
|
|
496
|
+
type: { type: "enum", sql: "type" },
|
|
497
|
+
organization_id: { type: "kw", sql: "CAST(organization_id AS TEXT)" },
|
|
498
|
+
scope: { type: "enum", sql: "scope" },
|
|
499
|
+
created_at: { type: "time", sql: "created_at" },
|
|
500
|
+
});
|
|
501
|
+
return database
|
|
502
|
+
.prepare(`SELECT * FROM projects WHERE deleted_at IS NULL${where ? ` AND (${where.sql})` : ""} ORDER BY name, id LIMIT 500`)
|
|
503
|
+
.all(...(where?.params ?? []))
|
|
504
|
+
.map(projectOf);
|
|
505
|
+
},
|
|
482
506
|
relate: async (key, input) => {
|
|
483
507
|
const from = related(key, input.from, true);
|
|
484
508
|
const to = related(key, input.to);
|
|
@@ -553,10 +577,19 @@ export const knowledgeStoreOver = (context) => {
|
|
|
553
577
|
.get(row, accountId, timestamp, timezone, at, at);
|
|
554
578
|
return reminder(key, String(made?.id));
|
|
555
579
|
},
|
|
556
|
-
reminders: async (key) =>
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
580
|
+
reminders: async (key, query) => {
|
|
581
|
+
const where = query &&
|
|
582
|
+
queryFilter(query, {
|
|
583
|
+
id: { type: "kw", sql: "CAST(id AS TEXT)" },
|
|
584
|
+
state: { type: "enum", sql: "state" },
|
|
585
|
+
due_at: { type: "time", sql: "due_at" },
|
|
586
|
+
revision: { type: "num", sql: "revision" },
|
|
587
|
+
});
|
|
588
|
+
return database
|
|
589
|
+
.prepare(`SELECT * FROM reminders WHERE account_id=?${where ? ` AND (${where.sql})` : ""} ORDER BY due_at, id LIMIT 500`)
|
|
590
|
+
.all(account(key), ...(where?.params ?? []))
|
|
591
|
+
.map(reminderOf);
|
|
592
|
+
},
|
|
560
593
|
cancelReminder: async (key, id) => {
|
|
561
594
|
reminder(key, id);
|
|
562
595
|
database
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { QueryAst } from "@wirecat/cli-base/query";
|
|
1
2
|
import type { JsonValue } from "../../meetings/index.js";
|
|
2
3
|
import type { CacheDatabase } from "../driver.js";
|
|
3
4
|
type JsonObject = {
|
|
@@ -36,7 +37,7 @@ export interface MailRuleCount {
|
|
|
36
37
|
}
|
|
37
38
|
export interface MailRulesStore {
|
|
38
39
|
/** Oldest first. */
|
|
39
|
-
list(accountId: number): Promise<MailRule[]>;
|
|
40
|
+
list(accountId: number, query?: QueryAst): Promise<MailRule[]>;
|
|
40
41
|
/** A rule with the same conditions is replaced, and keeps its id and the emails it decided. */
|
|
41
42
|
upsert(accountId: number, rule: MailRuleInput, now: number): Promise<MailRule>;
|
|
42
43
|
/** Clears the rule from the emails it decided. Answers false when no rule has these conditions. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { queryFilter } from "./query-filter.js";
|
|
1
2
|
import { write } from "./transaction.js";
|
|
2
3
|
const sorted = (value) => Array.isArray(value)
|
|
3
4
|
? value.map(sorted)
|
|
@@ -23,8 +24,17 @@ const ruleOf = (row) => ({
|
|
|
23
24
|
// SQLite allows 32766 parameters; two are taken by the account and the rule.
|
|
24
25
|
const CHUNK = 30_000;
|
|
25
26
|
export const mailRulesOver = (database) => ({
|
|
26
|
-
async list(accountId) {
|
|
27
|
-
|
|
27
|
+
async list(accountId, query) {
|
|
28
|
+
const where = query &&
|
|
29
|
+
queryFilter(query, {
|
|
30
|
+
id: { type: "num", sql: "id" },
|
|
31
|
+
protected: { type: "bool", sql: "protected" },
|
|
32
|
+
source: { type: "kw", sql: "source" },
|
|
33
|
+
});
|
|
34
|
+
return database
|
|
35
|
+
.prepare(`SELECT * FROM mail_rules WHERE account_id = ?${where ? ` AND (${where.sql})` : ""} ORDER BY id`)
|
|
36
|
+
.all(accountId, ...(where?.params ?? []))
|
|
37
|
+
.map(ruleOf);
|
|
28
38
|
},
|
|
29
39
|
async upsert(accountId, rule, now) {
|
|
30
40
|
const row = database
|
|
@@ -51,6 +51,16 @@ export interface Link {
|
|
|
51
51
|
confirmed: boolean;
|
|
52
52
|
createdAt: string;
|
|
53
53
|
}
|
|
54
|
+
export interface LinkListFilter {
|
|
55
|
+
from?: string;
|
|
56
|
+
to?: string;
|
|
57
|
+
unresolved?: boolean;
|
|
58
|
+
id?: string;
|
|
59
|
+
kind?: Link["kind"];
|
|
60
|
+
role?: string;
|
|
61
|
+
origin?: Link["origin"];
|
|
62
|
+
confirmed?: boolean;
|
|
63
|
+
}
|
|
54
64
|
export interface LinkInput {
|
|
55
65
|
from: string;
|
|
56
66
|
to?: string;
|
|
@@ -123,11 +133,7 @@ export interface NotesStore extends NoteSearch, ImportedDocuments {
|
|
|
123
133
|
removed: true;
|
|
124
134
|
}>;
|
|
125
135
|
addLink(input: LinkInput): Promise<Link>;
|
|
126
|
-
links(options?:
|
|
127
|
-
from?: string;
|
|
128
|
-
to?: string;
|
|
129
|
-
unresolved?: boolean;
|
|
130
|
-
}): Promise<Link[]>;
|
|
136
|
+
links(options?: LinkListFilter): Promise<Link[]>;
|
|
131
137
|
removeLink(id: string): Promise<{
|
|
132
138
|
id: string;
|
|
133
139
|
removed: true;
|
|
@@ -404,10 +404,17 @@ export const notesStoreOver = (context) => {
|
|
|
404
404
|
const to = pair(options.to);
|
|
405
405
|
if (!from.known || !to.known)
|
|
406
406
|
return [];
|
|
407
|
+
const filters = [
|
|
408
|
+
...(options.id === undefined ? [] : [{ sql: "CAST(id AS TEXT) = ?", value: options.id }]),
|
|
409
|
+
...(options.kind === undefined ? [] : [{ sql: "kind = ?", value: options.kind }]),
|
|
410
|
+
...(options.role === undefined ? [] : [{ sql: "role = ?", value: options.role }]),
|
|
411
|
+
...(options.origin === undefined ? [] : [{ sql: "source = ?", value: options.origin }]),
|
|
412
|
+
...(options.confirmed === undefined ? [] : [{ sql: "confirmed = ?", value: options.confirmed ? 1 : 0 }]),
|
|
413
|
+
];
|
|
407
414
|
return database
|
|
408
415
|
.prepare("SELECT * FROM links WHERE (? IS NULL OR (from_type = ? AND from_id = ?)) AND (? IS NULL OR (to_type = ? AND to_id = ?)) " +
|
|
409
|
-
|
|
410
|
-
.all(from.type, from.type, from.id, to.type, to.type, to.id, options.unresolved ? 1 : 0)
|
|
416
|
+
`AND (? = 0 OR to_id IS NULL)${filters.map(({ sql }) => ` AND (${sql})`).join("")} ORDER BY created_at, id LIMIT 5000`)
|
|
417
|
+
.all(from.type, from.type, from.id, to.type, to.type, to.id, options.unresolved ? 1 : 0, ...filters.map(({ value }) => value))
|
|
411
418
|
.map((row) => linkOf(database, row));
|
|
412
419
|
},
|
|
413
420
|
removeLink: async (id) => write(database, () => {
|
|
@@ -9,6 +9,7 @@ import { backfillNormalized, pendingNormalization } from "./backfill.js";
|
|
|
9
9
|
import { fillFolded } from "./folded.js";
|
|
10
10
|
import { logPruner } from "./log-pruning.js";
|
|
11
11
|
import { openSqlite } from "./open.js";
|
|
12
|
+
import { loadProviders } from "./providers.js";
|
|
12
13
|
import { assertReadCompatible } from "./read-compatibility.js";
|
|
13
14
|
import { stemsState } from "./stems.js";
|
|
14
15
|
import { fillStems, followDefaultStemmers } from "./stems-fill.js";
|
|
@@ -56,6 +57,7 @@ export const openStoreContext = async ({ path, env, now = Date.now, command, rea
|
|
|
56
57
|
fillStems(database, { now });
|
|
57
58
|
logPruner(database, now)();
|
|
58
59
|
}
|
|
60
|
+
loadProviders(database);
|
|
59
61
|
return { ...opened, now, sharedConfig: sharedConfigPath(file, env ?? process.env) };
|
|
60
62
|
}
|
|
61
63
|
catch (error) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ProviderEntry } from "../../domain/providers.js";
|
|
2
|
+
import type { CacheDatabase } from "../driver.js";
|
|
3
|
+
export declare const PROVIDERS_SETTING = "providers";
|
|
4
|
+
/** The entries as stored, unchecked: a newer CLI may have written a kind this build does not know. */
|
|
5
|
+
export declare const storedProvidersOf: (database: CacheDatabase) => unknown[];
|
|
6
|
+
/** Called on every open: the module state follows the store the process opened last. */
|
|
7
|
+
export declare const loadProviders: (database: CacheDatabase) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Writes `entry` over the stored one of its name and loads the result. Every run of every CLI calls it, so it
|
|
10
|
+
* writes only when the entry changed. Entries this build cannot read stay stored for the CLIs that can.
|
|
11
|
+
*/
|
|
12
|
+
export declare const registerProvider: (database: CacheDatabase, value: ProviderEntry, now: number) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { addProvider, providerEntryOf, useStoredProviders } from "../../domain/providers.js";
|
|
2
|
+
import { write } from "./transaction.js";
|
|
3
|
+
export const PROVIDERS_SETTING = "providers";
|
|
4
|
+
/** The entries as stored, unchecked: a newer CLI may have written a kind this build does not know. */
|
|
5
|
+
export const storedProvidersOf = (database) => {
|
|
6
|
+
const row = database.prepare("SELECT value FROM store_settings WHERE key = ?").get(PROVIDERS_SETTING);
|
|
7
|
+
if (!row)
|
|
8
|
+
return [];
|
|
9
|
+
try {
|
|
10
|
+
const value = JSON.parse(String(row.value));
|
|
11
|
+
return Array.isArray(value) ? value : [];
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
/** Called on every open: the module state follows the store the process opened last. */
|
|
18
|
+
export const loadProviders = (database) => {
|
|
19
|
+
useStoredProviders(storedProvidersOf(database));
|
|
20
|
+
};
|
|
21
|
+
const nameOf = (stored) => typeof stored === "object" && stored !== null ? stored.name : undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Writes `entry` over the stored one of its name and loads the result. Every run of every CLI calls it, so it
|
|
24
|
+
* writes only when the entry changed. Entries this build cannot read stay stored for the CLIs that can.
|
|
25
|
+
*/
|
|
26
|
+
export const registerProvider = (database, value, now) => {
|
|
27
|
+
const entry = providerEntryOf(value);
|
|
28
|
+
write(database, () => {
|
|
29
|
+
const stored = storedProvidersOf(database);
|
|
30
|
+
const others = stored.filter((one) => nameOf(one) !== entry.name);
|
|
31
|
+
try {
|
|
32
|
+
useStoredProviders(others);
|
|
33
|
+
addProvider(entry);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
useStoredProviders(stored);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
if (stored.some((one) => JSON.stringify(one) === JSON.stringify(entry)))
|
|
40
|
+
return;
|
|
41
|
+
database
|
|
42
|
+
.prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
|
|
43
|
+
.run(PROVIDERS_SETTING, JSON.stringify([...others, entry]), now);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -83,7 +83,7 @@ export interface Label {
|
|
|
83
83
|
origin: "file" | "owner";
|
|
84
84
|
}
|
|
85
85
|
/** A thing's tags by name, with whether only a file states each. */
|
|
86
|
-
export declare const labelsOf: (database: CacheDatabase, thing: Thing) => Label[];
|
|
86
|
+
export declare const labelsOf: (database: CacheDatabase, thing: Thing, tag?: string) => Label[];
|
|
87
87
|
/**
|
|
88
88
|
* Marks one topic as the thing's main one, or clears it with `null`: the topic is tagged on it if it was
|
|
89
89
|
* not, and any other main topic stops being main.
|
|
@@ -156,9 +156,9 @@ export const removeTags = ({ database }, thing, tags, source) => {
|
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
158
|
/** A thing's tags by name, with whether only a file states each. */
|
|
159
|
-
export const labelsOf = (database, thing) => database
|
|
160
|
-
.prepare(
|
|
161
|
-
.all(thing.type, thing.id)
|
|
159
|
+
export const labelsOf = (database, thing, tag) => database
|
|
160
|
+
.prepare(`SELECT t.name, g.source FROM taggings g JOIN tags t ON t.id = g.tag_id WHERE g.taggable_type=? AND g.taggable_id=?${tag === undefined ? "" : " AND t.name = ?"} ORDER BY t.name`)
|
|
161
|
+
.all(thing.type, thing.id, ...(tag === undefined ? [] : [tag]))
|
|
162
162
|
.map((row) => ({ tag: String(row.name), origin: row.source === "file" ? "file" : "owner" }));
|
|
163
163
|
/**
|
|
164
164
|
* Marks one topic as the thing's main one, or clears it with `null`: the topic is tagged on it if it was
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.413.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",
|
|
@@ -128,6 +128,10 @@
|
|
|
128
128
|
"./update": {
|
|
129
129
|
"types": "./dist/update/index.d.ts",
|
|
130
130
|
"default": "./dist/update/index.js"
|
|
131
|
+
},
|
|
132
|
+
"./oauth": {
|
|
133
|
+
"types": "./dist/oauth/index.d.ts",
|
|
134
|
+
"default": "./dist/oauth/index.js"
|
|
131
135
|
}
|
|
132
136
|
},
|
|
133
137
|
"scripts": {
|