@wirecat/cli-core 0.662.0 → 0.663.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 +88 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/cli/bodies.js +2 -1
- package/dist/calendar/cli/index.js +13 -10
- package/dist/calendar/mcp/index.d.ts +3 -1
- package/dist/calendar/mcp/index.js +4 -4
- package/dist/cli/call-stats-command.d.ts +18 -0
- package/dist/cli/call-stats-command.js +52 -0
- package/dist/cli/contract-templates.js +2 -0
- package/dist/cli/envelope.d.ts +0 -5
- package/dist/cli/envelope.js +25 -0
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +2 -1
- package/dist/cli/meeting-batch.d.ts +2 -1
- package/dist/cli/meeting-batch.js +7 -5
- package/dist/cli/meeting-preparation-command.js +5 -5
- package/dist/cli/meeting-preparation-read.d.ts +5 -5
- package/dist/cli/meeting-preparation-read.js +13 -21
- package/dist/cli/meeting-series-inventory-command.js +2 -2
- package/dist/cli/meeting-series-inventory-read.d.ts +2 -2
- package/dist/cli/meeting-series-inventory-read.js +7 -15
- package/dist/cli/messenger/admin-statistics-command.js +2 -2
- package/dist/cli/messenger/counters-command.js +2 -2
- package/dist/cli/messenger/media-archive-command.js +5 -4
- package/dist/cli/messenger/media-archive-move-command.js +1 -1
- package/dist/cli/messenger/media-archive-timer-command.js +5 -4
- package/dist/cli/messenger/metadata-command.js +3 -3
- package/dist/cli/messenger/rankings-command.js +3 -3
- package/dist/cli/messenger/tags-command.js +7 -2
- package/dist/cli/messenger/tasks-command.js +2 -2
- package/dist/cli/paging.d.ts +10 -0
- package/dist/cli/paging.js +29 -0
- package/dist/cli/runs/command.js +6 -4
- package/dist/cli/runs/search-command.js +9 -5
- package/dist/cli/schedule/schedule-command.js +1 -5
- package/dist/domain/moment.d.ts +29 -0
- package/dist/domain/moment.js +58 -0
- package/dist/domain/providers.d.ts +6 -4
- package/dist/domain/providers.js +10 -5
- package/dist/domain/send-time.d.ts +3 -4
- package/dist/domain/send-time.js +10 -24
- package/dist/entities/fields.d.ts +2 -2
- package/dist/entities/fields.js +2 -2
- package/dist/entities/index.d.ts +92 -1
- package/dist/entities/index.js +3 -2
- package/dist/entities/meeting.d.ts +1 -1
- package/dist/entities/meeting.js +1 -1
- package/dist/errors/reasons.js +0 -1
- package/dist/mail/cli/index.js +4 -2
- package/dist/mail/facts.d.ts +5 -2
- package/dist/mail/facts.js +6 -3
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/meeting-notes.js +1 -1
- package/dist/mail/probe.d.ts +5 -2
- package/dist/mail/probe.js +9 -5
- package/dist/mail/server-search.js +1 -1
- package/dist/mail/sync.js +1 -1
- package/dist/mcp/meeting-preparation.js +1 -1
- package/dist/mcp/meeting-series-inventory.js +1 -1
- package/dist/mcp/prompts.js +6 -9
- package/dist/meetings/call-answers.d.ts +106 -0
- package/dist/meetings/call-answers.js +171 -0
- package/dist/meetings/call-stats.d.ts +121 -0
- package/dist/meetings/call-stats.js +211 -0
- package/dist/meetings/calls.d.ts +76 -0
- package/dist/meetings/calls.js +78 -0
- package/dist/meetings/cli/index.d.ts +8 -0
- package/dist/meetings/cli/index.js +10 -22
- package/dist/meetings/cli/search.d.ts +9 -2
- package/dist/meetings/cli/search.js +16 -26
- package/dist/meetings/index.d.ts +3 -0
- package/dist/meetings/index.js +3 -0
- package/dist/meetings/mcp/index.d.ts +6 -3
- package/dist/meetings/mcp/index.js +2 -4
- package/dist/meetings/mcp/search.d.ts +6 -1
- package/dist/meetings/mcp/search.js +3 -3
- package/dist/meetings/read-through.d.ts +2 -1
- package/dist/meetings/read-through.js +10 -1
- package/dist/meetings/stats.d.ts +3 -0
- package/dist/meetings/stats.js +3 -3
- package/dist/meetings/testing/index.d.ts +1 -0
- package/dist/meetings/testing/index.js +1 -0
- package/dist/meetings/testing/paging.d.ts +6 -0
- package/dist/meetings/testing/paging.js +5 -0
- package/dist/moderation/rules.d.ts +2 -0
- package/dist/moderation/rules.js +16 -2
- package/dist/search/fusion.d.ts +17 -0
- package/dist/search/fusion.js +17 -0
- package/dist/search/lucene/resolved.d.ts +2 -0
- package/dist/search/question-plan.d.ts +2 -0
- package/dist/search/question-plan.js +5 -0
- package/dist/search/service-query.d.ts +6 -1
- package/dist/search/service-query.js +9 -1
- package/dist/services/agenda-mail.js +2 -1
- package/dist/services/agenda.js +5 -3
- package/dist/services/attachments.js +4 -2
- package/dist/services/call-stats.d.ts +17 -0
- package/dist/services/call-stats.js +41 -0
- package/dist/services/chats.js +4 -2
- package/dist/services/conversations.js +4 -2
- package/dist/services/deps.d.ts +1 -1
- package/dist/services/document-source.d.ts +1 -1
- package/dist/services/document-source.js +4 -3
- package/dist/services/documents/ingestion.js +11 -40
- package/dist/services/documents/plan.d.ts +1 -1
- package/dist/services/documents/plan.js +30 -17
- package/dist/services/documents/ports.d.ts +5 -0
- package/dist/services/documents/sync.js +1 -1
- package/dist/services/embeddings-search.js +20 -4
- package/dist/services/events-search.js +2 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/mail-search.d.ts +1 -1
- package/dist/services/mail-search.js +10 -11
- package/dist/services/media-archive-move.js +2 -4
- package/dist/services/media-archive.d.ts +0 -1
- package/dist/services/media-archive.js +2 -12
- package/dist/services/meeting-combined.js +1 -1
- package/dist/services/messages-combined.js +15 -4
- package/dist/services/moderation.js +10 -2
- package/dist/services/moment.d.ts +4 -10
- package/dist/services/moment.js +16 -44
- package/dist/services/notes-search.d.ts +0 -2
- package/dist/services/notes-search.js +1 -2
- package/dist/services/search-all.js +2 -1
- package/dist/services/tags.js +4 -2
- package/dist/services/task-stats.js +2 -2
- package/dist/services/tasks.js +2 -2
- package/dist/store/accounts.js +2 -1
- package/dist/store/sqlite/account-purge.d.ts +3 -0
- package/dist/store/sqlite/account-purge.js +143 -0
- package/dist/store/sqlite/accounts.d.ts +0 -2
- package/dist/store/sqlite/accounts.js +2 -134
- package/dist/store/sqlite/calendar.d.ts +1 -0
- package/dist/store/sqlite/calendar.js +5 -5
- package/dist/store/sqlite/catalog.js +2 -16
- package/dist/store/sqlite/chats.js +2 -1
- package/dist/store/sqlite/context-document-source.d.ts +3 -3
- package/dist/store/sqlite/context-document-source.js +9 -7
- package/dist/store/sqlite/context-evidence.js +9 -3
- package/dist/store/sqlite/document-listing.js +2 -1
- package/dist/store/sqlite/events.js +2 -1
- package/dist/store/sqlite/file-note.d.ts +6 -0
- package/dist/store/sqlite/file-note.js +15 -0
- package/dist/store/sqlite/files.d.ts +3 -2
- package/dist/store/sqlite/files.js +5 -3
- package/dist/store/sqlite/identities.js +2 -1
- package/dist/store/sqlite/imported-documents.js +2 -2
- package/dist/store/sqlite/knowledge.js +19 -19
- package/dist/store/sqlite/lucene-fields.js +8 -12
- package/dist/store/sqlite/mail-rules.js +2 -1
- package/dist/store/sqlite/meeting-calls.d.ts +4 -0
- package/dist/store/sqlite/meeting-calls.js +66 -0
- package/dist/store/sqlite/meetings.d.ts +2 -2
- package/dist/store/sqlite/meetings.js +4 -1
- package/dist/store/sqlite/mention-sources.js +2 -1
- package/dist/store/sqlite/mentions.js +2 -2
- package/dist/store/sqlite/messages.js +6 -1
- package/dist/store/sqlite/note-search.js +8 -11
- package/dist/store/sqlite/notes.d.ts +2 -0
- package/dist/store/sqlite/notes.js +24 -13
- package/dist/store/sqlite/organizations.js +2 -2
- package/dist/store/sqlite/people-list.js +3 -3
- package/dist/store/sqlite/query-filter.d.ts +3 -3
- package/dist/store/sqlite/query-filter.js +3 -3
- package/dist/store/sqlite/reads.d.ts +4 -4
- package/dist/store/sqlite/reads.js +4 -4
- package/dist/store/sqlite/search.js +11 -7
- package/dist/store/sqlite/test-accounts.js +1 -1
- package/dist/store/sqlite/trigram-match.d.ts +9 -0
- package/dist/store/sqlite/trigram-match.js +28 -0
- package/dist/store/sqlite/work-tasks.js +1 -1
- package/package.json +3 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
import { communicationFields } from "../context/communication-selection.js";
|
|
4
|
-
import {
|
|
5
|
-
import { validateMeetingChange } from "../meetings/index.js";
|
|
4
|
+
import { typedTime } from "../entities/index.js";
|
|
6
5
|
import { MEETING_PREPARATION_LIMITS, validateMeetingPreparationRequest, } from "../services/index.js";
|
|
7
6
|
import { validatePreparationCommunications } from "../services/meeting-communications-selection.js";
|
|
7
|
+
import { momentOf } from "../services/moment.js";
|
|
8
8
|
import { meetingPreparationAnswer } from "./meeting-preparation-answer.js";
|
|
9
9
|
const bound = (name) => {
|
|
10
10
|
const { min, max } = MEETING_PREPARATION_LIMITS[name];
|
|
@@ -12,27 +12,19 @@ const bound = (name) => {
|
|
|
12
12
|
};
|
|
13
13
|
export const meetingPreparationInput = v.strictObject({
|
|
14
14
|
series_id: v.pipe(v.string(), v.minLength(1), v.maxLength(1000)),
|
|
15
|
-
communications: v.optional(v.strictObject({ ...communicationFields, after: v.optional(
|
|
15
|
+
communications: v.optional(v.strictObject({ ...communicationFields, after: v.optional(typedTime), before: v.optional(typedTime) })),
|
|
16
16
|
project: v.optional(v.pipe(v.string(), v.minLength(1), v.maxLength(200))),
|
|
17
|
-
after: v.optional(
|
|
18
|
-
until: v.optional(
|
|
19
|
-
history_after: v.optional(
|
|
17
|
+
after: v.optional(typedTime),
|
|
18
|
+
until: v.optional(typedTime),
|
|
19
|
+
history_after: v.optional(typedTime),
|
|
20
20
|
meetings: bound("meetings"),
|
|
21
21
|
cues: bound("cues"),
|
|
22
22
|
context_limit: bound("contextLimit"),
|
|
23
23
|
max_read_bytes: bound("maxReadBytes"),
|
|
24
24
|
bytes: bound("bytes"),
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return fallback;
|
|
29
|
-
try {
|
|
30
|
-
return Date.parse(validateMeetingChange({ startTime: value }, false).startTime);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
throw new CliError("validation_error", `${field} must be a valid ISO timestamp with a zone`);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
26
|
+
// A date alone ends a window at the end of that day and starts one at its start.
|
|
27
|
+
const instant = (value, fallback, field, now, end = false) => value === undefined ? fallback : momentOf(value, field, now, { end });
|
|
36
28
|
export const readMeetingPreparation = async (read, input, signal, now = Date.now()) => {
|
|
37
29
|
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
38
30
|
throw new CliError("validation_error", "meeting preparation arguments are required");
|
|
@@ -48,9 +40,9 @@ export const readMeetingPreparation = async (read, input, signal, now = Date.now
|
|
|
48
40
|
throw new CliError("validation_error", `invalid meeting preparation field: ${String(field)}`);
|
|
49
41
|
}
|
|
50
42
|
const args = parsed.output;
|
|
51
|
-
const after = instant(args.after, now, "after");
|
|
52
|
-
const until = instant(args.until, after + 7 * 86400000, "until");
|
|
53
|
-
const historyAfter = instant(args.history_after, after - 30 * 86400000, "history_after");
|
|
43
|
+
const after = instant(args.after, now, "after", now);
|
|
44
|
+
const until = instant(args.until, after + 7 * 86400000, "until", now, true);
|
|
45
|
+
const historyAfter = instant(args.history_after, after - 30 * 86400000, "history_after", now);
|
|
54
46
|
const request = validateMeetingPreparationRequest(args.series_id, {
|
|
55
47
|
...(args.project === undefined ? {} : { project: args.project }),
|
|
56
48
|
...(args.communications === undefined
|
|
@@ -58,8 +50,8 @@ export const readMeetingPreparation = async (read, input, signal, now = Date.now
|
|
|
58
50
|
: {
|
|
59
51
|
communications: {
|
|
60
52
|
...args.communications,
|
|
61
|
-
after: instant(args.communications.after, Math.max(0, instant(args.communications.before, after, "communications.before") - 14 * 86400000), "communications.after"),
|
|
62
|
-
before: instant(args.communications.before, after, "communications.before"),
|
|
53
|
+
after: instant(args.communications.after, Math.max(0, instant(args.communications.before, after, "communications.before", now, true) - 14 * 86400000), "communications.after", now),
|
|
54
|
+
before: instant(args.communications.before, after, "communications.before", now, true),
|
|
63
55
|
},
|
|
64
56
|
}),
|
|
65
57
|
after,
|
|
@@ -14,8 +14,8 @@ export const addMeetingSeriesInventoryCommand = (program, deps) => {
|
|
|
14
14
|
return annotate(meetings
|
|
15
15
|
.command("scheduled")
|
|
16
16
|
.description("discover candidate meeting series from one bounded provider page")
|
|
17
|
-
.option("--since-time <time>", "
|
|
18
|
-
.option("--before-time <time>", "exclusive
|
|
17
|
+
.option("--since-time <time>", "window start, an ISO date or time, local without a zone (default now)")
|
|
18
|
+
.option("--before-time <time>", "exclusive window end, an ISO date or time; a date alone covers that day (default seven days after start)")
|
|
19
19
|
.option("--limit <n>", "series candidates in one provider page, 1–100 (default 100)", integer)
|
|
20
20
|
.option("--max-read-bytes <bytes>", "normalized provider-page bytes, at most 1048576 (default 65536)", integer)
|
|
21
21
|
.option("--bytes <bytes>", "answer item UTF-8 JSON bytes, 2048–1048576 (default 65536)", integer)
|
|
@@ -2,8 +2,8 @@ import * as v from "valibot";
|
|
|
2
2
|
import { type MeetingSeriesInventoryRequest, type MeetingSeriesInventoryResult } from "../meetings/index.js";
|
|
3
3
|
export type MeetingSeriesInventoryReader = (request: MeetingSeriesInventoryRequest) => Promise<MeetingSeriesInventoryResult>;
|
|
4
4
|
export declare const meetingSeriesInventoryInput: v.StrictObjectSchema<{
|
|
5
|
-
readonly after: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
6
|
-
readonly until: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.
|
|
5
|
+
readonly after: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "an ISO 8601 date or time, in the computer's zone without one; or 30m, 2h, 7d ago">]>, undefined>;
|
|
6
|
+
readonly until: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 64, undefined>, v.DescriptionAction<string, "an ISO 8601 date or time, in the computer's zone without one; or 30m, 2h, 7d ago">]>, undefined>;
|
|
7
7
|
readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, undefined>;
|
|
8
8
|
readonly max_read_bytes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, undefined>;
|
|
9
9
|
readonly bytes: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, undefined>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
import { meetingSeriesInventory,
|
|
4
|
-
import {
|
|
3
|
+
import { meetingSeriesInventory, typedTime } from "../entities/index.js";
|
|
4
|
+
import { validateMeetingSeriesInventoryCursor, } from "../meetings/index.js";
|
|
5
|
+
import { momentOf } from "../services/moment.js";
|
|
5
6
|
import { itemOf, metaNow, sealed, snakeKeys } from "./envelope.js";
|
|
6
7
|
const bounded = (min, max) => v.optional(v.pipe(v.number(), v.integer(), v.minValue(min), v.maxValue(max)));
|
|
7
8
|
export const meetingSeriesInventoryInput = v.strictObject({
|
|
8
|
-
after: v.optional(
|
|
9
|
-
until: v.optional(
|
|
9
|
+
after: v.optional(typedTime),
|
|
10
|
+
until: v.optional(typedTime),
|
|
10
11
|
limit: bounded(1, 100),
|
|
11
12
|
max_read_bytes: bounded(1, 1048576),
|
|
12
13
|
bytes: bounded(2048, 1048576),
|
|
@@ -20,16 +21,7 @@ const storedInstant = (value) => {
|
|
|
20
21
|
throw new CliError("invalid_response", "meeting inventory scheduled_start_at is invalid");
|
|
21
22
|
return new Date(value).toISOString();
|
|
22
23
|
};
|
|
23
|
-
const instant = (value, fallback, field) => {
|
|
24
|
-
if (value === undefined)
|
|
25
|
-
return fallback;
|
|
26
|
-
try {
|
|
27
|
-
return Date.parse(validateMeetingChange({ startTime: value }, false).startTime);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
throw new CliError("validation_error", `invalid meeting inventory ${field}`);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
24
|
+
const instant = (value, fallback, field, now, end = false) => value === undefined ? fallback : momentOf(value, `meeting inventory ${field}`, now, { end });
|
|
33
25
|
export const boundMeetingSeriesInventoryItem = (item) => {
|
|
34
26
|
if (Buffer.byteLength(JSON.stringify(item), "utf8") > item.limits.bytes)
|
|
35
27
|
throw new CliError("validation_error", "meeting inventory bytes cannot fit the provider page; increase bytes or lower limit");
|
|
@@ -51,7 +43,7 @@ export const readMeetingSeriesInventory = async (read, input, signal, now = Date
|
|
|
51
43
|
const args = parsed.output;
|
|
52
44
|
if (args.cursor !== undefined)
|
|
53
45
|
validateMeetingSeriesInventoryCursor(args.cursor);
|
|
54
|
-
const after = instant(args.after, now, "after"), until = instant(args.until, after + 7 * 86400000, "until");
|
|
46
|
+
const after = instant(args.after, now, "after", now), until = instant(args.until, after + 7 * 86400000, "until", now, true);
|
|
55
47
|
if (!Number.isSafeInteger(after) || !Number.isSafeInteger(until) || after >= until || until - after > 366 * 86400000)
|
|
56
48
|
throw new CliError("validation_error", "meeting inventory after/until must form a finite window of at most 366 days");
|
|
57
49
|
signal?.throwIfAborted();
|
|
@@ -32,7 +32,7 @@ export const adminStatisticsCommand = (messenger, report) => {
|
|
|
32
32
|
command.option("--saved <name|id>", "run a saved report of this kind; typed report options replace stored options");
|
|
33
33
|
command
|
|
34
34
|
.option("--timezone <zone>", "the IANA timezone for calendar date boundaries")
|
|
35
|
-
.option("--limit <n>", "report rows, 1–100;
|
|
35
|
+
.option("--limit <n>", "report rows, 1–100; the configured limit if not given", positiveCount("--limit"));
|
|
36
36
|
if (report !== "discussion")
|
|
37
37
|
command.option("--answerer <person>", "stored name, alias, @username, ID or person:provider/account/id; ambiguous names require a choice; repeat for more", collect);
|
|
38
38
|
if (report !== "newcomers")
|
|
@@ -44,7 +44,7 @@ export const adminStatisticsCommand = (messenger, report) => {
|
|
|
44
44
|
const { answerer, ...options } = this.opts();
|
|
45
45
|
const found = await context.withServices((services) => services.adminStatistics.report(report, {
|
|
46
46
|
...options,
|
|
47
|
-
limit: options.limit ??
|
|
47
|
+
limit: options.limit ?? Math.min(context.settings.limit, 100),
|
|
48
48
|
...(answerer ? { answerers: answerer } : {}),
|
|
49
49
|
...(report === "newcomers" ? { chat: argument } : filters),
|
|
50
50
|
signal: environmentOf(this).commandSignal ?? environmentOf(this).signal,
|
|
@@ -21,7 +21,7 @@ export const countersCommand = (messenger) => {
|
|
|
21
21
|
.option("--timezone <zone>", "IANA timezone for query dates")
|
|
22
22
|
.option("--selection <json>", "pinned counter-targets selection from counters show; conflicts with query and scope")
|
|
23
23
|
.option("--counters <names>", "distinct views,reactions,comments fields; all three by default")
|
|
24
|
-
.option("--limit <n>", "messages, 1–100;
|
|
24
|
+
.option("--limit <n>", "messages, 1–100; the configured limit if not given", positiveCount("--limit"));
|
|
25
25
|
if (operation === "refresh")
|
|
26
26
|
command;
|
|
27
27
|
if (operation === "show")
|
|
@@ -41,7 +41,7 @@ export const countersCommand = (messenger) => {
|
|
|
41
41
|
refuseLocalWrite(context, messenger.app.command, "stats.messages.counters.sync");
|
|
42
42
|
const query = {
|
|
43
43
|
...options,
|
|
44
|
-
limit: options.limit ??
|
|
44
|
+
limit: options.limit ?? Math.min(context.settings.limit, 100),
|
|
45
45
|
...(words.length ? { text: words.join(" ") } : {}),
|
|
46
46
|
signal: environmentOf(this).commandSignal ?? environmentOf(this).signal,
|
|
47
47
|
};
|
|
@@ -3,7 +3,8 @@ import { annotate } from "@wirecat/cli-base/commands";
|
|
|
3
3
|
import { parseDuration } from "../../domain/duration.js";
|
|
4
4
|
import { refusedPlace } from "../../sends/upload.js";
|
|
5
5
|
import { FETCHING } from "../../services/archive.js";
|
|
6
|
-
import { archiveMedia, checkMediaArchive
|
|
6
|
+
import { archiveMedia, checkMediaArchive } from "../../services/media-archive.js";
|
|
7
|
+
import { momentOf } from "../../services/moment.js";
|
|
7
8
|
import { environmentOf, setExitCode } from "../context.js";
|
|
8
9
|
import { FETCH, LOCAL_READ } from "../effects.js";
|
|
9
10
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -21,12 +22,12 @@ export const addMediaArchiveCommands = (archive, messenger) => {
|
|
|
21
22
|
.addHelpText("after", `\nMedia is saved only when you request a download; serve does not save these copies.\nTo disable an installed daily backup: ${messenger.app.command} <profile> attachments jobs stop <dir>.`)
|
|
22
23
|
.argument("<dir>", "archive directory; created if missing")
|
|
23
24
|
.option("--chat <chat>", `only this chat; repeat for more; ${messenger.chatArgument}`, (value, previous) => [...previous, value], [])
|
|
24
|
-
.option("--since-time <time>", "include messages from this ISO
|
|
25
|
+
.option("--since-time <time>", "include messages from this time: ISO 8601, a date, today, yesterday, or 2h, 7d ago")
|
|
25
26
|
.option("--pause <duration>", "pause between history pages", messenger.fetching?.pause ?? FETCHING.pause)
|
|
26
27
|
.action(async function (directory) {
|
|
27
28
|
const context = messengerContext(this, messenger);
|
|
28
29
|
const options = this.opts();
|
|
29
|
-
|
|
30
|
+
const sinceTime = options.sinceTime && new Date(momentOf(options.sinceTime, "--since-time")).toISOString();
|
|
30
31
|
const pauseMs = parseDuration(options.pause, "--pause");
|
|
31
32
|
if (context.settings.offline)
|
|
32
33
|
throw new CliError("validation_error", "archiving media needs online mode");
|
|
@@ -42,7 +43,7 @@ export const addMediaArchiveCommands = (archive, messenger) => {
|
|
|
42
43
|
const result = await context.withServices((services) => archiveMedia(services, {
|
|
43
44
|
directory,
|
|
44
45
|
chats: options.chat,
|
|
45
|
-
sinceTime:
|
|
46
|
+
...(sinceTime ? { sinceTime } : {}),
|
|
46
47
|
pauseMs,
|
|
47
48
|
signal,
|
|
48
49
|
pageSize: messenger.history === "store" ? 100 : (messenger.fetching ?? FETCHING).page,
|
|
@@ -17,7 +17,7 @@ export const addMediaArchiveMove = (attachments, messenger) => {
|
|
|
17
17
|
.description("move older images into another verified archive; remember their new locations")
|
|
18
18
|
.argument("<dir>", "source media archive directory")
|
|
19
19
|
.argument("<archive-dir>", "destination archive directory; created if needed")
|
|
20
|
-
.requiredOption("--before-time <time>", "move images whose message date is before this ISO
|
|
20
|
+
.requiredOption("--before-time <time>", "move images whose message date is before this time: ISO 8601, a date (its start), today, or 7d ago")
|
|
21
21
|
.option("--dry-run", "show counts and bytes without moving files or creating the destination")
|
|
22
22
|
.addHelpText("after", "\nCopies are verified at the destination before local image bytes are removed.\nSource manifests retain relocation records; checks follow them and downloads do not fetch them again.\nImages without a recorded message date are left in place and counted as undated.")
|
|
23
23
|
.action(async function (directory, archiveDirectory) {
|
|
@@ -5,7 +5,7 @@ import { annotate } from "@wirecat/cli-base/commands";
|
|
|
5
5
|
import { dailyArchiveTimer, manageDailyArchiveTimer, runArchiveTimerCommand, } from "../../background/daily-archive-timer.js";
|
|
6
6
|
import { thisMachine } from "../../background/system.js";
|
|
7
7
|
import { refusedPlace } from "../../sends/upload.js";
|
|
8
|
-
import {
|
|
8
|
+
import { momentOf } from "../../services/moment.js";
|
|
9
9
|
import { environmentOf } from "../context.js";
|
|
10
10
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
11
11
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -33,7 +33,7 @@ export const addMediaArchiveTimers = (attachments, messenger) => {
|
|
|
33
33
|
.option("--at <HH:mm>", "daily start time", "03:00")
|
|
34
34
|
.option("--timezone <zone>", "IANA time zone of the daily start time", "UTC")
|
|
35
35
|
.option("--chat <chat>", `only this chat; repeat for more; ${messenger.chatArgument}`, (value, previous) => [...previous, value], [])
|
|
36
|
-
.option("--since-time <time>", "include messages from this ISO
|
|
36
|
+
.option("--since-time <time>", "include messages from this time: ISO 8601, a date, today, yesterday, or 2h, 7d ago; fixed when installed");
|
|
37
37
|
command.action(async function (directory) {
|
|
38
38
|
const context = messengerContext(this, messenger);
|
|
39
39
|
const environment = environmentOf(this);
|
|
@@ -43,7 +43,8 @@ export const addMediaArchiveTimers = (attachments, messenger) => {
|
|
|
43
43
|
run: (args, env) => runArchiveTimerCommand(args, env, signal),
|
|
44
44
|
};
|
|
45
45
|
const options = this.opts();
|
|
46
|
-
|
|
46
|
+
// Fixed now: `2h` read again at every daily run would be a different start each night.
|
|
47
|
+
const sinceTime = options.sinceTime && new Date(momentOf(options.sinceTime, "--since-time")).toISOString();
|
|
47
48
|
if (action === "install" && refusedPlace(directory, messenger.app, context.env))
|
|
48
49
|
throw new CliError("validation_error", "the archive cannot write credential, application or message-store folders");
|
|
49
50
|
// Canonicalize existing destinations so a symlink alias addresses the same timer.
|
|
@@ -59,7 +60,7 @@ export const addMediaArchiveTimers = (attachments, messenger) => {
|
|
|
59
60
|
entry: system.entry,
|
|
60
61
|
env: context.env,
|
|
61
62
|
chats: options.chat,
|
|
62
|
-
sinceTime
|
|
63
|
+
sinceTime,
|
|
63
64
|
at: options.at,
|
|
64
65
|
timeZone: options.timezone,
|
|
65
66
|
});
|
|
@@ -28,13 +28,13 @@ export const metadataCommand = (messenger) => {
|
|
|
28
28
|
.description("fetch group and channel descriptions again and cache them")
|
|
29
29
|
.option("--chat <chat>", "stored group/channel; repeat for several", (value, previous) => [...previous, value], [])
|
|
30
30
|
.option("--only-missing", "only chats with no metadata yet; without --chat, every stored group/channel")
|
|
31
|
-
.option("--limit <n>", "process at most 1–500 chats", positiveCount("--limit")
|
|
31
|
+
.option("--limit <n>", "process at most 1–500 chats; the configured limit if not given", positiveCount("--limit"))
|
|
32
32
|
.action(async function () {
|
|
33
33
|
const context = messengerContext(this, messenger);
|
|
34
34
|
refuseLocalWrite(context, messenger.app.command, "metadata.sync");
|
|
35
35
|
const options = this.opts();
|
|
36
|
-
const limit =
|
|
37
|
-
if (
|
|
36
|
+
const limit = options.limit ?? Math.min(context.settings.limit, 500);
|
|
37
|
+
if (limit > 500)
|
|
38
38
|
throw new CliError("validation_error", "--limit takes 1–500");
|
|
39
39
|
if (options.chat.length === 0 && !options.onlyMissing)
|
|
40
40
|
throw new CliError("validation_error", "name a chat with --chat, or give --only-missing");
|
|
@@ -90,24 +90,24 @@ export const rankingEvidenceCommand = (messenger, target) => annotate(new Comman
|
|
|
90
90
|
: "the exact native person id from the ranking row")
|
|
91
91
|
.requiredOption("--selection <json>", "the resolved ranking selection returned in drilldown", selectionOf)
|
|
92
92
|
.requiredOption("--component <name>", "the exposed ranking component")
|
|
93
|
-
.option("--limit <n>", "evidence rows, 1–100;
|
|
93
|
+
.option("--limit <n>", "evidence rows, 1–100; the configured limit if not given", positiveCount("--limit"))
|
|
94
94
|
.option("--cursor <cursor>", "continue the same component and stored-evidence fingerprint")
|
|
95
95
|
.action(async function (reference) {
|
|
96
96
|
const context = messengerContext(this, messenger);
|
|
97
97
|
const options = this.opts();
|
|
98
98
|
if (isRetentionSelection(options.selection))
|
|
99
99
|
assertRetentionEvidenceRead(context.settings.permissions);
|
|
100
|
+
const limit = options.limit ?? Math.min(context.settings.limit, 100);
|
|
100
101
|
const found = await context.withServices((services) => (isRetentionSelection(options.selection)
|
|
101
102
|
? services.retention
|
|
102
103
|
: isAdminSelection(options.selection)
|
|
103
104
|
? services.adminStatistics
|
|
104
105
|
: services.rankings).evidence(target, reference, options.selection, {
|
|
105
106
|
component: options.component,
|
|
106
|
-
limit
|
|
107
|
+
limit,
|
|
107
108
|
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
108
109
|
signal: environmentOf(this).commandSignal ?? environmentOf(this).signal,
|
|
109
110
|
}));
|
|
110
|
-
const limit = options.limit ?? 20;
|
|
111
111
|
const body = evidenceAnswer(`stats ${target} evidence`, found, {
|
|
112
112
|
[target === "messages" ? "message" : "person"]: reference,
|
|
113
113
|
selection: JSON.stringify(options.selection),
|
|
@@ -39,7 +39,7 @@ export const tagsCommand = (messenger) => {
|
|
|
39
39
|
}))
|
|
40
40
|
.description("derive local group/channel tags from cached metadata using keyword rules")
|
|
41
41
|
.option("--chat <chat>", "a stored group/channel; repeat to select several", (value, previous) => [...previous, value], [])
|
|
42
|
-
.option("--limit <n>", "process at most 1–500 chats", positiveCount("--limit")
|
|
42
|
+
.option("--limit <n>", "process at most 1–500 chats; the configured limit if not given", positiveCount("--limit"))
|
|
43
43
|
.option("--sync-first", "read current descriptions from the messenger before classifying")
|
|
44
44
|
.option("--dry-run", "preview cached classification without changing the store")
|
|
45
45
|
.action(async function () {
|
|
@@ -47,7 +47,12 @@ export const tagsCommand = (messenger) => {
|
|
|
47
47
|
const { chat, limit, syncFirst, dryRun } = this.opts();
|
|
48
48
|
if (!dryRun)
|
|
49
49
|
refuseLocalWrite(context, messenger.app.command, "tags.rebuild");
|
|
50
|
-
const done = await context.withServices((services) => services.metadata.auto({
|
|
50
|
+
const done = await context.withServices((services) => services.metadata.auto({
|
|
51
|
+
chats: chat,
|
|
52
|
+
limit: limit ?? Math.min(context.settings.limit, 500),
|
|
53
|
+
refresh: syncFirst,
|
|
54
|
+
dryRun,
|
|
55
|
+
}));
|
|
51
56
|
renderAnswer(this, context, itemOf(snakeKeys(done)));
|
|
52
57
|
});
|
|
53
58
|
targetOptions(annotate(tags.command("add"), {
|
|
@@ -111,8 +111,8 @@ const durationOf = (flag) => (typed) => {
|
|
|
111
111
|
const planOptions = (command, verb) => command
|
|
112
112
|
.option("--title <title>", `one line: the action and its object — ${verb}`)
|
|
113
113
|
.option("--description <text>", "the detail, in Markdown: who owes whom, done when, next step, keywords")
|
|
114
|
-
.option("--due <time>", "when it must be done: an ISO 8601 time or 2h, 3d from now; none clears it", dateOrNone("--due", { end: true }))
|
|
115
|
-
.option("--remind-time <time>", "when to look at it again: an ISO 8601 time or 2h, 3d from now; none clears it", dateOrNone("--remind-time"))
|
|
114
|
+
.option("--due <time>", "when it must be done: an ISO 8601 time, a date (its end), today, or 2h, 3d from now; none clears it", dateOrNone("--due", { end: true }))
|
|
115
|
+
.option("--remind-time <time>", "when to look at it again: an ISO 8601 time, a date (its start), today, or 2h, 3d from now; none clears it", dateOrNone("--remind-time"))
|
|
116
116
|
.option("--assignee <person...>", "who does it: sender (whoever sent the task's message) or person:<id>; none clears it. Leave it out when " +
|
|
117
117
|
"unsure: a task with no assignee is better than none");
|
|
118
118
|
const certaintyArgument = (typed) => {
|
package/dist/cli/paging.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ import type { Settings } from "./settings.js";
|
|
|
8
8
|
*/
|
|
9
9
|
/** Refused as typed: by the time a number reaches the settings, `abc` is `NaN` and `12abc` is `12`. */
|
|
10
10
|
export declare const positiveCount: (flag: string) => (value: string) => number;
|
|
11
|
+
/**
|
|
12
|
+
* The configured `limit`, for a command with no messenger context to read it from, such as `runs list`. A command
|
|
13
|
+
* whose own maximum is lower caps it there: a configured `limit: 200` is a listing's page, not a refused flag.
|
|
14
|
+
*/
|
|
15
|
+
export declare const configuredLimit: (command: Command, most?: number) => number;
|
|
11
16
|
export declare const withPaging: (command: Command) => Command;
|
|
12
17
|
/**
|
|
13
18
|
* Which rows to ask the store for. `--all` means no limit, which the store reads as "everything".
|
|
@@ -20,3 +25,8 @@ export declare const window: ({ limit, page, all }: Settings) => {
|
|
|
20
25
|
limit?: number;
|
|
21
26
|
offset: number;
|
|
22
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* `--limit` and `--page` of a command outside a messenger's context (`meetings list`, `events list`): the flag, else
|
|
30
|
+
* the profile's `defaults.limit`, as the shared listings resolve it. Outside `run()`, the shipped default.
|
|
31
|
+
*/
|
|
32
|
+
export declare const pagingOf: (command: Command) => Pick<Settings, "limit" | "page">;
|
package/dist/cli/paging.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { environmentOf, withAgentLevels } from "./context.js";
|
|
3
|
+
import { DEFAULT_CONFIG } from "./default-config.js";
|
|
2
4
|
/**
|
|
3
5
|
* The three flags every listing shares, so no command invents its own spelling of them.
|
|
4
6
|
*
|
|
@@ -11,6 +13,16 @@ export const positiveCount = (flag) => (value) => {
|
|
|
11
13
|
throw new CliError("validation_error", `${flag} takes a whole number from 1 upwards, not "${value}"`);
|
|
12
14
|
return Number(value);
|
|
13
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* The configured `limit`, for a command with no messenger context to read it from, such as `runs list`. A command
|
|
18
|
+
* whose own maximum is lower caps it there: a configured `limit: 200` is a listing's page, not a refused flag.
|
|
19
|
+
*/
|
|
20
|
+
export const configuredLimit = (command, most = Number.POSITIVE_INFINITY) => {
|
|
21
|
+
const { resolveSettings, env } = environmentOf(command);
|
|
22
|
+
const { limit: _typed, ...flags } = command.optsWithGlobals();
|
|
23
|
+
const configured = resolveSettings?.(flags, { needsProfile: false, ...(env ? { env } : {}) }).limit ?? DEFAULT_CONFIG.defaults.limit;
|
|
24
|
+
return Math.min(configured, most);
|
|
25
|
+
};
|
|
14
26
|
export const withPaging = (command) => command
|
|
15
27
|
.option("--limit <n>", "how many to show", positiveCount("--limit"))
|
|
16
28
|
.option("--page <n>", "which page, starting at 1", positiveCount("--page"))
|
|
@@ -23,3 +35,20 @@ export const withPaging = (command) => command
|
|
|
23
35
|
* CLI that pages this way has this; it is in `--help` rather than engineered away.
|
|
24
36
|
*/
|
|
25
37
|
export const window = ({ limit, page, all }) => all ? { offset: 0 } : { limit, offset: (page - 1) * limit };
|
|
38
|
+
/**
|
|
39
|
+
* `--limit` and `--page` of a command outside a messenger's context (`meetings list`, `events list`): the flag, else
|
|
40
|
+
* the profile's `defaults.limit`, as the shared listings resolve it. Outside `run()`, the shipped default.
|
|
41
|
+
*/
|
|
42
|
+
export const pagingOf = (command) => {
|
|
43
|
+
const environment = environmentOf(command);
|
|
44
|
+
const flags = command.optsWithGlobals();
|
|
45
|
+
if (!environment.resolveSettings)
|
|
46
|
+
return { limit: flags.limit ?? DEFAULT_CONFIG.defaults.limit, page: flags.page ?? 1 };
|
|
47
|
+
const { limit, page } = environment.resolveSettings(withAgentLevels(command, command.optsWithGlobals()), {
|
|
48
|
+
env: environment.env ?? process.env,
|
|
49
|
+
needsProfile: false,
|
|
50
|
+
readOnly: true,
|
|
51
|
+
});
|
|
52
|
+
// A host's settings are force-cast to `Settings`; one that leaves these out must still page, not offset by NaN.
|
|
53
|
+
return { limit: limit ?? DEFAULT_CONFIG.defaults.limit, page: page ?? 1 };
|
|
54
|
+
};
|
package/dist/cli/runs/command.js
CHANGED
|
@@ -7,7 +7,7 @@ import { LOCAL_READ, NO_EFFECTS } from "../effects.js";
|
|
|
7
7
|
import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
8
8
|
import { typedQuery, withQuery } from "../list-query.js";
|
|
9
9
|
import { answerLocally } from "../local-times.js";
|
|
10
|
-
import { positiveCount } from "../paging.js";
|
|
10
|
+
import { configuredLimit, positiveCount } from "../paging.js";
|
|
11
11
|
import { lineOf } from "../steps.js";
|
|
12
12
|
import { RUNS_QUERY, runListFilter } from "./query.js";
|
|
13
13
|
/** Reading the log is not itself worth recording, so **nothing here starts a run**. */
|
|
@@ -25,11 +25,13 @@ export const runsCommand = (app) => {
|
|
|
25
25
|
effects: LOCAL_READ,
|
|
26
26
|
}), RUNS_QUERY)
|
|
27
27
|
.description("recorded runs, newest first")
|
|
28
|
-
.option("--limit <n>", "how many to show", positiveCount("--limit")
|
|
29
|
-
.option("--page <n>", "which page, starting at 1", positiveCount("--page")
|
|
28
|
+
.option("--limit <n>", "how many to show", positiveCount("--limit"))
|
|
29
|
+
.option("--page <n>", "which page, starting at 1", positiveCount("--page"))
|
|
30
30
|
.action(function (words) {
|
|
31
31
|
const filter = runListFilter(words);
|
|
32
|
-
const
|
|
32
|
+
const typed = this.opts();
|
|
33
|
+
const limit = typed.limit ?? configuredLimit(this);
|
|
34
|
+
const page = typed.page ?? 1;
|
|
33
35
|
const output = outputFor(this);
|
|
34
36
|
const { renderer } = output;
|
|
35
37
|
const runs = listRuns(dir(this), { atLeast: page * limit + 1, filter });
|
|
@@ -5,22 +5,26 @@ import { environmentOf, outputFor } from "../context.js";
|
|
|
5
5
|
import { LOCAL_READ } from "../effects.js";
|
|
6
6
|
import { renderAnswer } from "../envelope.js";
|
|
7
7
|
import { typedQuery, withQuery } from "../list-query.js";
|
|
8
|
-
import { positiveCount } from "../paging.js";
|
|
8
|
+
import { configuredLimit, positiveCount } from "../paging.js";
|
|
9
9
|
import { runsFound, searchRuns } from "./search.js";
|
|
10
10
|
import { RUN_SEARCH_QUERY, runSearchFilter } from "./search-query.js";
|
|
11
11
|
/** Diagnostic files are independent of linked accounts and never start a recorded run themselves. */
|
|
12
12
|
export const runsSearchCommand = (app) => annotate(withQuery(new Command("runs")
|
|
13
13
|
.summary("search recorded diagnostic metadata and events")
|
|
14
14
|
.description("search recorded diagnostic metadata and events; literal words and field:value terms joined by AND; no message contents")
|
|
15
|
-
.option("--limit <n>", "matches per page, at most 100", positiveCount("--limit")
|
|
16
|
-
.option("--page <n>", "result page", positiveCount("--page")
|
|
15
|
+
.option("--limit <n>", "matches per page, at most 100", positiveCount("--limit"))
|
|
16
|
+
.option("--page <n>", "result page", positiveCount("--page")), RUN_SEARCH_QUERY), {
|
|
17
17
|
effects: LOCAL_READ,
|
|
18
18
|
output: { entity: "run", view: "hit" },
|
|
19
19
|
examples: [`${app.command} search runs timeout status:failed --limit 10`],
|
|
20
20
|
}).action(function (words) {
|
|
21
21
|
const filter = runSearchFilter(words);
|
|
22
|
-
const
|
|
22
|
+
const typed = this.opts();
|
|
23
23
|
const dir = runsDirFor(app, environmentOf(this).env ?? process.env);
|
|
24
|
-
const found = searchRuns(dir, {
|
|
24
|
+
const found = searchRuns(dir, {
|
|
25
|
+
...filter,
|
|
26
|
+
limit: typed.limit ?? configuredLimit(this, 100),
|
|
27
|
+
page: typed.page ?? 1,
|
|
28
|
+
});
|
|
25
29
|
renderAnswer(this, outputFor(this), runsFound(found, { query: typedQuery(words) }));
|
|
26
30
|
});
|
|
@@ -53,11 +53,7 @@ const whenOf = ({ every, at = [], atTime }, minimum) => {
|
|
|
53
53
|
}
|
|
54
54
|
if (atTime) {
|
|
55
55
|
// As messages send --at-time: a date alone would be its midnight, which nobody means by "send on the 20th".
|
|
56
|
-
|
|
57
|
-
throw new CliError("validation_error", `--at-time needs a time of day as well: ${atTime.trim()}T09:00`);
|
|
58
|
-
const time = aheadOf(atTime, "--at-time");
|
|
59
|
-
if (time <= Date.now())
|
|
60
|
-
throw new CliError("validation_error", "--at-time is in the past");
|
|
56
|
+
const time = aheadOf(atTime, "--at-time", Date.now(), { refuseDate: true, soonest: 0 });
|
|
61
57
|
return { once: new Date(time).toISOString() };
|
|
62
58
|
}
|
|
63
59
|
if (at.length > 0) {
|
package/dist/domain/moment.d.ts
CHANGED
|
@@ -6,3 +6,32 @@ export interface MomentZone {
|
|
|
6
6
|
}
|
|
7
7
|
/** A typed date or time as epoch ms, with the flag named when it is not one. */
|
|
8
8
|
export declare const calendarMoment: (wanted: string, flag: string, { zone, end }?: MomentZone) => number;
|
|
9
|
+
export declare const MINUTE = 60000;
|
|
10
|
+
export declare const YEAR: number;
|
|
11
|
+
export interface Reading {
|
|
12
|
+
time: number;
|
|
13
|
+
/** Read in a zone: a date, `today`, or a time without an offset. A relative or offset time is not. */
|
|
14
|
+
local: boolean;
|
|
15
|
+
dateAlone: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The shared time grammar: an ISO date or date-time, seconds and zone optional, a space allowed for the `T`; `today`,
|
|
19
|
+
* `yesterday`; or `30m`, `2h`, `7d` counted by `direction` from now. `undefined` when the value has none of these shapes.
|
|
20
|
+
*/
|
|
21
|
+
export declare const readMoment: (typed: string, flag: string, { zone, end, now, direction }?: MomentZone & {
|
|
22
|
+
now?: number;
|
|
23
|
+
direction?: 1 | -1;
|
|
24
|
+
}) => Reading | undefined;
|
|
25
|
+
export interface AheadOptions extends MomentZone {
|
|
26
|
+
/** A date alone has no time of day to act at: sending "on the 20th" means nobody knows when. */
|
|
27
|
+
refuseDate?: boolean;
|
|
28
|
+
/** The least lead from now, in ms: 0 refuses the past, a minute is what a messenger schedules at the soonest. */
|
|
29
|
+
soonest?: number;
|
|
30
|
+
/** The most lead from now, in ms, where a messenger caps it. */
|
|
31
|
+
latest?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A time ahead, the one parser of every future flag: the grammar of `readMoment`, relative times counted forward.
|
|
35
|
+
* `none` is not a time; a caller that clears a date checks for it first. The past is allowed unless `soonest` is given.
|
|
36
|
+
*/
|
|
37
|
+
export declare const aheadOf: (reference: string, flag: string, now?: number, options?: AheadOptions) => number;
|
package/dist/domain/moment.js
CHANGED
|
@@ -12,3 +12,61 @@ export const calendarMoment = (wanted, flag, { zone, end = false } = {}) => {
|
|
|
12
12
|
throw new CliError("validation_error", `${flag}: "${wanted}" is not a time${alternative ? ` — ${alternative}` : ""}`);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
+
export const MINUTE = 60_000;
|
|
16
|
+
export const YEAR = 365 * 24 * 60 * MINUTE;
|
|
17
|
+
const RELATIVE = /^(\d+)(m|h|d)$/;
|
|
18
|
+
const RELATIVE_MS = { m: MINUTE, h: 60 * MINUTE, d: 24 * 60 * MINUTE };
|
|
19
|
+
const DATE_ALONE = /^\d{4}-\d{2}-\d{2}$/;
|
|
20
|
+
const ZONED = /(?:Z|[+-]\d{2}:?\d{2})$/i;
|
|
21
|
+
/** `today` or `yesterday` as the date it is in `zone` at `now`. */
|
|
22
|
+
const dayWord = (word, zone, now) => {
|
|
23
|
+
const today = new Intl.DateTimeFormat("en-CA", { timeZone: zone }).format(now);
|
|
24
|
+
if (word === "today")
|
|
25
|
+
return today;
|
|
26
|
+
const date = new Date(`${today}T00:00:00Z`);
|
|
27
|
+
date.setUTCDate(date.getUTCDate() - 1);
|
|
28
|
+
return date.toISOString().slice(0, 10);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The shared time grammar: an ISO date or date-time, seconds and zone optional, a space allowed for the `T`; `today`,
|
|
32
|
+
* `yesterday`; or `30m`, `2h`, `7d` counted by `direction` from now. `undefined` when the value has none of these shapes.
|
|
33
|
+
*/
|
|
34
|
+
export const readMoment = (typed, flag, { zone, end = false, now = Date.now(), direction = -1 } = {}) => {
|
|
35
|
+
const wanted = typed.trim();
|
|
36
|
+
const [, amount, unit] = RELATIVE.exec(wanted) ?? [];
|
|
37
|
+
if (amount && unit)
|
|
38
|
+
return { time: now + direction * Number(amount) * (RELATIVE_MS[unit] ?? 0), local: false, dateAlone: false };
|
|
39
|
+
const word = wanted.toLowerCase();
|
|
40
|
+
const date = word === "today" || word === "yesterday" ? dayWord(word, timezoneOf(zone), now) : wanted;
|
|
41
|
+
// By shape: `Date.parse("12345")` is the year 12345, so a message id would pass as a date.
|
|
42
|
+
if (!/^\d{4}-\d{2}-\d{2}/.test(date))
|
|
43
|
+
return undefined;
|
|
44
|
+
const iso = date.replace(/^(\d{4}-\d{2}-\d{2}) +(?=\d)/, "$1T");
|
|
45
|
+
return {
|
|
46
|
+
time: calendarMoment(iso, flag, { ...(zone === undefined ? {} : { zone }), end }),
|
|
47
|
+
local: !ZONED.test(iso),
|
|
48
|
+
dateAlone: DATE_ALONE.test(iso),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const lead = (ms) => (ms === MINUTE ? "a minute" : ms === YEAR ? "a year" : `${Math.ceil(ms / MINUTE)} minutes`);
|
|
52
|
+
/**
|
|
53
|
+
* A time ahead, the one parser of every future flag: the grammar of `readMoment`, relative times counted forward.
|
|
54
|
+
* `none` is not a time; a caller that clears a date checks for it first. The past is allowed unless `soonest` is given.
|
|
55
|
+
*/
|
|
56
|
+
export const aheadOf = (reference, flag, now = Date.now(), options = {}) => {
|
|
57
|
+
const { refuseDate = false, soonest, latest, ...at } = options;
|
|
58
|
+
const read = readMoment(reference, flag, { ...at, now, direction: 1 });
|
|
59
|
+
if (read === undefined)
|
|
60
|
+
throw new CliError("validation_error", `${flag} takes an ISO 8601 time, today, or 30m, 2h, 3d from now — not "${reference.trim()}"`);
|
|
61
|
+
if (refuseDate && read.dateAlone)
|
|
62
|
+
throw new CliError("validation_error", DATE_ALONE.test(reference.trim())
|
|
63
|
+
? `${flag} needs a time of day as well: ${reference.trim()}T09:00`
|
|
64
|
+
: `${flag} needs a time of day as well, like 2026-11-20T09:00`);
|
|
65
|
+
if (soonest === 0 && read.time <= now)
|
|
66
|
+
throw new CliError("validation_error", `${flag} is in the past`);
|
|
67
|
+
if (soonest !== undefined && soonest > 0 && read.time < now + soonest)
|
|
68
|
+
throw new CliError("validation_error", `${flag} has to be at least ${lead(soonest)} from now`);
|
|
69
|
+
if (latest !== undefined && read.time > now + latest)
|
|
70
|
+
throw new CliError("validation_error", `${flag} can be at most ${lead(latest)} from now`);
|
|
71
|
+
return read.time;
|
|
72
|
+
};
|
|
@@ -46,11 +46,13 @@ 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
|
|
50
|
-
*
|
|
49
|
+
* files as `documents` rows. Any registry entry of kind `documents` that a sync fills; an import-only one (`import`)
|
|
50
|
+
* keeps its documents beside its other records instead.
|
|
51
51
|
*/
|
|
52
|
-
export declare const
|
|
53
|
-
export declare const isDocumentAccountProvider: (provider:
|
|
52
|
+
export declare const documentAccountProviders: () => string[];
|
|
53
|
+
export declare const isDocumentAccountProvider: (provider: unknown) => boolean;
|
|
54
|
+
/** The documents account providers as a SQL list, for `IN (…)`; names are checked words, so they need no binding. */
|
|
55
|
+
export declare const documentAccountProvidersSql: () => string;
|
|
54
56
|
/**
|
|
55
57
|
* What the owner adds by hand (`saveAddedSource`): one account, `owner`. Neither a folder nor a documents account, so no
|
|
56
58
|
* folder can be bound to it and no sync deletes a source whose file is gone.
|