@wirecat/cli-core 0.563.0 → 0.565.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 +125 -0
- package/dist/calendar/busy.d.ts +10 -10
- package/dist/calendar/busy.js +9 -9
- package/dist/calendar/cli/answers.d.ts +7 -8
- package/dist/calendar/cli/answers.js +4 -5
- package/dist/calendar/cli/bodies.d.ts +33 -0
- package/dist/calendar/cli/bodies.js +52 -0
- package/dist/calendar/cli/files.d.ts +8 -0
- package/dist/calendar/cli/files.js +41 -0
- package/dist/calendar/cli/index.d.ts +58 -51
- package/dist/calendar/cli/index.js +311 -284
- package/dist/calendar/cli/remind.d.ts +2 -11
- package/dist/calendar/cli/remind.js +81 -81
- package/dist/calendar/cli/search-all.d.ts +3 -8
- package/dist/calendar/cli/search-all.js +47 -42
- package/dist/calendar/mcp/index.d.ts +1 -1
- package/dist/calendar/prepare.d.ts +1 -1
- package/dist/calendar/testing/answers.d.ts +27 -5
- package/dist/calendar/testing/answers.js +88 -17
- package/dist/calendar/testing/writer.d.ts +1 -0
- package/dist/calendar/testing/writer.js +6 -0
- package/dist/calendar/writer.d.ts +6 -1
- package/dist/calendar/writes.d.ts +3 -1
- package/dist/calendar/writes.js +42 -20
- package/dist/cli/config-command.js +1 -1
- package/dist/cli/config-issues.d.ts +3 -1
- package/dist/cli/config-issues.js +2 -2
- package/dist/cli/contract-evidence.d.ts +1 -1
- package/dist/cli/early-refusal.d.ts +2 -1
- package/dist/cli/early-refusal.js +4 -2
- package/dist/cli/entry.d.ts +6 -2
- package/dist/cli/entry.js +4 -1
- package/dist/cli/envelope.d.ts +2 -2
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/messenger/archive-commands.js +17 -0
- package/dist/cli/messenger/catch-up-answers.d.ts +5 -0
- package/dist/cli/messenger/catch-up-answers.js +3 -0
- package/dist/cli/messenger/search-answers.d.ts +1 -0
- package/dist/cli/messenger/search-answers.js +1 -1
- package/dist/cli/messenger/stats-answers.d.ts +3 -3
- package/dist/cli/messenger/stats-answers.js +21 -9
- package/dist/cli/messenger/store-maintenance-command.d.ts +1 -1
- package/dist/cli/messenger/tasks-command.js +35 -14
- package/dist/cli/permission-keys.d.ts +3 -1
- package/dist/cli/permission-keys.js +2 -1
- package/dist/cli/preview.d.ts +12 -0
- package/dist/cli/preview.js +8 -1
- package/dist/cli/settings.d.ts +2 -0
- package/dist/cli/settings.js +8 -1
- package/dist/conversations/mail-text.d.ts +6 -0
- package/dist/conversations/mail-text.js +73 -0
- package/dist/domain/calendar.d.ts +2 -0
- package/dist/domain/calendar.js +6 -0
- package/dist/entities/chat-stats.d.ts +16 -2
- package/dist/entities/chat-stats.js +18 -3
- package/dist/entities/index.d.ts +50 -802
- package/dist/entities/index.js +23 -16
- package/dist/entities/mail-counts.d.ts +15 -0
- package/dist/entities/mail-counts.js +16 -0
- package/dist/entities/meeting.d.ts +1 -1
- package/dist/entities/meeting.js +1 -1
- package/dist/entities/store-records.d.ts +8 -0
- package/dist/entities/store-records.js +8 -0
- package/dist/errors/reasons.js +19 -1
- package/dist/mail/cli/index.d.ts +5 -0
- package/dist/mail/cli/index.js +27 -3
- package/dist/mail/cli/review.js +11 -4
- package/dist/mail/index.d.ts +2 -0
- package/dist/mail/index.js +2 -0
- package/dist/mail/stats.d.ts +50 -0
- package/dist/mail/stats.js +60 -0
- package/dist/mail/whole.d.ts +4 -4
- package/dist/mail/whole.js +4 -3
- package/dist/mcp/meeting-preparation.d.ts +1 -1
- package/dist/mcp/meeting-project-candidates.d.ts +1 -1
- package/dist/mcp/meeting-series-inventory.d.ts +1 -1
- package/dist/meetings/index.d.ts +2 -2
- package/dist/meetings/index.js +2 -2
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/meetings/mcp/passage.d.ts +1 -1
- package/dist/meetings/mcp/project-evidence.d.ts +1 -1
- package/dist/meetings/mcp/search.d.ts +1 -1
- package/dist/meetings/read-answers.d.ts +22 -1
- package/dist/meetings/read-answers.js +38 -0
- package/dist/meetings/stats.d.ts +44 -0
- package/dist/meetings/stats.js +77 -7
- package/dist/search/lucene/registry.js +2 -1
- package/dist/search/question-plan.d.ts +16 -0
- package/dist/search/question-plan.js +34 -0
- package/dist/services/events-search.d.ts +5 -1
- package/dist/services/events-search.js +10 -4
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/meeting-stats.d.ts +12 -1
- package/dist/services/meeting-stats.js +12 -0
- package/dist/services/messages-discovery.d.ts +1 -5
- package/dist/services/messages-discovery.js +5 -18
- package/dist/services/messages-meaning.js +25 -3
- package/dist/services/messages.js +4 -3
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.d.ts +5 -1
- package/dist/services/notes-search.js +16 -5
- package/dist/services/proposals/ids.d.ts +2 -2
- package/dist/services/proposals/ids.js +5 -3
- package/dist/services/proposals/kinds/findings.d.ts +1 -1
- package/dist/services/proposals/kinds/findings.js +1 -1
- package/dist/services/proposals/kinds/meeting-findings.d.ts +7 -0
- package/dist/services/proposals/kinds/meeting-findings.js +73 -0
- package/dist/services/proposals/kinds/task-close.d.ts +7 -0
- package/dist/services/proposals/kinds/task-close.js +76 -0
- package/dist/services/proposals/registry.js +4 -0
- package/dist/services/search-all.d.ts +5 -0
- package/dist/services/search-all.js +47 -14
- package/dist/services/task-stats.d.ts +41 -0
- package/dist/services/task-stats.js +126 -0
- package/dist/services/tasks.d.ts +17 -4
- package/dist/services/tasks.js +31 -14
- package/dist/store/chats.d.ts +3 -1
- package/dist/store/chats.js +6 -0
- package/dist/store/decisions.d.ts +4 -2
- package/dist/store/decisions.js +5 -3
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/exports.js +1 -1
- package/dist/store/index.d.ts +2 -1
- package/dist/store/index.js +1 -1
- package/dist/store/sqlite/completeness.d.ts +17 -0
- package/dist/store/sqlite/completeness.js +49 -13
- package/dist/store/sqlite/lucene-fields.js +2 -0
- package/dist/store/sqlite/lucene-groups.d.ts +15 -0
- package/dist/store/sqlite/lucene-groups.js +21 -0
- package/dist/store/sqlite/lucene.d.ts +2 -9
- package/dist/store/sqlite/lucene.js +1 -12
- package/dist/store/sqlite/meeting-stats.d.ts +2 -0
- package/dist/store/sqlite/meeting-stats.js +27 -1
- package/dist/store/sqlite/retention.js +2 -7
- package/dist/store/sqlite/task-board.js +2 -0
- package/dist/store/sqlite/task-stats.d.ts +32 -0
- package/dist/store/sqlite/task-stats.js +45 -0
- package/dist/store/sqlite/tasks.d.ts +2 -1
- package/dist/store/sqlite/tasks.js +2 -0
- package/package.json +3 -3
- package/parity.json +13 -1
|
@@ -1,12 +1,3 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
interface RemindHelpers {
|
|
5
|
-
deps: CalendarCommandDeps;
|
|
6
|
-
now: () => number;
|
|
7
|
-
zone: () => string;
|
|
8
|
-
print: (value: unknown, command: Command) => void;
|
|
9
|
-
example: (command: Command, ...lines: string[]) => Command;
|
|
10
|
-
}
|
|
11
|
-
export declare const addRemind: (events: Command, writes: CalendarWrites, { deps, now, zone, print, example }: RemindHelpers) => void;
|
|
12
|
-
export {};
|
|
2
|
+
import type { CommandHelpers } from "./index.js";
|
|
3
|
+
export declare const addRemind: (events: Command, { within, now, zone, example }: CommandHelpers) => void;
|
|
@@ -11,9 +11,10 @@ import { DEFAULT_PERMISSIONS, levelFor } from "../../sends/permissions.js";
|
|
|
11
11
|
import { dueEvents, openReminders, reminderItem, remindersPath, runHook } from "../remind.js";
|
|
12
12
|
import { syncCalendars } from "../sync.js";
|
|
13
13
|
import { CALENDAR_WRITE_DEFAULTS, EVENTS_REMIND_HOOK_KEY } from "../writer.js";
|
|
14
|
+
import { listBody } from "./bodies.js";
|
|
14
15
|
const REMIND_MIN_MS = 60_000;
|
|
15
16
|
const REMIND_MAX_MS = 86_400_000;
|
|
16
|
-
export const addRemind = (events,
|
|
17
|
+
export const addRemind = (events, { within, now, zone, example }) => {
|
|
17
18
|
const remind = example(destroysNothing(annotate(events.command("remind"), { effects: FETCH, mcp: false, literal_after_dashes: true }))
|
|
18
19
|
.description("tell once about each event that starts within --due-within: print it, or run your program for it with the " +
|
|
19
20
|
"event as JSON on its standard input; for cron or a timer every few minutes, syncing first unless --offline")
|
|
@@ -23,94 +24,93 @@ export const addRemind = (events, writes, { deps, now, zone, print, example }) =
|
|
|
23
24
|
.option("--due-within <duration>", "the events that start within this long from now, 1m to 1d", "10m")
|
|
24
25
|
.option("--dry-run", "say what it would remind; run nothing, sync nothing, remember nothing");
|
|
25
26
|
remind.action(async (program, opts, command) => {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
27
|
+
const dueWithin = parseDuration(opts.dueWithin, "--due-within");
|
|
28
|
+
if (dueWithin < REMIND_MIN_MS || dueWithin > REMIND_MAX_MS)
|
|
28
29
|
throw new CliError("validation_error", "--due-within takes 1m to 1d", { reason: "remind.window" });
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!opts.dryRun && deps.source && !command.optsWithGlobals().offline) {
|
|
51
|
-
// A reminder from what the store already holds beats none: a failed sync is said in meta and the run goes on.
|
|
52
|
-
try {
|
|
53
|
-
// Feeds wait for `sync`: a timer runs this every few minutes, and a feed's server is not Google.
|
|
54
|
-
const report = await syncCalendars(deps.source, deps.store, {
|
|
55
|
-
accountId: deps.accountId,
|
|
56
|
-
now: at,
|
|
57
|
-
budget: runBudgetOf(command),
|
|
58
|
-
...(deps.expand ? { expand: deps.expand } : {}),
|
|
59
|
-
});
|
|
60
|
-
if (report.synced.some((one) => one.error !== undefined))
|
|
61
|
-
issues.push({ code: "provider_error", reason: "sync.partial", source: accountName });
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
issues.push({
|
|
65
|
-
code: error instanceof CliError ? error.code : "provider_error",
|
|
66
|
-
reason: "sync.failed",
|
|
67
|
-
source: accountName,
|
|
68
|
-
});
|
|
30
|
+
await within(command, async (run) => {
|
|
31
|
+
if (!run.writes)
|
|
32
|
+
throw new CliError("configuration_error", "this profile cannot run reminders");
|
|
33
|
+
const writes = run.writes();
|
|
34
|
+
const settings = writes.settings();
|
|
35
|
+
const env = writes.env ?? process.env;
|
|
36
|
+
const hook = program.length > 0;
|
|
37
|
+
const defaults = { ...DEFAULT_PERMISSIONS, ...CALENDAR_WRITE_DEFAULTS, ...settings.permissionDefaults };
|
|
38
|
+
const { level, key: named } = levelFor(settings.permissions, EVENTS_REMIND_HOOK_KEY, defaults);
|
|
39
|
+
if (hook && !opts.dryRun) {
|
|
40
|
+
if (settings.readOnlyLock)
|
|
41
|
+
throw readOnlyRefusal(settings.readOnlyLock, "run a program for a reminder");
|
|
42
|
+
if (level === "deny" || level === "readonly")
|
|
43
|
+
throw levelRefusal({
|
|
44
|
+
profile: settings.profile,
|
|
45
|
+
command: writes.app.command,
|
|
46
|
+
key: EVENTS_REMIND_HOOK_KEY,
|
|
47
|
+
level,
|
|
48
|
+
named,
|
|
49
|
+
permissionSources: settings.permissionSources,
|
|
50
|
+
});
|
|
69
51
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
52
|
+
const at = now();
|
|
53
|
+
const issues = [];
|
|
54
|
+
const accountName = `${run.account.provider}:${run.account.account}`;
|
|
55
|
+
if (!opts.dryRun && !command.optsWithGlobals().offline) {
|
|
56
|
+
// A reminder from what the store already holds beats none: a failed sync is said in meta and the run goes on.
|
|
57
|
+
try {
|
|
58
|
+
// Feeds wait for `sync`: a timer runs this every few minutes, and a feed's server is not Google.
|
|
59
|
+
const report = await syncCalendars(run.source(), run.store, {
|
|
60
|
+
accountId: run.accountId,
|
|
61
|
+
now: at,
|
|
62
|
+
budget: runBudgetOf(command),
|
|
63
|
+
...(run.expand ? { expand: run.expand } : {}),
|
|
64
|
+
});
|
|
65
|
+
if (report.synced.some((one) => one.error !== undefined))
|
|
66
|
+
issues.push({ code: "provider_error", reason: "sync.partial", source: accountName });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
issues.push({
|
|
70
|
+
code: error instanceof CliError ? error.code : "provider_error",
|
|
71
|
+
reason: "sync.failed",
|
|
72
|
+
source: accountName,
|
|
87
73
|
});
|
|
88
|
-
if (exitCode !== 0) {
|
|
89
|
-
failed.push({ ref: item.ref, exit_code: exitCode });
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
74
|
}
|
|
93
|
-
reminders?.remember(details);
|
|
94
|
-
items.push(item);
|
|
95
75
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
76
|
+
const window = { from: at, to: at + dueWithin };
|
|
77
|
+
const path = remindersPath(resolvePaths({ appName: writes.app.appName, prefix: writes.app.envPrefix, env }).state, settings.profile);
|
|
78
|
+
const reminders = opts.dryRun ? undefined : openReminders(path, at);
|
|
79
|
+
try {
|
|
80
|
+
const due = await dueEvents(run.store, run.accountId, window, reminders?.reminded ?? {});
|
|
81
|
+
if (hook && !opts.dryRun && due.length > 0 && level === "ask")
|
|
82
|
+
await terminalAsker(command)(EVENTS_REMIND_HOOK_KEY, { chatId: null, count: due.length });
|
|
83
|
+
const items = [];
|
|
84
|
+
const failed = [];
|
|
85
|
+
for (const details of due) {
|
|
86
|
+
const item = reminderItem(details);
|
|
87
|
+
if (hook && !opts.dryRun) {
|
|
88
|
+
const exitCode = await runHook(program, `${JSON.stringify(item)}\n`, {
|
|
89
|
+
...env,
|
|
90
|
+
[`${writes.app.envPrefix}_PROFILE`]: settings.profile,
|
|
91
|
+
[`${writes.app.envPrefix}_EVENT`]: item.ref,
|
|
92
|
+
});
|
|
93
|
+
if (exitCode !== 0) {
|
|
94
|
+
failed.push({ ref: item.ref, exit_code: exitCode });
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
reminders?.remember(details);
|
|
99
|
+
items.push(item);
|
|
100
|
+
}
|
|
101
|
+
if (failed.length)
|
|
102
|
+
throw new CliError("configuration_error", `${program[0]} failed for ${failed.length} of ${due.length} events ` +
|
|
103
|
+
`(${failed.map((one) => `${one.ref}: exit ${one.exit_code}`).join(", ")}); the next run tries them again`, { reason: "remind.hook-failed", reminded: items.map(({ ref }) => ref), failed, retryable: true });
|
|
104
|
+
return listBody(command, { items, page: 1 }, {
|
|
105
105
|
complete: issues.length === 0,
|
|
106
106
|
...(issues.length ? { issues } : {}),
|
|
107
107
|
window: { since: new Date(window.from).toISOString(), until: new Date(window.to).toISOString() },
|
|
108
108
|
...clockMeta(at, zone()),
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
reminders?.close();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
115
|
});
|
|
116
116
|
};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import type { AppIdentity } from "../../ports/app.js";
|
|
3
|
-
import type {
|
|
4
|
-
interface SearchAllHelpers {
|
|
5
|
-
/** Read through, never copied: a CLI's deps may be getters that work only once a profile is open. */
|
|
6
|
-
deps: CalendarCommandDeps;
|
|
3
|
+
import type { CommandHelpers } from "./index.js";
|
|
4
|
+
interface SearchAllHelpers extends Pick<CommandHelpers, "within" | "zone" | "example"> {
|
|
7
5
|
app: AppIdentity;
|
|
8
|
-
zone: () => string;
|
|
9
|
-
messages: (what: string) => NonNullable<CalendarCommandDeps["messages"]>;
|
|
10
|
-
example: (command: Command, ...lines: string[]) => Command;
|
|
11
6
|
}
|
|
12
7
|
/**
|
|
13
8
|
* `search all` beside `search events`: the messenger's shared search over the store, without a messenger server.
|
|
14
9
|
* Events are the calendar's own kind and always read; meeting transcripts only when `--source` names a meeting account.
|
|
15
10
|
*/
|
|
16
|
-
export declare const addSearchAll: (searches: Command, {
|
|
11
|
+
export declare const addSearchAll: (searches: Command, { within, app, zone, example }: SearchAllHelpers) => void;
|
|
17
12
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
+
import { outputFor } from "../../cli/context.js";
|
|
4
5
|
import { LOCAL_READ } from "../../cli/effects.js";
|
|
5
6
|
import { historySkipsOf } from "../../cli/messenger/history-gaps.js";
|
|
6
7
|
import { allAnswer, offsetOf, SOURCE_SEARCHED } from "../../cli/messenger/search-answers.js";
|
|
@@ -8,12 +9,13 @@ import { searchAllLine, searchAllOptions } from "../../cli/messenger/search-comm
|
|
|
8
9
|
import { SAVE_HELP } from "../../meetings/index.js";
|
|
9
10
|
import { meaningLane } from "../../services/messages-meaning.js";
|
|
10
11
|
import { searchAllWithMeetings } from "../../services/search-all-meetings.js";
|
|
12
|
+
import { messagesOf } from "./bodies.js";
|
|
11
13
|
const DEFAULT_LIMIT = 20;
|
|
12
14
|
/**
|
|
13
15
|
* `search all` beside `search events`: the messenger's shared search over the store, without a messenger server.
|
|
14
16
|
* Events are the calendar's own kind and always read; meeting transcripts only when `--source` names a meeting account.
|
|
15
17
|
*/
|
|
16
|
-
export const addSearchAll = (searches, {
|
|
18
|
+
export const addSearchAll = (searches, { within, app, zone, example }) => {
|
|
17
19
|
const all = annotate(new Command("all"), { effects: LOCAL_READ, partial: true, output: { entity: "hit" } })
|
|
18
20
|
.summary("search stored messages, notes, calendar events and selected meeting transcripts")
|
|
19
21
|
.description("search calendar events, messages from the other WireCat tools and notes in the local store, and a meeting " +
|
|
@@ -27,46 +29,49 @@ export const addSearchAll = (searches, { deps, app, zone, messages, example }) =
|
|
|
27
29
|
example(all, "search all roadmap", 'search all "quarterly review" --source telegram,gcal --json');
|
|
28
30
|
all.action(async (words, _opts, leaf) => {
|
|
29
31
|
const opts = leaf.opts();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
32
|
+
let lines = "";
|
|
33
|
+
await within(leaf, async (run) => {
|
|
34
|
+
if (run.locked && opts.source !== undefined)
|
|
35
|
+
throw new CliError("permission_error", "this process is locked to one profile; search all reads its own calendar only, without --source", { reason: "profile.locked" });
|
|
36
|
+
const store = messagesOf(run, "search all");
|
|
37
|
+
const limit = opts.limit ?? DEFAULT_LIMIT;
|
|
38
|
+
const offset = offsetOf(opts.page, limit);
|
|
39
|
+
const env = run.env ?? process.env;
|
|
40
|
+
const found = await searchAllWithMeetings(store, run.account, {
|
|
41
|
+
text: words.join(" "),
|
|
42
|
+
limit,
|
|
43
|
+
...(offset === undefined ? {} : { offset }),
|
|
44
|
+
...(opts.exact ? { exact: true } : {}),
|
|
45
|
+
timezone: opts.timezone ?? zone(),
|
|
46
|
+
env,
|
|
47
|
+
only: opts.only ?? SOURCE_SEARCHED,
|
|
48
|
+
...(opts.source === undefined ? {} : { source: opts.source }),
|
|
49
|
+
...(opts.maxMeetings === undefined ? {} : { maxMeetings: opts.maxMeetings }),
|
|
50
|
+
...(run.locked ? { scope: { events: [run.account] } } : {}),
|
|
51
|
+
}, { app }, undefined, meaningLane({ env, messenger: { app }, store: async () => store }));
|
|
52
|
+
const note = (text) => outputFor(leaf).renderer.note(text);
|
|
53
|
+
const globals = leaf.optsWithGlobals();
|
|
54
|
+
if (!globals.json && !globals.jsonl)
|
|
55
|
+
note(`searched: ${found.accounts.map(({ provider, account }) => `${provider}:${account}`).join(", ") || "nothing"}`);
|
|
56
|
+
for (const { resource, source, reason } of found.skipped)
|
|
57
|
+
note(`${resource ?? source} not searched: ${reason}`);
|
|
58
|
+
if (found.notes?.meaningSkipped)
|
|
59
|
+
note(`notes by words only: ${found.notes.meaningSkipped}`);
|
|
60
|
+
if (found.events?.meaningSkipped)
|
|
61
|
+
note(`events by words only: ${found.events.meaningSkipped}`);
|
|
62
|
+
const again = {
|
|
63
|
+
query: words.join(" "),
|
|
64
|
+
...(opts.only === undefined ? {} : { only: opts.only.join(",") }),
|
|
65
|
+
...(opts.source === undefined ? {} : { source: opts.source }),
|
|
66
|
+
...(opts.maxMeetings === undefined ? {} : { max_meetings: opts.maxMeetings }),
|
|
67
|
+
...(opts.exact ? { exact: true } : {}),
|
|
68
|
+
...(opts.timezone === undefined ? {} : { timezone: opts.timezone }),
|
|
69
|
+
};
|
|
70
|
+
if (!found.items.length)
|
|
71
|
+
note("nothing found in what the local store holds");
|
|
72
|
+
const skips = await historySkipsOf(store, found.accounts).catch(() => []);
|
|
73
|
+
lines = found.items.map(searchAllLine).join("");
|
|
74
|
+
return allAnswer("search all", found, { limit, page: opts.page ?? 1, again }, opts.exact === true, skips);
|
|
75
|
+
}, () => lines);
|
|
71
76
|
});
|
|
72
77
|
};
|
|
@@ -1479,7 +1479,7 @@ export declare const callCalendarTool: (store: EventStore, name: string, input:
|
|
|
1479
1479
|
}[];
|
|
1480
1480
|
structuredContent: {
|
|
1481
1481
|
error: {
|
|
1482
|
-
code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "internal_error" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
|
|
1482
|
+
code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "conflict" | "internal_error" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
|
|
1483
1483
|
reason: string;
|
|
1484
1484
|
message: string;
|
|
1485
1485
|
param?: string | undefined;
|
|
@@ -125,7 +125,7 @@ export declare const eventPreparation: (details: EventDetails, options: Preparat
|
|
|
125
125
|
accounts?: string[] | undefined;
|
|
126
126
|
complete: boolean;
|
|
127
127
|
issues?: {
|
|
128
|
-
code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
|
|
128
|
+
code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "conflict" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
|
|
129
129
|
reason?: string | undefined;
|
|
130
130
|
source: string;
|
|
131
131
|
}[] | undefined;
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../../ports/app.js";
|
|
3
|
+
import { type CalendarCommandOptions, type CalendarRun } from "../cli/index.js";
|
|
4
|
+
/** Each item of a printed calendar answer, parsed against the command's declared entity. */
|
|
5
|
+
export declare const checkCalendarAnswer: (root: Command, argv: readonly string[], envelope: unknown) => void;
|
|
6
|
+
export declare const CALENDAR_TEST_APP: AppIdentity;
|
|
7
|
+
/** A printed answer: an item's fields beside `meta` and `next`, or the list's `items` and `page`. */
|
|
8
|
+
export type CalendarAnswer = Record<string, unknown> & {
|
|
9
|
+
items: Record<string, unknown>[];
|
|
10
|
+
meta: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export interface CalendarTestProgram {
|
|
13
|
+
root: Command;
|
|
14
|
+
/** Runs the words with `--json` and gives what was printed, its item spread at the top; checked by its entity. */
|
|
15
|
+
cli: (...args: string[]) => Promise<CalendarAnswer>;
|
|
16
|
+
/** Runs the words as a person at a terminal would, and gives the text printed. */
|
|
17
|
+
text: (...args: string[]) => Promise<string>;
|
|
18
|
+
/** Every line on stderr. */
|
|
19
|
+
stderr: string[];
|
|
20
|
+
/** How many times the profile was opened, and how. */
|
|
21
|
+
opened: {
|
|
22
|
+
readOnly: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
2
25
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* goes into the host's envelope, never into the item.
|
|
26
|
+
* The shared calendar commands on a bare program over `run`, as an app mounts them, printing to captured streams. A
|
|
27
|
+
* test of the commands themselves; an app's own tests go through its `run()`.
|
|
6
28
|
*/
|
|
7
|
-
export declare const
|
|
29
|
+
export declare const calendarTestProgram: (run: CalendarRun, options?: Partial<CalendarCommandOptions>) => CalendarTestProgram;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
1
2
|
import * as v from "valibot";
|
|
2
3
|
import { answerEntitySchema } from "../../cli/answer-entity.js";
|
|
3
|
-
import {
|
|
4
|
+
import { provide } from "../../cli/context.js";
|
|
5
|
+
import { addCalendarCommands } from "../cli/index.js";
|
|
4
6
|
const commandAt = (root, argv) => {
|
|
5
7
|
let at = root;
|
|
6
8
|
for (const word of argv) {
|
|
@@ -11,28 +13,97 @@ const commandAt = (root, argv) => {
|
|
|
11
13
|
}
|
|
12
14
|
return at;
|
|
13
15
|
};
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
* snake_case, a list's items one by one, a search's hits each with the search's `untrusted`, and no `next`. A `meta`
|
|
17
|
-
* goes into the host's envelope, never into the item.
|
|
18
|
-
*/
|
|
19
|
-
export const checkCalendarAnswer = (root, argv, value) => {
|
|
16
|
+
/** Each item of a printed calendar answer, parsed against the command's declared entity. */
|
|
17
|
+
export const checkCalendarAnswer = (root, argv, envelope) => {
|
|
20
18
|
const command = commandAt(root, argv);
|
|
21
19
|
const schema = answerEntitySchema(command);
|
|
22
20
|
if (!schema)
|
|
23
21
|
throw new Error(`${argv.join(" ")} declares no answer entity`);
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
?.filter((field) => field.startsWith("hits."))
|
|
27
|
-
.map((field) => field.slice("hits.".length));
|
|
28
|
-
const items = Array.isArray(body.items)
|
|
29
|
-
? body.items
|
|
30
|
-
: Array.isArray(body.hits)
|
|
31
|
-
? body.hits.map((hit) => ({ ...hit, untrusted: marker }))
|
|
32
|
-
: [body];
|
|
33
|
-
for (const item of items) {
|
|
22
|
+
const body = envelope;
|
|
23
|
+
for (const item of body.items ?? [body.item]) {
|
|
34
24
|
const parsed = v.safeParse(schema, item);
|
|
35
25
|
if (!parsed.success)
|
|
36
26
|
throw new Error(`${argv.join(" ")}: ${parsed.issues.map((issue) => `${v.getDotPath(issue) ?? ""} ${issue.message}`).join("; ")}`);
|
|
37
27
|
}
|
|
38
28
|
};
|
|
29
|
+
export const CALENDAR_TEST_APP = {
|
|
30
|
+
command: "gcal",
|
|
31
|
+
appName: "gcal-cli",
|
|
32
|
+
envPrefix: "GCAL",
|
|
33
|
+
description: "synthetic",
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The shared calendar commands on a bare program over `run`, as an app mounts them, printing to captured streams. A
|
|
38
|
+
* test of the commands themselves; an app's own tests go through its `run()`.
|
|
39
|
+
*/
|
|
40
|
+
export const calendarTestProgram = (run, options = {}) => {
|
|
41
|
+
const stderr = [];
|
|
42
|
+
const opened = [];
|
|
43
|
+
let data = "";
|
|
44
|
+
const build = (tty = false) => {
|
|
45
|
+
const root = new Command("gcal")
|
|
46
|
+
.exitOverride()
|
|
47
|
+
.configureOutput({ writeErr: () => undefined, writeOut: () => undefined })
|
|
48
|
+
.option("--json")
|
|
49
|
+
.option("--jsonl")
|
|
50
|
+
.option("--offline")
|
|
51
|
+
.option("--full")
|
|
52
|
+
.option("--timeout <duration>")
|
|
53
|
+
.option("--yes")
|
|
54
|
+
.option("--dry-run");
|
|
55
|
+
addCalendarCommands(root, {
|
|
56
|
+
app: CALENDAR_TEST_APP,
|
|
57
|
+
open: async (_command, access) => {
|
|
58
|
+
opened.push(access);
|
|
59
|
+
return run;
|
|
60
|
+
},
|
|
61
|
+
now: () => Date.now(),
|
|
62
|
+
timezone: "UTC",
|
|
63
|
+
// A help example names a file; no test writes into the working folder.
|
|
64
|
+
readFile: async () => "",
|
|
65
|
+
writeFile: async () => undefined,
|
|
66
|
+
...options,
|
|
67
|
+
});
|
|
68
|
+
provide(root, {
|
|
69
|
+
streams: {
|
|
70
|
+
data: (text) => {
|
|
71
|
+
data += text;
|
|
72
|
+
},
|
|
73
|
+
diagnostic: (text) => {
|
|
74
|
+
stderr.push(text);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
tty,
|
|
78
|
+
});
|
|
79
|
+
return root;
|
|
80
|
+
};
|
|
81
|
+
const root = build();
|
|
82
|
+
const cli = async (...args) => {
|
|
83
|
+
const fresh = build();
|
|
84
|
+
data = "";
|
|
85
|
+
const dashes = args.indexOf("--");
|
|
86
|
+
const argv = args.includes("--json")
|
|
87
|
+
? args
|
|
88
|
+
: dashes < 0
|
|
89
|
+
? [...args, "--json"]
|
|
90
|
+
: [...args.slice(0, dashes), "--json", ...args.slice(dashes)];
|
|
91
|
+
await fresh.parseAsync(argv, { from: "user" });
|
|
92
|
+
if (!data.trim())
|
|
93
|
+
throw new Error(`${args.join(" ")} printed nothing`);
|
|
94
|
+
const envelope = JSON.parse(data);
|
|
95
|
+
// A --dry-run preview answers what would happen, not the command's entity.
|
|
96
|
+
if (!args.includes("--dry-run"))
|
|
97
|
+
checkCalendarAnswer(fresh, args, envelope);
|
|
98
|
+
// The run's own facts differ every run; a test compares the rest.
|
|
99
|
+
const { item, meta, ...rest } = envelope;
|
|
100
|
+
const { run_id: _run, duration_ms: _duration, ...facts } = meta;
|
|
101
|
+
return { ...(item ?? {}), ...rest, meta: facts };
|
|
102
|
+
};
|
|
103
|
+
const text = async (...args) => {
|
|
104
|
+
data = "";
|
|
105
|
+
await build(true).parseAsync(args, { from: "user" });
|
|
106
|
+
return data;
|
|
107
|
+
};
|
|
108
|
+
return { root, cli, text, stderr, opened };
|
|
109
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { calendarConflict } from "../writer.js";
|
|
3
3
|
export const fakeCalendarWriter = (options = {}) => {
|
|
4
|
+
const now = options.now ?? Date.now;
|
|
4
5
|
const calendars = new Map();
|
|
6
|
+
const made = new Map();
|
|
5
7
|
const calls = [];
|
|
6
8
|
let version = 0;
|
|
7
9
|
let lose = false;
|
|
@@ -89,8 +91,12 @@ export const fakeCalendarWriter = (options = {}) => {
|
|
|
89
91
|
participants: [],
|
|
90
92
|
});
|
|
91
93
|
of(calendar.externalId).set(id, entry);
|
|
94
|
+
made.set(id, now());
|
|
92
95
|
return answer(entry);
|
|
93
96
|
},
|
|
97
|
+
async quickAdded(calendar, since) {
|
|
98
|
+
return [...of(calendar.externalId).values()].filter((one) => (made.get(one.externalId) ?? -1) >= since);
|
|
99
|
+
},
|
|
94
100
|
/** Keeps one event per UID on a calendar: a UID sent again replaces the event under the same id. */
|
|
95
101
|
async importEvent(calendar, event) {
|
|
96
102
|
const held = [...of(calendar.externalId).values()].find((one) => one.icalUid === event.uid);
|
|
@@ -67,11 +67,16 @@ export interface CalendarWriter {
|
|
|
67
67
|
}): Promise<EntryInput>;
|
|
68
68
|
/**
|
|
69
69
|
* Optional: the provider makes an event from one line of text, reading its date, time and place its own way. The
|
|
70
|
-
* provider picks the id, so a retry after `outcome_unknown`
|
|
70
|
+
* provider picks the id, so a retry after `outcome_unknown` first asks `quickAdded`.
|
|
71
71
|
*/
|
|
72
72
|
quickAdd?(calendar: StoredCalendar, text: string, options: {
|
|
73
73
|
notify: boolean;
|
|
74
74
|
}): Promise<EntryInput>;
|
|
75
|
+
/**
|
|
76
|
+
* With `quickAdd`: the events this account made on `calendar` at or after `since` (epoch ms), so a retry of a quick
|
|
77
|
+
* add whose answer was lost finds the event instead of making a second one.
|
|
78
|
+
*/
|
|
79
|
+
quickAdded?(calendar: StoredCalendar, since: number): Promise<EntryInput[]>;
|
|
75
80
|
/**
|
|
76
81
|
* Optional: adds a private copy of an event read from an iCalendar file, under its own UID, as Google's
|
|
77
82
|
* `events.import`. The provider mails nobody. Sending the same UID again goes to the provider again; what it does
|
|
@@ -86,10 +86,12 @@ export declare const createEvent: (context: WriteContext, calendarReference: str
|
|
|
86
86
|
}>;
|
|
87
87
|
/**
|
|
88
88
|
* An event the provider makes from one line of text, as Google's quickAdd. Nobody is mailed unless `notify` says so:
|
|
89
|
-
* the attendees are known only once the provider has read the text.
|
|
89
|
+
* the attendees are known only once the provider has read the text. The provider picks the event's id, so a retry
|
|
90
|
+
* with the `id` a lost attempt named first looks for the event that attempt made.
|
|
90
91
|
*/
|
|
91
92
|
export declare const createEventFromText: (context: WriteContext, calendarReference: string, text: string, options?: {
|
|
92
93
|
notify?: boolean;
|
|
94
|
+
id?: string;
|
|
93
95
|
}) => Promise<{
|
|
94
96
|
operation_id: string;
|
|
95
97
|
event: string | null;
|