@wirecat/cli-core 0.659.0 → 0.661.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 +119 -0
- package/dist/attachments/markup.js +2 -11
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/calendar/mcp/index.js +23 -17
- package/dist/cli/ask-before-write.d.ts +8 -0
- package/dist/cli/ask-before-write.js +28 -0
- package/dist/cli/bot/api-http.d.ts +43 -0
- package/dist/cli/bot/api-http.js +160 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/messenger/rankings-command.js +2 -1
- package/dist/cli/messenger/serve-command.js +7 -2
- package/dist/cli/messenger/tasks-command.d.ts +7 -2
- package/dist/cli/messenger/tasks-command.js +6 -3
- package/dist/cli/schedule/schedule-command.js +3 -0
- package/dist/domain/html-entities.d.ts +5 -0
- package/dist/domain/html-entities.js +56 -0
- package/dist/domain/locator.js +12 -4
- package/dist/domain/providers.js +1 -1
- package/dist/domain/references.js +11 -3
- package/dist/entities/index.d.ts +33 -93
- package/dist/entities/listings.d.ts +4 -4
- package/dist/entities/listings.js +2 -2
- package/dist/errors/reasons.js +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mail/headers.js +3 -3
- package/dist/mail/parse.js +9 -8
- package/dist/mail/resume.d.ts +4 -1
- package/dist/mail/resume.js +11 -2
- package/dist/mail/retry.d.ts +2 -1
- package/dist/mail/retry.js +6 -4
- package/dist/mail/sender-scores.js +1 -6
- package/dist/mail/stored.d.ts +4 -1
- package/dist/mail/stored.js +6 -1
- package/dist/mail/sync.js +8 -3
- package/dist/mail/testing/fake.d.ts +2 -0
- package/dist/mail/testing/fake.js +3 -1
- package/dist/mcp/all-profiles.js +8 -18
- package/dist/mcp/app-server.js +1 -16
- package/dist/mcp/bot/server.js +9 -7
- package/dist/mcp/caller.js +2 -1
- package/dist/mcp/prompts.js +17 -2
- package/dist/mcp/server.js +10 -16
- package/dist/mcp/stdio-wire.d.ts +5 -2
- package/dist/mcp/stdio-wire.js +39 -12
- package/dist/mcp/tool.js +3 -1
- package/dist/mcp/tools/messages-photo.js +4 -2
- package/dist/meetings/answers.d.ts +35 -27
- package/dist/meetings/answers.js +3 -2
- package/dist/meetings/cli/index.d.ts +13 -0
- package/dist/meetings/cli/index.js +61 -16
- package/dist/meetings/cli/management.d.ts +16 -0
- package/dist/meetings/cli/management.js +90 -0
- package/dist/meetings/cli/search.js +8 -2
- package/dist/meetings/hit-query.js +11 -6
- package/dist/meetings/index.d.ts +5 -3
- package/dist/meetings/index.js +4 -2
- package/dist/meetings/item.d.ts +33 -19
- package/dist/meetings/item.js +29 -4
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/pull.d.ts +27 -2
- package/dist/meetings/pull.js +103 -78
- package/dist/meetings/read-through.d.ts +74 -0
- package/dist/meetings/read-through.js +330 -0
- package/dist/meetings/reads.d.ts +1 -0
- package/dist/meetings/reads.js +4 -2
- package/dist/meetings/result-items.d.ts +31 -0
- package/dist/meetings/result-items.js +31 -0
- package/dist/meetings/source.d.ts +47 -0
- package/dist/meetings/store.d.ts +7 -0
- package/dist/meetings/testing/memory.js +8 -1
- package/dist/search/service-query.d.ts +63 -0
- package/dist/search/service-query.js +57 -0
- package/dist/sends/guard.js +7 -1
- package/dist/sends/permissions.js +4 -0
- package/dist/services/listings.js +2 -1
- package/dist/services/message-resolution.js +6 -3
- package/dist/services/messages-search.js +3 -4
- package/dist/services/server-search.d.ts +2 -1
- package/dist/services/server-search.js +36 -32
- package/dist/store/sqlite/meetings.js +15 -1
- package/dist/store/sqlite/mention-drain.d.ts +4 -1
- package/dist/store/sqlite/mention-drain.js +7 -3
- package/dist/store/sqlite/messages.js +12 -1
- package/dist/store/sqlite/query-filter.d.ts +1 -0
- package/dist/store/sqlite/query-filter.js +2 -2
- package/dist/store/sqlite/tags.js +1 -1
- package/package.json +1 -1
package/dist/sends/guard.js
CHANGED
|
@@ -49,7 +49,11 @@ const weightOf = ({ kind = "message", action, count, people }) => kind === "dele
|
|
|
49
49
|
? Math.max(1, people ?? count ?? 1)
|
|
50
50
|
: 1;
|
|
51
51
|
/** A scheduled message counts in the hour the provider sends it. */
|
|
52
|
-
const timeOf = (entry) =>
|
|
52
|
+
const timeOf = (entry) => {
|
|
53
|
+
const scheduled = entry.scheduledFor === undefined ? Number.NaN : Date.parse(entry.scheduledFor);
|
|
54
|
+
// A journal line with an unreadable time still counts, in the hour it was written: never in no hour at all.
|
|
55
|
+
return Number.isNaN(scheduled) ? Date.parse(entry.at) : scheduled;
|
|
56
|
+
};
|
|
53
57
|
/** A write the profile's level refuses, worded alike by the guard and by the check before connecting. */
|
|
54
58
|
/** A write the first-run answer stops, whatever the profile allows. */
|
|
55
59
|
export const ceilingRefusal = (key, command) => new CliError("permission_error", `${key} is not allowed: setup's answer keeps every WireCat tool read-only; ` +
|
|
@@ -119,6 +123,8 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
119
123
|
"do fewer at a time");
|
|
120
124
|
}
|
|
121
125
|
const at = request.scheduledFor ? Date.parse(request.scheduledFor) : now().getTime();
|
|
126
|
+
if (Number.isNaN(at))
|
|
127
|
+
throw new CliError("validation_error", `"${request.scheduledFor}" is not a time to send at — use ISO 8601`);
|
|
122
128
|
const counted = entries
|
|
123
129
|
.filter(countsTowardLimit)
|
|
124
130
|
.filter((entry) => entry.outcome === "sent" || entry.outcome === "outcome_unknown" || entry.outcome === "reserved")
|
|
@@ -42,6 +42,10 @@ export const DEFAULT_PERMISSIONS = {
|
|
|
42
42
|
"schedule.run": "ask",
|
|
43
43
|
"schedule.exec": "ask",
|
|
44
44
|
"doctor.reports.create": "ask",
|
|
45
|
+
// A meeting changed on the service reaches its invitees: asked first, as zoom's `remote-meetings` was.
|
|
46
|
+
"meetings.create": "ask",
|
|
47
|
+
"meetings.update": "ask",
|
|
48
|
+
"meetings.cancel": "ask",
|
|
45
49
|
};
|
|
46
50
|
/** Commands under a housekeeping word, or store maintenance, that still have a key of their own: their path. */
|
|
47
51
|
export const KEYED_UNDER_HOUSEKEEPING = new Set(Object.keys(DEFAULT_PERMISSIONS).filter((key) => /^(store|server|models|images|schedule|doctor)\./.test(key)));
|
|
@@ -123,7 +123,8 @@ export const showDocument = async (store, reference, text) => {
|
|
|
123
123
|
text: found.text,
|
|
124
124
|
text_offset: Math.min(text.offset, found.textLength),
|
|
125
125
|
text_length: found.textLength,
|
|
126
|
-
|
|
126
|
+
// SQLite's substr and length count code points; a JavaScript string's length counts UTF-16 units.
|
|
127
|
+
has_more: found.text !== null && text.offset + [...found.text].length < found.textLength,
|
|
127
128
|
extraction: found.extraction,
|
|
128
129
|
extraction_error: found.extractionError,
|
|
129
130
|
language: found.language,
|
|
@@ -131,12 +131,15 @@ export const chatAmong = async (messenger, store, accounts, reference) => {
|
|
|
131
131
|
const [only] = accounts;
|
|
132
132
|
if (accounts.length === 1 && only)
|
|
133
133
|
return { account: only, chatId: await storedChatId(messenger, reference, store, only, { includeLeft: true }) };
|
|
134
|
-
const
|
|
135
|
-
const held = (await store.chats.chats(account, {})).items;
|
|
136
|
-
const chatId = await storedChatId(messenger, reference, store, account).catch(missing);
|
|
134
|
+
const among = async (includeLeft) => (await Promise.all(accounts.map(async (account) => {
|
|
135
|
+
const held = (await store.chats.chats(account, includeLeft ? { includeLeft } : {})).items;
|
|
136
|
+
const chatId = await storedChatId(messenger, reference, store, account, { includeLeft }).catch(missing);
|
|
137
137
|
const chat = held.find((one) => one.id === chatId);
|
|
138
138
|
return chat ? [{ account, chat }] : [];
|
|
139
139
|
}))).flat();
|
|
140
|
+
// As with one account, a chat left behind is found when no account still holds one by that name.
|
|
141
|
+
const current = await among(false);
|
|
142
|
+
const found = current.length > 0 ? current : await among(true);
|
|
140
143
|
const [one] = found;
|
|
141
144
|
if (found.length === 1 && one)
|
|
142
145
|
return { account: one.account, chatId: one.chat.id };
|
|
@@ -15,8 +15,9 @@ import { chatAmong, chatsMatchingIn, senderAmong, sendersMatching } from "./mess
|
|
|
15
15
|
import { accountsOfKind, listedAccounts, MAIL } from "./search-kind.js";
|
|
16
16
|
const PERSON_FIELDS = new Set(["from", "to", "cc", "bcc"]);
|
|
17
17
|
const MAIL_FIELDS = new Set(["to", "cc", "bcc", "subject", "mailbox", "label", "is", "list"]);
|
|
18
|
-
import {
|
|
18
|
+
import { parseLucene, timezoneOf, walkQuery, } from "@wirecat/cli-base/query";
|
|
19
19
|
import { MESSAGE_PARSING, searchError } from "../search/lucene/types.js";
|
|
20
|
+
import { rangeOf } from "../search/service-query.js";
|
|
20
21
|
const positiveSources = (node) => node.kind === "predicate"
|
|
21
22
|
? node.field === "in"
|
|
22
23
|
? [node.value.toLowerCase()]
|
|
@@ -118,9 +119,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
118
119
|
if (node.field === "date")
|
|
119
120
|
return {
|
|
120
121
|
...node,
|
|
121
|
-
resolution: {
|
|
122
|
-
date: dateRange(node.value, node.operator === "range" ? (node.upper ?? "*") : node.value, node.operator === "range" ? node.lower_inclusive === true : true, node.operator === "range" ? node.upper_inclusive === true : true, timezone, node.span),
|
|
123
|
-
},
|
|
122
|
+
resolution: { date: rangeOf(node, timezone) },
|
|
124
123
|
};
|
|
125
124
|
return node;
|
|
126
125
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Id } from "../domain/models.js";
|
|
2
|
+
import { type Backend } from "../search/service-query.js";
|
|
2
3
|
import type { ServiceDeps } from "./deps.js";
|
|
3
4
|
import type { SearchQuery } from "./messages.js";
|
|
4
5
|
export declare const SERVER_SEARCH_KEY = "messages.server-search";
|
|
@@ -13,7 +14,7 @@ export declare const SERVER_BOUNDS: {
|
|
|
13
14
|
textBytes: number;
|
|
14
15
|
};
|
|
15
16
|
export declare const DEFAULT_BACKEND = "both";
|
|
16
|
-
export type Backend
|
|
17
|
+
export type { Backend };
|
|
17
18
|
export interface ServerOptions {
|
|
18
19
|
timeMs?: number;
|
|
19
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { capability } from "../ports/messenger.js";
|
|
3
|
+
import { serviceCallsOf, windowOf } from "../search/service-query.js";
|
|
3
4
|
import { prepareLucene } from "./messages-search.js";
|
|
4
5
|
export const SERVER_SEARCH_KEY = "messages.server-search";
|
|
5
6
|
/**
|
|
@@ -27,33 +28,40 @@ const merge = (one, other) => {
|
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
30
|
const sameAccount = (one, other) => one.provider === other.provider && one.account === other.account;
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// The server reads words, one chat, one sender and a date range; the strict local query decides the rest.
|
|
32
|
+
const serverReads = (account) => ({
|
|
33
|
+
fields: {
|
|
34
|
+
text: ["term", "phrase"],
|
|
35
|
+
exact: ["term", "phrase"],
|
|
36
|
+
chat: ["term", "phrase"],
|
|
37
|
+
from: ["term", "phrase"],
|
|
38
|
+
date: ["term", "range"],
|
|
39
|
+
},
|
|
40
|
+
maxCalls: SERVER_BOUNDS.maxCalls,
|
|
41
|
+
all: { words: [] },
|
|
42
|
+
leaf: (node) => {
|
|
43
|
+
if (node.field === "text" || node.field === "exact")
|
|
44
|
+
return { words: node.value === "" ? [] : [node.value] };
|
|
36
45
|
const { chat, sender, date } = node.resolution ?? {};
|
|
46
|
+
// Another account's chat holds nothing this account's server can return.
|
|
37
47
|
if (chat)
|
|
38
|
-
return sameAccount(chat.account, account) ?
|
|
48
|
+
return sameAccount(chat.account, account) ? { words: [], chat: chat.chatId } : undefined;
|
|
39
49
|
if (sender?.provider === account.provider)
|
|
40
|
-
return
|
|
41
|
-
if (date)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return should.length ? should.flatMap(({ node }) => branchesOf(node, account)) : [{ words: [] }];
|
|
56
|
-
};
|
|
50
|
+
return { words: [], from: sender.id };
|
|
51
|
+
if (date) {
|
|
52
|
+
const { from, to } = windowOf(date);
|
|
53
|
+
return {
|
|
54
|
+
words: [],
|
|
55
|
+
...(from === undefined ? {} : { minDate: from }),
|
|
56
|
+
...(to === undefined ? {} : { maxDate: to }),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// `from:me` and the like: nothing the server filters, so the call is not narrowed.
|
|
60
|
+
return { words: [] };
|
|
61
|
+
},
|
|
62
|
+
both: merge,
|
|
63
|
+
sends: ({ words }) => words.length > 0,
|
|
64
|
+
});
|
|
57
65
|
const asQuery = ({ words, from, ...rest }) => ({
|
|
58
66
|
text: words.join(" "),
|
|
59
67
|
...rest,
|
|
@@ -123,15 +131,12 @@ export const searchServer = async (deps, request) => {
|
|
|
123
131
|
: { words: [] };
|
|
124
132
|
if (!scoped)
|
|
125
133
|
return skip("other_accounts");
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
...new Map(all.filter(({ words }) => words.length).map((branch) => [JSON.stringify(branch), branch])).values(),
|
|
129
|
-
];
|
|
130
|
-
if (!unique.length)
|
|
134
|
+
const { calls, complete } = serviceCallsOf(execution.root, serverReads(account), scoped);
|
|
135
|
+
if (!calls.length)
|
|
131
136
|
return skip("no_words");
|
|
132
|
-
if (deps.messenger.serverSearch === "chat" &&
|
|
137
|
+
if (deps.messenger.serverSearch === "chat" && calls.some(({ chat }) => chat === undefined))
|
|
133
138
|
return skip("needs_chat");
|
|
134
|
-
if (
|
|
139
|
+
if (!complete)
|
|
135
140
|
report.complete = false;
|
|
136
141
|
const controller = new AbortController();
|
|
137
142
|
const timer = setTimeout(() => controller.abort(), timeMs);
|
|
@@ -141,7 +146,6 @@ export const searchServer = async (deps, request) => {
|
|
|
141
146
|
resolve(BOUND);
|
|
142
147
|
stop.addEventListener("abort", () => resolve(BOUND), { once: true });
|
|
143
148
|
});
|
|
144
|
-
const calls = unique.slice(0, SERVER_BOUNDS.maxCalls);
|
|
145
149
|
const pending = new Set(calls);
|
|
146
150
|
const found = [];
|
|
147
151
|
let open = true;
|
|
@@ -430,6 +430,7 @@ const MEETING_COLUMNS = {
|
|
|
430
430
|
ended_at: { type: "time", sql: "ended_at" },
|
|
431
431
|
duration_ms: { type: "num", sql: "duration_ms" },
|
|
432
432
|
participants_count: { type: "num", sql: "participants_count" },
|
|
433
|
+
provider_id: { type: "kw", sql: "external_id" },
|
|
433
434
|
created_at: { type: "time", sql: "created_at" },
|
|
434
435
|
updated_at: { type: "time", sql: "updated_at" },
|
|
435
436
|
};
|
|
@@ -452,8 +453,15 @@ const filtered = (filter = {}) => {
|
|
|
452
453
|
add("started_at >= ?", filter.since);
|
|
453
454
|
if (filter.until !== undefined)
|
|
454
455
|
add("started_at <= ?", filter.until);
|
|
456
|
+
// One bound list: an OR of ids per meeting grows past SQLite's expression depth at about a thousand.
|
|
457
|
+
if (filter.ids !== undefined)
|
|
458
|
+
add("id IN (SELECT value FROM json_each(?))", JSON.stringify(filter.ids));
|
|
455
459
|
if (filter.query !== undefined) {
|
|
456
|
-
const compiled = queryFilter(filter.query, MEETING_COLUMNS, {
|
|
460
|
+
const compiled = queryFilter(filter.query, MEETING_COLUMNS, {
|
|
461
|
+
command: "meetings list",
|
|
462
|
+
...(filter.timezone === undefined ? {} : { zone: filter.timezone }),
|
|
463
|
+
...(filter.now === undefined ? {} : { now: filter.now }),
|
|
464
|
+
});
|
|
457
465
|
where.push(`(${compiled.sql})`);
|
|
458
466
|
params.push(...compiled.params);
|
|
459
467
|
}
|
|
@@ -659,6 +667,12 @@ export const meetingStoreOver = (context) => {
|
|
|
659
667
|
async meeting(id) {
|
|
660
668
|
return details(database, id);
|
|
661
669
|
},
|
|
670
|
+
async meetingByExternalId(accountId, externalId) {
|
|
671
|
+
const row = database
|
|
672
|
+
.prepare("SELECT id FROM meetings WHERE account_id = ? AND external_id = ?")
|
|
673
|
+
.get(accountId, externalId);
|
|
674
|
+
return row ? details(database, Number(row.id)) : null;
|
|
675
|
+
},
|
|
662
676
|
async participants(query, accountId) {
|
|
663
677
|
return participants(database, query, accountId);
|
|
664
678
|
},
|
|
@@ -9,7 +9,10 @@ type Decision = {
|
|
|
9
9
|
target_id: unknown;
|
|
10
10
|
author: unknown;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The stored Telegram chat or account a `t.me` link names, as a rules decision; nothing for any other link. Never a
|
|
14
|
+
* chat of another messenger that happens to share the username.
|
|
15
|
+
*/
|
|
13
16
|
export declare const telegramLink: (database: CacheDatabase) => (value: string) => Decision | undefined;
|
|
14
17
|
/**
|
|
15
18
|
* People whose names are looked for: not the owner, and only people met in a messenger, a meeting or a confirmed
|
|
@@ -8,10 +8,14 @@ import { placeOf } from "./place-key.js";
|
|
|
8
8
|
/** Mentions a store write finds before it commits: an older binary may have queued thousands. */
|
|
9
9
|
export const DRAIN_ON_WRITE = 500;
|
|
10
10
|
const METHOD = "rules";
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The stored Telegram chat or account a `t.me` link names, as a rules decision; nothing for any other link. Never a
|
|
13
|
+
* chat of another messenger that happens to share the username.
|
|
14
|
+
*/
|
|
12
15
|
export const telegramLink = (database) => {
|
|
13
|
-
const chat = database.prepare("SELECT 'linked' AS status, 'chat' AS target_type, id AS target_id, 'rules' AS author FROM chats " +
|
|
14
|
-
"
|
|
16
|
+
const chat = database.prepare("SELECT 'linked' AS status, 'chat' AS target_type, c.id AS target_id, 'rules' AS author FROM chats c " +
|
|
17
|
+
"JOIN accounts a ON a.id = c.account_id WHERE a.provider = 'telegram' " +
|
|
18
|
+
"AND ((? IS NOT NULL AND lower(c.username) = lower(?)) OR c.external_id = ?) ORDER BY c.id LIMIT 1");
|
|
15
19
|
const account = database.prepare("SELECT 'linked' AS status, 'identity' AS target_type, id AS target_id, 'rules' AS author FROM identities " +
|
|
16
20
|
"WHERE provider = 'telegram' AND lower(username) = lower(?) ORDER BY id LIMIT 1");
|
|
17
21
|
return (value) => {
|
|
@@ -143,6 +143,17 @@ export const upsertMessage = (context, key, accountKey, chatKey, received, via,
|
|
|
143
143
|
else {
|
|
144
144
|
pk = found.pk;
|
|
145
145
|
const edit = message.editedAt !== null;
|
|
146
|
+
// A copy from before the stored edit (a history page fetched before serve saw the edit, a late edit event)
|
|
147
|
+
// keeps the newer text; its reactions and counters may still be fresher.
|
|
148
|
+
const stale = !revived &&
|
|
149
|
+
found.editedAt !== null &&
|
|
150
|
+
(fields.editedAt !== null
|
|
151
|
+
? Number(fields.editedAt) < found.editedAt
|
|
152
|
+
: seenAt !== undefined && seenAt < found.editedAt);
|
|
153
|
+
if (stale) {
|
|
154
|
+
fields.editedAt = null;
|
|
155
|
+
fields.normalizedText = null;
|
|
156
|
+
}
|
|
146
157
|
// An edit event may carry only the new text, stamped with the edit's time: a send time never moves later,
|
|
147
158
|
// and an edit that counts no reactions has not seen them.
|
|
148
159
|
if (edit) {
|
|
@@ -169,7 +180,7 @@ export const upsertMessage = (context, key, accountKey, chatKey, received, via,
|
|
|
169
180
|
}
|
|
170
181
|
statements.update.run({ ...fields, pk });
|
|
171
182
|
// A tombstone emptied the text: there is no earlier version to keep.
|
|
172
|
-
if (found.text !== message.text && !revived) {
|
|
183
|
+
if (found.text !== message.text && !revived && !stale) {
|
|
173
184
|
orm
|
|
174
185
|
.insert(messageRevisions)
|
|
175
186
|
.values({ messageId: pk, text: found.text, editedAt: found.editedAt, createdAt: now() })
|
|
@@ -21,6 +21,7 @@ export type ColumnMap = Readonly<Record<string, {
|
|
|
21
21
|
where: (node: Predicate) => Where;
|
|
22
22
|
}>>;
|
|
23
23
|
export interface FilterOptions extends QueryContext {
|
|
24
|
+
/** Where `today` and a bare date start; the machine's zone when absent, as search reads them. */
|
|
24
25
|
zone?: string;
|
|
25
26
|
now?: number;
|
|
26
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dateRange, queryError, } from "@wirecat/cli-base/query";
|
|
1
|
+
import { dateRange, queryError, timezoneOf, } from "@wirecat/cli-base/query";
|
|
2
2
|
import { fold } from "../normalize.js";
|
|
3
3
|
import { sql } from "./drizzle/core.js";
|
|
4
4
|
/** A wildcard term as a GLOB pattern: `\x` is a literal x, and a literal `*`, `?` or `[` is bracketed. */
|
|
@@ -53,7 +53,7 @@ const leaf = (node, columns, options) => {
|
|
|
53
53
|
const range = node.operator === "range"
|
|
54
54
|
? [node.value, node.upper ?? "*", node.lower_inclusive ?? true, node.upper_inclusive ?? true]
|
|
55
55
|
: [node.value, node.value, true, true];
|
|
56
|
-
const { lower, upper, lower_inclusive, upper_inclusive } = dateRange(range[0], range[1], range[2], range[3], options.zone
|
|
56
|
+
const { lower, upper, lower_inclusive, upper_inclusive } = dateRange(range[0], range[1], range[2], range[3], timezoneOf(options.zone), node.span, options.now);
|
|
57
57
|
return all([
|
|
58
58
|
{ sql: `${sql} IS NOT NULL`, params: [] },
|
|
59
59
|
...(lower === undefined ? [] : [{ sql: `${sql} ${lower_inclusive ? ">=" : ">"} ?`, params: [lower] }]),
|
|
@@ -282,7 +282,7 @@ export const tagsOf = ({ database }, key, filter) => {
|
|
|
282
282
|
"WHEN 'email' THEN 'message' ELSE u.type END AS tag_type, (u.type = 'chat' AND EXISTS (SELECT 1 FROM " +
|
|
283
283
|
`canonical_auto_tag_claims ac JOIN resolved_tags rt ON rt.id=ac.tag_id WHERE ac.chat_id = u.target_id AND rt.canonical_id = u.tag_id)) AS auto FROM (${union}) u) GROUP BY tag,type,target_id) x ` +
|
|
284
284
|
`WHERE ${where.length === 0 ? "1" : where.map(({ sql }) => `(${sql})`).join(" AND ")} ` +
|
|
285
|
-
"ORDER BY x.tag, x.type, x.created_at, x.chat_id, x.person_id, x.message_id" +
|
|
285
|
+
"ORDER BY x.tag, x.type, x.created_at, x.chat_id, x.person_id, x.message_id, x.target_id" +
|
|
286
286
|
(filter.window ? " LIMIT ? OFFSET ?" : ""))
|
|
287
287
|
.all(...chosen.flatMap(({ params }) => (selectedTag === undefined ? params : [...params, selectedTag])), ...where.flatMap(({ params }) => params), ...(filter.window ? [filter.window.limit, filter.window.offset] : []));
|
|
288
288
|
const result = rows.map((row) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.661.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",
|